fipamo/themes/dash/assets/js/dash.min.js

3386 lines
106 KiB
JavaScript
Raw Normal View History

2018-10-31 17:00:31 +01:00
// 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;
2018-10-31 17:00:31 +01:00
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;
2018-10-31 17:00:31 +01:00
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) {
2018-10-31 17:00:31 +01:00
"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(/&lt;/g, '<').replace(/&gt;/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(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
// string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
}
if (!noquotes) {
string = string.replace(/&quot;/g, '"');
} // Put this in last place to avoid escape being double-decoded
string = string.replace(/&amp;/g, '&');
return string;
} //--------------------------
// event handlers
//--------------------------
}]);
return StringUtils;
}();
var _default = StringUtils;
exports.default = _default;
},{}],"tasks/EntryTasks.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 EntryTasks =
/*#__PURE__*/
function () {
//--------------------------
// constructor
//--------------------------
function EntryTasks() {
_classCallCheck(this, EntryTasks);
var folio = [];
this.dataUtils = new _DataUtils.default();
} //--------------------------
// methods
//--------------------------
_createClass(EntryTasks, [{
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-text-code').innerHTML;
postData.append("title", document.getElementById('entry_title').value);
postData.append('slug', new _StringUtils.default().cleanString(document.getElementById('entry_title').value));
postData.append("entry_plaintext", txt.value);
postData.append("origin_date", document.getElementById('entry-date').value);
2018-10-31 17:00:31 +01:00
postData.append("tags", document.getElementById('entry_tags').value);
var postURL;
var postEventType;
if (edit) {
var postID = document.getElementById('option-update').getAttribute('data-id');
2018-10-31 17:00:31 +01:00
postURL = "/api/blog/update/" + postID;
postEventType = DataEvent.POST_UPDATED;
} else {
postURL = "/api/blog/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('option-update').getAttribute('data-id');
return new Promise(function (resolve, reject) {
self.dataUtils.request("/api/blog/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;
}
2018-10-31 17:00:31 +01:00
}, {
key: "validateForm",
value: function validateForm() {
var valid = false;
if (this.entry_form.title.value == "" || this.entry_form.price.value == "" || this.entry_form.description == "") {
return valid;
} else {
valid = true;
return valid;
}
} //--------------------------
// event handlers
//--------------------------
}]);
return EntryTasks;
}();
exports.default = EntryTasks;
},{"../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";
2018-11-02 21:25:47 +01:00
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
*/
2018-11-02 21:25:47 +01:00
var createMirror = function createMirror(element, html) {
2018-11-02 21:25:47 +01:00
/**
* The mirror element
2018-11-02 21:25:47 +01:00
*/
var mirror = document.createElement('div');
2018-11-02 21:25:47 +01:00
/**
* Create the CSS for the mirror object
2018-11-02 21:25:47 +01:00
*
* @return {object} The style object
2018-11-02 21:25:47 +01:00
*/
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;
};
2018-11-02 21:25:47 +01:00
/**
* Initialize the mirror
2018-11-02 21:25:47 +01:00
*
* @param {string} html The html
*
* @return {void}
2018-11-02 21:25:47 +01:00
*/
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);
};
2018-11-02 21:25:47 +01:00
/**
* Get the rect
2018-11-02 21:25:47 +01:00
*
* @return {Rect} The bounding rect
2018-11-02 21:25:47 +01:00
*/
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;
};
2018-11-02 21:25:47 +01:00
initialize(html);
return {
rect: rect
};
};
2018-11-02 21:25:47 +01:00
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
};
2018-11-02 21:25:47 +01:00
}
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) {
2018-11-02 21:25:47 +01:00
/**
* Get the current position
2018-11-02 21:25:47 +01:00
*
* @returns {int} The caret position
2018-11-02 21:25:47 +01:00
*/
var getPos = function getPos() {
return element.selectionStart;
};
2018-11-02 21:25:47 +01:00
/**
* Set the position
2018-11-02 21:25:47 +01:00
*
* @param {int} pos The position
*
* @return {Element} The element
2018-11-02 21:25:47 +01:00
*/
var setPos = function setPos(pos) {
element.setSelectionRange(pos, pos);
return element;
};
2018-11-02 21:25:47 +01:00
/**
* The offset
2018-11-02 21:25:47 +01:00
*
* @param {int} pos The position
*
* @return {object} The offset
2018-11-02 21:25:47 +01:00
*/
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
};
};
2018-11-02 21:25:47 +01:00
/**
* Get the current position
2018-11-02 21:25:47 +01:00
*
* @param {int} pos The position
*
* @return {object} The position
2018-11-02 21:25:47 +01:00
*/
var getPosition = function getPosition(pos) {
var format = function format(val) {
var value = val.replace(/<|>|`|"|&/g, '?').replace(/\r\n|\r|\n/g, '<br/>');
return value;
2018-11-02 21:25:47 +01:00
};
if (ctx.customPos || ctx.customPos === 0) {
pos = ctx.customPos;
2018-11-02 21:25:47 +01:00
}
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;
};
2018-11-02 21:25:47 +01:00
return {
getPos: getPos,
setPos: setPos,
getOffset: getOffset$$1,
getPosition: getPosition
2018-11-02 21:25:47 +01:00
};
};
/**
* Create an Editable Caret
* @param {Element} element The editable element
* @param {object|null} ctx The context
*
* @return {EditableCaret}
*/
2018-11-02 21:25:47 +01:00
var createEditableCaret = function createEditableCaret(element, ctx) {
2018-11-02 21:25:47 +01:00
/**
* Set the caret position
2018-11-02 21:25:47 +01:00
*
* @param {int} pos The position to se
*
* @return {Element} The element
2018-11-02 21:25:47 +01:00
*/
var setPos = function setPos(pos) {
var sel = ctx.window.getSelection();
2018-11-02 21:25:47 +01:00
if (sel) {
var offset = 0;
var found = false;
2018-11-02 21:25:47 +01:00
var find = function find(position, parent) {
for (var i = 0; i < parent.childNodes.length; i++) {
var node = parent.childNodes[i];
2018-11-02 21:25:47 +01:00
if (found) {
break;
}
2018-11-02 21:25:47 +01:00
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);
}
}
};
2018-11-02 21:25:47 +01:00
find(pos, element);
}
2018-11-02 21:25:47 +01:00
return element;
2018-11-02 21:25:47 +01:00
};
/**
* Get the offset
2018-11-02 21:25:47 +01:00
*
* @return {object} The offset
2018-11-02 21:25:47 +01:00
*/
var getOffset = function getOffset() {
var range = getRange();
var offset = {
height: 0,
left: 0,
right: 0
2018-11-02 21:25:47 +01:00
};
if (!range) {
return offset;
}
2018-11-02 21:25:47 +01:00
var hasCustomPos = ctx.customPos || ctx.customPos === 0; // endContainer in Firefox would be the element at the start of
// the line
2018-11-02 21:25:47 +01:00
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
2018-11-02 21:25:47 +01:00
};
clonedRange.detach();
}
2018-11-02 21:25:47 +01:00
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();
2018-11-02 21:25:47 +01:00
}
if (offset) {
var doc = ctx.document.documentElement;
offset.top += ctx.window.pageYOffset - (doc.clientTop || 0);
offset.left += ctx.window.pageXOffset - (doc.clientLeft || 0);
}
2018-11-02 21:25:47 +01:00
return offset;
};
2018-11-02 21:25:47 +01:00
/**
* Get the position
*
* @return {object} The position
2018-11-02 21:25:47 +01:00
*/
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;
};
2018-11-02 21:25:47 +01:00
/**
* Get the range
2018-11-02 21:25:47 +01:00
*
* @return {Range|null}
2018-11-02 21:25:47 +01:00
*/
var getRange = function getRange() {
if (!ctx.window.getSelection) {
return;
}
2018-11-02 21:25:47 +01:00
var sel = ctx.window.getSelection();
return sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
};
2018-11-02 21:25:47 +01:00
/**
* Get the caret position
2018-11-02 21:25:47 +01:00
*
* @return {int} The position
2018-11-02 21:25:47 +01:00
*/
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;
};
2018-11-02 21:25:47 +01:00
return {
getPos: getPos,
setPos: setPos,
getPosition: getPosition,
getOffset: getOffset,
getRange: getRange
};
};
2018-11-02 21:25:47 +01:00
var createCaret = function createCaret(element, ctx) {
if (isContentEditable(element)) {
return createEditableCaret(element, ctx);
2018-11-02 21:25:47 +01:00
}
return createInputCaret(element, ctx);
};
2018-11-02 21:25:47 +01:00
var position = function position(element, value) {
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = settings;
2018-11-02 21:25:47 +01:00
if (isObject(value)) {
options = value;
value = null;
2018-11-02 21:25:47 +01:00
}
var ctx = getContext(options);
var caret = createCaret(element, ctx);
2018-11-02 21:25:47 +01:00
if (value || value === 0) {
return caret.setPos(value);
2018-11-02 21:25:47 +01:00
}
return caret.getPosition();
};
/**
*
* @param {Element} element The DOM element
* @param {number|undefined} value The value to set
* @param {object} settings Any settings for context
*/
2018-11-02 21:25:47 +01:00
exports.position = position;
2018-11-02 21:25:47 +01:00
var offset = function offset(element, value) {
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = settings;
2018-11-02 21:25:47 +01:00
if (isObject(value)) {
options = value;
value = null;
2018-11-02 21:25:47 +01:00
}
var ctx = getContext(options);
var caret = createCaret(element, ctx);
return caret.getOffset(value);
};
2018-11-02 21:25:47 +01:00
exports.offset = offset;
},{}],"tools/utilities/TextEditor.jsx":[function(require,module,exports) {
"use strict";
2018-11-02 21:25:47 +01:00
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
2018-11-02 21:25:47 +01:00
var DataEvent = _interopRequireWildcard(require("../events/DataEvent"));
2018-11-02 21:25:47 +01:00
var _DateUtils = _interopRequireDefault(require("./DateUtils"));
2018-11-02 21:25:47 +01:00
var _caretPos = require("caret-pos");
2018-11-02 21:25:47 +01:00
var _EventEmitter2 = _interopRequireDefault(require("../events/EventEmitter"));
var EditorEvent = _interopRequireWildcard(require("../events/EditorEvent"));
2018-11-02 21:25:47 +01:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2018-11-02 21:25:47 +01:00
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; } }
2018-11-02 21:25:47 +01:00
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"); } }
2018-11-02 21:25:47 +01:00
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); } }
2018-11-02 21:25:47 +01:00
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
2018-11-02 21:25:47 +01:00
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);
2018-11-02 21:25:47 +01:00
_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;
2018-11-02 21:25:47 +01:00
if (window.pageYOffset >= fixLimit) {
document.getElementById('edit-control').style.position = "fixed";
} else {
document.getElementById('edit-control').style.position = "relative";
}
});
_this.refresh();
return _this;
} //--------------------------
// methods
//--------------------------
2018-11-02 21:25:47 +01:00
_createClass(TextEditor, [{
key: "setInputs",
value: function setInputs() {
var _this2 = this;
2018-11-02 21:25:47 +01:00
var self = this;
var editorButtons = document.querySelectorAll('.editor-button');
2018-11-02 21:25:47 +01:00
for (var i = 0, length = editorButtons.length; i < length; i++) {
editorButtons[i].addEventListener('click', function (e) {
return _this2.handleEditorOption(e);
}, false);
}
2018-11-02 21:25:47 +01:00
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('option-update').classList.remove('submit-start');
document.getElementById('option-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('option-update').classList.add('submit-start');
document.getElementById('option-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
//--------------------------
2018-11-02 21:25:47 +01:00
}, {
key: "handleEditorOption",
value: function handleEditorOption(e) {
e.preventDefault();
var self = this;
var sel, range, pulled;
sel = window.getSelection(); //console.log(sel)
2018-11-02 21:25:47 +01:00
if (sel.rangeCount) {
range = sel.getRangeAt(0);
pulled = sel.getRangeAt(0).toString();
range.deleteContents();
2018-11-02 21:25:47 +01:00
switch (e.target.id) {
case "option-bold":
range.insertNode(document.createTextNode("**" + pulled + "**"));
break;
2018-11-02 21:25:47 +01:00
case "option-italic":
range.insertNode(document.createTextNode("*" + pulled + "*"));
break;
2018-11-02 21:25:47 +01:00
case "option-strikethrough":
range.insertNode(document.createTextNode("<del>" + pulled + "</del>"));
break;
2018-11-02 21:25:47 +01:00
case "option-header1":
range.insertNode(document.createTextNode("# " + pulled));
break;
2018-11-02 21:25:47 +01:00
case "option-header2":
range.insertNode(document.createTextNode("## " + pulled));
break;
2018-11-02 21:25:47 +01:00
case "option-header3":
range.insertNode(document.createTextNode("### " + pulled));
break;
2018-11-02 21:25:47 +01:00
case "option-image":
this.caretPos = (0, _caretPos.position)(this.textEditor).pos;
this.emitEvent(EditorEvent.EDITOR_UPLOAD_POST_IMAGE);
break;
case "submit-save":
case "option-save":
this.emitEvent(EditorEvent.EDITOR_SAVE);
break;
case "submit-update":
case "option-update":
this.emitEvent(EditorEvent.EDITOR_UPDATE);
break;
case "option-link":
range.insertNode(document.createTextNode("[" + pulled + "](PASTE URL HERE)"));
break;
2018-11-02 21:25:47 +01:00
case "option-delete":
this.emitEvent(EditorEvent.EDITOR_DELETE);
break;
2018-11-02 21:25:47 +01:00
default:
//range.insertNode(document.createTextNode("[" + self.url + "](PASTE URL HERE)"));
break;
2018-11-02 21:25:47 +01:00
}
}
2018-11-02 21:25:47 +01:00
this.refresh();
}
}]);
2018-11-02 21:25:47 +01:00
return TextEditor;
}(_EventEmitter2.default);
2018-11-02 21:25:47 +01:00
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';
2018-11-02 21:25:47 +01:00
/**
* @file A generic set of mutation-free date functions.
*/
2018-11-02 21:25:47 +01:00
/**
* 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;
}
2018-11-02 21:25:47 +01:00
/**
* 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());
}
2018-11-02 21:25:47 +01:00
/**
* 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;
}
2018-11-02 21:25:47 +01:00
/**
* 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);
2018-11-02 21:25:47 +01:00
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);
2018-11-02 21:25:47 +01:00
}
return dt;
2018-11-02 21:25:47 +01:00
}
/**
* 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;
}
2018-11-02 21:25:47 +01:00
/**
* 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;
2018-11-02 21:25:47 +01:00
}
/**
* 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());
}
2018-11-02 21:25:47 +01:00
/**
* 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);
};
}
2018-11-02 21:25:47 +01:00
/**
* 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;
}
2018-11-02 21:25:47 +01:00
function dropTime(dt) {
dt = new Date(dt);
dt.setHours(0, 0, 0, 0);
return dt;
}
2018-11-02 21:25:47 +01:00
/**
* @file Utility functions for function manipulation.
*/
2018-11-02 21:25:47 +01:00
/**
* 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);
2018-11-02 21:25:47 +01:00
};
}
/**
* noop is a function which does nothing at all.
*/
function noop() { }
2018-11-02 21:25:47 +01:00
/**
* 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];
}
2018-11-02 21:25:47 +01:00
}
return o1;
}
2018-11-02 21:25:47 +01:00
/**
* @file Responsible for sanitizing and creating date picker options.
*/
2018-11-02 21:25:47 +01:00
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',
};
2018-11-02 21:25:47 +01:00
/**
* 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);
2018-11-02 21:25:47 +01:00
return opts;
2018-11-02 21:25:47 +01:00
}
function defaults() {
return {
lang: english,
2018-11-02 21:25:47 +01:00
// Possible values: dp-modal, dp-below, dp-permanent
mode: 'dp-modal',
2018-11-02 21:25:47 +01:00
// The date to hilight initially if the date picker has no
// initial value.
hilightedDate: now(),
2018-11-02 21:25:47 +01:00
format: function (dt) {
return (dt.getMonth() + 1) + '/' + dt.getDate() + '/' + dt.getFullYear();
},
2018-11-02 21:25:47 +01:00
parse: function (str) {
var date = new Date(str);
return isNaN(date) ? now() : date;
},
dateClass: function () { },
2018-11-02 21:25:47 +01:00
inRange: function () {
return true;
}
};
}
2018-11-02 21:25:47 +01:00
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;
};
2018-11-02 21:25:47 +01:00
}
/**
* @file Helper functions for dealing with dom elements.
2018-11-02 21:25:47 +01:00
*/
var Key = {
left: 37,
up: 38,
right: 39,
down: 40,
enter: 13,
esc: 27,
};
2018-11-02 21:25:47 +01:00
/**
* 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);
2018-11-02 21:25:47 +01:00
return function () {
el.removeEventListener(evt, handler, true);
2018-11-02 21:25:47 +01:00
};
}
var CustomEvent = shimCustomEvent();
2018-11-02 21:25:47 +01:00
function shimCustomEvent() {
var CustomEvent = window.CustomEvent;
2018-11-02 21:25:47 +01:00
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;
};
2018-11-02 21:25:47 +01:00
CustomEvent.prototype = window.Event.prototype;
}
2018-11-02 21:25:47 +01:00
return CustomEvent;
2018-11-02 21:25:47 +01:00
}
/**
* @file Manages the calendar / day-picker view.
*/
2018-11-02 21:25:47 +01:00
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
};
2018-11-02 21:25:47 +01:00
/**
* view renders the calendar (day picker) as an HTML string.
*
* @param {DatePickerContext} context the date picker being rendered
* @returns {string}
2018-11-02 21:25:47 +01:00
*/
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();
2018-11-02 21:25:47 +01:00
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);
2018-11-02 21:25:47 +01:00
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>'
);
}
2018-11-02 21:25:47 +01:00
/**
* 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;
2018-11-02 21:25:47 +01:00
if (key === Key.esc) {
dp.close();
} else if (shiftBy) {
e.preventDefault();
dp.setState({
hilightedDate: shiftDay(dp.state.hilightedDate, shiftBy)
});
}
}
2018-11-02 21:25:47 +01:00
function selectToday(e, dp) {
dp.setState({
selectedDate: now(),
});
}
2018-11-02 21:25:47 +01:00
function clear(e, dp) {
dp.setState({
selectedDate: null,
});
2018-11-02 21:25:47 +01:00
}
function close(e, dp) {
dp.close();
}
2018-11-02 21:25:47 +01:00
function showMonthPicker(e, dp) {
dp.setState({
view: 'month'
});
}
2018-11-02 21:25:47 +01:00
function showYearPicker(e, dp) {
dp.setState({
view: 'year'
});
}
2018-11-02 21:25:47 +01:00
function gotoNextMonth(e, dp) {
var hilightedDate = dp.state.hilightedDate;
dp.setState({
hilightedDate: shiftMonth(hilightedDate, 1)
});
}
2018-11-02 21:25:47 +01:00
function gotoPrevMonth(e, dp) {
var hilightedDate = dp.state.hilightedDate;
dp.setState({
hilightedDate: shiftMonth(hilightedDate, -1)
});
2018-11-02 21:25:47 +01:00
}
function selectDay(e, dp) {
dp.setState({
selectedDate: new Date(parseInt(e.target.getAttribute('data-date'))),
});
}
2018-11-02 21:25:47 +01:00
function mapDays(currentDate, dayOffset, fn) {
var result = '';
var iter = new Date(currentDate);
iter.setDate(1);
iter.setDate(1 - iter.getDay() + dayOffset);
2018-11-02 21:25:47 +01:00
// 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);
2018-11-02 21:25:47 +01:00
}
// 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);
2018-11-02 21:25:47 +01:00
}
return result;
2018-11-02 21:25:47 +01:00
}
/**
* @file Manages the month-picker view.
2018-11-02 21:25:47 +01:00
*/
var monthPicker = {
onKeyDown: keyDown$1,
onClick: {
'dp-month': onChooseMonth
},
render: render$1
};
2018-11-02 21:25:47 +01:00
function onChooseMonth(e, dp) {
dp.setState({
hilightedDate: setMonth(dp.state.hilightedDate, parseInt(e.target.getAttribute('data-month'))),
view: 'day',
});
}
2018-11-02 21:25:47 +01:00
/**
* render renders the month picker as an HTML string
2018-11-02 21:25:47 +01:00
*
* @param {DatePickerContext} dp the date picker context
* @returns {string}
2018-11-02 21:25:47 +01:00
*/
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();
2018-11-02 21:25:47 +01:00
return (
'<div class="dp-months">' +
months.map(function (month, i) {
var className = 'dp-month';
className += (currentMonth === i ? ' dp-current' : '');
2018-11-02 21:25:47 +01:00
return (
'<button tabindex="-1" type="button" class="' + className + '" data-month="' + i + '">' +
month +
'</button>'
);
}).join('') +
'</div>'
);
2018-11-02 21:25:47 +01:00
}
2018-10-31 17:00:31 +01:00
/**
* keyDown handles keydown events that occur in the month picker
2018-10-31 17:00:31 +01:00
*
* @param {Event} e
* @param {DatePickerContext} dp
2018-10-31 17:00:31 +01:00
*/
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;
2018-10-31 17:00:31 +01:00
if (key === Key.esc) {
dp.setState({
view: 'day',
});
} else if (shiftBy) {
e.preventDefault();
dp.setState({
hilightedDate: shiftMonth(dp.state.hilightedDate, shiftBy, true)
});
2018-10-31 17:00:31 +01:00
}
}
2018-10-31 17:00:31 +01:00
/**
* @file Manages the year-picker view.
2018-10-31 17:00:31 +01:00
*/
var yearPicker = {
render: render$2,
onKeyDown: keyDown$2,
onClick: {
'dp-year': onChooseYear
},
2018-10-31 17:00:31 +01:00
};
2018-10-31 17:00:31 +01:00
/**
* view renders the year picker as an HTML string.
2018-10-31 17:00:31 +01:00
*
* @param {DatePickerContext} dp the date picker context
* @returns {string}
2018-10-31 17:00:31 +01:00
*/
function render$2(dp) {
var state = dp.state;
var currentYear = state.hilightedDate.getFullYear();
var selectedYear = state.selectedDate.getFullYear();
2018-10-31 17:00:31 +01:00
return (
'<div class="dp-years">' +
mapYears(dp, function (year) {
var className = 'dp-year';
className += (year === currentYear ? ' dp-current' : '');
className += (year === selectedYear ? ' dp-selected' : '');
2018-10-31 17:00:31 +01:00
return (
'<button tabindex="-1" type="button" class="' + className + '" data-year="' + year + '">' +
year +
'</button>'
);
}) +
'</div>'
);
}
2018-10-31 17:00:31 +01:00
function onChooseYear(e, dp) {
dp.setState({
hilightedDate: setYear(dp.state.hilightedDate, parseInt(e.target.getAttribute('data-year'))),
view: 'day',
});
}
2018-10-31 17:00:31 +01:00
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;
2018-10-31 17:00:31 +01:00
if (key === Key.esc) {
dp.setState({
view: 'day',
});
} else if (shiftBy) {
e.preventDefault();
var shiftedYear = shiftYear(dp.state.hilightedDate, shiftBy);
2018-10-31 17:00:31 +01:00
dp.setState({
hilightedDate: constrainDate(shiftedYear, opts.min, opts.max),
});
}
}
2018-10-31 17:00:31 +01:00
function mapYears(dp, fn) {
var result = '';
var max = dp.opts.max.getFullYear();
2018-10-31 17:00:31 +01:00
for (var i = max; i >= dp.opts.min.getFullYear(); --i) {
result += fn(i);
}
2018-10-31 17:00:31 +01:00
return result;
2018-10-31 17:00:31 +01:00
}
/**
* @file Defines the base date picker behavior, overridden by various modes.
*/
var views = {
day: dayPicker,
year: yearPicker,
month: monthPicker
2018-10-31 17:00:31 +01:00
};
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>',
2018-10-31 17:00:31 +01:00
attachToDom: function () {
document.body.appendChild(dp.el);
},
2018-10-31 17:00:31 +01:00
updateInput: function (selectedDate) {
var e = new CustomEvent('change', {bubbles: true});
e.simulated = true;
input.value = selectedDate ? opts.format(selectedDate) : '';
input.dispatchEvent(e);
},
2018-10-31 17:00:31 +01:00
computeSelectedDate: function () {
return opts.parse(input.value);
},
2018-10-31 17:00:31 +01:00
currentView: function() {
return views[dp.state.view];
},
2018-10-31 17:00:31 +01:00
open: function () {
if (closing) {
return;
}
2018-10-31 17:00:31 +01:00
if (!dp.el) {
dp.el = createContainerElement(opts, dp.containerHTML);
attachContainerEvents(dp);
}
2018-10-31 17:00:31 +01:00
selectedDate = constrainDate(dp.computeSelectedDate(), opts.min, opts.max);
dp.state.hilightedDate = selectedDate || opts.hilightedDate;
dp.state.view = 'day';
2018-10-31 17:00:31 +01:00
dp.attachToDom();
dp.render();
2018-10-31 17:00:31 +01:00
emit('open');
},
2018-10-31 17:00:31 +01:00
isVisible: function () {
return !!dp.el && !!dp.el.parentNode;
},
2018-10-31 17:00:31 +01:00
hasFocus: function () {
var focused = document.activeElement;
return dp.el &&
dp.el.contains(focused) &&
focused.className.indexOf('dp-focuser') < 0;
},
2018-10-31 17:00:31 +01:00
shouldHide: function () {
return dp.isVisible();
},
2018-10-31 17:00:31 +01:00
close: function (becauseOfBlur) {
var el = dp.el;
2018-10-31 17:00:31 +01:00
if (!dp.isVisible()) {
return;
}
2018-10-31 17:00:31 +01:00
if (el) {
var parent = el.parentNode;
parent && parent.removeChild(el);
}
2018-10-31 17:00:31 +01:00
closing = true;
2018-10-31 17:00:31 +01:00
if (becauseOfBlur && dp.shouldFocusOnBlur) {
focusInput(input);
}
2018-10-31 17:00:31 +01:00
// 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);
2018-10-31 17:00:31 +01:00
emit('close');
},
2018-10-31 17:00:31 +01:00
destroy: function () {
dp.close();
detatchInputEvents();
},
2018-10-31 17:00:31 +01:00
render: function () {
if (!dp.el) {
return;
2018-10-31 17:00:31 +01:00
}
var hadFocus = dp.hasFocus();
var html = dp.currentView().render(dp);
html && (dp.el.firstChild.innerHTML = html);
2018-10-31 17:00:31 +01:00
dp.adjustPosition();
2018-10-31 17:00:31 +01:00
if (hadFocus || dp.shouldFocusOnRender) {
focusCurrent(dp);
}
},
2018-10-31 17:00:31 +01:00
// 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();
},
2018-10-31 17:00:31 +01:00
};
detatchInputEvents = attachInputEvents(input, dp);
2018-10-31 17:00:31 +01:00
// 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;
}
2018-10-31 17:00:31 +01:00
if (dt) {
selectedDate = new Date(dt);
dp.state.hilightedDate = selectedDate;
} else {
selectedDate = dt;
}
dp.updateInput(selectedDate);
emit('select');
dp.close();
},
view: 'day',
2018-10-31 17:00:31 +01:00
};
}
return dp;
}
2018-10-31 17:00:31 +01:00
function createContainerElement(opts, containerHTML) {
var el = document.createElement('div');
2018-10-31 17:00:31 +01:00
el.className = opts.mode;
el.innerHTML = containerHTML;
2018-10-31 17:00:31 +01:00
return el;
}
2018-10-31 17:00:31 +01:00
function attachInputEvents(input, dp) {
var bufferShow = bufferFn(5, function () {
if (dp.shouldHide()) {
dp.close();
} else {
dp.open();
}
});
2018-10-31 17:00:31 +01:00
var off = [
on('blur', input, bufferFn(150, function () {
if (!dp.hasFocus()) {
dp.close(true);
}
})),
2018-10-31 17:00:31 +01:00
on('mousedown', input, function () {
if (input === document.activeElement) {
bufferShow();
}
}),
2018-10-31 17:00:31 +01:00
on('focus', input, bufferShow),
2018-10-31 17:00:31 +01:00
on('input', input, function (e) {
var date = dp.opts.parse(e.target.value);
isNaN(date) || dp.setState({
hilightedDate: date
});
}),
];
2018-10-31 17:00:31 +01:00
// Unregister all events that were registered above.
return function() {
off.forEach(function (f) {
f();
});
};
}
2018-10-31 17:00:31 +01:00
function focusCurrent(dp) {
var current = dp.el.querySelector('.dp-current');
return current && current.focus();
}
2018-10-31 17:00:31 +01:00
function attachContainerEvents(dp) {
var el = dp.el;
var calEl = el.querySelector('.dp');
2018-10-31 17:00:31 +01:00
// Hack to get iOS to show active CSS states
el.ontouchstart = noop;
2018-10-31 17:00:31 +01:00
function onClick(e) {
e.target.className.split(' ').forEach(function(evt) {
var handler = dp.currentView().onClick[evt];
handler && handler(e, dp);
});
}
2018-10-31 17:00:31 +01:00
// 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);
}
}));
2018-10-31 17:00:31 +01:00
on('keydown', el, function (e) {
if (e.keyCode === Key.enter) {
onClick(e);
} else {
dp.currentView().onKeyDown(e, dp);
}
});
2018-10-31 17:00:31 +01:00
// 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);
}
});
2018-10-31 17:00:31 +01:00
on('click', el, onClick);
2018-10-31 17:00:31 +01:00
}
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();
2018-10-31 17:00:31 +01:00
// iOS zonks out if we don't blur the input, so...
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
input.blur();
}
2018-10-31 17:00:31 +01:00
}
/**
* @file Defines the modal date picker behavior.
*/
2018-10-31 17:00:31 +01:00
function ModalMode(input, emit, opts) {
var dp = BaseMode(input, emit, opts);
2018-10-31 17:00:31 +01:00
// 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;
2018-10-31 17:00:31 +01:00
// 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>';
2018-10-31 17:00:31 +01:00
return dp;
2018-10-31 17:00:31 +01:00
}
/**
* @file Defines the dropdown date picker behavior.
*/
2018-10-31 17:00:31 +01:00
function DropdownMode(input, emit, opts) {
var dp = BaseMode(input, emit, opts);
2018-10-31 17:00:31 +01:00
dp.shouldFocusOnBlur = false;
2018-10-31 17:00:31 +01:00
Object.defineProperty(dp, 'shouldFocusOnRender', {
get: function() {
return input !== document.activeElement;
}
});
2018-10-31 17:00:31 +01:00
dp.adjustPosition = function () {
autoPosition(input, dp);
};
2018-10-31 17:00:31 +01:00
return dp;
}
function autoPosition(input, dp) {
var inputPos = input.getBoundingClientRect();
var win = window;
2018-11-02 21:25:47 +01:00
adjustCalY(dp, inputPos, win);
adjustCalX(dp, inputPos, win);
2018-10-31 17:00:31 +01:00
dp.el.style.visibility = '';
}
2018-11-02 21:25:47 +01:00
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;
2018-10-31 17:00:31 +01:00
cal.style.left = left + 'px';
}
2018-10-31 17:00:31 +01:00
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;
2018-10-31 17:00:31 +01:00
if (cal.classList) {
cal.classList.toggle('dp-is-above', isAbove);
cal.classList.toggle('dp-is-below', !isAbove);
}
cal.style.top = top + 'px';
}
2018-10-31 17:00:31 +01:00
/**
* @file Defines the permanent date picker behavior.
*/
2018-10-31 17:00:31 +01:00
function PermanentMode(root, emit, opts) {
var dp = BaseMode(root, emit, opts);
2018-10-31 17:00:31 +01:00
dp.close = noop;
dp.destroy = noop;
dp.updateInput = noop;
dp.shouldFocusOnRender = opts.shouldFocusOnRender;
2018-10-31 17:00:31 +01:00
dp.computeSelectedDate = function () {
return opts.hilightedDate;
};
2018-10-31 17:00:31 +01:00
dp.attachToDom = function () {
root.appendChild(dp.el);
};
2018-10-31 17:00:31 +01:00
dp.open();
2018-10-31 17:00:31 +01:00
return dp;
}
2018-10-31 17:00:31 +01:00
/**
* @file Defines the various date picker modes (modal, dropdown, permanent)
*/
2018-10-31 17:00:31 +01:00
function Mode(input, emit, opts) {
input = input && input.tagName ? input : document.querySelector(input);
2018-10-31 17:00:31 +01:00
if (opts.mode === 'dp-modal') {
return ModalMode(input, emit, opts);
}
2018-10-31 17:00:31 +01:00
if (opts.mode === 'dp-below') {
return DropdownMode(input, emit, opts);
}
2018-10-31 17:00:31 +01:00
if (opts.mode === 'dp-permanent') {
return PermanentMode(input, emit, opts);
}
}
2018-10-31 17:00:31 +01:00
/**
* @file Defines simple event emitter behavior.
*/
2018-10-31 17:00:31 +01:00
/**
* Emitter constructs a new emitter object which has on/off methods.
*
* @returns {EventEmitter}
*/
function Emitter() {
var handlers = {};
2018-10-31 17:00:31 +01:00
function onOne(name, handler) {
(handlers[name] = (handlers[name] || [])).push(handler);
}
2018-10-31 17:00:31 +01:00
function onMany(fns) {
for (var name in fns) {
onOne(name, fns[name]);
}
}
2018-10-31 17:00:31 +01:00
return {
on: function (name, handler) {
if (handler) {
onOne(name, handler);
} else {
onMany(name);
}
2018-10-31 17:00:31 +01:00
return this;
},
2018-10-31 17:00:31 +01:00
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;
});
2018-10-31 17:00:31 +01:00
}
return this;
2018-10-31 17:00:31 +01:00
}
};
}
2018-10-31 17:00:31 +01:00
/**
* @file The root date picker file, defines public exports for the library.
*/
2018-10-31 17:00:31 +01:00
/**
* 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
*/
2018-10-31 17:00:31 +01:00
/**
* 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)
*/
2018-10-31 17:00:31 +01:00
/**
* 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
*/
2018-10-31 17:00:31 +01:00
/**
* 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)
*/
2018-10-31 17:00:31 +01:00
/**
* 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,
};
2018-10-31 17:00:31 +01:00
function emit(evt) {
emitter.emit(evt, me);
2018-10-31 17:00:31 +01:00
}
return me;
}
2018-10-31 17:00:31 +01:00
return TinyDatePicker;
})));
},{}],"controllers/DashEntry.jsx":[function(require,module,exports) {
2018-10-31 17:00:31 +01:00
"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 _EntryTasks = _interopRequireDefault(require("../tasks/EntryTasks"));
var EditorEvent = _interopRequireWildcard(require("../tools/events/EditorEvent"));
2018-10-31 17:00:31 +01:00
var _TextEditor = _interopRequireDefault(require("../tools/utilities/TextEditor"));
var _tinyDatePicker = _interopRequireDefault(require("tiny-date-picker"));
var _DateUtils = _interopRequireDefault(require("../tools/utilities/DateUtils"));
2018-10-31 17:00:31 +01:00
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 Entry =
/*#__PURE__*/
function () {
//--------------------------
// constructor
//--------------------------
function Entry() {
var _this = this;
2018-10-31 17:00:31 +01:00
_classCallCheck(this, Entry);
reframe('iframe');
var self = this;
2018-10-31 17:00:31 +01:00
this.uploadFiles;
this.dataUtils = new _DataUtils.default();
this.dateUtils = new _DateUtils.default();
if (document.getElementById('edit-text-code')) {
this.editor = new _TextEditor.default(document.getElementById('edit-text-code'), document.getElementById('header').offsetHeight + document.getElementById('entry-header').offsetHeight + document.getElementById('entry-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('entry-date'), {
mode: 'dp-below',
format: function format(date) {
//return date;
return self.dateUtils.getDate('origin', date);
}
});
}
this.start();
2018-10-31 17:00:31 +01:00
} //--------------------------
// methods
//--------------------------
_createClass(Entry, [{
key: "start",
value: function start() {
var self = this;
2018-10-31 17:00:31 +01:00
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;
2018-10-31 17:00:31 +01:00
}
});
}
});
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();
});
}
}
} //--------------------------
// event handlers
//--------------------------
2018-10-31 17:00:31 +01:00
}, {
key: "handleEditorOptions",
value: function handleEditorOptions(e) {
var _this2 = this;
switch (e) {
case EditorEvent.EDITOR_SAVE:
case EditorEvent.EDITOR_UPDATE:
2018-10-31 17:00:31 +01:00
var edit = false;
if (e == EditorEvent.EDITOR_UPDATE) edit = true;
2018-10-31 17:00:31 +01:00
new _EntryTasks.default().submitPost(edit, Entry.uploadFiles).then(function (response) {
var note = JSON.parse(response['response']['request'].response);
_this2.editor.notify(note.message, note.postID);
if (note.message == DataEvent.POST_ADDED) window.location = "/@/dashboard/entries/edit/" + note.postID;
2018-10-31 17:00:31 +01:00
}).catch(function (err) {
console.log(err);
});
break;
case EditorEvent.EDITOR_DELETE:
if (confirm('Aye! You know you\'re deleting this post, right?')) {
new _EntryTasks.default().deletePost().then(function (response) {
var note = JSON.parse(response['response']['request'].response);
window.location = "/@/dashboard/entries/"; //console.log(note);
}).catch(function (err) {
console.log(err);
});
} else {// Do nothing!
}
2018-10-31 17:00:31 +01:00
break;
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
document.getElementById('post-image').click();
break;
}
}
2018-10-31 17:00:31 +01:00
}, {
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);
Entry.uploadFiles = e.target.files;
for (var i = 0, f; f = Entry.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: "handleDrop",
value: function handleDrop(e) {
e.stopPropagation();
e.preventDefault();
Entry.uploadFiles = e.dataTransfer.files; //console.log(MemberArea.uploadFiles.length);
for (var i = 0, f; f = Entry.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);
});
}
2018-10-31 17:00:31 +01:00
}]);
return Entry;
}();
exports.default = Entry;
Entry.uploadFiles = [];
},{"../tools/utilities/DataUtils":"tools/utilities/DataUtils.jsx","../tools/events/DataEvent":"tools/events/DataEvent.jsx","../tools/effects/Animate":"tools/effects/Animate.jsx","../tasks/EntryTasks":"tasks/EntryTasks.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) {
2018-10-31 17:00:31 +01:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _DataUtils = _interopRequireWildcard(require("../tools/utilities/DataUtils.jsx"));
var _DashEntry = _interopRequireDefault(require("./DashEntry"));
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 'entries':
this;
this.currentDisplay = new _DashEntry.default();
break;
default:
// just chill
break;
}
this.start();
} //--------------------------
// event handlers
//--------------------------
}]);
return DisplayManager;
}();
exports.default = DisplayManager;
},{"../tools/utilities/DataUtils.jsx":"tools/utilities/DataUtils.jsx","./DashEntry":"controllers/DashEntry.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);
2018-11-02 21:25:47 +01:00
},{"./Base.jsx":"Base.jsx"}],"../../../../../../.nvm/versions/node/v8.12.0/lib/node_modules/parcel-bundler/src/builtins/hmr-runtime.js":[function(require,module,exports) {
2018-10-31 17:00:31 +01:00
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';
2018-11-02 21:25:47 +01:00
var ws = new WebSocket(protocol + '://' + hostname + ':' + "60962" + '/');
2018-10-31 17:00:31 +01:00
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);
});
}
2018-11-02 21:25:47 +01:00
},{}]},{},["../../../../../../.nvm/versions/node/v8.12.0/lib/node_modules/parcel-bundler/src/builtins/hmr-runtime.js","Start.jsx"], null)
2018-10-31 17:00:31 +01:00
//# sourceMappingURL=/dash/assets/js/dash.min.map