3413 lines
108 KiB
JavaScript
3413 lines
108 KiB
JavaScript
// modules are defined as an array
|
|
// [ module function, map of requires ]
|
|
//
|
|
// map of requires is short require name -> numeric require
|
|
//
|
|
// anything defined in a previous bundle is accessed via the
|
|
// orig method which is the require for previous bundles
|
|
|
|
// eslint-disable-next-line no-global-assign
|
|
parcelRequire = (function (modules, cache, entry, globalName) {
|
|
// Save the require from previous bundle to this closure if any
|
|
var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
|
|
var nodeRequire = typeof require === 'function' && require;
|
|
|
|
function newRequire(name, jumped) {
|
|
if (!cache[name]) {
|
|
if (!modules[name]) {
|
|
// if we cannot find the module within our internal map or
|
|
// cache jump to the current global require ie. the last bundle
|
|
// that was added to the page.
|
|
var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
|
|
if (!jumped && currentRequire) {
|
|
return currentRequire(name, true);
|
|
}
|
|
|
|
// If there are other bundles on this page the require from the
|
|
// previous one is saved to 'previousRequire'. Repeat this as
|
|
// many times as there are bundles until the module is found or
|
|
// we exhaust the require chain.
|
|
if (previousRequire) {
|
|
return previousRequire(name, true);
|
|
}
|
|
|
|
// Try the node require function if it exists.
|
|
if (nodeRequire && typeof name === 'string') {
|
|
return nodeRequire(name);
|
|
}
|
|
|
|
var err = new Error('Cannot find module \'' + name + '\'');
|
|
err.code = 'MODULE_NOT_FOUND';
|
|
throw err;
|
|
}
|
|
|
|
localRequire.resolve = resolve;
|
|
localRequire.cache = {};
|
|
|
|
var module = cache[name] = new newRequire.Module(name);
|
|
|
|
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
|
|
}
|
|
|
|
return cache[name].exports;
|
|
|
|
function localRequire(x){
|
|
return newRequire(localRequire.resolve(x));
|
|
}
|
|
|
|
function resolve(x){
|
|
return modules[name][1][x] || x;
|
|
}
|
|
}
|
|
|
|
function Module(moduleName) {
|
|
this.id = moduleName;
|
|
this.bundle = newRequire;
|
|
this.exports = {};
|
|
}
|
|
|
|
newRequire.isParcelRequire = true;
|
|
newRequire.Module = Module;
|
|
newRequire.modules = modules;
|
|
newRequire.cache = cache;
|
|
newRequire.parent = previousRequire;
|
|
newRequire.register = function (id, exports) {
|
|
modules[id] = [function (require, module) {
|
|
module.exports = exports;
|
|
}, {}];
|
|
};
|
|
|
|
for (var i = 0; i < entry.length; i++) {
|
|
newRequire(entry[i]);
|
|
}
|
|
|
|
if (entry.length) {
|
|
// Expose entry point to Node, AMD or browser globals
|
|
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
|
var mainExports = newRequire(entry[entry.length - 1]);
|
|
|
|
// CommonJS
|
|
if (typeof exports === "object" && typeof module !== "undefined") {
|
|
module.exports = mainExports;
|
|
|
|
// RequireJS
|
|
} else if (typeof define === "function" && define.amd) {
|
|
define(function () {
|
|
return mainExports;
|
|
});
|
|
|
|
// <script>
|
|
} else if (globalName) {
|
|
this[globalName] = mainExports;
|
|
}
|
|
}
|
|
|
|
// Override the current require with this new one
|
|
return newRequire;
|
|
})({"tools/events/EventEmitter.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var EventEmitter =
|
|
/*#__PURE__*/
|
|
function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function EventEmitter() {
|
|
_classCallCheck(this, EventEmitter);
|
|
|
|
this.listeners = new Map();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(EventEmitter, [{
|
|
key: "addListener",
|
|
value: function addListener(label, callback) {
|
|
this.listeners.has(label) || this.listeners.set(label, []);
|
|
this.listeners.get(label).push(callback);
|
|
}
|
|
}, {
|
|
key: "removeListener",
|
|
value: function removeListener(label, callback) {
|
|
var isFunction = function isFunction(obj) {
|
|
return typeof obj == 'function' || false;
|
|
};
|
|
|
|
var listeners = this.listeners.get(label),
|
|
index;
|
|
|
|
if (listeners && listeners.length) {
|
|
index = listeners.reduce(function (i, listener, index) {
|
|
return isFunction(listener) && listener === callback ? i = index : i;
|
|
}, -1);
|
|
|
|
if (index > -1) {
|
|
listeners.splice(index, 1);
|
|
this.listeners.set(label, listeners);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}, {
|
|
key: "emitEvent",
|
|
value: function emitEvent(label) {
|
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
args[_key - 1] = arguments[_key];
|
|
}
|
|
|
|
var listeners = this.listeners.get(label);
|
|
|
|
if (listeners && listeners.length) {
|
|
listeners.forEach(function (listener) {
|
|
listener.apply(void 0, args);
|
|
});
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return EventEmitter;
|
|
}();
|
|
|
|
var _default = EventEmitter;
|
|
exports.default = _default;
|
|
},{}],"tools/events/DataEvent.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = exports.POST_DELETED = exports.POST_UPDATED = exports.POST_ADDED = exports.POST_ERROR = exports.POST_IMAGE_ADDED = exports.PROJECTS_SORTED = exports.PROJECT_ADDED = exports.PROJECT_UPDATED = exports.ARCHIVES_ENTRY_LOADED = exports.ARCHIVES_PAGE_LOADED = exports.ARCHIVES_JSON_LOADED = exports.HTML_LOADED = exports.SETTINGS_LOADED = exports.IMG_REQUEST_LAME = exports.IMG_REQUEST_GOOD = exports.REQUEST_LAME = exports.REQUEST_GOOD = void 0;
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
var REQUEST_GOOD = 'requestGood';
|
|
exports.REQUEST_GOOD = REQUEST_GOOD;
|
|
var REQUEST_LAME = 'requestLame';
|
|
exports.REQUEST_LAME = REQUEST_LAME;
|
|
var IMG_REQUEST_GOOD = 'imgRequestGood';
|
|
exports.IMG_REQUEST_GOOD = IMG_REQUEST_GOOD;
|
|
var IMG_REQUEST_LAME = 'imgRequestLame';
|
|
exports.IMG_REQUEST_LAME = IMG_REQUEST_LAME;
|
|
var SETTINGS_LOADED = 'dataLoaded';
|
|
exports.SETTINGS_LOADED = SETTINGS_LOADED;
|
|
var HTML_LOADED = 'htmlLoaded';
|
|
exports.HTML_LOADED = HTML_LOADED;
|
|
var ARCHIVES_JSON_LOADED = 'archivesJSONLoaded';
|
|
exports.ARCHIVES_JSON_LOADED = ARCHIVES_JSON_LOADED;
|
|
var ARCHIVES_PAGE_LOADED = 'archivesPAGELoaded';
|
|
exports.ARCHIVES_PAGE_LOADED = ARCHIVES_PAGE_LOADED;
|
|
var ARCHIVES_ENTRY_LOADED = 'archivesEntryLoaded';
|
|
exports.ARCHIVES_ENTRY_LOADED = ARCHIVES_ENTRY_LOADED;
|
|
var PROJECT_UPDATED = 'projectUpdated';
|
|
exports.PROJECT_UPDATED = PROJECT_UPDATED;
|
|
var PROJECT_ADDED = 'projectAdded';
|
|
exports.PROJECT_ADDED = PROJECT_ADDED;
|
|
var PROJECTS_SORTED = 'projectsSorted';
|
|
exports.PROJECTS_SORTED = PROJECTS_SORTED;
|
|
var POST_IMAGE_ADDED = 'postImageAdded';
|
|
exports.POST_IMAGE_ADDED = POST_IMAGE_ADDED;
|
|
var POST_ERROR = 'postError';
|
|
exports.POST_ERROR = POST_ERROR;
|
|
var POST_ADDED = 'postAdded';
|
|
exports.POST_ADDED = POST_ADDED;
|
|
var POST_UPDATED = 'postUpdated';
|
|
exports.POST_UPDATED = POST_UPDATED;
|
|
var POST_DELETED = 'postImageAdded';
|
|
exports.POST_DELETED = POST_DELETED;
|
|
|
|
var DataEvent = function DataEvent() {
|
|
_classCallCheck(this, DataEvent);
|
|
};
|
|
|
|
var _default = new DataEvent();
|
|
|
|
exports.default = _default;
|
|
},{}],"tools/utilities/DataUtils.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = exports.CONTENT_TYPE_FORM = exports.CONTENT_TYPE_JSON = exports.REQUEST_TYPE_DELETE = exports.REQUEST_TYPE_PUT = exports.REQUEST_TYPE_GET = exports.REQUEST_TYPE_POST = void 0;
|
|
|
|
var _EventEmitter2 = _interopRequireDefault(require("../events/EventEmitter.jsx"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../events/DataEvent.jsx"));
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
|
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
|
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
|
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
|
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
|
|
var REQUEST_TYPE_POST = "POST";
|
|
exports.REQUEST_TYPE_POST = REQUEST_TYPE_POST;
|
|
var REQUEST_TYPE_GET = "GET";
|
|
exports.REQUEST_TYPE_GET = REQUEST_TYPE_GET;
|
|
var REQUEST_TYPE_PUT = "PUT";
|
|
exports.REQUEST_TYPE_PUT = REQUEST_TYPE_PUT;
|
|
var REQUEST_TYPE_DELETE = "DELETE";
|
|
exports.REQUEST_TYPE_DELETE = REQUEST_TYPE_DELETE;
|
|
var CONTENT_TYPE_JSON = 'json';
|
|
exports.CONTENT_TYPE_JSON = CONTENT_TYPE_JSON;
|
|
var CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
|
|
exports.CONTENT_TYPE_FORM = CONTENT_TYPE_FORM;
|
|
|
|
var DataUtils =
|
|
/*#__PURE__*/
|
|
function (_EventEmitter) {
|
|
_inherits(DataUtils, _EventEmitter);
|
|
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function DataUtils() {
|
|
var _this;
|
|
|
|
_classCallCheck(this, DataUtils);
|
|
|
|
_this = _possibleConstructorReturn(this, _getPrototypeOf(DataUtils).call(this));
|
|
|
|
var self = _assertThisInitialized(_assertThisInitialized(_this));
|
|
|
|
return _this;
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(DataUtils, [{
|
|
key: "request",
|
|
value: function request(requestURL, eventType) {
|
|
var requestType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : REQUEST_TYPE_GET;
|
|
var contentType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : CONTENT_TYPE_JSON;
|
|
var requestData = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
var self = this;
|
|
return new Promise(function (resolve, reject) {
|
|
var request = new XMLHttpRequest();
|
|
request.upload.onprogress = self.handleLoadProgress;
|
|
request.open(requestType, requestURL, true);
|
|
|
|
request.onload = function (e) {
|
|
if (request.status == 200) {
|
|
resolve({
|
|
request: request,
|
|
eventType: eventType
|
|
});
|
|
} else {
|
|
reject({
|
|
request: request,
|
|
eventType: eventType
|
|
});
|
|
}
|
|
|
|
;
|
|
};
|
|
|
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
|
switch (contentType) {
|
|
case CONTENT_TYPE_JSON:
|
|
request.setRequestHeader("Content-type", "application/" + contentType);
|
|
request.send(JSON.stringify(requestData));
|
|
break;
|
|
|
|
case CONTENT_TYPE_FORM:
|
|
request.send(requestData);
|
|
break;
|
|
}
|
|
} else {
|
|
request.send();
|
|
}
|
|
});
|
|
}
|
|
}, {
|
|
key: "imgLoad",
|
|
value: function imgLoad(url) {
|
|
'use strict'; // Create new promise with the Promise() constructor;
|
|
// This has as its argument a function with two parameters, resolve and reject
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
// Standard XHR to load an image
|
|
var request = new XMLHttpRequest();
|
|
request.open('GET', url);
|
|
request.responseType = 'blob'; // When the request loads, check whether it was successful
|
|
|
|
request.onload = function () {
|
|
if (request.status === 200) {
|
|
// If successful, resolve the promise by passing back the request response
|
|
resolve(request.response);
|
|
} else {
|
|
// If it fails, reject the promise with a error message
|
|
reject(new Error('Image didn\'t load successfully; error code:' + request.statusText));
|
|
}
|
|
};
|
|
|
|
request.onerror = function () {
|
|
// Also deal with the case when the entire request fails to begin with
|
|
// This is probably a network error, so reject the promise with an appropriate message
|
|
reject(new Error('There was a network error.'));
|
|
}; // Send the request
|
|
|
|
|
|
request.send();
|
|
});
|
|
}
|
|
}, {
|
|
key: "loadImage",
|
|
value: function loadImage(src) {
|
|
'use strict';
|
|
|
|
var self = this;
|
|
return new Promise(function (resolve, reject) {
|
|
// Get a reference to the body element, and create a new image object
|
|
var body = document.querySelector('body'),
|
|
myImage = new Image();
|
|
myImage.crossOrigin = ""; // or "anonymous"
|
|
// Call the function with the URL we want to load, but then chain the
|
|
// promise then() method on to the end of it. This contains two callbacks
|
|
|
|
self.imgLoad(src).then(function (response) {
|
|
// The first runs when the promise resolves, with the request.reponse specified within the resolve() method.
|
|
var imageURL = window.URL.createObjectURL(response);
|
|
resolve(imageURL); //$('background-content').setStyle('background-image', 'url('+imageURL+')') //myImage.src = imageURL;
|
|
//console.log(imageURL);
|
|
//body.appendChild(myImage);
|
|
// The second runs when the promise is rejected, and logs the Error specified with the reject() method.
|
|
}, function (Error) {
|
|
reject(Error);
|
|
});
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handleLoadProgress",
|
|
value: function handleLoadProgress(e) {
|
|
var percentComplete = Math.ceil(e.loaded / e.total * 100); //console.log(percentComplete);
|
|
}
|
|
}]);
|
|
|
|
return DataUtils;
|
|
}(_EventEmitter2.default);
|
|
|
|
var _default = DataUtils;
|
|
exports.default = _default;
|
|
},{"../events/EventEmitter.jsx":"tools/events/EventEmitter.jsx","../events/DataEvent.jsx":"tools/events/DataEvent.jsx"}],"tools/effects/Animate.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _EventEmitter2 = _interopRequireDefault(require("../events/EventEmitter.jsx"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
|
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
|
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
|
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
|
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
|
|
;
|
|
|
|
var Animate =
|
|
/*#__PURE__*/
|
|
function (_EventEmitter) {
|
|
_inherits(Animate, _EventEmitter);
|
|
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function Animate() {
|
|
_classCallCheck(this, Animate);
|
|
|
|
return _possibleConstructorReturn(this, _getPrototypeOf(Animate).call(this));
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(Animate, [{
|
|
key: "object",
|
|
value: function object(properties) {
|
|
var animation = anime(properties); //animation.start(properties);
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return Animate;
|
|
}(_EventEmitter2.default);
|
|
|
|
var _default = Animate;
|
|
exports.default = _default;
|
|
},{"../events/EventEmitter.jsx":"tools/events/EventEmitter.jsx"}],"tools/utilities/StringUtils.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var StringUtils =
|
|
/*#__PURE__*/
|
|
function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function StringUtils() {
|
|
_classCallCheck(this, StringUtils);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(StringUtils, [{
|
|
key: "cleanString",
|
|
value: function cleanString(string) {
|
|
var clean = string.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g, '').toLowerCase().replace(/[\/_| -]+/g, '-');
|
|
return clean;
|
|
}
|
|
}, {
|
|
key: "decodeHTML",
|
|
value: function decodeHTML(string, quote_style) {
|
|
var optTemp = 0,
|
|
i = 0,
|
|
noquotes = false;
|
|
|
|
if (typeof quote_style === 'undefined') {
|
|
quote_style = 2;
|
|
}
|
|
|
|
string = string.toString().replace(/</g, '<').replace(/>/g, '>');
|
|
var OPTS = {
|
|
'ENT_NOQUOTES': 0,
|
|
'ENT_HTML_QUOTE_SINGLE': 1,
|
|
'ENT_HTML_QUOTE_DOUBLE': 2,
|
|
'ENT_COMPAT': 2,
|
|
'ENT_QUOTES': 3,
|
|
'ENT_IGNORE': 4
|
|
};
|
|
|
|
if (quote_style === 0) {
|
|
noquotes = true;
|
|
}
|
|
|
|
if (typeof quote_style !== 'number') {
|
|
// Allow for a single string or an array of string flags
|
|
quote_style = [].concat(quote_style);
|
|
|
|
for (i = 0; i < quote_style.length; i++) {
|
|
// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
|
|
if (OPTS[quote_style[i]] === 0) {
|
|
noquotes = true;
|
|
} else if (OPTS[quote_style[i]]) {
|
|
optTemp = optTemp | OPTS[quote_style[i]];
|
|
}
|
|
}
|
|
|
|
quote_style = optTemp;
|
|
}
|
|
|
|
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
|
|
string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
|
|
// string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
|
|
}
|
|
|
|
if (!noquotes) {
|
|
string = string.replace(/"/g, '"');
|
|
} // Put this in last place to avoid escape being double-decoded
|
|
|
|
|
|
string = string.replace(/&/g, '&');
|
|
return string;
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return StringUtils;
|
|
}();
|
|
|
|
var _default = StringUtils;
|
|
exports.default = _default;
|
|
},{}],"actions/PostActions.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _DataUtils = _interopRequireWildcard(require("../tools/utilities/DataUtils"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../tools/events/DataEvent"));
|
|
|
|
var _StringUtils = _interopRequireDefault(require("../tools/utilities/StringUtils"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var PostActions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function PostActions() {
|
|
_classCallCheck(this, PostActions);
|
|
|
|
var folio = [];
|
|
this.dataUtils = new _DataUtils.default();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(PostActions, [{
|
|
key: "start",
|
|
value: function start() {}
|
|
}, {
|
|
key: "submitPost",
|
|
value: function submitPost(edit, uploadFiles) {
|
|
var self = this;
|
|
return new Promise(function (resolve, reject) {
|
|
//collect form data
|
|
//if(!this.validateForm())
|
|
var postData = new FormData(); //let projectImages = document.getElementById('projectImages');
|
|
//var fileSelect = projectImages;
|
|
|
|
var files = uploadFiles;
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i]; // Check the file type.
|
|
|
|
if (!file.type.match('image.*')) {
|
|
continue;
|
|
} // Add the file to the request.
|
|
|
|
|
|
postData.append('feature_image', file, file.name);
|
|
} //var category = document.getElementById("content_category");
|
|
//let project_form = document.forms.namedItem("folio-project");
|
|
|
|
|
|
var txt = document.createElement("textarea");
|
|
txt.innerHTML = document.getElementById('edit-post-text').innerHTML;
|
|
postData.append("title", document.getElementById('post_title').value);
|
|
postData.append('slug', new _StringUtils.default().cleanString(document.getElementById('post_title').value));
|
|
postData.append("post_plaintext", txt.value);
|
|
postData.append("origin_date", document.getElementById('post-date').value);
|
|
postData.append("tags", document.getElementById('post_tags').value);
|
|
postData.append("status_page", document.getElementById('option-page').getAttribute('data-active'));
|
|
postData.append("status_feature", document.getElementById('option-feature').getAttribute('data-active'));
|
|
postData.append("status_published", document.getElementById('option-published').getAttribute('data-active'));
|
|
var postURL;
|
|
var postEventType;
|
|
|
|
if (edit) {
|
|
var postID = document.getElementById('edit-update').getAttribute('data-id');
|
|
postURL = "/api/post/update/" + postID;
|
|
postEventType = DataEvent.POST_UPDATED;
|
|
} else {
|
|
postURL = "/api/post/add";
|
|
postEventType = DataEvent.POST_ADDED;
|
|
}
|
|
|
|
self.dataUtils.request(postURL, postEventType, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM, postData).then(function (response) {
|
|
resolve({
|
|
response: response
|
|
});
|
|
}).catch(function (err) {
|
|
reject({
|
|
err: err
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "deletePost",
|
|
value: function deletePost() {
|
|
var self = this;
|
|
var postID = document.getElementById('edit-update').getAttribute('data-id');
|
|
return new Promise(function (resolve, reject) {
|
|
self.dataUtils.request("/api/post/delete/" + postID, DataEvent.POST_DELETED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM).then(function (response) {
|
|
resolve({
|
|
response: response
|
|
});
|
|
}).catch(function (err) {
|
|
reject({
|
|
err: err
|
|
});
|
|
});
|
|
}); //this.dataUtils.re
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return PostActions;
|
|
}();
|
|
|
|
exports.default = PostActions;
|
|
},{"../tools/utilities/DataUtils":"tools/utilities/DataUtils.jsx","../tools/events/DataEvent":"tools/events/DataEvent.jsx","../tools/utilities/StringUtils":"tools/utilities/StringUtils.jsx"}],"tools/events/EditorEvent.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = exports.EDITOR_UPDATE = exports.EDITOR_SAVE = exports.EDITOR_UPLOAD_POST_IMAGE = exports.EDITOR_DELETE = void 0;
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
var EDITOR_DELETE = 'editorDelete';
|
|
exports.EDITOR_DELETE = EDITOR_DELETE;
|
|
var EDITOR_UPLOAD_POST_IMAGE = 'editorUploadImage';
|
|
exports.EDITOR_UPLOAD_POST_IMAGE = EDITOR_UPLOAD_POST_IMAGE;
|
|
var EDITOR_SAVE = 'editorSave';
|
|
exports.EDITOR_SAVE = EDITOR_SAVE;
|
|
var EDITOR_UPDATE = 'editorUpdate';
|
|
exports.EDITOR_UPDATE = EDITOR_UPDATE;
|
|
|
|
var EditorEvent = function EditorEvent() {
|
|
_classCallCheck(this, EditorEvent);
|
|
};
|
|
|
|
var _default = new EditorEvent();
|
|
|
|
exports.default = _default;
|
|
},{}],"tools/utilities/DateUtils.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var DateUtils =
|
|
/*#__PURE__*/
|
|
function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function DateUtils() {
|
|
_classCallCheck(this, DateUtils);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(DateUtils, [{
|
|
key: "getMKtime",
|
|
value: function getMKtime() {
|
|
var time = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), new Date().getHours(), new Date().getMinutes(), new Date().getSeconds(), 0).getTime() / 1000;
|
|
return time;
|
|
}
|
|
}, {
|
|
key: "convertMKtime",
|
|
value: function convertMKtime(seconds) {
|
|
var date = new Date(seconds * 1000);
|
|
return date;
|
|
}
|
|
}, {
|
|
key: "getDate",
|
|
value: function getDate(type, rawdate) {
|
|
var day = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCDate()) : String(new Date().getUTCDate());
|
|
var month = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMonth() + 1) : String(new Date().getUTCMonth() + 1);
|
|
var year = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCFullYear()) : String(new Date().getUTCFullYear());
|
|
var hour = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCHours()) : String(new Date().getUTCHours());
|
|
var minute = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMinutes()) : String(new Date().getUTCMinutes());
|
|
var seconds = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCSeconds()) : String(new Date().getUTCSeconds());
|
|
var millisecond = rawdate != null || rawdate != '' ? String(new Date(rawdate).getUTCMilliseconds()) : String(new Date().getUTCMilliseconds());
|
|
var offset = rawdate != null || rawdate != '' ? String(new Date(rawdate).getTimezoneOffset()) : String(new Date().getTimezoneOffset());
|
|
if (day.length == 1) day = String("0" + day);
|
|
if (month.length == 1) month = String("0" + month);
|
|
offset = String(offset / 60);
|
|
if (offset.length == 1) offset = String("0" + offset);
|
|
|
|
switch (type) {
|
|
case "day":
|
|
return day;
|
|
break;
|
|
|
|
case "month":
|
|
return month;
|
|
break;
|
|
|
|
case "year":
|
|
return year;
|
|
break;
|
|
|
|
case "stamp":
|
|
return String(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds + "." + millisecond + "-" + offset);
|
|
break;
|
|
|
|
default:
|
|
return String(year + "-" + month + "-" + day);
|
|
break;
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return DateUtils;
|
|
}();
|
|
|
|
var _default = DateUtils;
|
|
exports.default = _default;
|
|
},{}],"../../../../node_modules/caret-pos/lib/esm2015/main.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.getOffset = exports.offset = exports.position = void 0;
|
|
var attributes = ['borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopStyle', 'borderRightStyle', 'borderBottomStyle', 'borderLeftStyle', 'borderTopWidth', 'boxSizing', 'fontFamily', 'fontSize', 'fontWeight', 'height', 'letterSpacing', 'lineHeight', 'marginBottom', 'marginLeft', 'marginRight', 'marginTop', 'outlineWidth', 'overflow', 'overflowX', 'overflowY', 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop', 'textAlign', 'textOverflow', 'textTransform', 'whiteSpace', 'wordBreak', 'wordWrap'];
|
|
/**
|
|
* Create a mirror
|
|
*
|
|
* @param {Element} element The element
|
|
* @param {string} html The html
|
|
*
|
|
* @return {object} The mirror object
|
|
*/
|
|
|
|
var createMirror = function createMirror(element, html) {
|
|
/**
|
|
* The mirror element
|
|
*/
|
|
var mirror = document.createElement('div');
|
|
/**
|
|
* Create the CSS for the mirror object
|
|
*
|
|
* @return {object} The style object
|
|
*/
|
|
|
|
var mirrorCss = function mirrorCss() {
|
|
var css = {
|
|
position: 'absolute',
|
|
left: -9999,
|
|
top: 0,
|
|
zIndex: -2000
|
|
};
|
|
|
|
if (element.tagName === 'TEXTAREA') {
|
|
attributes.push('width');
|
|
}
|
|
|
|
attributes.forEach(function (attr) {
|
|
css[attr] = getComputedStyle(element)[attr];
|
|
});
|
|
return css;
|
|
};
|
|
/**
|
|
* Initialize the mirror
|
|
*
|
|
* @param {string} html The html
|
|
*
|
|
* @return {void}
|
|
*/
|
|
|
|
|
|
var initialize = function initialize(html) {
|
|
var styles = mirrorCss();
|
|
Object.keys(styles).forEach(function (key) {
|
|
mirror.style[key] = styles[key];
|
|
});
|
|
mirror.innerHTML = html;
|
|
element.parentNode.insertBefore(mirror, element.nextSibling);
|
|
};
|
|
/**
|
|
* Get the rect
|
|
*
|
|
* @return {Rect} The bounding rect
|
|
*/
|
|
|
|
|
|
var rect = function rect() {
|
|
var marker = mirror.ownerDocument.getElementById('caret-position-marker');
|
|
var boundingRect = {
|
|
left: marker.offsetLeft,
|
|
top: marker.offsetTop,
|
|
height: marker.offsetHeight
|
|
};
|
|
mirror.parentNode.removeChild(mirror);
|
|
return boundingRect;
|
|
};
|
|
|
|
initialize(html);
|
|
return {
|
|
rect: rect
|
|
};
|
|
};
|
|
|
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
return typeof obj;
|
|
} : function (obj) {
|
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
};
|
|
/**
|
|
* Check if a DOM Element is content editable
|
|
*
|
|
* @param {Element} element The DOM element
|
|
*
|
|
* @return {bool} If it is content editable
|
|
*/
|
|
|
|
|
|
var isContentEditable = function isContentEditable(element) {
|
|
return !!(element.contentEditable && element.contentEditable === 'true');
|
|
};
|
|
/**
|
|
* Get the context from settings passed in
|
|
*
|
|
* @param {object} settings The settings object
|
|
*
|
|
* @return {object} window and document
|
|
*/
|
|
|
|
|
|
var getContext = function getContext() {
|
|
var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
var customPos = settings.customPos,
|
|
iframe = settings.iframe,
|
|
noShadowCaret = settings.noShadowCaret;
|
|
|
|
if (iframe) {
|
|
return {
|
|
iframe: iframe,
|
|
window: iframe.contentWindow,
|
|
document: iframe.contentDocument || iframe.contentWindow.document,
|
|
noShadowCaret: noShadowCaret,
|
|
customPos: customPos
|
|
};
|
|
}
|
|
|
|
return {
|
|
window: window,
|
|
document: document,
|
|
noShadowCaret: noShadowCaret,
|
|
customPos: customPos
|
|
};
|
|
};
|
|
/**
|
|
* Get the offset of an element
|
|
*
|
|
* @param {Element} element The DOM element
|
|
* @param {object} ctx The context
|
|
*
|
|
* @return {object} top and left
|
|
*/
|
|
|
|
|
|
var getOffset = function getOffset(element, ctx) {
|
|
var win = ctx && ctx.window || window;
|
|
var doc = ctx && ctx.document || document;
|
|
var rect = element.getBoundingClientRect();
|
|
var docEl = doc.documentElement;
|
|
var scrollLeft = win.pageXOffset || docEl.scrollLeft;
|
|
var scrollTop = win.pageYOffset || docEl.scrollTop;
|
|
return {
|
|
top: rect.top + scrollTop,
|
|
left: rect.left + scrollLeft
|
|
};
|
|
};
|
|
/**
|
|
* Check if a value is an object
|
|
*
|
|
* @param {any} value The value to check
|
|
*
|
|
* @return {bool} If it is an object
|
|
*/
|
|
|
|
|
|
exports.getOffset = getOffset;
|
|
|
|
var isObject = function isObject(value) {
|
|
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null;
|
|
};
|
|
/**
|
|
* Create a Input caret object.
|
|
*
|
|
* @param {Element} element The element
|
|
* @param {Object} ctx The context
|
|
*/
|
|
|
|
|
|
var createInputCaret = function createInputCaret(element, ctx) {
|
|
/**
|
|
* Get the current position
|
|
*
|
|
* @returns {int} The caret position
|
|
*/
|
|
var getPos = function getPos() {
|
|
return element.selectionStart;
|
|
};
|
|
/**
|
|
* Set the position
|
|
*
|
|
* @param {int} pos The position
|
|
*
|
|
* @return {Element} The element
|
|
*/
|
|
|
|
|
|
var setPos = function setPos(pos) {
|
|
element.setSelectionRange(pos, pos);
|
|
return element;
|
|
};
|
|
/**
|
|
* The offset
|
|
*
|
|
* @param {int} pos The position
|
|
*
|
|
* @return {object} The offset
|
|
*/
|
|
|
|
|
|
var getOffset$$1 = function getOffset$$1(pos) {
|
|
var rect = getOffset(element);
|
|
var position = getPosition(pos);
|
|
return {
|
|
top: rect.top + position.top + ctx.document.body.scrollTop,
|
|
left: rect.left + position.left + ctx.document.body.scrollLeft,
|
|
height: position.height
|
|
};
|
|
};
|
|
/**
|
|
* Get the current position
|
|
*
|
|
* @param {int} pos The position
|
|
*
|
|
* @return {object} The position
|
|
*/
|
|
|
|
|
|
var getPosition = function getPosition(pos) {
|
|
var format = function format(val) {
|
|
var value = val.replace(/<|>|`|"|&/g, '?').replace(/\r\n|\r|\n/g, '<br/>');
|
|
return value;
|
|
};
|
|
|
|
if (ctx.customPos || ctx.customPos === 0) {
|
|
pos = ctx.customPos;
|
|
}
|
|
|
|
var position = pos === undefined ? getPos() : pos;
|
|
var startRange = element.value.slice(0, position);
|
|
var endRange = element.value.slice(position);
|
|
var html = '<span style="position: relative; display: inline;">' + format(startRange) + '</span>';
|
|
html += '<span id="caret-position-marker" style="position: relative; display: inline;">|</span>';
|
|
html += '<span style="position: relative; display: inline;">' + format(endRange) + '</span>';
|
|
var mirror = createMirror(element, html);
|
|
var rect = mirror.rect();
|
|
rect.pos = getPos();
|
|
return rect;
|
|
};
|
|
|
|
return {
|
|
getPos: getPos,
|
|
setPos: setPos,
|
|
getOffset: getOffset$$1,
|
|
getPosition: getPosition
|
|
};
|
|
};
|
|
/**
|
|
* Create an Editable Caret
|
|
* @param {Element} element The editable element
|
|
* @param {object|null} ctx The context
|
|
*
|
|
* @return {EditableCaret}
|
|
*/
|
|
|
|
|
|
var createEditableCaret = function createEditableCaret(element, ctx) {
|
|
/**
|
|
* Set the caret position
|
|
*
|
|
* @param {int} pos The position to se
|
|
*
|
|
* @return {Element} The element
|
|
*/
|
|
var setPos = function setPos(pos) {
|
|
var sel = ctx.window.getSelection();
|
|
|
|
if (sel) {
|
|
var offset = 0;
|
|
var found = false;
|
|
|
|
var find = function find(position, parent) {
|
|
for (var i = 0; i < parent.childNodes.length; i++) {
|
|
var node = parent.childNodes[i];
|
|
|
|
if (found) {
|
|
break;
|
|
}
|
|
|
|
if (node.nodeType === 3) {
|
|
if (offset + node.length >= position) {
|
|
found = true;
|
|
var range = ctx.document.createRange();
|
|
range.setStart(node, position - offset);
|
|
sel.removeAllRanges();
|
|
sel.addRange(range);
|
|
break;
|
|
} else {
|
|
offset += node.length;
|
|
}
|
|
} else {
|
|
find(pos, node);
|
|
}
|
|
}
|
|
};
|
|
|
|
find(pos, element);
|
|
}
|
|
|
|
return element;
|
|
};
|
|
/**
|
|
* Get the offset
|
|
*
|
|
* @return {object} The offset
|
|
*/
|
|
|
|
|
|
var getOffset = function getOffset() {
|
|
var range = getRange();
|
|
var offset = {
|
|
height: 0,
|
|
left: 0,
|
|
right: 0
|
|
};
|
|
|
|
if (!range) {
|
|
return offset;
|
|
}
|
|
|
|
var hasCustomPos = ctx.customPos || ctx.customPos === 0; // endContainer in Firefox would be the element at the start of
|
|
// the line
|
|
|
|
if (range.endOffset - 1 > 0 && range.endContainer !== element || hasCustomPos) {
|
|
var clonedRange = range.cloneRange();
|
|
var fixedPosition = hasCustomPos ? ctx.customPos : range.endOffset;
|
|
clonedRange.setStart(range.endContainer, fixedPosition - 1 < 0 ? 0 : fixedPosition - 1);
|
|
clonedRange.setEnd(range.endContainer, fixedPosition);
|
|
var rect = clonedRange.getBoundingClientRect();
|
|
offset = {
|
|
height: rect.height,
|
|
left: rect.left + rect.width,
|
|
top: rect.top
|
|
};
|
|
clonedRange.detach();
|
|
}
|
|
|
|
if ((!offset || offset && offset.height === 0) && !ctx.noShadowCaret) {
|
|
var _clonedRange = range.cloneRange();
|
|
|
|
var shadowCaret = ctx.document.createTextNode('|');
|
|
|
|
_clonedRange.insertNode(shadowCaret);
|
|
|
|
_clonedRange.selectNode(shadowCaret);
|
|
|
|
var _rect = _clonedRange.getBoundingClientRect();
|
|
|
|
offset = {
|
|
height: _rect.height,
|
|
left: _rect.left,
|
|
top: _rect.top
|
|
};
|
|
shadowCaret.parentNode.removeChild(shadowCaret);
|
|
|
|
_clonedRange.detach();
|
|
}
|
|
|
|
if (offset) {
|
|
var doc = ctx.document.documentElement;
|
|
offset.top += ctx.window.pageYOffset - (doc.clientTop || 0);
|
|
offset.left += ctx.window.pageXOffset - (doc.clientLeft || 0);
|
|
}
|
|
|
|
return offset;
|
|
};
|
|
/**
|
|
* Get the position
|
|
*
|
|
* @return {object} The position
|
|
*/
|
|
|
|
|
|
var getPosition = function getPosition() {
|
|
var offset = getOffset();
|
|
var pos = getPos();
|
|
var rect = element.getBoundingClientRect();
|
|
var inputOffset = {
|
|
top: rect.top + ctx.document.body.scrollTop,
|
|
left: rect.left + ctx.document.body.scrollLeft
|
|
};
|
|
offset.left -= inputOffset.left;
|
|
offset.top -= inputOffset.top;
|
|
offset.pos = pos;
|
|
return offset;
|
|
};
|
|
/**
|
|
* Get the range
|
|
*
|
|
* @return {Range|null}
|
|
*/
|
|
|
|
|
|
var getRange = function getRange() {
|
|
if (!ctx.window.getSelection) {
|
|
return;
|
|
}
|
|
|
|
var sel = ctx.window.getSelection();
|
|
return sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
|
|
};
|
|
/**
|
|
* Get the caret position
|
|
*
|
|
* @return {int} The position
|
|
*/
|
|
|
|
|
|
var getPos = function getPos() {
|
|
var range = getRange();
|
|
var clonedRange = range.cloneRange();
|
|
clonedRange.selectNodeContents(element);
|
|
clonedRange.setEnd(range.endContainer, range.endOffset);
|
|
var pos = clonedRange.toString().length;
|
|
clonedRange.detach();
|
|
return pos;
|
|
};
|
|
|
|
return {
|
|
getPos: getPos,
|
|
setPos: setPos,
|
|
getPosition: getPosition,
|
|
getOffset: getOffset,
|
|
getRange: getRange
|
|
};
|
|
};
|
|
|
|
var createCaret = function createCaret(element, ctx) {
|
|
if (isContentEditable(element)) {
|
|
return createEditableCaret(element, ctx);
|
|
}
|
|
|
|
return createInputCaret(element, ctx);
|
|
};
|
|
|
|
var position = function position(element, value) {
|
|
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
var options = settings;
|
|
|
|
if (isObject(value)) {
|
|
options = value;
|
|
value = null;
|
|
}
|
|
|
|
var ctx = getContext(options);
|
|
var caret = createCaret(element, ctx);
|
|
|
|
if (value || value === 0) {
|
|
return caret.setPos(value);
|
|
}
|
|
|
|
return caret.getPosition();
|
|
};
|
|
/**
|
|
*
|
|
* @param {Element} element The DOM element
|
|
* @param {number|undefined} value The value to set
|
|
* @param {object} settings Any settings for context
|
|
*/
|
|
|
|
|
|
exports.position = position;
|
|
|
|
var offset = function offset(element, value) {
|
|
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
var options = settings;
|
|
|
|
if (isObject(value)) {
|
|
options = value;
|
|
value = null;
|
|
}
|
|
|
|
var ctx = getContext(options);
|
|
var caret = createCaret(element, ctx);
|
|
return caret.getOffset(value);
|
|
};
|
|
|
|
exports.offset = offset;
|
|
},{}],"tools/utilities/TextEditor.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../events/DataEvent"));
|
|
|
|
var _DateUtils = _interopRequireDefault(require("./DateUtils"));
|
|
|
|
var _caretPos = require("caret-pos");
|
|
|
|
var _EventEmitter2 = _interopRequireDefault(require("../events/EventEmitter"));
|
|
|
|
var EditorEvent = _interopRequireWildcard(require("../events/EditorEvent"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
|
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
|
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
|
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
|
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
|
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
|
|
var TextEditor =
|
|
/*#__PURE__*/
|
|
function (_EventEmitter) {
|
|
_inherits(TextEditor, _EventEmitter);
|
|
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function TextEditor(textEditor, scrollLimit) {
|
|
var _this;
|
|
|
|
_classCallCheck(this, TextEditor);
|
|
|
|
_this = _possibleConstructorReturn(this, _getPrototypeOf(TextEditor).call(this));
|
|
hljs.initHighlightingOnLoad(); //this.dataUtils = new DataUtils();
|
|
|
|
_this.dateUtils = new _DateUtils.default();
|
|
_this.textEditor = textEditor;
|
|
_this.fixLimit = scrollLimit;
|
|
_this.caretPos = null;
|
|
_this.url = '';
|
|
|
|
var self = _assertThisInitialized(_assertThisInitialized(_this));
|
|
|
|
_this.setInputs();
|
|
|
|
window.addEventListener("scroll", function (f) {
|
|
var fixLimit = _this.fixLimit;
|
|
|
|
if (window.pageYOffset >= fixLimit) {
|
|
document.getElementById('edit-control').style.position = "fixed";
|
|
} else {
|
|
document.getElementById('edit-control').style.position = "relative";
|
|
}
|
|
});
|
|
|
|
_this.refresh();
|
|
|
|
return _this;
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(TextEditor, [{
|
|
key: "setInputs",
|
|
value: function setInputs() {
|
|
var _this2 = this;
|
|
|
|
var self = this;
|
|
var editorButtons = document.querySelectorAll('.editor-button');
|
|
|
|
for (var i = 0, length = editorButtons.length; i < length; i++) {
|
|
editorButtons[i].addEventListener('click', function (e) {
|
|
return _this2.handleEditorOption(e);
|
|
}, false);
|
|
}
|
|
|
|
this.textEditor.addEventListener('input', function (f) {
|
|
if (f.inputType == "insertParagraph") {
|
|
var caret = (0, _caretPos.position)(self.textEditor).pos + 1;
|
|
var spiffed = hljs.highlight('markdown', self.textEditor.innerText).value;
|
|
var temp = document.createElement("div");
|
|
temp.innerText = spiffed;
|
|
self.textEditor.innerHTML = temp.innerText;
|
|
(0, _caretPos.position)(self.textEditor, caret);
|
|
} else {
|
|
self.refresh();
|
|
}
|
|
});
|
|
}
|
|
}, {
|
|
key: "refresh",
|
|
value: function refresh() {
|
|
var caret = (0, _caretPos.position)(this.textEditor).pos;
|
|
var spiffed = hljs.highlight('markdown', this.textEditor.innerText).value;
|
|
var temp = document.createElement("div");
|
|
temp.innerText = spiffed;
|
|
this.textEditor.innerHTML = temp.innerText;
|
|
(0, _caretPos.position)(this.textEditor, caret);
|
|
}
|
|
}, {
|
|
key: "notify",
|
|
value: function notify(type, data) {
|
|
switch (type) {
|
|
case DataEvent.POST_UPDATED:
|
|
document.getElementById('submit-update').classList.add('icon-hide');
|
|
document.getElementById('submit-good').classList.remove('icon-hide');
|
|
document.getElementById('edit-update').classList.remove('submit-start');
|
|
document.getElementById('edit-update').classList.add('submit-cool');
|
|
setTimeout(function (f) {
|
|
document.getElementById('submit-update').classList.remove('icon-hide');
|
|
document.getElementById('submit-good').classList.add('icon-hide');
|
|
document.getElementById('edit-update').classList.add('submit-start');
|
|
document.getElementById('edit-update').classList.remove('submit-cool');
|
|
}, 2000);
|
|
break;
|
|
|
|
case DataEvent.POST_ADDED:
|
|
// do nothing
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
(0, _caretPos.position)(this.textEditor, this.caretPos);
|
|
var sel, range, pulled;
|
|
sel = window.getSelection(); //console.log(sel)
|
|
//console.log(note.message)
|
|
|
|
if (sel.rangeCount) {
|
|
range = sel.getRangeAt(0);
|
|
pulled = sel.getRangeAt(0).toString();
|
|
range.deleteContents();
|
|
range.insertNode(document.createTextNode("![image alt text](" + data + " 'image title')"));
|
|
}
|
|
|
|
this.refresh();
|
|
break;
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handleEditorOption",
|
|
value: function handleEditorOption(e) {
|
|
e.preventDefault();
|
|
var self = this;
|
|
var sel, range, pulled;
|
|
sel = window.getSelection(); //console.log(sel)
|
|
|
|
if (sel.rangeCount) {
|
|
range = sel.getRangeAt(0);
|
|
pulled = sel.getRangeAt(0).toString();
|
|
range.deleteContents();
|
|
|
|
switch (e.target.id) {
|
|
case "edit-bold":
|
|
range.insertNode(document.createTextNode("**" + pulled + "**"));
|
|
break;
|
|
|
|
case "edit-italic":
|
|
range.insertNode(document.createTextNode("*" + pulled + "*"));
|
|
break;
|
|
|
|
case "edit-strikethrough":
|
|
range.insertNode(document.createTextNode("<del>" + pulled + "</del>"));
|
|
break;
|
|
|
|
case "edit-header1":
|
|
range.insertNode(document.createTextNode("# " + pulled));
|
|
break;
|
|
|
|
case "edit-header2":
|
|
range.insertNode(document.createTextNode("## " + pulled));
|
|
break;
|
|
|
|
case "edit-header3":
|
|
range.insertNode(document.createTextNode("### " + pulled));
|
|
break;
|
|
|
|
case "edit-image":
|
|
this.caretPos = (0, _caretPos.position)(this.textEditor).pos;
|
|
this.emitEvent(EditorEvent.EDITOR_UPLOAD_POST_IMAGE);
|
|
break;
|
|
|
|
case "submit-save":
|
|
case "edit-save":
|
|
this.emitEvent(EditorEvent.EDITOR_SAVE);
|
|
break;
|
|
|
|
case "submit-update":
|
|
case "edit-update":
|
|
this.emitEvent(EditorEvent.EDITOR_UPDATE);
|
|
break;
|
|
|
|
case "edit-link":
|
|
range.insertNode(document.createTextNode("[" + pulled + "](PASTE URL HERE)"));
|
|
break;
|
|
|
|
case "edit-delete":
|
|
this.emitEvent(EditorEvent.EDITOR_DELETE);
|
|
break;
|
|
|
|
default:
|
|
//range.insertNode(document.createTextNode("[" + self.url + "](PASTE URL HERE)"));
|
|
break;
|
|
}
|
|
}
|
|
|
|
this.refresh();
|
|
}
|
|
}]);
|
|
|
|
return TextEditor;
|
|
}(_EventEmitter2.default);
|
|
|
|
var _default = TextEditor;
|
|
exports.default = _default;
|
|
},{"../events/DataEvent":"tools/events/DataEvent.jsx","./DateUtils":"tools/utilities/DateUtils.jsx","caret-pos":"../../../../node_modules/caret-pos/lib/esm2015/main.js","../events/EventEmitter":"tools/events/EventEmitter.jsx","../events/EditorEvent":"tools/events/EditorEvent.jsx"}],"../../../../node_modules/tiny-date-picker/dist/tiny-date-picker.js":[function(require,module,exports) {
|
|
var define;
|
|
var global = arguments[3];
|
|
(function (global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
(global.TinyDatePicker = factory());
|
|
}(this, (function () { 'use strict';
|
|
|
|
/**
|
|
* @file A generic set of mutation-free date functions.
|
|
*/
|
|
|
|
/**
|
|
* now returns the current date without any time values
|
|
*
|
|
* @returns {Date}
|
|
*/
|
|
function now() {
|
|
var dt = new Date();
|
|
dt.setHours(0, 0, 0, 0);
|
|
return dt;
|
|
}
|
|
|
|
/**
|
|
* dateEq compares two dates
|
|
*
|
|
* @param {Date} date1 the first date
|
|
* @param {Date} date2 the second date
|
|
* @returns {boolean}
|
|
*/
|
|
function datesEq(date1, date2) {
|
|
return (date1 && date1.toDateString()) === (date2 && date2.toDateString());
|
|
}
|
|
|
|
/**
|
|
* shiftDay shifts the specified date by n days
|
|
*
|
|
* @param {Date} dt
|
|
* @param {number} n
|
|
* @returns {Date}
|
|
*/
|
|
function shiftDay(dt, n) {
|
|
dt = new Date(dt);
|
|
dt.setDate(dt.getDate() + n);
|
|
return dt;
|
|
}
|
|
|
|
/**
|
|
* shiftMonth shifts the specified date by a specified number of months
|
|
*
|
|
* @param {Date} dt
|
|
* @param {number} n
|
|
* @param {boolean} wrap optional, if true, does not change year
|
|
* value, defaults to false
|
|
* @returns {Date}
|
|
*/
|
|
function shiftMonth(dt, n, wrap) {
|
|
dt = new Date(dt);
|
|
|
|
var dayOfMonth = dt.getDate();
|
|
var month = dt.getMonth() + n;
|
|
|
|
dt.setDate(1);
|
|
dt.setMonth(wrap ? (12 + month) % 12 : month);
|
|
dt.setDate(dayOfMonth);
|
|
|
|
// If dayOfMonth = 31, but the target month only has 30 or 29 or whatever...
|
|
// head back to the max of the target month
|
|
if (dt.getDate() < dayOfMonth) {
|
|
dt.setDate(0);
|
|
}
|
|
|
|
return dt;
|
|
}
|
|
|
|
/**
|
|
* shiftYear shifts the specified date by n years
|
|
*
|
|
* @param {Date} dt
|
|
* @param {number} n
|
|
* @returns {Date}
|
|
*/
|
|
function shiftYear(dt, n) {
|
|
dt = new Date(dt);
|
|
dt.setFullYear(dt.getFullYear() + n);
|
|
return dt;
|
|
}
|
|
|
|
/**
|
|
* setYear changes the specified date to the specified year
|
|
*
|
|
* @param {Date} dt
|
|
* @param {number} year
|
|
*/
|
|
function setYear(dt, year) {
|
|
dt = new Date(dt);
|
|
dt.setFullYear(year);
|
|
return dt;
|
|
}
|
|
|
|
/**
|
|
* setMonth changes the specified date to the specified month
|
|
*
|
|
* @param {Date} dt
|
|
* @param {number} month
|
|
*/
|
|
function setMonth(dt, month) {
|
|
return shiftMonth(dt, month - dt.getMonth());
|
|
}
|
|
|
|
/**
|
|
* dateOrParse creates a function which, given a date or string, returns a date
|
|
*
|
|
* @param {function} parse the function used to parse strings
|
|
* @returns {function}
|
|
*/
|
|
function dateOrParse(parse) {
|
|
return function (dt) {
|
|
return dropTime(typeof dt === 'string' ? parse(dt) : dt);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* constrainDate returns dt or min/max depending on whether dt is out of bounds (inclusive)
|
|
*
|
|
* @export
|
|
* @param {Date} dt
|
|
* @param {Date} min
|
|
* @param {Date} max
|
|
* @returns {Date}
|
|
*/
|
|
function constrainDate(dt, min, max) {
|
|
return (dt < min) ? min :
|
|
(dt > max) ? max :
|
|
dt;
|
|
}
|
|
|
|
function dropTime(dt) {
|
|
dt = new Date(dt);
|
|
dt.setHours(0, 0, 0, 0);
|
|
return dt;
|
|
}
|
|
|
|
/**
|
|
* @file Utility functions for function manipulation.
|
|
*/
|
|
|
|
/**
|
|
* bufferFn buffers calls to fn so they only happen every ms milliseconds
|
|
*
|
|
* @param {number} ms number of milliseconds
|
|
* @param {function} fn the function to be buffered
|
|
* @returns {function}
|
|
*/
|
|
function bufferFn(ms, fn) {
|
|
var timeout = undefined;
|
|
return function () {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(fn, ms);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* noop is a function which does nothing at all.
|
|
*/
|
|
function noop() { }
|
|
|
|
/**
|
|
* copy properties from object o2 to object o1.
|
|
*
|
|
* @params {Object} o1
|
|
* @params {Object} o2
|
|
* @returns {Object}
|
|
*/
|
|
function cp() {
|
|
var args = arguments;
|
|
var o1 = args[0];
|
|
for (var i = 1; i < args.length; ++i) {
|
|
var o2 = args[i] || {};
|
|
for (var key in o2) {
|
|
o1[key] = o2[key];
|
|
}
|
|
}
|
|
return o1;
|
|
}
|
|
|
|
/**
|
|
* @file Responsible for sanitizing and creating date picker options.
|
|
*/
|
|
|
|
var english = {
|
|
days: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
months: [
|
|
'January',
|
|
'February',
|
|
'March',
|
|
'April',
|
|
'May',
|
|
'June',
|
|
'July',
|
|
'August',
|
|
'September',
|
|
'October',
|
|
'November',
|
|
'December',
|
|
],
|
|
today: 'Today',
|
|
clear: 'Clear',
|
|
close: 'Close',
|
|
};
|
|
|
|
/**
|
|
* DatePickerOptions constructs a new date picker options object, overriding
|
|
* default values with any values specified in opts.
|
|
*
|
|
* @param {DatePickerOptions} opts
|
|
* @returns {DatePickerOptions}
|
|
*/
|
|
function DatePickerOptions(opts) {
|
|
opts = opts || {};
|
|
opts = cp(defaults(), opts);
|
|
var parse = dateOrParse(opts.parse);
|
|
opts.lang = cp(english, opts.lang);
|
|
opts.parse = parse;
|
|
opts.inRange = makeInRangeFn(opts);
|
|
opts.min = parse(opts.min || shiftYear(now(), -100));
|
|
opts.max = parse(opts.max || shiftYear(now(), 100));
|
|
opts.hilightedDate = opts.parse(opts.hilightedDate);
|
|
|
|
return opts;
|
|
}
|
|
|
|
function defaults() {
|
|
return {
|
|
lang: english,
|
|
|
|
// Possible values: dp-modal, dp-below, dp-permanent
|
|
mode: 'dp-modal',
|
|
|
|
// The date to hilight initially if the date picker has no
|
|
// initial value.
|
|
hilightedDate: now(),
|
|
|
|
format: function (dt) {
|
|
return (dt.getMonth() + 1) + '/' + dt.getDate() + '/' + dt.getFullYear();
|
|
},
|
|
|
|
parse: function (str) {
|
|
var date = new Date(str);
|
|
return isNaN(date) ? now() : date;
|
|
},
|
|
|
|
dateClass: function () { },
|
|
|
|
inRange: function () {
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
|
|
function makeInRangeFn(opts) {
|
|
var inRange = opts.inRange; // Cache this version, and return a variant
|
|
|
|
return function (dt, dp) {
|
|
return inRange(dt, dp) && opts.min <= dt && opts.max >= dt;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @file Helper functions for dealing with dom elements.
|
|
*/
|
|
|
|
var Key = {
|
|
left: 37,
|
|
up: 38,
|
|
right: 39,
|
|
down: 40,
|
|
enter: 13,
|
|
esc: 27,
|
|
};
|
|
|
|
/**
|
|
* on attaches an event handler to the specified element, and returns an
|
|
* off function which can be used to remove the handler.
|
|
*
|
|
* @param {string} evt the name of the event to handle
|
|
* @param {HTMLElement} el the element to attach to
|
|
* @param {function} handler the event handler
|
|
* @returns {function} the off function
|
|
*/
|
|
function on(evt, el, handler) {
|
|
el.addEventListener(evt, handler, true);
|
|
|
|
return function () {
|
|
el.removeEventListener(evt, handler, true);
|
|
};
|
|
}
|
|
|
|
var CustomEvent = shimCustomEvent();
|
|
|
|
function shimCustomEvent() {
|
|
var CustomEvent = window.CustomEvent;
|
|
|
|
if (typeof CustomEvent !== 'function') {
|
|
CustomEvent = function (event, params) {
|
|
params = params || {bubbles: false, cancelable: false, detail: undefined};
|
|
var evt = document.createEvent('CustomEvent');
|
|
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
|
return evt;
|
|
};
|
|
|
|
CustomEvent.prototype = window.Event.prototype;
|
|
}
|
|
|
|
return CustomEvent;
|
|
}
|
|
|
|
/**
|
|
* @file Manages the calendar / day-picker view.
|
|
*/
|
|
|
|
var dayPicker = {
|
|
onKeyDown: keyDown,
|
|
onClick: {
|
|
'dp-day': selectDay,
|
|
'dp-next': gotoNextMonth,
|
|
'dp-prev': gotoPrevMonth,
|
|
'dp-today': selectToday,
|
|
'dp-clear': clear,
|
|
'dp-close': close,
|
|
'dp-cal-month': showMonthPicker,
|
|
'dp-cal-year': showYearPicker,
|
|
},
|
|
render: render
|
|
};
|
|
|
|
/**
|
|
* view renders the calendar (day picker) as an HTML string.
|
|
*
|
|
* @param {DatePickerContext} context the date picker being rendered
|
|
* @returns {string}
|
|
*/
|
|
function render(dp) {
|
|
var opts = dp.opts;
|
|
var lang = opts.lang;
|
|
var state = dp.state;
|
|
var dayNames = lang.days;
|
|
var dayOffset = opts.dayOffset || 0;
|
|
var selectedDate = state.selectedDate;
|
|
var hilightedDate = state.hilightedDate;
|
|
var hilightedMonth = hilightedDate.getMonth();
|
|
var today = now().getTime();
|
|
|
|
return (
|
|
'<div class="dp-cal">' +
|
|
'<header class="dp-cal-header">' +
|
|
'<button tabindex="-1" type="button" class="dp-prev">Prev</button>' +
|
|
'<button tabindex="-1" type="button" class="dp-cal-month">' +
|
|
lang.months[hilightedMonth] +
|
|
'</button>' +
|
|
'<button tabindex="-1" type="button" class="dp-cal-year">' +
|
|
hilightedDate.getFullYear() +
|
|
'</button>' +
|
|
'<button tabindex="-1" type="button" class="dp-next">Next</button>' +
|
|
'</header>' +
|
|
'<div class="dp-days">' +
|
|
dayNames.map(function (name, i) {
|
|
return (
|
|
'<span class="dp-col-header">' + dayNames[(i + dayOffset) % dayNames.length] + '</span>'
|
|
);
|
|
}).join('') +
|
|
mapDays(hilightedDate, dayOffset, function (date) {
|
|
var isNotInMonth = date.getMonth() !== hilightedMonth;
|
|
var isDisabled = !opts.inRange(date);
|
|
var isToday = date.getTime() === today;
|
|
var className = 'dp-day';
|
|
className += (isNotInMonth ? ' dp-edge-day' : '');
|
|
className += (datesEq(date, hilightedDate) ? ' dp-current' : '');
|
|
className += (datesEq(date, selectedDate) ? ' dp-selected' : '');
|
|
className += (isDisabled ? ' dp-day-disabled' : '');
|
|
className += (isToday ? ' dp-day-today' : '');
|
|
className += ' ' + opts.dateClass(date, dp);
|
|
|
|
return (
|
|
'<button tabindex="-1" type="button" class="' + className + '" data-date="' + date.getTime() + '">' +
|
|
date.getDate() +
|
|
'</button>'
|
|
);
|
|
}) +
|
|
'</div>' +
|
|
'<footer class="dp-cal-footer">' +
|
|
'<button tabindex="-1" type="button" class="dp-today">' + lang.today + '</button>' +
|
|
'<button tabindex="-1" type="button" class="dp-clear">' + lang.clear + '</button>' +
|
|
'<button tabindex="-1" type="button" class="dp-close">' + lang.close + '</button>' +
|
|
'</footer>' +
|
|
'</div>'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* keyDown handles the key down event for the day-picker
|
|
*
|
|
* @param {Event} e
|
|
* @param {DatePickerContext} dp
|
|
*/
|
|
function keyDown(e, dp) {
|
|
var key = e.keyCode;
|
|
var shiftBy =
|
|
(key === Key.left) ? -1 :
|
|
(key === Key.right) ? 1 :
|
|
(key === Key.up) ? -7 :
|
|
(key === Key.down) ? 7 :
|
|
0;
|
|
|
|
if (key === Key.esc) {
|
|
dp.close();
|
|
} else if (shiftBy) {
|
|
e.preventDefault();
|
|
dp.setState({
|
|
hilightedDate: shiftDay(dp.state.hilightedDate, shiftBy)
|
|
});
|
|
}
|
|
}
|
|
|
|
function selectToday(e, dp) {
|
|
dp.setState({
|
|
selectedDate: now(),
|
|
});
|
|
}
|
|
|
|
function clear(e, dp) {
|
|
dp.setState({
|
|
selectedDate: null,
|
|
});
|
|
}
|
|
|
|
function close(e, dp) {
|
|
dp.close();
|
|
}
|
|
|
|
function showMonthPicker(e, dp) {
|
|
dp.setState({
|
|
view: 'month'
|
|
});
|
|
}
|
|
|
|
function showYearPicker(e, dp) {
|
|
dp.setState({
|
|
view: 'year'
|
|
});
|
|
}
|
|
|
|
function gotoNextMonth(e, dp) {
|
|
var hilightedDate = dp.state.hilightedDate;
|
|
dp.setState({
|
|
hilightedDate: shiftMonth(hilightedDate, 1)
|
|
});
|
|
}
|
|
|
|
function gotoPrevMonth(e, dp) {
|
|
var hilightedDate = dp.state.hilightedDate;
|
|
dp.setState({
|
|
hilightedDate: shiftMonth(hilightedDate, -1)
|
|
});
|
|
}
|
|
|
|
function selectDay(e, dp) {
|
|
dp.setState({
|
|
selectedDate: new Date(parseInt(e.target.getAttribute('data-date'))),
|
|
});
|
|
}
|
|
|
|
function mapDays(currentDate, dayOffset, fn) {
|
|
var result = '';
|
|
var iter = new Date(currentDate);
|
|
iter.setDate(1);
|
|
iter.setDate(1 - iter.getDay() + dayOffset);
|
|
|
|
// If we are showing monday as the 1st of the week,
|
|
// and the monday is the 2nd of the month, the sunday won't
|
|
// show, so we need to shift backwards
|
|
if (dayOffset && iter.getDate() === dayOffset + 1) {
|
|
iter.setDate(dayOffset - 6);
|
|
}
|
|
|
|
// We are going to have 6 weeks always displayed to keep a consistent
|
|
// calendar size
|
|
for (var day = 0; day < (6 * 7); ++day) {
|
|
result += fn(iter);
|
|
iter.setDate(iter.getDate() + 1);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* @file Manages the month-picker view.
|
|
*/
|
|
|
|
var monthPicker = {
|
|
onKeyDown: keyDown$1,
|
|
onClick: {
|
|
'dp-month': onChooseMonth
|
|
},
|
|
render: render$1
|
|
};
|
|
|
|
function onChooseMonth(e, dp) {
|
|
dp.setState({
|
|
hilightedDate: setMonth(dp.state.hilightedDate, parseInt(e.target.getAttribute('data-month'))),
|
|
view: 'day',
|
|
});
|
|
}
|
|
|
|
/**
|
|
* render renders the month picker as an HTML string
|
|
*
|
|
* @param {DatePickerContext} dp the date picker context
|
|
* @returns {string}
|
|
*/
|
|
function render$1(dp) {
|
|
var opts = dp.opts;
|
|
var lang = opts.lang;
|
|
var months = lang.months;
|
|
var currentDate = dp.state.hilightedDate;
|
|
var currentMonth = currentDate.getMonth();
|
|
|
|
return (
|
|
'<div class="dp-months">' +
|
|
months.map(function (month, i) {
|
|
var className = 'dp-month';
|
|
className += (currentMonth === i ? ' dp-current' : '');
|
|
|
|
return (
|
|
'<button tabindex="-1" type="button" class="' + className + '" data-month="' + i + '">' +
|
|
month +
|
|
'</button>'
|
|
);
|
|
}).join('') +
|
|
'</div>'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* keyDown handles keydown events that occur in the month picker
|
|
*
|
|
* @param {Event} e
|
|
* @param {DatePickerContext} dp
|
|
*/
|
|
function keyDown$1(e, dp) {
|
|
var key = e.keyCode;
|
|
var shiftBy =
|
|
(key === Key.left) ? -1 :
|
|
(key === Key.right) ? 1 :
|
|
(key === Key.up) ? -3 :
|
|
(key === Key.down) ? 3 :
|
|
0;
|
|
|
|
if (key === Key.esc) {
|
|
dp.setState({
|
|
view: 'day',
|
|
});
|
|
} else if (shiftBy) {
|
|
e.preventDefault();
|
|
dp.setState({
|
|
hilightedDate: shiftMonth(dp.state.hilightedDate, shiftBy, true)
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @file Manages the year-picker view.
|
|
*/
|
|
|
|
var yearPicker = {
|
|
render: render$2,
|
|
onKeyDown: keyDown$2,
|
|
onClick: {
|
|
'dp-year': onChooseYear
|
|
},
|
|
};
|
|
|
|
/**
|
|
* view renders the year picker as an HTML string.
|
|
*
|
|
* @param {DatePickerContext} dp the date picker context
|
|
* @returns {string}
|
|
*/
|
|
function render$2(dp) {
|
|
var state = dp.state;
|
|
var currentYear = state.hilightedDate.getFullYear();
|
|
var selectedYear = state.selectedDate.getFullYear();
|
|
|
|
return (
|
|
'<div class="dp-years">' +
|
|
mapYears(dp, function (year) {
|
|
var className = 'dp-year';
|
|
className += (year === currentYear ? ' dp-current' : '');
|
|
className += (year === selectedYear ? ' dp-selected' : '');
|
|
|
|
return (
|
|
'<button tabindex="-1" type="button" class="' + className + '" data-year="' + year + '">' +
|
|
year +
|
|
'</button>'
|
|
);
|
|
}) +
|
|
'</div>'
|
|
);
|
|
}
|
|
|
|
function onChooseYear(e, dp) {
|
|
dp.setState({
|
|
hilightedDate: setYear(dp.state.hilightedDate, parseInt(e.target.getAttribute('data-year'))),
|
|
view: 'day',
|
|
});
|
|
}
|
|
|
|
function keyDown$2(e, dp) {
|
|
var key = e.keyCode;
|
|
var opts = dp.opts;
|
|
var shiftBy =
|
|
(key === Key.left || key === Key.up) ? 1 :
|
|
(key === Key.right || key === Key.down) ? -1 :
|
|
0;
|
|
|
|
if (key === Key.esc) {
|
|
dp.setState({
|
|
view: 'day',
|
|
});
|
|
} else if (shiftBy) {
|
|
e.preventDefault();
|
|
var shiftedYear = shiftYear(dp.state.hilightedDate, shiftBy);
|
|
|
|
dp.setState({
|
|
hilightedDate: constrainDate(shiftedYear, opts.min, opts.max),
|
|
});
|
|
}
|
|
}
|
|
|
|
function mapYears(dp, fn) {
|
|
var result = '';
|
|
var max = dp.opts.max.getFullYear();
|
|
|
|
for (var i = max; i >= dp.opts.min.getFullYear(); --i) {
|
|
result += fn(i);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* @file Defines the base date picker behavior, overridden by various modes.
|
|
*/
|
|
|
|
var views = {
|
|
day: dayPicker,
|
|
year: yearPicker,
|
|
month: monthPicker
|
|
};
|
|
|
|
function BaseMode(input, emit, opts) {
|
|
var detatchInputEvents; // A function that detaches all events from the input
|
|
var closing = false; // A hack to prevent calendar from re-opening when closing.
|
|
var selectedDate; // The currently selected date
|
|
var dp = {
|
|
// The root DOM element for the date picker, initialized on first open.
|
|
el: undefined,
|
|
opts: opts,
|
|
shouldFocusOnBlur: true,
|
|
shouldFocusOnRender: true,
|
|
state: initialState(),
|
|
adjustPosition: noop,
|
|
containerHTML: '<div class="dp"></div>',
|
|
|
|
attachToDom: function () {
|
|
document.body.appendChild(dp.el);
|
|
},
|
|
|
|
updateInput: function (selectedDate) {
|
|
var e = new CustomEvent('change', {bubbles: true});
|
|
e.simulated = true;
|
|
input.value = selectedDate ? opts.format(selectedDate) : '';
|
|
input.dispatchEvent(e);
|
|
},
|
|
|
|
computeSelectedDate: function () {
|
|
return opts.parse(input.value);
|
|
},
|
|
|
|
currentView: function() {
|
|
return views[dp.state.view];
|
|
},
|
|
|
|
open: function () {
|
|
if (closing) {
|
|
return;
|
|
}
|
|
|
|
if (!dp.el) {
|
|
dp.el = createContainerElement(opts, dp.containerHTML);
|
|
attachContainerEvents(dp);
|
|
}
|
|
|
|
selectedDate = constrainDate(dp.computeSelectedDate(), opts.min, opts.max);
|
|
dp.state.hilightedDate = selectedDate || opts.hilightedDate;
|
|
dp.state.view = 'day';
|
|
|
|
dp.attachToDom();
|
|
dp.render();
|
|
|
|
emit('open');
|
|
},
|
|
|
|
isVisible: function () {
|
|
return !!dp.el && !!dp.el.parentNode;
|
|
},
|
|
|
|
hasFocus: function () {
|
|
var focused = document.activeElement;
|
|
return dp.el &&
|
|
dp.el.contains(focused) &&
|
|
focused.className.indexOf('dp-focuser') < 0;
|
|
},
|
|
|
|
shouldHide: function () {
|
|
return dp.isVisible();
|
|
},
|
|
|
|
close: function (becauseOfBlur) {
|
|
var el = dp.el;
|
|
|
|
if (!dp.isVisible()) {
|
|
return;
|
|
}
|
|
|
|
if (el) {
|
|
var parent = el.parentNode;
|
|
parent && parent.removeChild(el);
|
|
}
|
|
|
|
closing = true;
|
|
|
|
if (becauseOfBlur && dp.shouldFocusOnBlur) {
|
|
focusInput(input);
|
|
}
|
|
|
|
// When we close, the input often gains refocus, which
|
|
// can then launch the date picker again, so we buffer
|
|
// a bit and don't show the date picker within N ms of closing
|
|
setTimeout(function() {
|
|
closing = false;
|
|
}, 100);
|
|
|
|
emit('close');
|
|
},
|
|
|
|
destroy: function () {
|
|
dp.close();
|
|
detatchInputEvents();
|
|
},
|
|
|
|
render: function () {
|
|
if (!dp.el) {
|
|
return;
|
|
}
|
|
|
|
var hadFocus = dp.hasFocus();
|
|
var html = dp.currentView().render(dp);
|
|
html && (dp.el.firstChild.innerHTML = html);
|
|
|
|
dp.adjustPosition();
|
|
|
|
if (hadFocus || dp.shouldFocusOnRender) {
|
|
focusCurrent(dp);
|
|
}
|
|
},
|
|
|
|
// Conceptually similar to setState in React, updates
|
|
// the view state and re-renders.
|
|
setState: function (state) {
|
|
for (var key in state) {
|
|
dp.state[key] = state[key];
|
|
}
|
|
|
|
emit('statechange');
|
|
dp.render();
|
|
},
|
|
};
|
|
|
|
detatchInputEvents = attachInputEvents(input, dp);
|
|
|
|
// Builds the initial view state
|
|
// selectedDate is a special case and causes changes to hilightedDate
|
|
// hilightedDate is set on open, so remains undefined initially
|
|
// view is the current view (day, month, year)
|
|
function initialState() {
|
|
return {
|
|
get selectedDate() {
|
|
return selectedDate;
|
|
},
|
|
set selectedDate(dt) {
|
|
if (dt && !opts.inRange(dt)) {
|
|
return;
|
|
}
|
|
|
|
if (dt) {
|
|
selectedDate = new Date(dt);
|
|
dp.state.hilightedDate = selectedDate;
|
|
} else {
|
|
selectedDate = dt;
|
|
}
|
|
|
|
dp.updateInput(selectedDate);
|
|
emit('select');
|
|
dp.close();
|
|
},
|
|
view: 'day',
|
|
};
|
|
}
|
|
|
|
return dp;
|
|
}
|
|
|
|
function createContainerElement(opts, containerHTML) {
|
|
var el = document.createElement('div');
|
|
|
|
el.className = opts.mode;
|
|
el.innerHTML = containerHTML;
|
|
|
|
return el;
|
|
}
|
|
|
|
function attachInputEvents(input, dp) {
|
|
var bufferShow = bufferFn(5, function () {
|
|
if (dp.shouldHide()) {
|
|
dp.close();
|
|
} else {
|
|
dp.open();
|
|
}
|
|
});
|
|
|
|
var off = [
|
|
on('blur', input, bufferFn(150, function () {
|
|
if (!dp.hasFocus()) {
|
|
dp.close(true);
|
|
}
|
|
})),
|
|
|
|
on('mousedown', input, function () {
|
|
if (input === document.activeElement) {
|
|
bufferShow();
|
|
}
|
|
}),
|
|
|
|
on('focus', input, bufferShow),
|
|
|
|
on('input', input, function (e) {
|
|
var date = dp.opts.parse(e.target.value);
|
|
isNaN(date) || dp.setState({
|
|
hilightedDate: date
|
|
});
|
|
}),
|
|
];
|
|
|
|
// Unregister all events that were registered above.
|
|
return function() {
|
|
off.forEach(function (f) {
|
|
f();
|
|
});
|
|
};
|
|
}
|
|
|
|
function focusCurrent(dp) {
|
|
var current = dp.el.querySelector('.dp-current');
|
|
return current && current.focus();
|
|
}
|
|
|
|
function attachContainerEvents(dp) {
|
|
var el = dp.el;
|
|
var calEl = el.querySelector('.dp');
|
|
|
|
// Hack to get iOS to show active CSS states
|
|
el.ontouchstart = noop;
|
|
|
|
function onClick(e) {
|
|
e.target.className.split(' ').forEach(function(evt) {
|
|
var handler = dp.currentView().onClick[evt];
|
|
handler && handler(e, dp);
|
|
});
|
|
}
|
|
|
|
// The calender fires a blur event *every* time we redraw
|
|
// this means we need to buffer the blur event to see if
|
|
// it still has no focus after redrawing, and only then
|
|
// do we return focus to the input. A possible other approach
|
|
// would be to set context.redrawing = true on redraw and
|
|
// set it to false in the blur event.
|
|
on('blur', calEl, bufferFn(150, function () {
|
|
if (!dp.hasFocus()) {
|
|
dp.close(true);
|
|
}
|
|
}));
|
|
|
|
on('keydown', el, function (e) {
|
|
if (e.keyCode === Key.enter) {
|
|
onClick(e);
|
|
} else {
|
|
dp.currentView().onKeyDown(e, dp);
|
|
}
|
|
});
|
|
|
|
// If the user clicks in non-focusable space, but
|
|
// still within the date picker, we don't want to
|
|
// hide, so we need to hack some things...
|
|
on('mousedown', calEl, function (e) {
|
|
e.target.focus && e.target.focus(); // IE hack
|
|
if (document.activeElement !== e.target) {
|
|
e.preventDefault();
|
|
focusCurrent(dp);
|
|
}
|
|
});
|
|
|
|
on('click', el, onClick);
|
|
}
|
|
|
|
function focusInput(input) {
|
|
// When the modal closes, we need to focus the original input so the
|
|
// user can continue tabbing from where they left off.
|
|
input.focus();
|
|
|
|
// iOS zonks out if we don't blur the input, so...
|
|
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
|
|
input.blur();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @file Defines the modal date picker behavior.
|
|
*/
|
|
|
|
function ModalMode(input, emit, opts) {
|
|
var dp = BaseMode(input, emit, opts);
|
|
|
|
// In modal mode, users really shouldn't be able to type in
|
|
// the input, as all input is done via the calendar.
|
|
input.readonly = true;
|
|
|
|
// In modal mode, we need to know when the user has tabbed
|
|
// off the end of the calendar, and set focus to the original
|
|
// input. To do this, we add a special element to the DOM.
|
|
// When the user tabs off the bottom of the calendar, they
|
|
// will tab onto this element.
|
|
dp.containerHTML += '<a href="#" class="dp-focuser">.</a>';
|
|
|
|
return dp;
|
|
}
|
|
|
|
/**
|
|
* @file Defines the dropdown date picker behavior.
|
|
*/
|
|
|
|
function DropdownMode(input, emit, opts) {
|
|
var dp = BaseMode(input, emit, opts);
|
|
|
|
dp.shouldFocusOnBlur = false;
|
|
|
|
Object.defineProperty(dp, 'shouldFocusOnRender', {
|
|
get: function() {
|
|
return input !== document.activeElement;
|
|
}
|
|
});
|
|
|
|
dp.adjustPosition = function () {
|
|
autoPosition(input, dp);
|
|
};
|
|
|
|
return dp;
|
|
}
|
|
|
|
function autoPosition(input, dp) {
|
|
var inputPos = input.getBoundingClientRect();
|
|
var win = window;
|
|
|
|
adjustCalY(dp, inputPos, win);
|
|
adjustCalX(dp, inputPos, win);
|
|
|
|
dp.el.style.visibility = '';
|
|
}
|
|
|
|
function adjustCalX(dp, inputPos, win) {
|
|
var cal = dp.el;
|
|
var scrollLeft = win.pageXOffset;
|
|
var inputLeft = inputPos.left + scrollLeft;
|
|
var maxRight = win.innerWidth + scrollLeft;
|
|
var offsetWidth = cal.offsetWidth;
|
|
var calRight = inputLeft + offsetWidth;
|
|
var shiftedLeft = maxRight - offsetWidth;
|
|
var left = calRight > maxRight && shiftedLeft > 0 ? shiftedLeft : inputLeft;
|
|
|
|
cal.style.left = left + 'px';
|
|
}
|
|
|
|
function adjustCalY(dp, inputPos, win) {
|
|
var cal = dp.el;
|
|
var scrollTop = win.pageYOffset;
|
|
var inputTop = scrollTop + inputPos.top;
|
|
var calHeight = cal.offsetHeight;
|
|
var belowTop = inputTop + inputPos.height + 8;
|
|
var aboveTop = inputTop - calHeight - 8;
|
|
var isAbove = (aboveTop > 0 && belowTop + calHeight > scrollTop + win.innerHeight);
|
|
var top = isAbove ? aboveTop : belowTop;
|
|
|
|
if (cal.classList) {
|
|
cal.classList.toggle('dp-is-above', isAbove);
|
|
cal.classList.toggle('dp-is-below', !isAbove);
|
|
}
|
|
cal.style.top = top + 'px';
|
|
}
|
|
|
|
/**
|
|
* @file Defines the permanent date picker behavior.
|
|
*/
|
|
|
|
function PermanentMode(root, emit, opts) {
|
|
var dp = BaseMode(root, emit, opts);
|
|
|
|
dp.close = noop;
|
|
dp.destroy = noop;
|
|
dp.updateInput = noop;
|
|
dp.shouldFocusOnRender = opts.shouldFocusOnRender;
|
|
|
|
dp.computeSelectedDate = function () {
|
|
return opts.hilightedDate;
|
|
};
|
|
|
|
dp.attachToDom = function () {
|
|
root.appendChild(dp.el);
|
|
};
|
|
|
|
dp.open();
|
|
|
|
return dp;
|
|
}
|
|
|
|
/**
|
|
* @file Defines the various date picker modes (modal, dropdown, permanent)
|
|
*/
|
|
|
|
function Mode(input, emit, opts) {
|
|
input = input && input.tagName ? input : document.querySelector(input);
|
|
|
|
if (opts.mode === 'dp-modal') {
|
|
return ModalMode(input, emit, opts);
|
|
}
|
|
|
|
if (opts.mode === 'dp-below') {
|
|
return DropdownMode(input, emit, opts);
|
|
}
|
|
|
|
if (opts.mode === 'dp-permanent') {
|
|
return PermanentMode(input, emit, opts);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @file Defines simple event emitter behavior.
|
|
*/
|
|
|
|
/**
|
|
* Emitter constructs a new emitter object which has on/off methods.
|
|
*
|
|
* @returns {EventEmitter}
|
|
*/
|
|
function Emitter() {
|
|
var handlers = {};
|
|
|
|
function onOne(name, handler) {
|
|
(handlers[name] = (handlers[name] || [])).push(handler);
|
|
}
|
|
|
|
function onMany(fns) {
|
|
for (var name in fns) {
|
|
onOne(name, fns[name]);
|
|
}
|
|
}
|
|
|
|
return {
|
|
on: function (name, handler) {
|
|
if (handler) {
|
|
onOne(name, handler);
|
|
} else {
|
|
onMany(name);
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
emit: function (name, arg) {
|
|
(handlers[name] || []).forEach(function (handler) {
|
|
handler(name, arg);
|
|
});
|
|
},
|
|
|
|
off: function (name, handler) {
|
|
if (!name) {
|
|
handlers = {};
|
|
} else if (!handler) {
|
|
handlers[name] = [];
|
|
} else {
|
|
handlers[name] = (handlers[name] || []).filter(function (h) {
|
|
return h !== handler;
|
|
});
|
|
}
|
|
|
|
return this;
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @file The root date picker file, defines public exports for the library.
|
|
*/
|
|
|
|
/**
|
|
* The date picker language configuration
|
|
* @typedef {Object} LangOptions
|
|
* @property {Array.<string>} [days] - Days of the week
|
|
* @property {Array.<string>} [months] - Months of the year
|
|
* @property {string} today - The label for the 'today' button
|
|
* @property {string} close - The label for the 'close' button
|
|
* @property {string} clear - The label for the 'clear' button
|
|
*/
|
|
|
|
/**
|
|
* The configuration options for a date picker.
|
|
*
|
|
* @typedef {Object} DatePickerOptions
|
|
* @property {LangOptions} [lang] - Configures the label text, defaults to English
|
|
* @property {('dp-modal'|'dp-below'|'dp-permanent')} [mode] - The date picker mode, defaults to 'dp-modal'
|
|
* @property {(string|Date)} [hilightedDate] - The date to hilight if no date is selected
|
|
* @property {function(string|Date):Date} [parse] - Parses a date, the complement of the "format" function
|
|
* @property {function(Date):string} [format] - Formats a date for displaying to user
|
|
* @property {function(Date):string} [dateClass] - Associates a custom CSS class with a date
|
|
* @property {function(Date):boolean} [inRange] - Indicates whether or not a date is selectable
|
|
* @property {(string|Date)} [min] - The minimum selectable date (inclusive, default 100 years ago)
|
|
* @property {(string|Date)} [max] - The maximum selectable date (inclusive, default 100 years from now)
|
|
*/
|
|
|
|
/**
|
|
* The state values for the date picker
|
|
*
|
|
* @typedef {Object} DatePickerState
|
|
* @property {string} view - The current view 'day' | 'month' | 'year'
|
|
* @property {Date} selectedDate - The date which has been selected by the user
|
|
* @property {Date} hilightedDate - The date which is currently hilighted / active
|
|
*/
|
|
|
|
/**
|
|
* An instance of TinyDatePicker
|
|
*
|
|
* @typedef {Object} DatePicker
|
|
* @property {DatePickerState} state - The values currently displayed.
|
|
* @property {function} on - Adds an event handler
|
|
* @property {function} off - Removes an event handler
|
|
* @property {function} setState - Changes the current state of the date picker
|
|
* @property {function} open - Opens the date picker
|
|
* @property {function} close - Closes the date picker
|
|
* @property {function} destroy - Destroys the date picker (removing all handlers from the input, too)
|
|
*/
|
|
|
|
/**
|
|
* TinyDatePicker constructs a new date picker for the specified input
|
|
*
|
|
* @param {HTMLElement | string} input The input or CSS selector associated with the datepicker
|
|
* @param {DatePickerOptions} opts The options for initializing the date picker
|
|
* @returns {DatePicker}
|
|
*/
|
|
function TinyDatePicker(input, opts) {
|
|
var emitter = Emitter();
|
|
var options = DatePickerOptions(opts);
|
|
var mode = Mode(input, emit, options);
|
|
var me = {
|
|
get state() {
|
|
return mode.state;
|
|
},
|
|
on: emitter.on,
|
|
off: emitter.off,
|
|
setState: mode.setState,
|
|
open: mode.open,
|
|
close: mode.close,
|
|
destroy: mode.destroy,
|
|
};
|
|
|
|
function emit(evt) {
|
|
emitter.emit(evt, me);
|
|
}
|
|
|
|
return me;
|
|
}
|
|
|
|
return TinyDatePicker;
|
|
|
|
})));
|
|
|
|
},{}],"controllers/PostEditor.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _DataUtils = _interopRequireWildcard(require("../tools/utilities/DataUtils"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../tools/events/DataEvent"));
|
|
|
|
var Ease = _interopRequireWildcard(require("../tools/effects/Animate"));
|
|
|
|
var _PostActions = _interopRequireDefault(require("../actions/PostActions"));
|
|
|
|
var EditorEvent = _interopRequireWildcard(require("../tools/events/EditorEvent"));
|
|
|
|
var _TextEditor = _interopRequireDefault(require("../tools/utilities/TextEditor"));
|
|
|
|
var _tinyDatePicker = _interopRequireDefault(require("tiny-date-picker"));
|
|
|
|
var _DateUtils = _interopRequireDefault(require("../tools/utilities/DateUtils"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var PostEditor =
|
|
/*#__PURE__*/
|
|
function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function PostEditor() {
|
|
var _this = this;
|
|
|
|
_classCallCheck(this, PostEditor);
|
|
|
|
reframe('iframe');
|
|
var self = this;
|
|
this.uploadFiles;
|
|
this.dataUtils = new _DataUtils.default();
|
|
this.dateUtils = new _DateUtils.default();
|
|
|
|
if (document.getElementById('edit-post-text')) {
|
|
this.editor = new _TextEditor.default(document.getElementById('edit-post-text'), document.getElementById('header').offsetHeight + document.getElementById('post-header').offsetHeight + document.getElementById('post-feature').offsetHeight);
|
|
this.editor.addListener(EditorEvent.EDITOR_DELETE, function (f) {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_DELETE);
|
|
}, false);
|
|
this.editor.addListener(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, function (f) {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_UPLOAD_POST_IMAGE);
|
|
}, false);
|
|
this.editor.addListener(EditorEvent.EDITOR_UPDATE, function (f) {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_UPDATE);
|
|
}, false);
|
|
this.editor.addListener(EditorEvent.EDITOR_SAVE, function (f) {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_SAVE);
|
|
}, false);
|
|
document.getElementById('post-image').addEventListener('change', function (e) {
|
|
return _this.handlePostImageAdd(e);
|
|
}, false);
|
|
(0, _tinyDatePicker.default)(document.getElementById('post-date'), {
|
|
mode: 'dp-below',
|
|
format: function format(date) {
|
|
//return date;
|
|
return self.dateUtils.getDate('origin', date);
|
|
}
|
|
});
|
|
}
|
|
|
|
this.start();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(PostEditor, [{
|
|
key: "start",
|
|
value: function start() {
|
|
var _this2 = this;
|
|
|
|
var self = this;
|
|
new Ease.default().object({
|
|
targets: document.getElementById('loader'),
|
|
duration: 300,
|
|
opacity: 0,
|
|
easing: 'easeInOutQuad',
|
|
complete: function complete() {
|
|
document.getElementById('loader').style.display = 'none';
|
|
document.getElementById('loader').style.visibility = 'hidden';
|
|
new Ease.default().object({
|
|
targets: document.getElementById('header'),
|
|
duration: 10,
|
|
opacity: 1,
|
|
easing: 'easeInOutQuad',
|
|
complete: function complete() {
|
|
if (document.getElementById('the-intro')) document.getElementById('the-intro').style.opacity = 1;
|
|
if (document.getElementById('blog-entry')) document.getElementById('blog-entry').style.opacity = 1;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
if (document.getElementById('featured-image-drop')) {
|
|
document.getElementById('featured-image-drop').addEventListener('dragover', this.handleDragOver, false);
|
|
document.getElementById('featured-image-drop').addEventListener('drop', this.handleDrop, false);
|
|
document.getElementById('featured-click').addEventListener('change', this.handleClicked, false);
|
|
|
|
if (document.getElementById('new-upload-link')) {
|
|
document.getElementById('new-upload-link').addEventListener('click', function (e) {
|
|
document.getElementById('featured-click').click();
|
|
});
|
|
}
|
|
|
|
var optionButtons = document.querySelectorAll('.post-option-btn');
|
|
|
|
for (var i = 0, length = optionButtons.length; i < length; i++) {
|
|
optionButtons[i].addEventListener('click', function (e) {
|
|
return _this2.handlePostOptions(e);
|
|
}, false);
|
|
}
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handlePostOptions",
|
|
value: function handlePostOptions(e) {
|
|
var currentOption;
|
|
|
|
switch (e.target.id) {
|
|
case "option-page-icon":
|
|
case "option-page":
|
|
currentOption = document.getElementById('option-page');
|
|
break;
|
|
|
|
case "option-feature-icon":
|
|
case "option-feature":
|
|
currentOption = document.getElementById('option-feature');
|
|
break;
|
|
|
|
case "option-published-icon":
|
|
case "option-published":
|
|
currentOption = document.getElementById('option-published');
|
|
break;
|
|
}
|
|
|
|
var active = currentOption.getAttribute('data-active');
|
|
active == 'false' ? currentOption.setAttribute('data-active', 'true') : currentOption.setAttribute('data-active', 'false');
|
|
}
|
|
}, {
|
|
key: "handleEditorOptions",
|
|
value: function handleEditorOptions(e) {
|
|
var _this3 = this;
|
|
|
|
switch (e) {
|
|
case EditorEvent.EDITOR_SAVE:
|
|
case EditorEvent.EDITOR_UPDATE:
|
|
var edit = false;
|
|
if (e == EditorEvent.EDITOR_UPDATE) edit = true;
|
|
new _PostActions.default().submitPost(edit, PostEditor.uploadFiles).then(function (response) {
|
|
var note = JSON.parse(response['response']['request'].response);
|
|
|
|
_this3.editor.notify(note.message, note.postID);
|
|
|
|
if (note.message == DataEvent.POST_ADDED) window.location = "/@/dashboard/posts/edit/" + note.postID;
|
|
}).catch(function (err) {
|
|
console.log(err);
|
|
});
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_DELETE:
|
|
if (confirm('Aye! You know you\'re deleting this post, right?')) {
|
|
new _PostActions.default().deletePost().then(function (response) {
|
|
var note = JSON.parse(response['response']['request'].response);
|
|
window.location = "/@/dashboard/posts/"; //console.log(note);
|
|
}).catch(function (err) {
|
|
console.log(err);
|
|
});
|
|
} else {// Do nothing!
|
|
}
|
|
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
document.getElementById('post-image').click();
|
|
break;
|
|
}
|
|
}
|
|
}, {
|
|
key: "handleDragOver",
|
|
value: function handleDragOver(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
|
|
}
|
|
}, {
|
|
key: "handleClicked",
|
|
value: function handleClicked(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault(); //console.log("IMAGES " + e.target.files);
|
|
|
|
PostEditor.uploadFiles = e.target.files;
|
|
|
|
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) {
|
|
// Only process image files.
|
|
if (!f.type.match('image.*')) {
|
|
continue;
|
|
}
|
|
|
|
var reader = new FileReader(); // Closure to capture the file information.
|
|
|
|
reader.onload = function (theFile) {
|
|
return function (f) {
|
|
// Render thumbnail.
|
|
var image = document.createElement('img');
|
|
image.src = f.target.result;
|
|
image.title = escape(theFile.name);
|
|
var span = document.createElement('div');
|
|
span.innerHTML = ['<img src="', f.target.result, '" title="', escape(theFile.name), '"/>'].join(''); //document.getElementById('featured-image-drop').insertBefore(span, null);
|
|
|
|
document.getElementById('featured-image-drop').innerHTML = '';
|
|
document.getElementById('featured-image-drop').appendChild(image);
|
|
};
|
|
}(f); // Read in the image file as a data URL.
|
|
|
|
|
|
reader.readAsDataURL(f);
|
|
}
|
|
}
|
|
}, {
|
|
key: "handleDrop",
|
|
value: function handleDrop(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
PostEditor.uploadFiles = e.dataTransfer.files; //console.log(MemberArea.uploadFiles.length);
|
|
|
|
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) {
|
|
// Only process image files.
|
|
if (!f.type.match('image.*')) {
|
|
continue;
|
|
}
|
|
|
|
var reader = new FileReader(); // Closure to capture the file information.
|
|
|
|
reader.onload = function (theFile) {
|
|
return function (f) {
|
|
// Render thumbnail.
|
|
var span = document.createElement('span');
|
|
span.innerHTML = ['<img src="', f.target.result, '" title="', escape(theFile.name), '"/>'].join(''); //document.getElementById('featured-image-drop').insertBefore(span, null);
|
|
|
|
document.getElementById('featured-image-drop').innerHTML = '';
|
|
document.getElementById('featured-image-drop').appendChild(span);
|
|
};
|
|
}(f); // Read in the image file as a data URL.
|
|
|
|
|
|
reader.readAsDataURL(f);
|
|
}
|
|
}
|
|
}, {
|
|
key: "handlePostImageAdd",
|
|
value: function handlePostImageAdd(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
var self = this;
|
|
var postData = new FormData();
|
|
var files = e.target.files;
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i]; // Check the file type.
|
|
|
|
if (!file.type.match('image.*')) {
|
|
continue;
|
|
}
|
|
|
|
postData.append('post_image', file, file.name);
|
|
}
|
|
|
|
this.dataUtils.request("/api/blog/add-post-image", DataEvent.POST_IMAGE_ADDED, _DataUtils.REQUEST_TYPE_POST, _DataUtils.CONTENT_TYPE_FORM, postData).then(function (response) {
|
|
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, JSON.parse(response.request['response']).url);
|
|
}).catch(function (err) {
|
|
console.log(err);
|
|
});
|
|
}
|
|
}]);
|
|
|
|
return PostEditor;
|
|
}();
|
|
|
|
exports.default = PostEditor;
|
|
PostEditor.uploadFiles = [];
|
|
},{"../tools/utilities/DataUtils":"tools/utilities/DataUtils.jsx","../tools/events/DataEvent":"tools/events/DataEvent.jsx","../tools/effects/Animate":"tools/effects/Animate.jsx","../actions/PostActions":"actions/PostActions.jsx","../tools/events/EditorEvent":"tools/events/EditorEvent.jsx","../tools/utilities/TextEditor":"tools/utilities/TextEditor.jsx","tiny-date-picker":"../../../../node_modules/tiny-date-picker/dist/tiny-date-picker.js","../tools/utilities/DateUtils":"tools/utilities/DateUtils.jsx"}],"controllers/DisplayManager.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _DataUtils = _interopRequireWildcard(require("../tools/utilities/DataUtils.jsx"));
|
|
|
|
var _PostEditor = _interopRequireDefault(require("./PostEditor"));
|
|
|
|
var _Animate = _interopRequireDefault(require("../tools/effects/Animate.jsx"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var DisplayManager =
|
|
/*#__PURE__*/
|
|
function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function DisplayManager() {
|
|
_classCallCheck(this, DisplayManager);
|
|
|
|
this.dataUtils = new _DataUtils.default();
|
|
this.currentDisplay = '';
|
|
this.urlPieces = document.URL.split("/"); //grab url so system knows what to display
|
|
|
|
this.chooseDisplay(this.urlPieces[5], this.urlPieces[6]);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(DisplayManager, [{
|
|
key: "start",
|
|
value: function start() {
|
|
var self = this;
|
|
new _Animate.default().object({
|
|
targets: document.getElementById('loader'),
|
|
duration: 300,
|
|
opacity: 0,
|
|
easing: 'easeInOutQuad',
|
|
complete: function complete() {
|
|
document.getElementById('loader').style.display = 'none';
|
|
document.getElementById('loader').style.visibility = 'hidden';
|
|
new _Animate.default().object({
|
|
targets: document.getElementById('header'),
|
|
duration: 10,
|
|
opacity: 1,
|
|
easing: 'easeInOutQuad',
|
|
complete: function complete() {
|
|
document.getElementById('loader').style.display = 'none';
|
|
document.getElementById('loader').style.visibility = 'hidden';
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}, {
|
|
key: "chooseDisplay",
|
|
value: function chooseDisplay(section, page) {
|
|
this.currentDisplay = ''; //console.log(section+" "+page)
|
|
|
|
switch (section) {
|
|
case 'posts':
|
|
this.currentDisplay = new _PostEditor.default();
|
|
break;
|
|
|
|
default:
|
|
// just chill
|
|
break;
|
|
}
|
|
|
|
this.start();
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return DisplayManager;
|
|
}();
|
|
|
|
exports.default = DisplayManager;
|
|
},{"../tools/utilities/DataUtils.jsx":"tools/utilities/DataUtils.jsx","./PostEditor":"controllers/PostEditor.jsx","../tools/effects/Animate.jsx":"tools/effects/Animate.jsx"}],"Base.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _DataUtils = _interopRequireWildcard(require("./tools/utilities/DataUtils.jsx"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("./tools/events/DataEvent.jsx"));
|
|
|
|
var _DisplayManager = _interopRequireDefault(require("./controllers/DisplayManager.jsx"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var Base =
|
|
/*#__PURE__*/
|
|
function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
//TODO: Flip to unified structure defined in BMG, brah
|
|
function Base() {
|
|
_classCallCheck(this, Base);
|
|
|
|
var self = this;
|
|
var admin = [];
|
|
var folio = [];
|
|
var displayManager = [];
|
|
this.dataUtils = new _DataUtils.default();
|
|
this.settings = [];
|
|
this.start();
|
|
}
|
|
|
|
_createClass(Base, [{
|
|
key: "start",
|
|
value: function start() {
|
|
this.displayManager = new _DisplayManager.default();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "loadSettings",
|
|
value: function loadSettings() {
|
|
var _this = this;
|
|
|
|
var self = this;
|
|
this.dataUtils.request('/base-assets/data/settings.json', DataEvent.SETTINGS_LOADED).then(function (response) {
|
|
_this.settings = JSON.parse(response['request'].response);
|
|
|
|
_this.start(); //transfer
|
|
|
|
}).catch(function (err) {//console.log(err);
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return Base;
|
|
}();
|
|
|
|
exports.default = Base;
|
|
},{"./tools/utilities/DataUtils.jsx":"tools/utilities/DataUtils.jsx","./tools/events/DataEvent.jsx":"tools/events/DataEvent.jsx","./controllers/DisplayManager.jsx":"controllers/DisplayManager.jsx"}],"Start.jsx":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
var _Base = _interopRequireDefault(require("./Base.jsx"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
var base = new _Base.default();
|
|
}, false);
|
|
},{"./Base.jsx":"Base.jsx"}],"../../../../../../.nvm/versions/node/v8.12.0/lib/node_modules/parcel-bundler/src/builtins/hmr-runtime.js":[function(require,module,exports) {
|
|
var global = arguments[3];
|
|
var OVERLAY_ID = '__parcel__error__overlay__';
|
|
var OldModule = module.bundle.Module;
|
|
|
|
function Module(moduleName) {
|
|
OldModule.call(this, moduleName);
|
|
this.hot = {
|
|
data: module.bundle.hotData,
|
|
_acceptCallbacks: [],
|
|
_disposeCallbacks: [],
|
|
accept: function (fn) {
|
|
this._acceptCallbacks.push(fn || function () {});
|
|
},
|
|
dispose: function (fn) {
|
|
this._disposeCallbacks.push(fn);
|
|
}
|
|
};
|
|
module.bundle.hotData = null;
|
|
}
|
|
|
|
module.bundle.Module = Module;
|
|
var parent = module.bundle.parent;
|
|
|
|
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
var hostname = "" || location.hostname;
|
|
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
|
var ws = new WebSocket(protocol + '://' + hostname + ':' + "57869" + '/');
|
|
|
|
ws.onmessage = function (event) {
|
|
var data = JSON.parse(event.data);
|
|
|
|
if (data.type === 'update') {
|
|
console.clear();
|
|
data.assets.forEach(function (asset) {
|
|
hmrApply(global.parcelRequire, asset);
|
|
});
|
|
data.assets.forEach(function (asset) {
|
|
if (!asset.isNew) {
|
|
hmrAccept(global.parcelRequire, asset.id);
|
|
}
|
|
});
|
|
}
|
|
|
|
if (data.type === 'reload') {
|
|
ws.close();
|
|
|
|
ws.onclose = function () {
|
|
location.reload();
|
|
};
|
|
}
|
|
|
|
if (data.type === 'error-resolved') {
|
|
console.log('[parcel] ✨ Error resolved');
|
|
removeErrorOverlay();
|
|
}
|
|
|
|
if (data.type === 'error') {
|
|
console.error('[parcel] 🚨 ' + data.error.message + '\n' + data.error.stack);
|
|
removeErrorOverlay();
|
|
var overlay = createErrorOverlay(data);
|
|
document.body.appendChild(overlay);
|
|
}
|
|
};
|
|
}
|
|
|
|
function removeErrorOverlay() {
|
|
var overlay = document.getElementById(OVERLAY_ID);
|
|
|
|
if (overlay) {
|
|
overlay.remove();
|
|
}
|
|
}
|
|
|
|
function createErrorOverlay(data) {
|
|
var overlay = document.createElement('div');
|
|
overlay.id = OVERLAY_ID; // html encode message and stack trace
|
|
|
|
var message = document.createElement('div');
|
|
var stackTrace = document.createElement('pre');
|
|
message.innerText = data.error.message;
|
|
stackTrace.innerText = data.error.stack;
|
|
overlay.innerHTML = '<div style="background: black; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; opacity: 0.85; font-family: Menlo, Consolas, monospace; z-index: 9999;">' + '<span style="background: red; padding: 2px 4px; border-radius: 2px;">ERROR</span>' + '<span style="top: 2px; margin-left: 5px; position: relative;">🚨</span>' + '<div style="font-size: 18px; font-weight: bold; margin-top: 20px;">' + message.innerHTML + '</div>' + '<pre>' + stackTrace.innerHTML + '</pre>' + '</div>';
|
|
return overlay;
|
|
}
|
|
|
|
function getParents(bundle, id) {
|
|
var modules = bundle.modules;
|
|
|
|
if (!modules) {
|
|
return [];
|
|
}
|
|
|
|
var parents = [];
|
|
var k, d, dep;
|
|
|
|
for (k in modules) {
|
|
for (d in modules[k][1]) {
|
|
dep = modules[k][1][d];
|
|
|
|
if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) {
|
|
parents.push(k);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (bundle.parent) {
|
|
parents = parents.concat(getParents(bundle.parent, id));
|
|
}
|
|
|
|
return parents;
|
|
}
|
|
|
|
function hmrApply(bundle, asset) {
|
|
var modules = bundle.modules;
|
|
|
|
if (!modules) {
|
|
return;
|
|
}
|
|
|
|
if (modules[asset.id] || !bundle.parent) {
|
|
var fn = new Function('require', 'module', 'exports', asset.generated.js);
|
|
asset.isNew = !modules[asset.id];
|
|
modules[asset.id] = [fn, asset.deps];
|
|
} else if (bundle.parent) {
|
|
hmrApply(bundle.parent, asset);
|
|
}
|
|
}
|
|
|
|
function hmrAccept(bundle, id) {
|
|
var modules = bundle.modules;
|
|
|
|
if (!modules) {
|
|
return;
|
|
}
|
|
|
|
if (!modules[id] && bundle.parent) {
|
|
return hmrAccept(bundle.parent, id);
|
|
}
|
|
|
|
var cached = bundle.cache[id];
|
|
bundle.hotData = {};
|
|
|
|
if (cached) {
|
|
cached.hot.data = bundle.hotData;
|
|
}
|
|
|
|
if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
|
|
cached.hot._disposeCallbacks.forEach(function (cb) {
|
|
cb(bundle.hotData);
|
|
});
|
|
}
|
|
|
|
delete bundle.cache[id];
|
|
bundle(id);
|
|
cached = bundle.cache[id];
|
|
|
|
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
|
cached.hot._acceptCallbacks.forEach(function (cb) {
|
|
cb();
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
return getParents(global.parcelRequire, id).some(function (id) {
|
|
return hmrAccept(global.parcelRequire, id);
|
|
});
|
|
}
|
|
},{}]},{},["../../../../../../.nvm/versions/node/v8.12.0/lib/node_modules/parcel-bundler/src/builtins/hmr-runtime.js","Start.jsx"], null)
|
|
//# sourceMappingURL=/dash/assets/js/dash.min.map
|