forked from projects/fipamo
4866 lines
152 KiB
JavaScript
4866 lines
152 KiB
JavaScript
// modules are defined as an array
|
|
// [ module function, map of requires ]
|
|
//
|
|
// map of requires is short require name -> numeric require
|
|
//
|
|
// anything defined in a previous bundle is accessed via the
|
|
// orig method which is the require for previous bundles
|
|
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;
|
|
}, {}];
|
|
};
|
|
|
|
var error;
|
|
for (var i = 0; i < entry.length; i++) {
|
|
try {
|
|
newRequire(entry[i]);
|
|
} catch (e) {
|
|
// Save first error but execute all entries
|
|
if (!error) {
|
|
error = e;
|
|
}
|
|
}
|
|
}
|
|
|
|
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
|
|
parcelRequire = newRequire;
|
|
|
|
if (error) {
|
|
// throw error from earlier, _after updating parcelRequire_
|
|
throw error;
|
|
}
|
|
|
|
return newRequire;
|
|
})({"events/DataEvent.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = exports.SEND_MAIL = exports.API_INIT_LAME = exports.API_INIT_GOOD = exports.API_INIT = exports.API_RENDER_PAGES = exports.API_IMAGES_UPLOAD = exports.API_SETTINGS_WRITE = exports.API_PAGE_DELETE = exports.API_PAGE_CREATE = exports.API_PAGE_WRITE = exports.UPLOAD_PROGRESS = exports.SITE_BACKGROUND_UPLOADED = exports.AVATAR_UPLOADED = exports.MENU_UPDATED = exports.MENU_DELETE_ITEM = exports.MENU_ADD_ITEM = exports.SETTINGS_NOT_UPDATED = exports.SETTINGS_UPDATED = exports.TAG_PAGES_NOT_RENDERED = exports.TAG_PAGES_RENDERED = exports.PAGES_NOT_RENDERED = exports.PAGES_RENDERED = exports.PAGE_DELETED = exports.PAGE_UPDATED = exports.PAGE_ADDED = exports.PAGE_ERROR = exports.FEATURE_IMAGE_ADDED = exports.POST_IMAGE_ADDED = exports.SETTINGS_LOADED = exports.IMG_REQUEST_LAME = exports.IMG_REQUEST_GOOD = exports.API_REQUEST_LAME = exports.API_REQUEST_GOOD = exports.REQUEST_LAME = exports.REQUEST_GOOD = void 0;
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
var REQUEST_GOOD = 'requestGood';
|
|
exports.REQUEST_GOOD = REQUEST_GOOD;
|
|
var REQUEST_LAME = 'requestLame';
|
|
exports.REQUEST_LAME = REQUEST_LAME;
|
|
var API_REQUEST_GOOD = 'apiUseAuthorized';
|
|
exports.API_REQUEST_GOOD = API_REQUEST_GOOD;
|
|
var API_REQUEST_LAME = 'apiUseNotAuthorized';
|
|
exports.API_REQUEST_LAME = API_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 = 'settingsLoaded';
|
|
exports.SETTINGS_LOADED = SETTINGS_LOADED;
|
|
var POST_IMAGE_ADDED = 'postImageAdded';
|
|
exports.POST_IMAGE_ADDED = POST_IMAGE_ADDED;
|
|
var FEATURE_IMAGE_ADDED = 'featureImageAdded';
|
|
exports.FEATURE_IMAGE_ADDED = FEATURE_IMAGE_ADDED;
|
|
var PAGE_ERROR = 'postError';
|
|
exports.PAGE_ERROR = PAGE_ERROR;
|
|
var PAGE_ADDED = 'postAdded';
|
|
exports.PAGE_ADDED = PAGE_ADDED;
|
|
var PAGE_UPDATED = 'postUpdated';
|
|
exports.PAGE_UPDATED = PAGE_UPDATED;
|
|
var PAGE_DELETED = 'postImageAdded';
|
|
exports.PAGE_DELETED = PAGE_DELETED;
|
|
var PAGES_RENDERED = 'pagesRendered';
|
|
exports.PAGES_RENDERED = PAGES_RENDERED;
|
|
var PAGES_NOT_RENDERED = 'pagesNotRendered';
|
|
exports.PAGES_NOT_RENDERED = PAGES_NOT_RENDERED;
|
|
var TAG_PAGES_RENDERED = 'tagPagesRendered';
|
|
exports.TAG_PAGES_RENDERED = TAG_PAGES_RENDERED;
|
|
var TAG_PAGES_NOT_RENDERED = 'tagPagesNotRendered';
|
|
exports.TAG_PAGES_NOT_RENDERED = TAG_PAGES_NOT_RENDERED;
|
|
var SETTINGS_UPDATED = 'settingsUpdated';
|
|
exports.SETTINGS_UPDATED = SETTINGS_UPDATED;
|
|
var SETTINGS_NOT_UPDATED = 'settingsNotUpdated';
|
|
exports.SETTINGS_NOT_UPDATED = SETTINGS_NOT_UPDATED;
|
|
var MENU_ADD_ITEM = 'menuAddItem';
|
|
exports.MENU_ADD_ITEM = MENU_ADD_ITEM;
|
|
var MENU_DELETE_ITEM = 'menuDeleteItem';
|
|
exports.MENU_DELETE_ITEM = MENU_DELETE_ITEM;
|
|
var MENU_UPDATED = 'menuUpdated';
|
|
exports.MENU_UPDATED = MENU_UPDATED;
|
|
var AVATAR_UPLOADED = 'avatarUploaded';
|
|
exports.AVATAR_UPLOADED = AVATAR_UPLOADED;
|
|
var SITE_BACKGROUND_UPLOADED = 'siteBackgroundUploaded';
|
|
exports.SITE_BACKGROUND_UPLOADED = SITE_BACKGROUND_UPLOADED;
|
|
var UPLOAD_PROGRESS = 'uploadProgress';
|
|
exports.UPLOAD_PROGRESS = UPLOAD_PROGRESS;
|
|
var API_PAGE_WRITE = 'writingItDown';
|
|
exports.API_PAGE_WRITE = API_PAGE_WRITE;
|
|
var API_PAGE_CREATE = 'writingNewEntry';
|
|
exports.API_PAGE_CREATE = API_PAGE_CREATE;
|
|
var API_PAGE_DELETE = 'erasingPage';
|
|
exports.API_PAGE_DELETE = API_PAGE_DELETE;
|
|
var API_SETTINGS_WRITE = 'savingSettings';
|
|
exports.API_SETTINGS_WRITE = API_SETTINGS_WRITE;
|
|
var API_IMAGES_UPLOAD = 'uploadProfileImages';
|
|
exports.API_IMAGES_UPLOAD = API_IMAGES_UPLOAD;
|
|
var API_RENDER_PAGES = 'renderPages';
|
|
exports.API_RENDER_PAGES = API_RENDER_PAGES;
|
|
var API_INIT = 'blogInit';
|
|
exports.API_INIT = API_INIT;
|
|
var API_INIT_GOOD = 'blogInitGood';
|
|
exports.API_INIT_GOOD = API_INIT_GOOD;
|
|
var API_INIT_LAME = 'blogInitLame';
|
|
exports.API_INIT_LAME = API_INIT_LAME;
|
|
var SEND_MAIL = 'sendMail';
|
|
exports.SEND_MAIL = SEND_MAIL;
|
|
|
|
var DataEvent = function DataEvent() {
|
|
_classCallCheck(this, DataEvent);
|
|
};
|
|
|
|
var _default = new DataEvent();
|
|
|
|
exports.default = _default;
|
|
},{}],"../libraries/FipamoAPI.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = exports.API_GET_PAGE = exports.API_GET_PAGES = exports.API_LOGIN = exports.API_INIT = exports.API_STATUS = 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 DataEvent = _interopRequireWildcard(require("../com/events/DataEvent"));
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } 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 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 API_STATUS = '/api/v1/auth/status';
|
|
exports.API_STATUS = API_STATUS;
|
|
var API_INIT = '/api/v1/auth/init';
|
|
exports.API_INIT = API_INIT;
|
|
var API_LOGIN = '/api/v1/auth/login';
|
|
exports.API_LOGIN = API_LOGIN;
|
|
var API_GET_PAGES = '/api/v1/page/published';
|
|
exports.API_GET_PAGES = API_GET_PAGES;
|
|
var API_GET_PAGE = '/api/v1/page/single';
|
|
exports.API_GET_PAGE = API_GET_PAGE;
|
|
|
|
var APIUtils = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function APIUtils() {
|
|
_classCallCheck(this, APIUtils);
|
|
} //--------------------------
|
|
// public
|
|
//--------------------------
|
|
|
|
|
|
_createClass(APIUtils, [{
|
|
key: "login",
|
|
value: function login(data) {
|
|
var _this = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this._request(API_LOGIN, DataEvent.AUTH_STATUS, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "init",
|
|
value: function init(data) {
|
|
var _this2 = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this2._request(API_INIT, DataEvent.API_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "getPages",
|
|
value: function getPages(num) {
|
|
var _this3 = this;
|
|
|
|
var pageNum = num;
|
|
if (pageNum === null || pageNum === '' || !pageNum) pageNum = 1;
|
|
return new Promise(function (resolve, reject) {
|
|
_this3._request(API_GET_PAGES + '/' + pageNum, DataEvent.API_GET_PAGES, REQUEST_TYPE_GET).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "getPage",
|
|
value: function getPage(id) {
|
|
var _this4 = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this4._request(API_GET_PAGE + '/' + id, DataEvent.API_GET_PAGES, REQUEST_TYPE_GET).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
} //--------------------------
|
|
// private
|
|
//--------------------------
|
|
|
|
}, {
|
|
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 () {
|
|
if (request.status == 200) {
|
|
var response = JSON.parse(request['response']);
|
|
resolve(response);
|
|
} else {
|
|
var error = JSON.parse(request['response']);
|
|
reject(error);
|
|
}
|
|
};
|
|
|
|
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();
|
|
}
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handleLoadProgress",
|
|
value: function handleLoadProgress(e) {
|
|
this.percentComplete = Math.ceil(e.loaded / e.total * 100); //pass element to display request progress
|
|
}
|
|
}]);
|
|
|
|
return APIUtils;
|
|
}();
|
|
|
|
exports.default = APIUtils;
|
|
},{"../com/events/DataEvent":"events/DataEvent.js"}],"utils/DataUtils.js":[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 DataUtils = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function DataUtils() {
|
|
_classCallCheck(this, DataUtils);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(DataUtils, [{
|
|
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 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);
|
|
});
|
|
});
|
|
}
|
|
/**
|
|
* Create a function to convert the serialize and convert the form data to JSON
|
|
* @param : $('#form_example');
|
|
* @return a JSON Stringify
|
|
*/
|
|
|
|
}, {
|
|
key: "formDataToJSON",
|
|
value: function formDataToJSON(form) {
|
|
var object = {};
|
|
var formData = new FormData(form);
|
|
formData.forEach(function (value, key) {
|
|
if (!object.hasOwnProperty(key)) {
|
|
object[key] = value;
|
|
return;
|
|
}
|
|
|
|
if (!Array.isArray(object[key])) {
|
|
object[key] = [object[key]];
|
|
}
|
|
|
|
object[key].push(value);
|
|
}); //let json = JSON.stringify(object);
|
|
|
|
return object;
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return DataUtils;
|
|
}();
|
|
|
|
exports.default = DataUtils;
|
|
},{}],"../libraries/FipamoAdminAPI.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = exports.API_SEND_MAIL = exports.API_NAV_SYNC = exports.API_PUBLISH_PAGES = exports.API_UPLOAD_BACKGROUND = exports.API_UPLOAD_AVATAR = exports.API_SETTINGS_SYNC = exports.API_IMAGE_UPLOAD = exports.API_DELETE_PAGE = exports.API_EDIT_PAGE = exports.API_NEW_PAGE = exports.API_GET_NAV = exports.API_STATUS = exports.CONTENT_TYPE_FORM = exports.CONTENT_TYPE_JSON = exports.TASK_PAGE_DELETE = exports.TASK_PAGE_EDIT = exports.TASK_PAGE_CREATE = exports.REQUEST_TYPE_DELETE = exports.REQUEST_TYPE_PUT = exports.REQUEST_TYPE_GET = exports.REQUEST_TYPE_POST = void 0;
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../com/events/DataEvent"));
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } 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 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 TASK_PAGE_CREATE = 'createNewPage';
|
|
exports.TASK_PAGE_CREATE = TASK_PAGE_CREATE;
|
|
var TASK_PAGE_EDIT = 'editPage';
|
|
exports.TASK_PAGE_EDIT = TASK_PAGE_EDIT;
|
|
var TASK_PAGE_DELETE = 'deletePage';
|
|
exports.TASK_PAGE_DELETE = TASK_PAGE_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 API_STATUS = '/api/v1/auth/status';
|
|
exports.API_STATUS = API_STATUS;
|
|
var API_GET_NAV = '/api/settings/nav';
|
|
exports.API_GET_NAV = API_GET_NAV;
|
|
var API_NEW_PAGE = '/api/v1/page/write/new';
|
|
exports.API_NEW_PAGE = API_NEW_PAGE;
|
|
var API_EDIT_PAGE = '/api/v1/page/write';
|
|
exports.API_EDIT_PAGE = API_EDIT_PAGE;
|
|
var API_DELETE_PAGE = '/api/v1/page/delete';
|
|
exports.API_DELETE_PAGE = API_DELETE_PAGE;
|
|
var API_IMAGE_UPLOAD = '/api/v1/page/add-post-image';
|
|
exports.API_IMAGE_UPLOAD = API_IMAGE_UPLOAD;
|
|
var API_SETTINGS_SYNC = '/api/v1/settings/sync';
|
|
exports.API_SETTINGS_SYNC = API_SETTINGS_SYNC;
|
|
var API_UPLOAD_AVATAR = '/api/v1/settings/add-avatar';
|
|
exports.API_UPLOAD_AVATAR = API_UPLOAD_AVATAR;
|
|
var API_UPLOAD_BACKGROUND = '/api/v1/settings/add-feature-background';
|
|
exports.API_UPLOAD_BACKGROUND = API_UPLOAD_BACKGROUND;
|
|
var API_PUBLISH_PAGES = '/api/v1/settings/publish-pages';
|
|
exports.API_PUBLISH_PAGES = API_PUBLISH_PAGES;
|
|
var API_NAV_SYNC = '/api/v1/settings/nav-sync';
|
|
exports.API_NAV_SYNC = API_NAV_SYNC;
|
|
var API_SEND_MAIL = '/api/v1/mailer';
|
|
exports.API_SEND_MAIL = API_SEND_MAIL;
|
|
|
|
var APIUtils = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function APIUtils() {
|
|
var _this = this;
|
|
|
|
_classCallCheck(this, APIUtils);
|
|
|
|
this.percentComplete = 0;
|
|
this.token = null; //checks backend to see if user is logged in
|
|
//and requests encrypted token for api calls
|
|
|
|
this._request(API_STATUS).then(function (response) {
|
|
if (response.type === DataEvent.API_REQUEST_GOOD) {
|
|
_this.token = response.token;
|
|
} else {//don't set token
|
|
}
|
|
});
|
|
} //--------------------------
|
|
// public
|
|
//--------------------------
|
|
|
|
|
|
_createClass(APIUtils, [{
|
|
key: "syncSettings",
|
|
value: function syncSettings(data) {
|
|
var _this2 = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this2._request(API_SETTINGS_SYNC, DataEvent.API_SETTINGS_WRITE, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "imageUpload",
|
|
value: function imageUpload(type, files) {
|
|
var _this3 = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
var url = '';
|
|
|
|
switch (type) {
|
|
case 'avatar-upload':
|
|
url = API_UPLOAD_AVATAR;
|
|
break;
|
|
|
|
case 'background-upload':
|
|
url = API_UPLOAD_BACKGROUND;
|
|
break;
|
|
|
|
default:
|
|
url = API_IMAGE_UPLOAD;
|
|
break;
|
|
}
|
|
|
|
var imageData = new FormData();
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
var file = files[i]; // Check the file type.
|
|
|
|
if (!file.type.match('image.*')) {
|
|
continue;
|
|
}
|
|
|
|
if (type === 'avatar-upload') {
|
|
imageData.append('avatar_upload', file, file.name);
|
|
} else if (type === 'background-upload') {
|
|
imageData.append('background_upload', file, file.name);
|
|
} else {
|
|
imageData.append('post_image', file, file.name);
|
|
}
|
|
}
|
|
|
|
_this3._request(url, DataEvent.API_IMAGES_UPLOAD, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData).then(function (r) {
|
|
resolve(r);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "publishSite",
|
|
value: function publishSite(data) {
|
|
var _this4 = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this4._request(API_PUBLISH_PAGES, DataEvent.API_RENDER_PAGES, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "pageActions",
|
|
value: function pageActions(task, data) {
|
|
var _this5 = this;
|
|
|
|
var url, event, content;
|
|
|
|
switch (task) {
|
|
case TASK_PAGE_CREATE:
|
|
url = API_NEW_PAGE;
|
|
event = DataEvent.API_PAGE_WRITE;
|
|
content = CONTENT_TYPE_FORM;
|
|
break;
|
|
|
|
case TASK_PAGE_EDIT:
|
|
url = API_EDIT_PAGE;
|
|
event = DataEvent.API_PAGE_WRITE;
|
|
content = CONTENT_TYPE_FORM;
|
|
break;
|
|
|
|
case TASK_PAGE_DELETE:
|
|
url = API_DELETE_PAGE;
|
|
event = DataEvent.API_PAGE_DELETE;
|
|
content = CONTENT_TYPE_JSON;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this5._request(url, event, REQUEST_TYPE_POST, content, data).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "syncNav",
|
|
value: function syncNav(data) {
|
|
var _this6 = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this6._request(API_NAV_SYNC, DataEvent.API_SETTINGS_WRITE, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
}, {
|
|
key: "sendMail",
|
|
value: function sendMail(message) {
|
|
var _this7 = this;
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
_this7._request(API_SEND_MAIL, DataEvent.SEND_MAIL, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, message).then(function (result) {
|
|
resolve(result);
|
|
}).catch(function (err) {
|
|
reject(err);
|
|
});
|
|
});
|
|
} //--------------------------
|
|
// private
|
|
//--------------------------
|
|
|
|
}, {
|
|
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 () {
|
|
if (request.status == 200) {
|
|
var response = JSON.parse(request['response']);
|
|
resolve(response);
|
|
} else {
|
|
var error = JSON.parse(request['response']);
|
|
reject(error);
|
|
}
|
|
};
|
|
|
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
|
if (eventType === DataEvent.API_PAGE_WRITE || eventType === DataEvent.API_IMAGES_UPLOAD || eventType === DataEvent.API_SETTINGS_WRITE || eventType === DataEvent.API_PAGE_DELETE || eventType === DataEvent.API_RENDER_PAGES) request.setRequestHeader('x-access-token', self.token);
|
|
|
|
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();
|
|
}
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handleLoadProgress",
|
|
value: function handleLoadProgress(e) {
|
|
this.percentComplete = Math.ceil(e.loaded / e.total * 100); //pass element to display request progress
|
|
}
|
|
}]);
|
|
|
|
return APIUtils;
|
|
}();
|
|
|
|
exports.default = APIUtils;
|
|
},{"../com/events/DataEvent":"events/DataEvent.js"}],"utils/StringUtils.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
|
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
|
|
var StringUtils = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function StringUtils() {
|
|
_classCallCheck(this, StringUtils);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(StringUtils, [{
|
|
key: "cleanString",
|
|
value: function cleanString(string) {
|
|
var clean = string.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g, '').toLowerCase().replace(/[\/_| -]+/g, '-');
|
|
return clean;
|
|
}
|
|
}, {
|
|
key: "decodeHTML",
|
|
value: function decodeHTML(string, quote_style) {
|
|
var optTemp = 0,
|
|
i = 0,
|
|
noquotes = false;
|
|
|
|
if (typeof quote_style === 'undefined') {
|
|
quote_style = 2;
|
|
}
|
|
|
|
string = string.toString().replace(/</g, '<').replace(/>/g, '>');
|
|
var OPTS = {
|
|
ENT_NOQUOTES: 0,
|
|
ENT_HTML_QUOTE_SINGLE: 1,
|
|
ENT_HTML_QUOTE_DOUBLE: 2,
|
|
ENT_COMPAT: 2,
|
|
ENT_QUOTES: 3,
|
|
ENT_IGNORE: 4
|
|
};
|
|
|
|
if (quote_style === 0) {
|
|
noquotes = true;
|
|
}
|
|
|
|
if (typeof quote_style !== 'number') {
|
|
// Allow for a single string or an array of string flags
|
|
quote_style = [].concat(quote_style);
|
|
|
|
for (i = 0; i < quote_style.length; i++) {
|
|
// Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
|
|
if (OPTS[quote_style[i]] === 0) {
|
|
noquotes = true;
|
|
} else if (OPTS[quote_style[i]]) {
|
|
optTemp = optTemp | OPTS[quote_style[i]];
|
|
}
|
|
}
|
|
|
|
quote_style = optTemp;
|
|
}
|
|
|
|
if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
|
|
string = string.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
|
|
// string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
|
|
}
|
|
|
|
if (!noquotes) {
|
|
string = string.replace(/"/g, '"');
|
|
} // Put this in last place to avoid escape being double-decoded
|
|
|
|
|
|
string = string.replace(/&/g, '&');
|
|
return string;
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return StringUtils;
|
|
}();
|
|
|
|
var _default = StringUtils;
|
|
exports.default = _default;
|
|
},{}],"actions/PageActions.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _StringUtils = _interopRequireDefault(require("../utils/StringUtils"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var PostActions = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function PostActions() {
|
|
_classCallCheck(this, PostActions);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(PostActions, [{
|
|
key: "collectInfo",
|
|
value: function collectInfo(image) {
|
|
return new Promise(function (resolve, reject) {
|
|
var pageInfo = new FormData();
|
|
var txt = document.createElement('textarea');
|
|
txt.innerHTML = document.getElementById('edit-post-text').innerHTML;
|
|
var html = txt.value; //html = html.replace(/<\/?span[^>]*>/g, ''); //removes highightjs styling
|
|
|
|
html = html.replace(/<\/?br[^>]*>/g, '\n'); //convert back to encoded line break for storage
|
|
|
|
pageInfo.append('id', document.getElementById('post-edit-index').getAttribute('data-index'));
|
|
pageInfo.append('uuid', document.getElementById('post-edit-index').getAttribute('data-uuid'));
|
|
pageInfo.append('layout', document.getElementById('post-edit-index').getAttribute('data-layout'));
|
|
pageInfo.append('current_title', document.getElementById('post-edit-index').getAttribute('data-slug'));
|
|
pageInfo.append('content', html);
|
|
pageInfo.append('title', document.getElementById('post_title').value);
|
|
pageInfo.append('created', document.getElementById('post-date').getAttribute('data-raw'));
|
|
pageInfo.append('slug', new _StringUtils.default().cleanString(document.getElementById('post_title').value));
|
|
pageInfo.append('tags', document.getElementById('post_tags').value);
|
|
pageInfo.append('menu', document.getElementById('option-menu-pin').getAttribute('data-active'));
|
|
pageInfo.append('featured', document.getElementById('option-feature').getAttribute('data-active'));
|
|
pageInfo.append('published', document.getElementById('option-published').getAttribute('data-active'));
|
|
|
|
if (image != null || image != undefined) {
|
|
if (image.type.match('image.*')) {
|
|
pageInfo.append('feature_image', image, image.name);
|
|
} else {
|
|
reject('Not an image file');
|
|
}
|
|
} else {
|
|
//check to see if image exists
|
|
var imageURL = document.getElementById('featured-image').src;
|
|
imageURL != null || imageURL != undefined ? pageInfo.append('feature_image', imageURL) : pageInfo.append('feature_image', null);
|
|
}
|
|
|
|
resolve(pageInfo);
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return PostActions;
|
|
}();
|
|
|
|
exports.default = PostActions;
|
|
},{"../utils/StringUtils":"utils/StringUtils.js"}],"events/EditorEvent.js":[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;
|
|
},{}],"../../node_modules/caret-pos/lib/esm2015/main.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.getOffset = exports.offset = exports.position = void 0;
|
|
var attributes = ['borderBottomWidth', 'borderLeftWidth', 'borderRightWidth', 'borderTopStyle', 'borderRightStyle', 'borderBottomStyle', 'borderLeftStyle', 'borderTopWidth', 'boxSizing', 'fontFamily', 'fontSize', 'fontWeight', 'height', 'letterSpacing', 'lineHeight', 'marginBottom', 'marginLeft', 'marginRight', 'marginTop', 'outlineWidth', 'overflow', 'overflowX', 'overflowY', 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop', 'textAlign', 'textOverflow', 'textTransform', 'whiteSpace', 'wordBreak', 'wordWrap'];
|
|
/**
|
|
* Create a mirror
|
|
*
|
|
* @param {Element} element The element
|
|
* @param {string} html The html
|
|
*
|
|
* @return {object} The mirror object
|
|
*/
|
|
|
|
var createMirror = function createMirror(element, html) {
|
|
/**
|
|
* The mirror element
|
|
*/
|
|
var mirror = document.createElement('div');
|
|
/**
|
|
* Create the CSS for the mirror object
|
|
*
|
|
* @return {object} The style object
|
|
*/
|
|
|
|
var mirrorCss = function mirrorCss() {
|
|
var css = {
|
|
position: 'absolute',
|
|
left: -9999,
|
|
top: 0,
|
|
zIndex: -2000
|
|
};
|
|
|
|
if (element.tagName === 'TEXTAREA') {
|
|
attributes.push('width');
|
|
}
|
|
|
|
attributes.forEach(function (attr) {
|
|
css[attr] = getComputedStyle(element)[attr];
|
|
});
|
|
return css;
|
|
};
|
|
/**
|
|
* Initialize the mirror
|
|
*
|
|
* @param {string} html The html
|
|
*
|
|
* @return {void}
|
|
*/
|
|
|
|
|
|
var initialize = function initialize(html) {
|
|
var styles = mirrorCss();
|
|
Object.keys(styles).forEach(function (key) {
|
|
mirror.style[key] = styles[key];
|
|
});
|
|
mirror.innerHTML = html;
|
|
element.parentNode.insertBefore(mirror, element.nextSibling);
|
|
};
|
|
/**
|
|
* Get the rect
|
|
*
|
|
* @return {Rect} The bounding rect
|
|
*/
|
|
|
|
|
|
var rect = function rect() {
|
|
var marker = mirror.ownerDocument.getElementById('caret-position-marker');
|
|
var boundingRect = {
|
|
left: marker.offsetLeft,
|
|
top: marker.offsetTop,
|
|
height: marker.offsetHeight
|
|
};
|
|
mirror.parentNode.removeChild(mirror);
|
|
return boundingRect;
|
|
};
|
|
|
|
initialize(html);
|
|
return {
|
|
rect: rect
|
|
};
|
|
};
|
|
|
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
|
return typeof obj;
|
|
} : function (obj) {
|
|
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
};
|
|
/**
|
|
* Check if a DOM Element is content editable
|
|
*
|
|
* @param {Element} element The DOM element
|
|
*
|
|
* @return {bool} If it is content editable
|
|
*/
|
|
|
|
|
|
var isContentEditable = function isContentEditable(element) {
|
|
return !!(element.contentEditable ? element.contentEditable === 'true' : element.getAttribute('contenteditable') === 'true');
|
|
};
|
|
/**
|
|
* Get the context from settings passed in
|
|
*
|
|
* @param {object} settings The settings object
|
|
*
|
|
* @return {object} window and document
|
|
*/
|
|
|
|
|
|
var getContext = function getContext() {
|
|
var settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
var customPos = settings.customPos,
|
|
iframe = settings.iframe,
|
|
noShadowCaret = settings.noShadowCaret;
|
|
|
|
if (iframe) {
|
|
return {
|
|
iframe: iframe,
|
|
window: iframe.contentWindow,
|
|
document: iframe.contentDocument || iframe.contentWindow.document,
|
|
noShadowCaret: noShadowCaret,
|
|
customPos: customPos
|
|
};
|
|
}
|
|
|
|
return {
|
|
window: window,
|
|
document: document,
|
|
noShadowCaret: noShadowCaret,
|
|
customPos: customPos
|
|
};
|
|
};
|
|
/**
|
|
* Get the offset of an element
|
|
*
|
|
* @param {Element} element The DOM element
|
|
* @param {object} ctx The context
|
|
*
|
|
* @return {object} top and left
|
|
*/
|
|
|
|
|
|
var getOffset = function getOffset(element, ctx) {
|
|
var win = ctx && ctx.window || window;
|
|
var doc = ctx && ctx.document || document;
|
|
var rect = element.getBoundingClientRect();
|
|
var docEl = doc.documentElement;
|
|
var scrollLeft = win.pageXOffset || docEl.scrollLeft;
|
|
var scrollTop = win.pageYOffset || docEl.scrollTop;
|
|
return {
|
|
top: rect.top + scrollTop,
|
|
left: rect.left + scrollLeft
|
|
};
|
|
};
|
|
/**
|
|
* Check if a value is an object
|
|
*
|
|
* @param {any} value The value to check
|
|
*
|
|
* @return {bool} If it is an object
|
|
*/
|
|
|
|
|
|
exports.getOffset = getOffset;
|
|
|
|
var isObject = function isObject(value) {
|
|
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null;
|
|
};
|
|
/**
|
|
* Create a Input caret object.
|
|
*
|
|
* @param {Element} element The element
|
|
* @param {Object} ctx The context
|
|
*/
|
|
|
|
|
|
var createInputCaret = function createInputCaret(element, ctx) {
|
|
/**
|
|
* Get the current position
|
|
*
|
|
* @returns {int} The caret position
|
|
*/
|
|
var getPos = function getPos() {
|
|
return element.selectionStart;
|
|
};
|
|
/**
|
|
* Set the position
|
|
*
|
|
* @param {int} pos The position
|
|
*
|
|
* @return {Element} The element
|
|
*/
|
|
|
|
|
|
var setPos = function setPos(pos) {
|
|
element.setSelectionRange(pos, pos);
|
|
return element;
|
|
};
|
|
/**
|
|
* The offset
|
|
*
|
|
* @param {int} pos The position
|
|
*
|
|
* @return {object} The offset
|
|
*/
|
|
|
|
|
|
var getOffset$$1 = function getOffset$$1(pos) {
|
|
var rect = getOffset(element);
|
|
var position = getPosition(pos);
|
|
return {
|
|
top: rect.top + position.top + ctx.document.body.scrollTop,
|
|
left: rect.left + position.left + ctx.document.body.scrollLeft,
|
|
height: position.height
|
|
};
|
|
};
|
|
/**
|
|
* Get the current position
|
|
*
|
|
* @param {int} pos The position
|
|
*
|
|
* @return {object} The position
|
|
*/
|
|
|
|
|
|
var getPosition = function getPosition(pos) {
|
|
var format = function format(val) {
|
|
var value = val.replace(/<|>|`|"|&/g, '?').replace(/\r\n|\r|\n/g, '<br/>');
|
|
return value;
|
|
};
|
|
|
|
if (ctx.customPos || ctx.customPos === 0) {
|
|
pos = ctx.customPos;
|
|
}
|
|
|
|
var position = pos === undefined ? getPos() : pos;
|
|
var startRange = element.value.slice(0, position);
|
|
var endRange = element.value.slice(position);
|
|
var html = '<span style="position: relative; display: inline;">' + format(startRange) + '</span>';
|
|
html += '<span id="caret-position-marker" style="position: relative; display: inline;">|</span>';
|
|
html += '<span style="position: relative; display: inline;">' + format(endRange) + '</span>';
|
|
var mirror = createMirror(element, html);
|
|
var rect = mirror.rect();
|
|
rect.pos = getPos();
|
|
return rect;
|
|
};
|
|
|
|
return {
|
|
getPos: getPos,
|
|
setPos: setPos,
|
|
getOffset: getOffset$$1,
|
|
getPosition: getPosition
|
|
};
|
|
};
|
|
/**
|
|
* Create an Editable Caret
|
|
* @param {Element} element The editable element
|
|
* @param {object|null} ctx The context
|
|
*
|
|
* @return {EditableCaret}
|
|
*/
|
|
|
|
|
|
var createEditableCaret = function createEditableCaret(element, ctx) {
|
|
/**
|
|
* Set the caret position
|
|
*
|
|
* @param {int} pos The position to se
|
|
*
|
|
* @return {Element} The element
|
|
*/
|
|
var setPos = function setPos(pos) {
|
|
var sel = ctx.window.getSelection();
|
|
|
|
if (sel) {
|
|
var offset = 0;
|
|
var found = false;
|
|
|
|
var find = function find(position, parent) {
|
|
for (var i = 0; i < parent.childNodes.length; i++) {
|
|
var node = parent.childNodes[i];
|
|
|
|
if (found) {
|
|
break;
|
|
}
|
|
|
|
if (node.nodeType === 3) {
|
|
if (offset + node.length >= position) {
|
|
found = true;
|
|
var range = ctx.document.createRange();
|
|
range.setStart(node, position - offset);
|
|
sel.removeAllRanges();
|
|
sel.addRange(range);
|
|
break;
|
|
} else {
|
|
offset += node.length;
|
|
}
|
|
} else {
|
|
find(pos, node);
|
|
}
|
|
}
|
|
};
|
|
|
|
find(pos, element);
|
|
}
|
|
|
|
return element;
|
|
};
|
|
/**
|
|
* Get the offset
|
|
*
|
|
* @return {object} The offset
|
|
*/
|
|
|
|
|
|
var getOffset = function getOffset() {
|
|
var range = getRange();
|
|
var offset = {
|
|
height: 0,
|
|
left: 0,
|
|
right: 0
|
|
};
|
|
|
|
if (!range) {
|
|
return offset;
|
|
}
|
|
|
|
var hasCustomPos = ctx.customPos || ctx.customPos === 0; // endContainer in Firefox would be the element at the start of
|
|
// the line
|
|
|
|
if (range.endOffset - 1 > 0 && range.endContainer !== element || hasCustomPos) {
|
|
var clonedRange = range.cloneRange();
|
|
var fixedPosition = hasCustomPos ? ctx.customPos : range.endOffset;
|
|
clonedRange.setStart(range.endContainer, fixedPosition - 1 < 0 ? 0 : fixedPosition - 1);
|
|
clonedRange.setEnd(range.endContainer, fixedPosition);
|
|
var rect = clonedRange.getBoundingClientRect();
|
|
offset = {
|
|
height: rect.height,
|
|
left: rect.left + rect.width,
|
|
top: rect.top
|
|
};
|
|
clonedRange.detach();
|
|
}
|
|
|
|
if ((!offset || offset && offset.height === 0) && !ctx.noShadowCaret) {
|
|
var _clonedRange = range.cloneRange();
|
|
|
|
var shadowCaret = ctx.document.createTextNode('|');
|
|
|
|
_clonedRange.insertNode(shadowCaret);
|
|
|
|
_clonedRange.selectNode(shadowCaret);
|
|
|
|
var _rect = _clonedRange.getBoundingClientRect();
|
|
|
|
offset = {
|
|
height: _rect.height,
|
|
left: _rect.left,
|
|
top: _rect.top
|
|
};
|
|
shadowCaret.parentNode.removeChild(shadowCaret);
|
|
|
|
_clonedRange.detach();
|
|
}
|
|
|
|
if (offset) {
|
|
var doc = ctx.document.documentElement;
|
|
offset.top += ctx.window.pageYOffset - (doc.clientTop || 0);
|
|
offset.left += ctx.window.pageXOffset - (doc.clientLeft || 0);
|
|
}
|
|
|
|
return offset;
|
|
};
|
|
/**
|
|
* Get the position
|
|
*
|
|
* @return {object} The position
|
|
*/
|
|
|
|
|
|
var getPosition = function getPosition() {
|
|
var offset = getOffset();
|
|
var pos = getPos();
|
|
var rect = element.getBoundingClientRect();
|
|
var inputOffset = {
|
|
top: rect.top + ctx.document.body.scrollTop,
|
|
left: rect.left + ctx.document.body.scrollLeft
|
|
};
|
|
offset.left -= inputOffset.left;
|
|
offset.top -= inputOffset.top;
|
|
offset.pos = pos;
|
|
return offset;
|
|
};
|
|
/**
|
|
* Get the range
|
|
*
|
|
* @return {Range|null}
|
|
*/
|
|
|
|
|
|
var getRange = function getRange() {
|
|
if (!ctx.window.getSelection) {
|
|
return;
|
|
}
|
|
|
|
var sel = ctx.window.getSelection();
|
|
return sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
|
|
};
|
|
/**
|
|
* Get the caret position
|
|
*
|
|
* @return {int} The position
|
|
*/
|
|
|
|
|
|
var getPos = function getPos() {
|
|
var range = getRange();
|
|
var clonedRange = range.cloneRange();
|
|
clonedRange.selectNodeContents(element);
|
|
clonedRange.setEnd(range.endContainer, range.endOffset);
|
|
var pos = clonedRange.toString().length;
|
|
clonedRange.detach();
|
|
return pos;
|
|
};
|
|
|
|
return {
|
|
getPos: getPos,
|
|
setPos: setPos,
|
|
getPosition: getPosition,
|
|
getOffset: getOffset,
|
|
getRange: getRange
|
|
};
|
|
};
|
|
|
|
var createCaret = function createCaret(element, ctx) {
|
|
if (isContentEditable(element)) {
|
|
return createEditableCaret(element, ctx);
|
|
}
|
|
|
|
return createInputCaret(element, ctx);
|
|
};
|
|
|
|
var position = function position(element, value) {
|
|
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
var options = settings;
|
|
|
|
if (isObject(value)) {
|
|
options = value;
|
|
value = null;
|
|
}
|
|
|
|
var ctx = getContext(options);
|
|
var caret = createCaret(element, ctx);
|
|
|
|
if (value || value === 0) {
|
|
return caret.setPos(value);
|
|
}
|
|
|
|
return caret.getPosition();
|
|
};
|
|
/**
|
|
*
|
|
* @param {Element} element The DOM element
|
|
* @param {number|undefined} value The value to set
|
|
* @param {object} settings Any settings for context
|
|
*/
|
|
|
|
|
|
exports.position = position;
|
|
|
|
var offset = function offset(element, value) {
|
|
var settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
var options = settings;
|
|
|
|
if (isObject(value)) {
|
|
options = value;
|
|
value = null;
|
|
}
|
|
|
|
var ctx = getContext(options);
|
|
var caret = createCaret(element, ctx);
|
|
return caret.getOffset(value);
|
|
};
|
|
|
|
exports.offset = offset;
|
|
},{}],"events/EventEmitter.js":[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;
|
|
},{}],"ui/TextEditor.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../events/DataEvent"));
|
|
|
|
var _caretPos = require("caret-pos");
|
|
|
|
var _EventEmitter2 = _interopRequireDefault(require("../events/EventEmitter"));
|
|
|
|
var EditorEvent = _interopRequireWildcard(require("../events/EditorEvent"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; 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 _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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
|
|
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 _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
|
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
|
|
var TextEditor = /*#__PURE__*/function (_EventEmitter) {
|
|
_inherits(TextEditor, _EventEmitter);
|
|
|
|
var _super = _createSuper(TextEditor);
|
|
|
|
/**
|
|
* Text Editor UI Component
|
|
* @constructor
|
|
* @param {object} textEditor - Text area that will edit text
|
|
* @param {number} scrollLimit - YPos where editor position will become fixed
|
|
*/
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function TextEditor(textEditor, scrollLimit) {
|
|
var _this;
|
|
|
|
_classCallCheck(this, TextEditor);
|
|
|
|
_this = _super.call(this); //hljs.initHighlightingOnLoad();
|
|
|
|
_this.textEditor = textEditor;
|
|
_this.fixLimit = scrollLimit;
|
|
_this.caretPos = null;
|
|
_this.url = '';
|
|
|
|
_this.setInputs();
|
|
|
|
window.addEventListener('scroll', function () {//var fixLimit = this.fixLimit;
|
|
|
|
/**
|
|
* edit scroller needs work
|
|
if (window.pageYOffset >= fixLimit) {
|
|
document.getElementById('edit-control').style.position = 'fixed';
|
|
} else {
|
|
document.getElementById('edit-control').style.position = 'relative';
|
|
}
|
|
*/
|
|
});
|
|
|
|
_this.refresh();
|
|
|
|
return _this;
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(TextEditor, [{
|
|
key: "setInputs",
|
|
value: function setInputs() {
|
|
var _this2 = this;
|
|
|
|
var self = this;
|
|
var editorButtons = document.querySelectorAll('.editor-button');
|
|
|
|
for (var i = 0, length = editorButtons.length; i < length; i++) {
|
|
editorButtons[i].addEventListener('click', function (e) {
|
|
return _this2.handleEditorOption(e);
|
|
}, false);
|
|
}
|
|
|
|
this.textEditor.addEventListener('input', function (e) {
|
|
var htmlTagRe = /<[a-z][\s\S]*>/g;
|
|
var text = _this2.textEditor.innerText;
|
|
if (e.inputType == 'insertParagraph') return; //cursor setting gets weird on return, so just back out
|
|
|
|
if (text.search(htmlTagRe) > -1) {
|
|
var caret = (0, _caretPos.position)(_this2.textEditor).pos;
|
|
self.refresh();
|
|
(0, _caretPos.position)(_this2.textEditor, caret);
|
|
}
|
|
});
|
|
}
|
|
}, {
|
|
key: "refresh",
|
|
value: function refresh() {
|
|
//var spiffed = hljs.highlight('markdown', this.textEditor.innerText).value;
|
|
var spiffed = this.textEditor.innerText;
|
|
spiffed = spiffed.replace(new RegExp('\r?\n', 'g'), '<br>');
|
|
var temp = document.createElement('div');
|
|
temp.innerText = spiffed;
|
|
this.textEditor.innerHTML = temp.innerText;
|
|
this.textEditor.style.maxWidth = '900px';
|
|
}
|
|
}, {
|
|
key: "notify",
|
|
value: function notify(type, data) {
|
|
switch (type) {
|
|
case DataEvent.POST_UPDATED:
|
|
document.getElementById('submit-update').classList.add('icon-hide');
|
|
document.getElementById('submit-good').classList.remove('icon-hide');
|
|
document.getElementById('edit-update').classList.remove('submit-start');
|
|
document.getElementById('edit-update').classList.add('submit-cool');
|
|
setTimeout(function () {
|
|
document.getElementById('submit-update').classList.remove('icon-hide');
|
|
document.getElementById('submit-good').classList.add('icon-hide');
|
|
document.getElementById('edit-update').classList.add('submit-start');
|
|
document.getElementById('edit-update').classList.remove('submit-cool');
|
|
}, 2000);
|
|
break;
|
|
|
|
case DataEvent.POST_ADDED:
|
|
// do nothing
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
(0, _caretPos.position)(this.textEditor, this.caretPos);
|
|
var sel, range; //var pulled;
|
|
|
|
sel = window.getSelection(); //console.log(sel)
|
|
//console.log(note.message)
|
|
|
|
if (sel.rangeCount) {
|
|
range = sel.getRangeAt(0); //pulled = sel.getRangeAt(0).toString();
|
|
|
|
range.deleteContents();
|
|
range.insertNode(document.createTextNode('![image alt text](' + data + " 'image title')"));
|
|
}
|
|
|
|
this.refresh();
|
|
break;
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handleEditorOption",
|
|
value: function handleEditorOption(e) {
|
|
e.preventDefault();
|
|
var sel, range, pulled;
|
|
sel = window.getSelection(); //console.log(sel)
|
|
|
|
if (sel.rangeCount) {
|
|
range = sel.getRangeAt(0);
|
|
pulled = sel.getRangeAt(0).toString();
|
|
range.deleteContents();
|
|
|
|
switch (e.target.id) {
|
|
case 'edit-bold':
|
|
range.insertNode(document.createTextNode('**' + pulled + '**'));
|
|
break;
|
|
|
|
case 'edit-italic':
|
|
range.insertNode(document.createTextNode('*' + pulled + '*'));
|
|
break;
|
|
|
|
case 'edit-strikethrough':
|
|
range.insertNode(document.createTextNode('<del>' + pulled + '</del>'));
|
|
break;
|
|
|
|
case 'edit-header1':
|
|
range.insertNode(document.createTextNode('# ' + pulled));
|
|
break;
|
|
|
|
case 'edit-header2':
|
|
range.insertNode(document.createTextNode('## ' + pulled));
|
|
break;
|
|
|
|
case 'edit-header3':
|
|
range.insertNode(document.createTextNode('### ' + pulled));
|
|
break;
|
|
|
|
case 'edit-image':
|
|
this.caretPos = (0, _caretPos.position)(this.textEditor).pos;
|
|
this.emitEvent(EditorEvent.EDITOR_UPLOAD_POST_IMAGE);
|
|
break;
|
|
|
|
case 'submit-save':
|
|
case 'edit-save':
|
|
this.emitEvent(EditorEvent.EDITOR_SAVE);
|
|
break;
|
|
|
|
case 'submit-update':
|
|
case 'edit-update':
|
|
this.emitEvent(EditorEvent.EDITOR_UPDATE);
|
|
break;
|
|
|
|
case 'edit-link':
|
|
range.insertNode(document.createTextNode('[' + pulled + '](PASTE URL HERE)'));
|
|
break;
|
|
|
|
case 'edit-delete':
|
|
this.emitEvent(EditorEvent.EDITOR_DELETE);
|
|
break;
|
|
|
|
default:
|
|
//range.insertNode(document.createTextNode("[" + self.url + "](PASTE URL HERE)"));
|
|
break;
|
|
}
|
|
}
|
|
|
|
this.refresh();
|
|
}
|
|
}]);
|
|
|
|
return TextEditor;
|
|
}(_EventEmitter2.default);
|
|
|
|
var _default = TextEditor;
|
|
exports.default = _default;
|
|
},{"../events/DataEvent":"events/DataEvent.js","caret-pos":"../../node_modules/caret-pos/lib/esm2015/main.js","../events/EventEmitter":"events/EventEmitter.js","../events/EditorEvent":"events/EditorEvent.js"}],"../../node_modules/animejs/lib/anime.es.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
/*
|
|
* anime.js v3.2.0
|
|
* (c) 2020 Julian Garnier
|
|
* Released under the MIT license
|
|
* animejs.com
|
|
*/
|
|
// Defaults
|
|
var defaultInstanceSettings = {
|
|
update: null,
|
|
begin: null,
|
|
loopBegin: null,
|
|
changeBegin: null,
|
|
change: null,
|
|
changeComplete: null,
|
|
loopComplete: null,
|
|
complete: null,
|
|
loop: 1,
|
|
direction: 'normal',
|
|
autoplay: true,
|
|
timelineOffset: 0
|
|
};
|
|
var defaultTweenSettings = {
|
|
duration: 1000,
|
|
delay: 0,
|
|
endDelay: 0,
|
|
easing: 'easeOutElastic(1, .5)',
|
|
round: 0
|
|
};
|
|
var validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skew', 'skewX', 'skewY', 'perspective', 'matrix', 'matrix3d']; // Caching
|
|
|
|
var cache = {
|
|
CSS: {},
|
|
springs: {}
|
|
}; // Utils
|
|
|
|
function minMax(val, min, max) {
|
|
return Math.min(Math.max(val, min), max);
|
|
}
|
|
|
|
function stringContains(str, text) {
|
|
return str.indexOf(text) > -1;
|
|
}
|
|
|
|
function applyArguments(func, args) {
|
|
return func.apply(null, args);
|
|
}
|
|
|
|
var is = {
|
|
arr: function (a) {
|
|
return Array.isArray(a);
|
|
},
|
|
obj: function (a) {
|
|
return stringContains(Object.prototype.toString.call(a), 'Object');
|
|
},
|
|
pth: function (a) {
|
|
return is.obj(a) && a.hasOwnProperty('totalLength');
|
|
},
|
|
svg: function (a) {
|
|
return a instanceof SVGElement;
|
|
},
|
|
inp: function (a) {
|
|
return a instanceof HTMLInputElement;
|
|
},
|
|
dom: function (a) {
|
|
return a.nodeType || is.svg(a);
|
|
},
|
|
str: function (a) {
|
|
return typeof a === 'string';
|
|
},
|
|
fnc: function (a) {
|
|
return typeof a === 'function';
|
|
},
|
|
und: function (a) {
|
|
return typeof a === 'undefined';
|
|
},
|
|
hex: function (a) {
|
|
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a);
|
|
},
|
|
rgb: function (a) {
|
|
return /^rgb/.test(a);
|
|
},
|
|
hsl: function (a) {
|
|
return /^hsl/.test(a);
|
|
},
|
|
col: function (a) {
|
|
return is.hex(a) || is.rgb(a) || is.hsl(a);
|
|
},
|
|
key: function (a) {
|
|
return !defaultInstanceSettings.hasOwnProperty(a) && !defaultTweenSettings.hasOwnProperty(a) && a !== 'targets' && a !== 'keyframes';
|
|
}
|
|
}; // Easings
|
|
|
|
function parseEasingParameters(string) {
|
|
var match = /\(([^)]+)\)/.exec(string);
|
|
return match ? match[1].split(',').map(function (p) {
|
|
return parseFloat(p);
|
|
}) : [];
|
|
} // Spring solver inspired by Webkit Copyright © 2016 Apple Inc. All rights reserved. https://webkit.org/demos/spring/spring.js
|
|
|
|
|
|
function spring(string, duration) {
|
|
var params = parseEasingParameters(string);
|
|
var mass = minMax(is.und(params[0]) ? 1 : params[0], .1, 100);
|
|
var stiffness = minMax(is.und(params[1]) ? 100 : params[1], .1, 100);
|
|
var damping = minMax(is.und(params[2]) ? 10 : params[2], .1, 100);
|
|
var velocity = minMax(is.und(params[3]) ? 0 : params[3], .1, 100);
|
|
var w0 = Math.sqrt(stiffness / mass);
|
|
var zeta = damping / (2 * Math.sqrt(stiffness * mass));
|
|
var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0;
|
|
var a = 1;
|
|
var b = zeta < 1 ? (zeta * w0 + -velocity) / wd : -velocity + w0;
|
|
|
|
function solver(t) {
|
|
var progress = duration ? duration * t / 1000 : t;
|
|
|
|
if (zeta < 1) {
|
|
progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress));
|
|
} else {
|
|
progress = (a + b * progress) * Math.exp(-progress * w0);
|
|
}
|
|
|
|
if (t === 0 || t === 1) {
|
|
return t;
|
|
}
|
|
|
|
return 1 - progress;
|
|
}
|
|
|
|
function getDuration() {
|
|
var cached = cache.springs[string];
|
|
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
|
|
var frame = 1 / 6;
|
|
var elapsed = 0;
|
|
var rest = 0;
|
|
|
|
while (true) {
|
|
elapsed += frame;
|
|
|
|
if (solver(elapsed) === 1) {
|
|
rest++;
|
|
|
|
if (rest >= 16) {
|
|
break;
|
|
}
|
|
} else {
|
|
rest = 0;
|
|
}
|
|
}
|
|
|
|
var duration = elapsed * frame * 1000;
|
|
cache.springs[string] = duration;
|
|
return duration;
|
|
}
|
|
|
|
return duration ? solver : getDuration;
|
|
} // Basic steps easing implementation https://developer.mozilla.org/fr/docs/Web/CSS/transition-timing-function
|
|
|
|
|
|
function steps(steps) {
|
|
if (steps === void 0) steps = 10;
|
|
return function (t) {
|
|
return Math.ceil(minMax(t, 0.000001, 1) * steps) * (1 / steps);
|
|
};
|
|
} // BezierEasing https://github.com/gre/bezier-easing
|
|
|
|
|
|
var bezier = function () {
|
|
var kSplineTableSize = 11;
|
|
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
|
|
|
function A(aA1, aA2) {
|
|
return 1.0 - 3.0 * aA2 + 3.0 * aA1;
|
|
}
|
|
|
|
function B(aA1, aA2) {
|
|
return 3.0 * aA2 - 6.0 * aA1;
|
|
}
|
|
|
|
function C(aA1) {
|
|
return 3.0 * aA1;
|
|
}
|
|
|
|
function calcBezier(aT, aA1, aA2) {
|
|
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
|
|
}
|
|
|
|
function getSlope(aT, aA1, aA2) {
|
|
return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
|
|
}
|
|
|
|
function binarySubdivide(aX, aA, aB, mX1, mX2) {
|
|
var currentX,
|
|
currentT,
|
|
i = 0;
|
|
|
|
do {
|
|
currentT = aA + (aB - aA) / 2.0;
|
|
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
|
|
|
if (currentX > 0.0) {
|
|
aB = currentT;
|
|
} else {
|
|
aA = currentT;
|
|
}
|
|
} while (Math.abs(currentX) > 0.0000001 && ++i < 10);
|
|
|
|
return currentT;
|
|
}
|
|
|
|
function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
|
|
for (var i = 0; i < 4; ++i) {
|
|
var currentSlope = getSlope(aGuessT, mX1, mX2);
|
|
|
|
if (currentSlope === 0.0) {
|
|
return aGuessT;
|
|
}
|
|
|
|
var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
|
aGuessT -= currentX / currentSlope;
|
|
}
|
|
|
|
return aGuessT;
|
|
}
|
|
|
|
function bezier(mX1, mY1, mX2, mY2) {
|
|
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) {
|
|
return;
|
|
}
|
|
|
|
var sampleValues = new Float32Array(kSplineTableSize);
|
|
|
|
if (mX1 !== mY1 || mX2 !== mY2) {
|
|
for (var i = 0; i < kSplineTableSize; ++i) {
|
|
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
|
}
|
|
}
|
|
|
|
function getTForX(aX) {
|
|
var intervalStart = 0;
|
|
var currentSample = 1;
|
|
var lastSample = kSplineTableSize - 1;
|
|
|
|
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
|
|
intervalStart += kSampleStepSize;
|
|
}
|
|
|
|
--currentSample;
|
|
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
|
var guessForT = intervalStart + dist * kSampleStepSize;
|
|
var initialSlope = getSlope(guessForT, mX1, mX2);
|
|
|
|
if (initialSlope >= 0.001) {
|
|
return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
|
} else if (initialSlope === 0.0) {
|
|
return guessForT;
|
|
} else {
|
|
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
|
|
}
|
|
}
|
|
|
|
return function (x) {
|
|
if (mX1 === mY1 && mX2 === mY2) {
|
|
return x;
|
|
}
|
|
|
|
if (x === 0 || x === 1) {
|
|
return x;
|
|
}
|
|
|
|
return calcBezier(getTForX(x), mY1, mY2);
|
|
};
|
|
}
|
|
|
|
return bezier;
|
|
}();
|
|
|
|
var penner = function () {
|
|
// Based on jQuery UI's implemenation of easing equations from Robert Penner (http://www.robertpenner.com/easing)
|
|
var eases = {
|
|
linear: function () {
|
|
return function (t) {
|
|
return t;
|
|
};
|
|
}
|
|
};
|
|
var functionEasings = {
|
|
Sine: function () {
|
|
return function (t) {
|
|
return 1 - Math.cos(t * Math.PI / 2);
|
|
};
|
|
},
|
|
Circ: function () {
|
|
return function (t) {
|
|
return 1 - Math.sqrt(1 - t * t);
|
|
};
|
|
},
|
|
Back: function () {
|
|
return function (t) {
|
|
return t * t * (3 * t - 2);
|
|
};
|
|
},
|
|
Bounce: function () {
|
|
return function (t) {
|
|
var pow2,
|
|
b = 4;
|
|
|
|
while (t < ((pow2 = Math.pow(2, --b)) - 1) / 11) {}
|
|
|
|
return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow((pow2 * 3 - 2) / 22 - t, 2);
|
|
};
|
|
},
|
|
Elastic: function (amplitude, period) {
|
|
if (amplitude === void 0) amplitude = 1;
|
|
if (period === void 0) period = .5;
|
|
var a = minMax(amplitude, 1, 10);
|
|
var p = minMax(period, .1, 2);
|
|
return function (t) {
|
|
return t === 0 || t === 1 ? t : -a * Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1 - p / (Math.PI * 2) * Math.asin(1 / a)) * (Math.PI * 2) / p);
|
|
};
|
|
}
|
|
};
|
|
var baseEasings = ['Quad', 'Cubic', 'Quart', 'Quint', 'Expo'];
|
|
baseEasings.forEach(function (name, i) {
|
|
functionEasings[name] = function () {
|
|
return function (t) {
|
|
return Math.pow(t, i + 2);
|
|
};
|
|
};
|
|
});
|
|
Object.keys(functionEasings).forEach(function (name) {
|
|
var easeIn = functionEasings[name];
|
|
eases['easeIn' + name] = easeIn;
|
|
|
|
eases['easeOut' + name] = function (a, b) {
|
|
return function (t) {
|
|
return 1 - easeIn(a, b)(1 - t);
|
|
};
|
|
};
|
|
|
|
eases['easeInOut' + name] = function (a, b) {
|
|
return function (t) {
|
|
return t < 0.5 ? easeIn(a, b)(t * 2) / 2 : 1 - easeIn(a, b)(t * -2 + 2) / 2;
|
|
};
|
|
};
|
|
});
|
|
return eases;
|
|
}();
|
|
|
|
function parseEasings(easing, duration) {
|
|
if (is.fnc(easing)) {
|
|
return easing;
|
|
}
|
|
|
|
var name = easing.split('(')[0];
|
|
var ease = penner[name];
|
|
var args = parseEasingParameters(easing);
|
|
|
|
switch (name) {
|
|
case 'spring':
|
|
return spring(easing, duration);
|
|
|
|
case 'cubicBezier':
|
|
return applyArguments(bezier, args);
|
|
|
|
case 'steps':
|
|
return applyArguments(steps, args);
|
|
|
|
default:
|
|
return applyArguments(ease, args);
|
|
}
|
|
} // Strings
|
|
|
|
|
|
function selectString(str) {
|
|
try {
|
|
var nodes = document.querySelectorAll(str);
|
|
return nodes;
|
|
} catch (e) {
|
|
return;
|
|
}
|
|
} // Arrays
|
|
|
|
|
|
function filterArray(arr, callback) {
|
|
var len = arr.length;
|
|
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
|
|
var result = [];
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
if (i in arr) {
|
|
var val = arr[i];
|
|
|
|
if (callback.call(thisArg, val, i, arr)) {
|
|
result.push(val);
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
function flattenArray(arr) {
|
|
return arr.reduce(function (a, b) {
|
|
return a.concat(is.arr(b) ? flattenArray(b) : b);
|
|
}, []);
|
|
}
|
|
|
|
function toArray(o) {
|
|
if (is.arr(o)) {
|
|
return o;
|
|
}
|
|
|
|
if (is.str(o)) {
|
|
o = selectString(o) || o;
|
|
}
|
|
|
|
if (o instanceof NodeList || o instanceof HTMLCollection) {
|
|
return [].slice.call(o);
|
|
}
|
|
|
|
return [o];
|
|
}
|
|
|
|
function arrayContains(arr, val) {
|
|
return arr.some(function (a) {
|
|
return a === val;
|
|
});
|
|
} // Objects
|
|
|
|
|
|
function cloneObject(o) {
|
|
var clone = {};
|
|
|
|
for (var p in o) {
|
|
clone[p] = o[p];
|
|
}
|
|
|
|
return clone;
|
|
}
|
|
|
|
function replaceObjectProps(o1, o2) {
|
|
var o = cloneObject(o1);
|
|
|
|
for (var p in o1) {
|
|
o[p] = o2.hasOwnProperty(p) ? o2[p] : o1[p];
|
|
}
|
|
|
|
return o;
|
|
}
|
|
|
|
function mergeObjects(o1, o2) {
|
|
var o = cloneObject(o1);
|
|
|
|
for (var p in o2) {
|
|
o[p] = is.und(o1[p]) ? o2[p] : o1[p];
|
|
}
|
|
|
|
return o;
|
|
} // Colors
|
|
|
|
|
|
function rgbToRgba(rgbValue) {
|
|
var rgb = /rgb\((\d+,\s*[\d]+,\s*[\d]+)\)/g.exec(rgbValue);
|
|
return rgb ? "rgba(" + rgb[1] + ",1)" : rgbValue;
|
|
}
|
|
|
|
function hexToRgba(hexValue) {
|
|
var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
var hex = hexValue.replace(rgx, function (m, r, g, b) {
|
|
return r + r + g + g + b + b;
|
|
});
|
|
var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
var r = parseInt(rgb[1], 16);
|
|
var g = parseInt(rgb[2], 16);
|
|
var b = parseInt(rgb[3], 16);
|
|
return "rgba(" + r + "," + g + "," + b + ",1)";
|
|
}
|
|
|
|
function hslToRgba(hslValue) {
|
|
var hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue) || /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(hslValue);
|
|
var h = parseInt(hsl[1], 10) / 360;
|
|
var s = parseInt(hsl[2], 10) / 100;
|
|
var l = parseInt(hsl[3], 10) / 100;
|
|
var a = hsl[4] || 1;
|
|
|
|
function hue2rgb(p, q, t) {
|
|
if (t < 0) {
|
|
t += 1;
|
|
}
|
|
|
|
if (t > 1) {
|
|
t -= 1;
|
|
}
|
|
|
|
if (t < 1 / 6) {
|
|
return p + (q - p) * 6 * t;
|
|
}
|
|
|
|
if (t < 1 / 2) {
|
|
return q;
|
|
}
|
|
|
|
if (t < 2 / 3) {
|
|
return p + (q - p) * (2 / 3 - t) * 6;
|
|
}
|
|
|
|
return p;
|
|
}
|
|
|
|
var r, g, b;
|
|
|
|
if (s == 0) {
|
|
r = g = b = l;
|
|
} else {
|
|
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
var p = 2 * l - q;
|
|
r = hue2rgb(p, q, h + 1 / 3);
|
|
g = hue2rgb(p, q, h);
|
|
b = hue2rgb(p, q, h - 1 / 3);
|
|
}
|
|
|
|
return "rgba(" + r * 255 + "," + g * 255 + "," + b * 255 + "," + a + ")";
|
|
}
|
|
|
|
function colorToRgb(val) {
|
|
if (is.rgb(val)) {
|
|
return rgbToRgba(val);
|
|
}
|
|
|
|
if (is.hex(val)) {
|
|
return hexToRgba(val);
|
|
}
|
|
|
|
if (is.hsl(val)) {
|
|
return hslToRgba(val);
|
|
}
|
|
} // Units
|
|
|
|
|
|
function getUnit(val) {
|
|
var split = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(val);
|
|
|
|
if (split) {
|
|
return split[1];
|
|
}
|
|
}
|
|
|
|
function getTransformUnit(propName) {
|
|
if (stringContains(propName, 'translate') || propName === 'perspective') {
|
|
return 'px';
|
|
}
|
|
|
|
if (stringContains(propName, 'rotate') || stringContains(propName, 'skew')) {
|
|
return 'deg';
|
|
}
|
|
} // Values
|
|
|
|
|
|
function getFunctionValue(val, animatable) {
|
|
if (!is.fnc(val)) {
|
|
return val;
|
|
}
|
|
|
|
return val(animatable.target, animatable.id, animatable.total);
|
|
}
|
|
|
|
function getAttribute(el, prop) {
|
|
return el.getAttribute(prop);
|
|
}
|
|
|
|
function convertPxToUnit(el, value, unit) {
|
|
var valueUnit = getUnit(value);
|
|
|
|
if (arrayContains([unit, 'deg', 'rad', 'turn'], valueUnit)) {
|
|
return value;
|
|
}
|
|
|
|
var cached = cache.CSS[value + unit];
|
|
|
|
if (!is.und(cached)) {
|
|
return cached;
|
|
}
|
|
|
|
var baseline = 100;
|
|
var tempEl = document.createElement(el.tagName);
|
|
var parentEl = el.parentNode && el.parentNode !== document ? el.parentNode : document.body;
|
|
parentEl.appendChild(tempEl);
|
|
tempEl.style.position = 'absolute';
|
|
tempEl.style.width = baseline + unit;
|
|
var factor = baseline / tempEl.offsetWidth;
|
|
parentEl.removeChild(tempEl);
|
|
var convertedUnit = factor * parseFloat(value);
|
|
cache.CSS[value + unit] = convertedUnit;
|
|
return convertedUnit;
|
|
}
|
|
|
|
function getCSSValue(el, prop, unit) {
|
|
if (prop in el.style) {
|
|
var uppercasePropName = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
var value = el.style[prop] || getComputedStyle(el).getPropertyValue(uppercasePropName) || '0';
|
|
return unit ? convertPxToUnit(el, value, unit) : value;
|
|
}
|
|
}
|
|
|
|
function getAnimationType(el, prop) {
|
|
if (is.dom(el) && !is.inp(el) && (getAttribute(el, prop) || is.svg(el) && el[prop])) {
|
|
return 'attribute';
|
|
}
|
|
|
|
if (is.dom(el) && arrayContains(validTransforms, prop)) {
|
|
return 'transform';
|
|
}
|
|
|
|
if (is.dom(el) && prop !== 'transform' && getCSSValue(el, prop)) {
|
|
return 'css';
|
|
}
|
|
|
|
if (el[prop] != null) {
|
|
return 'object';
|
|
}
|
|
}
|
|
|
|
function getElementTransforms(el) {
|
|
if (!is.dom(el)) {
|
|
return;
|
|
}
|
|
|
|
var str = el.style.transform || '';
|
|
var reg = /(\w+)\(([^)]*)\)/g;
|
|
var transforms = new Map();
|
|
var m;
|
|
|
|
while (m = reg.exec(str)) {
|
|
transforms.set(m[1], m[2]);
|
|
}
|
|
|
|
return transforms;
|
|
}
|
|
|
|
function getTransformValue(el, propName, animatable, unit) {
|
|
var defaultVal = stringContains(propName, 'scale') ? 1 : 0 + getTransformUnit(propName);
|
|
var value = getElementTransforms(el).get(propName) || defaultVal;
|
|
|
|
if (animatable) {
|
|
animatable.transforms.list.set(propName, value);
|
|
animatable.transforms['last'] = propName;
|
|
}
|
|
|
|
return unit ? convertPxToUnit(el, value, unit) : value;
|
|
}
|
|
|
|
function getOriginalTargetValue(target, propName, unit, animatable) {
|
|
switch (getAnimationType(target, propName)) {
|
|
case 'transform':
|
|
return getTransformValue(target, propName, animatable, unit);
|
|
|
|
case 'css':
|
|
return getCSSValue(target, propName, unit);
|
|
|
|
case 'attribute':
|
|
return getAttribute(target, propName);
|
|
|
|
default:
|
|
return target[propName] || 0;
|
|
}
|
|
}
|
|
|
|
function getRelativeValue(to, from) {
|
|
var operator = /^(\*=|\+=|-=)/.exec(to);
|
|
|
|
if (!operator) {
|
|
return to;
|
|
}
|
|
|
|
var u = getUnit(to) || 0;
|
|
var x = parseFloat(from);
|
|
var y = parseFloat(to.replace(operator[0], ''));
|
|
|
|
switch (operator[0][0]) {
|
|
case '+':
|
|
return x + y + u;
|
|
|
|
case '-':
|
|
return x - y + u;
|
|
|
|
case '*':
|
|
return x * y + u;
|
|
}
|
|
}
|
|
|
|
function validateValue(val, unit) {
|
|
if (is.col(val)) {
|
|
return colorToRgb(val);
|
|
}
|
|
|
|
if (/\s/g.test(val)) {
|
|
return val;
|
|
}
|
|
|
|
var originalUnit = getUnit(val);
|
|
var unitLess = originalUnit ? val.substr(0, val.length - originalUnit.length) : val;
|
|
|
|
if (unit) {
|
|
return unitLess + unit;
|
|
}
|
|
|
|
return unitLess;
|
|
} // getTotalLength() equivalent for circle, rect, polyline, polygon and line shapes
|
|
// adapted from https://gist.github.com/SebLambla/3e0550c496c236709744
|
|
|
|
|
|
function getDistance(p1, p2) {
|
|
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
|
|
}
|
|
|
|
function getCircleLength(el) {
|
|
return Math.PI * 2 * getAttribute(el, 'r');
|
|
}
|
|
|
|
function getRectLength(el) {
|
|
return getAttribute(el, 'width') * 2 + getAttribute(el, 'height') * 2;
|
|
}
|
|
|
|
function getLineLength(el) {
|
|
return getDistance({
|
|
x: getAttribute(el, 'x1'),
|
|
y: getAttribute(el, 'y1')
|
|
}, {
|
|
x: getAttribute(el, 'x2'),
|
|
y: getAttribute(el, 'y2')
|
|
});
|
|
}
|
|
|
|
function getPolylineLength(el) {
|
|
var points = el.points;
|
|
var totalLength = 0;
|
|
var previousPos;
|
|
|
|
for (var i = 0; i < points.numberOfItems; i++) {
|
|
var currentPos = points.getItem(i);
|
|
|
|
if (i > 0) {
|
|
totalLength += getDistance(previousPos, currentPos);
|
|
}
|
|
|
|
previousPos = currentPos;
|
|
}
|
|
|
|
return totalLength;
|
|
}
|
|
|
|
function getPolygonLength(el) {
|
|
var points = el.points;
|
|
return getPolylineLength(el) + getDistance(points.getItem(points.numberOfItems - 1), points.getItem(0));
|
|
} // Path animation
|
|
|
|
|
|
function getTotalLength(el) {
|
|
if (el.getTotalLength) {
|
|
return el.getTotalLength();
|
|
}
|
|
|
|
switch (el.tagName.toLowerCase()) {
|
|
case 'circle':
|
|
return getCircleLength(el);
|
|
|
|
case 'rect':
|
|
return getRectLength(el);
|
|
|
|
case 'line':
|
|
return getLineLength(el);
|
|
|
|
case 'polyline':
|
|
return getPolylineLength(el);
|
|
|
|
case 'polygon':
|
|
return getPolygonLength(el);
|
|
}
|
|
}
|
|
|
|
function setDashoffset(el) {
|
|
var pathLength = getTotalLength(el);
|
|
el.setAttribute('stroke-dasharray', pathLength);
|
|
return pathLength;
|
|
} // Motion path
|
|
|
|
|
|
function getParentSvgEl(el) {
|
|
var parentEl = el.parentNode;
|
|
|
|
while (is.svg(parentEl)) {
|
|
if (!is.svg(parentEl.parentNode)) {
|
|
break;
|
|
}
|
|
|
|
parentEl = parentEl.parentNode;
|
|
}
|
|
|
|
return parentEl;
|
|
}
|
|
|
|
function getParentSvg(pathEl, svgData) {
|
|
var svg = svgData || {};
|
|
var parentSvgEl = svg.el || getParentSvgEl(pathEl);
|
|
var rect = parentSvgEl.getBoundingClientRect();
|
|
var viewBoxAttr = getAttribute(parentSvgEl, 'viewBox');
|
|
var width = rect.width;
|
|
var height = rect.height;
|
|
var viewBox = svg.viewBox || (viewBoxAttr ? viewBoxAttr.split(' ') : [0, 0, width, height]);
|
|
return {
|
|
el: parentSvgEl,
|
|
viewBox: viewBox,
|
|
x: viewBox[0] / 1,
|
|
y: viewBox[1] / 1,
|
|
w: width / viewBox[2],
|
|
h: height / viewBox[3]
|
|
};
|
|
}
|
|
|
|
function getPath(path, percent) {
|
|
var pathEl = is.str(path) ? selectString(path)[0] : path;
|
|
var p = percent || 100;
|
|
return function (property) {
|
|
return {
|
|
property: property,
|
|
el: pathEl,
|
|
svg: getParentSvg(pathEl),
|
|
totalLength: getTotalLength(pathEl) * (p / 100)
|
|
};
|
|
};
|
|
}
|
|
|
|
function getPathProgress(path, progress) {
|
|
function point(offset) {
|
|
if (offset === void 0) offset = 0;
|
|
var l = progress + offset >= 1 ? progress + offset : 0;
|
|
return path.el.getPointAtLength(l);
|
|
}
|
|
|
|
var svg = getParentSvg(path.el, path.svg);
|
|
var p = point();
|
|
var p0 = point(-1);
|
|
var p1 = point(+1);
|
|
|
|
switch (path.property) {
|
|
case 'x':
|
|
return (p.x - svg.x) * svg.w;
|
|
|
|
case 'y':
|
|
return (p.y - svg.y) * svg.h;
|
|
|
|
case 'angle':
|
|
return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI;
|
|
}
|
|
} // Decompose value
|
|
|
|
|
|
function decomposeValue(val, unit) {
|
|
// const rgx = /-?\d*\.?\d+/g; // handles basic numbers
|
|
// const rgx = /[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation
|
|
var rgx = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation
|
|
|
|
var value = validateValue(is.pth(val) ? val.totalLength : val, unit) + '';
|
|
return {
|
|
original: value,
|
|
numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0],
|
|
strings: is.str(val) || unit ? value.split(rgx) : []
|
|
};
|
|
} // Animatables
|
|
|
|
|
|
function parseTargets(targets) {
|
|
var targetsArray = targets ? flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets)) : [];
|
|
return filterArray(targetsArray, function (item, pos, self) {
|
|
return self.indexOf(item) === pos;
|
|
});
|
|
}
|
|
|
|
function getAnimatables(targets) {
|
|
var parsed = parseTargets(targets);
|
|
return parsed.map(function (t, i) {
|
|
return {
|
|
target: t,
|
|
id: i,
|
|
total: parsed.length,
|
|
transforms: {
|
|
list: getElementTransforms(t)
|
|
}
|
|
};
|
|
});
|
|
} // Properties
|
|
|
|
|
|
function normalizePropertyTweens(prop, tweenSettings) {
|
|
var settings = cloneObject(tweenSettings); // Override duration if easing is a spring
|
|
|
|
if (/^spring/.test(settings.easing)) {
|
|
settings.duration = spring(settings.easing);
|
|
}
|
|
|
|
if (is.arr(prop)) {
|
|
var l = prop.length;
|
|
var isFromTo = l === 2 && !is.obj(prop[0]);
|
|
|
|
if (!isFromTo) {
|
|
// Duration divided by the number of tweens
|
|
if (!is.fnc(tweenSettings.duration)) {
|
|
settings.duration = tweenSettings.duration / l;
|
|
}
|
|
} else {
|
|
// Transform [from, to] values shorthand to a valid tween value
|
|
prop = {
|
|
value: prop
|
|
};
|
|
}
|
|
}
|
|
|
|
var propArray = is.arr(prop) ? prop : [prop];
|
|
return propArray.map(function (v, i) {
|
|
var obj = is.obj(v) && !is.pth(v) ? v : {
|
|
value: v
|
|
}; // Default delay value should only be applied to the first tween
|
|
|
|
if (is.und(obj.delay)) {
|
|
obj.delay = !i ? tweenSettings.delay : 0;
|
|
} // Default endDelay value should only be applied to the last tween
|
|
|
|
|
|
if (is.und(obj.endDelay)) {
|
|
obj.endDelay = i === propArray.length - 1 ? tweenSettings.endDelay : 0;
|
|
}
|
|
|
|
return obj;
|
|
}).map(function (k) {
|
|
return mergeObjects(k, settings);
|
|
});
|
|
}
|
|
|
|
function flattenKeyframes(keyframes) {
|
|
var propertyNames = filterArray(flattenArray(keyframes.map(function (key) {
|
|
return Object.keys(key);
|
|
})), function (p) {
|
|
return is.key(p);
|
|
}).reduce(function (a, b) {
|
|
if (a.indexOf(b) < 0) {
|
|
a.push(b);
|
|
}
|
|
|
|
return a;
|
|
}, []);
|
|
var properties = {};
|
|
|
|
var loop = function (i) {
|
|
var propName = propertyNames[i];
|
|
properties[propName] = keyframes.map(function (key) {
|
|
var newKey = {};
|
|
|
|
for (var p in key) {
|
|
if (is.key(p)) {
|
|
if (p == propName) {
|
|
newKey.value = key[p];
|
|
}
|
|
} else {
|
|
newKey[p] = key[p];
|
|
}
|
|
}
|
|
|
|
return newKey;
|
|
});
|
|
};
|
|
|
|
for (var i = 0; i < propertyNames.length; i++) loop(i);
|
|
|
|
return properties;
|
|
}
|
|
|
|
function getProperties(tweenSettings, params) {
|
|
var properties = [];
|
|
var keyframes = params.keyframes;
|
|
|
|
if (keyframes) {
|
|
params = mergeObjects(flattenKeyframes(keyframes), params);
|
|
}
|
|
|
|
for (var p in params) {
|
|
if (is.key(p)) {
|
|
properties.push({
|
|
name: p,
|
|
tweens: normalizePropertyTweens(params[p], tweenSettings)
|
|
});
|
|
}
|
|
}
|
|
|
|
return properties;
|
|
} // Tweens
|
|
|
|
|
|
function normalizeTweenValues(tween, animatable) {
|
|
var t = {};
|
|
|
|
for (var p in tween) {
|
|
var value = getFunctionValue(tween[p], animatable);
|
|
|
|
if (is.arr(value)) {
|
|
value = value.map(function (v) {
|
|
return getFunctionValue(v, animatable);
|
|
});
|
|
|
|
if (value.length === 1) {
|
|
value = value[0];
|
|
}
|
|
}
|
|
|
|
t[p] = value;
|
|
}
|
|
|
|
t.duration = parseFloat(t.duration);
|
|
t.delay = parseFloat(t.delay);
|
|
return t;
|
|
}
|
|
|
|
function normalizeTweens(prop, animatable) {
|
|
var previousTween;
|
|
return prop.tweens.map(function (t) {
|
|
var tween = normalizeTweenValues(t, animatable);
|
|
var tweenValue = tween.value;
|
|
var to = is.arr(tweenValue) ? tweenValue[1] : tweenValue;
|
|
var toUnit = getUnit(to);
|
|
var originalValue = getOriginalTargetValue(animatable.target, prop.name, toUnit, animatable);
|
|
var previousValue = previousTween ? previousTween.to.original : originalValue;
|
|
var from = is.arr(tweenValue) ? tweenValue[0] : previousValue;
|
|
var fromUnit = getUnit(from) || getUnit(originalValue);
|
|
var unit = toUnit || fromUnit;
|
|
|
|
if (is.und(to)) {
|
|
to = previousValue;
|
|
}
|
|
|
|
tween.from = decomposeValue(from, unit);
|
|
tween.to = decomposeValue(getRelativeValue(to, from), unit);
|
|
tween.start = previousTween ? previousTween.end : 0;
|
|
tween.end = tween.start + tween.delay + tween.duration + tween.endDelay;
|
|
tween.easing = parseEasings(tween.easing, tween.duration);
|
|
tween.isPath = is.pth(tweenValue);
|
|
tween.isColor = is.col(tween.from.original);
|
|
|
|
if (tween.isColor) {
|
|
tween.round = 1;
|
|
}
|
|
|
|
previousTween = tween;
|
|
return tween;
|
|
});
|
|
} // Tween progress
|
|
|
|
|
|
var setProgressValue = {
|
|
css: function (t, p, v) {
|
|
return t.style[p] = v;
|
|
},
|
|
attribute: function (t, p, v) {
|
|
return t.setAttribute(p, v);
|
|
},
|
|
object: function (t, p, v) {
|
|
return t[p] = v;
|
|
},
|
|
transform: function (t, p, v, transforms, manual) {
|
|
transforms.list.set(p, v);
|
|
|
|
if (p === transforms.last || manual) {
|
|
var str = '';
|
|
transforms.list.forEach(function (value, prop) {
|
|
str += prop + "(" + value + ") ";
|
|
});
|
|
t.style.transform = str;
|
|
}
|
|
}
|
|
}; // Set Value helper
|
|
|
|
function setTargetsValue(targets, properties) {
|
|
var animatables = getAnimatables(targets);
|
|
animatables.forEach(function (animatable) {
|
|
for (var property in properties) {
|
|
var value = getFunctionValue(properties[property], animatable);
|
|
var target = animatable.target;
|
|
var valueUnit = getUnit(value);
|
|
var originalValue = getOriginalTargetValue(target, property, valueUnit, animatable);
|
|
var unit = valueUnit || getUnit(originalValue);
|
|
var to = getRelativeValue(validateValue(value, unit), originalValue);
|
|
var animType = getAnimationType(target, property);
|
|
setProgressValue[animType](target, property, to, animatable.transforms, true);
|
|
}
|
|
});
|
|
} // Animations
|
|
|
|
|
|
function createAnimation(animatable, prop) {
|
|
var animType = getAnimationType(animatable.target, prop.name);
|
|
|
|
if (animType) {
|
|
var tweens = normalizeTweens(prop, animatable);
|
|
var lastTween = tweens[tweens.length - 1];
|
|
return {
|
|
type: animType,
|
|
property: prop.name,
|
|
animatable: animatable,
|
|
tweens: tweens,
|
|
duration: lastTween.end,
|
|
delay: tweens[0].delay,
|
|
endDelay: lastTween.endDelay
|
|
};
|
|
}
|
|
}
|
|
|
|
function getAnimations(animatables, properties) {
|
|
return filterArray(flattenArray(animatables.map(function (animatable) {
|
|
return properties.map(function (prop) {
|
|
return createAnimation(animatable, prop);
|
|
});
|
|
})), function (a) {
|
|
return !is.und(a);
|
|
});
|
|
} // Create Instance
|
|
|
|
|
|
function getInstanceTimings(animations, tweenSettings) {
|
|
var animLength = animations.length;
|
|
|
|
var getTlOffset = function (anim) {
|
|
return anim.timelineOffset ? anim.timelineOffset : 0;
|
|
};
|
|
|
|
var timings = {};
|
|
timings.duration = animLength ? Math.max.apply(Math, animations.map(function (anim) {
|
|
return getTlOffset(anim) + anim.duration;
|
|
})) : tweenSettings.duration;
|
|
timings.delay = animLength ? Math.min.apply(Math, animations.map(function (anim) {
|
|
return getTlOffset(anim) + anim.delay;
|
|
})) : tweenSettings.delay;
|
|
timings.endDelay = animLength ? timings.duration - Math.max.apply(Math, animations.map(function (anim) {
|
|
return getTlOffset(anim) + anim.duration - anim.endDelay;
|
|
})) : tweenSettings.endDelay;
|
|
return timings;
|
|
}
|
|
|
|
var instanceID = 0;
|
|
|
|
function createNewInstance(params) {
|
|
var instanceSettings = replaceObjectProps(defaultInstanceSettings, params);
|
|
var tweenSettings = replaceObjectProps(defaultTweenSettings, params);
|
|
var properties = getProperties(tweenSettings, params);
|
|
var animatables = getAnimatables(params.targets);
|
|
var animations = getAnimations(animatables, properties);
|
|
var timings = getInstanceTimings(animations, tweenSettings);
|
|
var id = instanceID;
|
|
instanceID++;
|
|
return mergeObjects(instanceSettings, {
|
|
id: id,
|
|
children: [],
|
|
animatables: animatables,
|
|
animations: animations,
|
|
duration: timings.duration,
|
|
delay: timings.delay,
|
|
endDelay: timings.endDelay
|
|
});
|
|
} // Core
|
|
|
|
|
|
var activeInstances = [];
|
|
var pausedInstances = [];
|
|
var raf;
|
|
|
|
var engine = function () {
|
|
function play() {
|
|
raf = requestAnimationFrame(step);
|
|
}
|
|
|
|
function step(t) {
|
|
var activeInstancesLength = activeInstances.length;
|
|
|
|
if (activeInstancesLength) {
|
|
var i = 0;
|
|
|
|
while (i < activeInstancesLength) {
|
|
var activeInstance = activeInstances[i];
|
|
|
|
if (!activeInstance.paused) {
|
|
activeInstance.tick(t);
|
|
} else {
|
|
var instanceIndex = activeInstances.indexOf(activeInstance);
|
|
|
|
if (instanceIndex > -1) {
|
|
activeInstances.splice(instanceIndex, 1);
|
|
activeInstancesLength = activeInstances.length;
|
|
}
|
|
}
|
|
|
|
i++;
|
|
}
|
|
|
|
play();
|
|
} else {
|
|
raf = cancelAnimationFrame(raf);
|
|
}
|
|
}
|
|
|
|
return play;
|
|
}();
|
|
|
|
function handleVisibilityChange() {
|
|
if (document.hidden) {
|
|
activeInstances.forEach(function (ins) {
|
|
return ins.pause();
|
|
});
|
|
pausedInstances = activeInstances.slice(0);
|
|
anime.running = activeInstances = [];
|
|
} else {
|
|
pausedInstances.forEach(function (ins) {
|
|
return ins.play();
|
|
});
|
|
}
|
|
}
|
|
|
|
if (typeof document !== 'undefined') {
|
|
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
} // Public Instance
|
|
|
|
|
|
function anime(params) {
|
|
if (params === void 0) params = {};
|
|
var startTime = 0,
|
|
lastTime = 0,
|
|
now = 0;
|
|
var children,
|
|
childrenLength = 0;
|
|
var resolve = null;
|
|
|
|
function makePromise(instance) {
|
|
var promise = window.Promise && new Promise(function (_resolve) {
|
|
return resolve = _resolve;
|
|
});
|
|
instance.finished = promise;
|
|
return promise;
|
|
}
|
|
|
|
var instance = createNewInstance(params);
|
|
var promise = makePromise(instance);
|
|
|
|
function toggleInstanceDirection() {
|
|
var direction = instance.direction;
|
|
|
|
if (direction !== 'alternate') {
|
|
instance.direction = direction !== 'normal' ? 'normal' : 'reverse';
|
|
}
|
|
|
|
instance.reversed = !instance.reversed;
|
|
children.forEach(function (child) {
|
|
return child.reversed = instance.reversed;
|
|
});
|
|
}
|
|
|
|
function adjustTime(time) {
|
|
return instance.reversed ? instance.duration - time : time;
|
|
}
|
|
|
|
function resetTime() {
|
|
startTime = 0;
|
|
lastTime = adjustTime(instance.currentTime) * (1 / anime.speed);
|
|
}
|
|
|
|
function seekChild(time, child) {
|
|
if (child) {
|
|
child.seek(time - child.timelineOffset);
|
|
}
|
|
}
|
|
|
|
function syncInstanceChildren(time) {
|
|
if (!instance.reversePlayback) {
|
|
for (var i = 0; i < childrenLength; i++) {
|
|
seekChild(time, children[i]);
|
|
}
|
|
} else {
|
|
for (var i$1 = childrenLength; i$1--;) {
|
|
seekChild(time, children[i$1]);
|
|
}
|
|
}
|
|
}
|
|
|
|
function setAnimationsProgress(insTime) {
|
|
var i = 0;
|
|
var animations = instance.animations;
|
|
var animationsLength = animations.length;
|
|
|
|
while (i < animationsLength) {
|
|
var anim = animations[i];
|
|
var animatable = anim.animatable;
|
|
var tweens = anim.tweens;
|
|
var tweenLength = tweens.length - 1;
|
|
var tween = tweens[tweenLength]; // Only check for keyframes if there is more than one tween
|
|
|
|
if (tweenLength) {
|
|
tween = filterArray(tweens, function (t) {
|
|
return insTime < t.end;
|
|
})[0] || tween;
|
|
}
|
|
|
|
var elapsed = minMax(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration;
|
|
var eased = isNaN(elapsed) ? 1 : tween.easing(elapsed);
|
|
var strings = tween.to.strings;
|
|
var round = tween.round;
|
|
var numbers = [];
|
|
var toNumbersLength = tween.to.numbers.length;
|
|
var progress = void 0;
|
|
|
|
for (var n = 0; n < toNumbersLength; n++) {
|
|
var value = void 0;
|
|
var toNumber = tween.to.numbers[n];
|
|
var fromNumber = tween.from.numbers[n] || 0;
|
|
|
|
if (!tween.isPath) {
|
|
value = fromNumber + eased * (toNumber - fromNumber);
|
|
} else {
|
|
value = getPathProgress(tween.value, eased * toNumber);
|
|
}
|
|
|
|
if (round) {
|
|
if (!(tween.isColor && n > 2)) {
|
|
value = Math.round(value * round) / round;
|
|
}
|
|
}
|
|
|
|
numbers.push(value);
|
|
} // Manual Array.reduce for better performances
|
|
|
|
|
|
var stringsLength = strings.length;
|
|
|
|
if (!stringsLength) {
|
|
progress = numbers[0];
|
|
} else {
|
|
progress = strings[0];
|
|
|
|
for (var s = 0; s < stringsLength; s++) {
|
|
var a = strings[s];
|
|
var b = strings[s + 1];
|
|
var n$1 = numbers[s];
|
|
|
|
if (!isNaN(n$1)) {
|
|
if (!b) {
|
|
progress += n$1 + ' ';
|
|
} else {
|
|
progress += n$1 + b;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
setProgressValue[anim.type](animatable.target, anim.property, progress, animatable.transforms);
|
|
anim.currentValue = progress;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
function setCallback(cb) {
|
|
if (instance[cb] && !instance.passThrough) {
|
|
instance[cb](instance);
|
|
}
|
|
}
|
|
|
|
function countIteration() {
|
|
if (instance.remaining && instance.remaining !== true) {
|
|
instance.remaining--;
|
|
}
|
|
}
|
|
|
|
function setInstanceProgress(engineTime) {
|
|
var insDuration = instance.duration;
|
|
var insDelay = instance.delay;
|
|
var insEndDelay = insDuration - instance.endDelay;
|
|
var insTime = adjustTime(engineTime);
|
|
instance.progress = minMax(insTime / insDuration * 100, 0, 100);
|
|
instance.reversePlayback = insTime < instance.currentTime;
|
|
|
|
if (children) {
|
|
syncInstanceChildren(insTime);
|
|
}
|
|
|
|
if (!instance.began && instance.currentTime > 0) {
|
|
instance.began = true;
|
|
setCallback('begin');
|
|
}
|
|
|
|
if (!instance.loopBegan && instance.currentTime > 0) {
|
|
instance.loopBegan = true;
|
|
setCallback('loopBegin');
|
|
}
|
|
|
|
if (insTime <= insDelay && instance.currentTime !== 0) {
|
|
setAnimationsProgress(0);
|
|
}
|
|
|
|
if (insTime >= insEndDelay && instance.currentTime !== insDuration || !insDuration) {
|
|
setAnimationsProgress(insDuration);
|
|
}
|
|
|
|
if (insTime > insDelay && insTime < insEndDelay) {
|
|
if (!instance.changeBegan) {
|
|
instance.changeBegan = true;
|
|
instance.changeCompleted = false;
|
|
setCallback('changeBegin');
|
|
}
|
|
|
|
setCallback('change');
|
|
setAnimationsProgress(insTime);
|
|
} else {
|
|
if (instance.changeBegan) {
|
|
instance.changeCompleted = true;
|
|
instance.changeBegan = false;
|
|
setCallback('changeComplete');
|
|
}
|
|
}
|
|
|
|
instance.currentTime = minMax(insTime, 0, insDuration);
|
|
|
|
if (instance.began) {
|
|
setCallback('update');
|
|
}
|
|
|
|
if (engineTime >= insDuration) {
|
|
lastTime = 0;
|
|
countIteration();
|
|
|
|
if (!instance.remaining) {
|
|
instance.paused = true;
|
|
|
|
if (!instance.completed) {
|
|
instance.completed = true;
|
|
setCallback('loopComplete');
|
|
setCallback('complete');
|
|
|
|
if (!instance.passThrough && 'Promise' in window) {
|
|
resolve();
|
|
promise = makePromise(instance);
|
|
}
|
|
}
|
|
} else {
|
|
startTime = now;
|
|
setCallback('loopComplete');
|
|
instance.loopBegan = false;
|
|
|
|
if (instance.direction === 'alternate') {
|
|
toggleInstanceDirection();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
instance.reset = function () {
|
|
var direction = instance.direction;
|
|
instance.passThrough = false;
|
|
instance.currentTime = 0;
|
|
instance.progress = 0;
|
|
instance.paused = true;
|
|
instance.began = false;
|
|
instance.loopBegan = false;
|
|
instance.changeBegan = false;
|
|
instance.completed = false;
|
|
instance.changeCompleted = false;
|
|
instance.reversePlayback = false;
|
|
instance.reversed = direction === 'reverse';
|
|
instance.remaining = instance.loop;
|
|
children = instance.children;
|
|
childrenLength = children.length;
|
|
|
|
for (var i = childrenLength; i--;) {
|
|
instance.children[i].reset();
|
|
}
|
|
|
|
if (instance.reversed && instance.loop !== true || direction === 'alternate' && instance.loop === 1) {
|
|
instance.remaining++;
|
|
}
|
|
|
|
setAnimationsProgress(instance.reversed ? instance.duration : 0);
|
|
}; // Set Value helper
|
|
|
|
|
|
instance.set = function (targets, properties) {
|
|
setTargetsValue(targets, properties);
|
|
return instance;
|
|
};
|
|
|
|
instance.tick = function (t) {
|
|
now = t;
|
|
|
|
if (!startTime) {
|
|
startTime = now;
|
|
}
|
|
|
|
setInstanceProgress((now + (lastTime - startTime)) * anime.speed);
|
|
};
|
|
|
|
instance.seek = function (time) {
|
|
setInstanceProgress(adjustTime(time));
|
|
};
|
|
|
|
instance.pause = function () {
|
|
instance.paused = true;
|
|
resetTime();
|
|
};
|
|
|
|
instance.play = function () {
|
|
if (!instance.paused) {
|
|
return;
|
|
}
|
|
|
|
if (instance.completed) {
|
|
instance.reset();
|
|
}
|
|
|
|
instance.paused = false;
|
|
activeInstances.push(instance);
|
|
resetTime();
|
|
|
|
if (!raf) {
|
|
engine();
|
|
}
|
|
};
|
|
|
|
instance.reverse = function () {
|
|
toggleInstanceDirection();
|
|
instance.completed = instance.reversed ? false : true;
|
|
resetTime();
|
|
};
|
|
|
|
instance.restart = function () {
|
|
instance.reset();
|
|
instance.play();
|
|
};
|
|
|
|
instance.reset();
|
|
|
|
if (instance.autoplay) {
|
|
instance.play();
|
|
}
|
|
|
|
return instance;
|
|
} // Remove targets from animation
|
|
|
|
|
|
function removeTargetsFromAnimations(targetsArray, animations) {
|
|
for (var a = animations.length; a--;) {
|
|
if (arrayContains(targetsArray, animations[a].animatable.target)) {
|
|
animations.splice(a, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
function removeTargets(targets) {
|
|
var targetsArray = parseTargets(targets);
|
|
|
|
for (var i = activeInstances.length; i--;) {
|
|
var instance = activeInstances[i];
|
|
var animations = instance.animations;
|
|
var children = instance.children;
|
|
removeTargetsFromAnimations(targetsArray, animations);
|
|
|
|
for (var c = children.length; c--;) {
|
|
var child = children[c];
|
|
var childAnimations = child.animations;
|
|
removeTargetsFromAnimations(targetsArray, childAnimations);
|
|
|
|
if (!childAnimations.length && !child.children.length) {
|
|
children.splice(c, 1);
|
|
}
|
|
}
|
|
|
|
if (!animations.length && !children.length) {
|
|
instance.pause();
|
|
}
|
|
}
|
|
} // Stagger helpers
|
|
|
|
|
|
function stagger(val, params) {
|
|
if (params === void 0) params = {};
|
|
var direction = params.direction || 'normal';
|
|
var easing = params.easing ? parseEasings(params.easing) : null;
|
|
var grid = params.grid;
|
|
var axis = params.axis;
|
|
var fromIndex = params.from || 0;
|
|
var fromFirst = fromIndex === 'first';
|
|
var fromCenter = fromIndex === 'center';
|
|
var fromLast = fromIndex === 'last';
|
|
var isRange = is.arr(val);
|
|
var val1 = isRange ? parseFloat(val[0]) : parseFloat(val);
|
|
var val2 = isRange ? parseFloat(val[1]) : 0;
|
|
var unit = getUnit(isRange ? val[1] : val) || 0;
|
|
var start = params.start || 0 + (isRange ? val1 : 0);
|
|
var values = [];
|
|
var maxValue = 0;
|
|
return function (el, i, t) {
|
|
if (fromFirst) {
|
|
fromIndex = 0;
|
|
}
|
|
|
|
if (fromCenter) {
|
|
fromIndex = (t - 1) / 2;
|
|
}
|
|
|
|
if (fromLast) {
|
|
fromIndex = t - 1;
|
|
}
|
|
|
|
if (!values.length) {
|
|
for (var index = 0; index < t; index++) {
|
|
if (!grid) {
|
|
values.push(Math.abs(fromIndex - index));
|
|
} else {
|
|
var fromX = !fromCenter ? fromIndex % grid[0] : (grid[0] - 1) / 2;
|
|
var fromY = !fromCenter ? Math.floor(fromIndex / grid[0]) : (grid[1] - 1) / 2;
|
|
var toX = index % grid[0];
|
|
var toY = Math.floor(index / grid[0]);
|
|
var distanceX = fromX - toX;
|
|
var distanceY = fromY - toY;
|
|
var value = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
|
|
|
|
if (axis === 'x') {
|
|
value = -distanceX;
|
|
}
|
|
|
|
if (axis === 'y') {
|
|
value = -distanceY;
|
|
}
|
|
|
|
values.push(value);
|
|
}
|
|
|
|
maxValue = Math.max.apply(Math, values);
|
|
}
|
|
|
|
if (easing) {
|
|
values = values.map(function (val) {
|
|
return easing(val / maxValue) * maxValue;
|
|
});
|
|
}
|
|
|
|
if (direction === 'reverse') {
|
|
values = values.map(function (val) {
|
|
return axis ? val < 0 ? val * -1 : -val : Math.abs(maxValue - val);
|
|
});
|
|
}
|
|
}
|
|
|
|
var spacing = isRange ? (val2 - val1) / maxValue : val1;
|
|
return start + spacing * (Math.round(values[i] * 100) / 100) + unit;
|
|
};
|
|
} // Timeline
|
|
|
|
|
|
function timeline(params) {
|
|
if (params === void 0) params = {};
|
|
var tl = anime(params);
|
|
tl.duration = 0;
|
|
|
|
tl.add = function (instanceParams, timelineOffset) {
|
|
var tlIndex = activeInstances.indexOf(tl);
|
|
var children = tl.children;
|
|
|
|
if (tlIndex > -1) {
|
|
activeInstances.splice(tlIndex, 1);
|
|
}
|
|
|
|
function passThrough(ins) {
|
|
ins.passThrough = true;
|
|
}
|
|
|
|
for (var i = 0; i < children.length; i++) {
|
|
passThrough(children[i]);
|
|
}
|
|
|
|
var insParams = mergeObjects(instanceParams, replaceObjectProps(defaultTweenSettings, params));
|
|
insParams.targets = insParams.targets || params.targets;
|
|
var tlDuration = tl.duration;
|
|
insParams.autoplay = false;
|
|
insParams.direction = tl.direction;
|
|
insParams.timelineOffset = is.und(timelineOffset) ? tlDuration : getRelativeValue(timelineOffset, tlDuration);
|
|
passThrough(tl);
|
|
tl.seek(insParams.timelineOffset);
|
|
var ins = anime(insParams);
|
|
passThrough(ins);
|
|
children.push(ins);
|
|
var timings = getInstanceTimings(children, params);
|
|
tl.delay = timings.delay;
|
|
tl.endDelay = timings.endDelay;
|
|
tl.duration = timings.duration;
|
|
tl.seek(0);
|
|
tl.reset();
|
|
|
|
if (tl.autoplay) {
|
|
tl.play();
|
|
}
|
|
|
|
return tl;
|
|
};
|
|
|
|
return tl;
|
|
}
|
|
|
|
anime.version = '3.2.0';
|
|
anime.speed = 1;
|
|
anime.running = activeInstances;
|
|
anime.remove = removeTargets;
|
|
anime.get = getOriginalTargetValue;
|
|
anime.set = setTargetsValue;
|
|
anime.convertPx = convertPxToUnit;
|
|
anime.path = getPath;
|
|
anime.setDashoffset = setDashoffset;
|
|
anime.stagger = stagger;
|
|
anime.timeline = timeline;
|
|
anime.easing = parseEasings;
|
|
anime.penner = penner;
|
|
|
|
anime.random = function (min, max) {
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
};
|
|
|
|
var _default = anime;
|
|
exports.default = _default;
|
|
},{}],"ui/Notifications.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _animeEs = _interopRequireDefault(require("animejs/lib/anime.es.js"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var notifcation = document.getElementById('notifications');
|
|
var message = document.getElementById('notifyMessage');
|
|
var messageText = document.getElementById('message-text');
|
|
|
|
var Notfications = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function Notfications() {
|
|
_classCallCheck(this, Notfications);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(Notfications, [{
|
|
key: "alert",
|
|
value: function alert(text, status) {
|
|
messageText.innerHTML = text;
|
|
notifcation.style.display = 'flex';
|
|
var color = '';
|
|
status ? color = '#32cd32' : color = '#F64747';
|
|
(0, _animeEs.default)({
|
|
targets: messageText,
|
|
backgroundColor: color,
|
|
easing: 'easeInOutQuint',
|
|
duration: 500,
|
|
complete: function complete() {
|
|
setTimeout(function () {
|
|
(0, _animeEs.default)({
|
|
targets: messageText,
|
|
backgroundColor: '#374857',
|
|
easing: 'easeOutQuint',
|
|
duration: 500
|
|
});
|
|
}, 1000);
|
|
}
|
|
});
|
|
(0, _animeEs.default)({
|
|
targets: message,
|
|
marginTop: '-20px',
|
|
easing: 'easeInOutQuint',
|
|
duration: 500,
|
|
opacity: 1,
|
|
complete: function complete() {
|
|
setTimeout(function () {
|
|
(0, _animeEs.default)({
|
|
targets: message,
|
|
marginTop: '-125px',
|
|
easing: 'easeOutQuint',
|
|
duration: 500,
|
|
opacity: 0,
|
|
complete: function complete() {
|
|
notifcation.style.display = 'none';
|
|
}
|
|
});
|
|
}, 1000);
|
|
}
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return Notfications;
|
|
}();
|
|
|
|
exports.default = Notfications;
|
|
},{"animejs/lib/anime.es.js":"../../node_modules/animejs/lib/anime.es.js"}],"controllers/PageEditor.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _FipamoAdminAPI = _interopRequireWildcard(require("../../libraries/FipamoAdminAPI"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../events/DataEvent"));
|
|
|
|
var _PageActions = _interopRequireDefault(require("../actions/PageActions"));
|
|
|
|
var EditorEvent = _interopRequireWildcard(require("../events/EditorEvent"));
|
|
|
|
var _TextEditor = _interopRequireDefault(require("../ui/TextEditor"));
|
|
|
|
var _Notifications = _interopRequireDefault(require("../ui/Notifications"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } 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 admin = new _FipamoAdminAPI.default();
|
|
var notify = new _Notifications.default();
|
|
|
|
var PostEditor = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function PostEditor() {
|
|
var _this = this;
|
|
|
|
_classCallCheck(this, PostEditor);
|
|
|
|
var self = this;
|
|
this.urlPieces = document.URL.split('/');
|
|
this.post = [];
|
|
this.postID = null;
|
|
this.postUUID = null;
|
|
this.postLayout = null;
|
|
|
|
if (document.getElementById('post-edit-index').getAttribute('data-index')) {
|
|
this.postID = document.getElementById('post-edit-index').getAttribute('data-index');
|
|
this.postUUID = document.getElementById('post-edit-index').getAttribute('data-uuid');
|
|
this.postLayout = document.getElementById('post-edit-index').getAttribute('data-layout');
|
|
}
|
|
|
|
if (document.getElementById('edit-post-text')) {
|
|
this.editor = new _TextEditor.default(document.getElementById('edit-post-text'), document.getElementById('header').offsetHeight + document.getElementById('post-header').offsetHeight + document.getElementById('post-feature').offsetHeight);
|
|
this.editor.addListener(EditorEvent.EDITOR_DELETE, function () {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_DELETE);
|
|
}, false);
|
|
this.editor.addListener(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, function () {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_UPLOAD_POST_IMAGE);
|
|
}, false);
|
|
this.editor.addListener(EditorEvent.EDITOR_UPDATE, function () {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_UPDATE);
|
|
}, false);
|
|
this.editor.addListener(EditorEvent.EDITOR_SAVE, function () {
|
|
return _this.handleEditorOptions(EditorEvent.EDITOR_SAVE);
|
|
}, false);
|
|
document.getElementById('post-image-upload').addEventListener('change', function (e) {
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
}, false);
|
|
/*
|
|
TinyDatePicker(document.getElementById('post-date'), {
|
|
mode: 'dp-below',
|
|
format() {
|
|
//return self.dateUtils.getDate('origin', date);
|
|
}
|
|
});
|
|
*/
|
|
|
|
this.start();
|
|
}
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(PostEditor, [{
|
|
key: "start",
|
|
value: function start() {
|
|
var _this2 = this;
|
|
|
|
if (document.getElementById('featured-image-drop')) {
|
|
document.getElementById('featured-image-drop').addEventListener('dragover', this.handleImageActions, false);
|
|
document.getElementById('featured-image-drop').addEventListener('drop', this.handleImageActions, false);
|
|
document.getElementById('featured-image-upload').addEventListener('change', function (e) {
|
|
return _this2.handleImageActions(e);
|
|
}, false);
|
|
|
|
if (document.getElementById('new-feature-upload')) {
|
|
document.getElementById('new-feature-upload').addEventListener('click', function () {
|
|
document.getElementById('featured-image-upload').click();
|
|
});
|
|
}
|
|
|
|
var optionButtons = document.querySelectorAll('.post-option-btn');
|
|
|
|
for (var i = 0, length = optionButtons.length; i < length; i++) {
|
|
optionButtons[i].addEventListener('click', function (e) {
|
|
return _this2.handlePostOptions(e);
|
|
}, false);
|
|
}
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handlePostOptions",
|
|
value: function handlePostOptions(e) {
|
|
var currentOption;
|
|
|
|
switch (e.target.id) {
|
|
case 'option-page-icon':
|
|
case 'option-menu-pin':
|
|
currentOption = document.getElementById('option-menu-pin');
|
|
break;
|
|
|
|
case 'option-feature-icon':
|
|
case 'option-feature':
|
|
currentOption = document.getElementById('option-feature');
|
|
break;
|
|
|
|
case 'option-published-icon':
|
|
case 'option-published':
|
|
currentOption = document.getElementById('option-published');
|
|
break;
|
|
}
|
|
|
|
var active = currentOption.getAttribute('data-active');
|
|
active == 'false' ? currentOption.setAttribute('data-active', 'true') : currentOption.setAttribute('data-active', 'false');
|
|
}
|
|
}, {
|
|
key: "handleEditorOptions",
|
|
value: function handleEditorOptions(e) {
|
|
switch (e) {
|
|
case EditorEvent.EDITOR_SAVE:
|
|
case EditorEvent.EDITOR_UPDATE:
|
|
var task = '';
|
|
e === EditorEvent.EDITOR_SAVE ? task = _FipamoAdminAPI.TASK_PAGE_CREATE : task = _FipamoAdminAPI.TASK_PAGE_EDIT;
|
|
new _PageActions.default().collectInfo(document.getElementById('featured-image-upload').files[0]).then(function (page) {
|
|
admin.pageActions(task, page).then(function (r) {
|
|
if (r.type === DataEvent.PAGE_ERROR || r.type === DataEvent.API_REQUEST_LAME) {
|
|
notify.alert(r.message, false);
|
|
} else {
|
|
if (r.type === DataEvent.PAGE_UPDATED) {
|
|
notify.alert(r.message, true);
|
|
} else {
|
|
notify.alert(r.message, true);
|
|
window.location = '/@/dashboard/page/edit/' + r.id;
|
|
}
|
|
}
|
|
}).catch(function (err) {
|
|
notify.alert(err, false);
|
|
});
|
|
});
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_DELETE:
|
|
if (this.postLayout === 'index') {
|
|
notify.alert('Index cannot be deleted', false);
|
|
return;
|
|
}
|
|
|
|
if (confirm("AYE! You know you're deleting this post, right?")) {
|
|
var id = {
|
|
id: this.postUUID
|
|
};
|
|
admin.pageActions(_FipamoAdminAPI.TASK_PAGE_DELETE, id).then(function () {
|
|
window.location = '/@/dashboard/page/list/';
|
|
}).catch(function (err) {
|
|
notify.alert(err, false);
|
|
});
|
|
} else {// Do nothing!
|
|
}
|
|
|
|
break;
|
|
|
|
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
|
|
document.getElementById('post-image-upload').click();
|
|
break;
|
|
}
|
|
}
|
|
}, {
|
|
key: "handleImageActions",
|
|
value: function handleImageActions(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
|
|
switch (e.type) {
|
|
case 'dragover':
|
|
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
|
|
|
|
break;
|
|
|
|
case 'change':
|
|
case 'drop':
|
|
e.type == 'drop' ? PostEditor.uploadFiles = e.dataTransfer.files : PostEditor.uploadFiles = e.target.files;
|
|
|
|
for (var i = 0, f; f = PostEditor.uploadFiles[i]; i++) {
|
|
// Only process image files.
|
|
if (!f.type.match('image.*')) {
|
|
continue;
|
|
}
|
|
|
|
var reader = new FileReader(); // Closure to capture the file information.
|
|
|
|
reader.onload = function (theFile) {
|
|
return function (f) {
|
|
// Render thumbnail.
|
|
var image = document.createElement('img');
|
|
image.src = f.target.result;
|
|
image.title = escape(theFile.name);
|
|
var span = document.createElement('div');
|
|
span.innerHTML = ['<img src="', f.target.result, '" title="', escape(theFile.name), '"/>'].join('');
|
|
document.getElementById('featured-image-drop').innerHTML = '';
|
|
document.getElementById('featured-image-drop').appendChild(image);
|
|
};
|
|
}(f); // Read in the image file as a data URL.
|
|
|
|
|
|
reader.readAsDataURL(f);
|
|
}
|
|
|
|
}
|
|
}
|
|
}, {
|
|
key: "handleImageUpload",
|
|
value: function handleImageUpload(type, files) {
|
|
var self = this;
|
|
admin.imageUpload(type, files).then(function (r) {
|
|
if (r.type == DataEvent.POST_IMAGE_ADDED) self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
|
|
}).catch(function () {//console.log('ERROR', err);
|
|
});
|
|
}
|
|
}]);
|
|
|
|
return PostEditor;
|
|
}();
|
|
|
|
exports.default = PostEditor;
|
|
PostEditor.uploadFiles = [];
|
|
},{"../../libraries/FipamoAdminAPI":"../libraries/FipamoAdminAPI.js","../events/DataEvent":"events/DataEvent.js","../actions/PageActions":"actions/PageActions.js","../events/EditorEvent":"events/EditorEvent.js","../ui/TextEditor":"ui/TextEditor.js","../ui/Notifications":"ui/Notifications.js"}],"controllers/PostIndex.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _PageEditor = _interopRequireDefault(require("./PageEditor"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var PostIndex = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function PostIndex(page) {
|
|
_classCallCheck(this, PostIndex);
|
|
|
|
this.currentPage = null;
|
|
this.choosePage(page);
|
|
this.start();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(PostIndex, [{
|
|
key: "start",
|
|
value: function start() {}
|
|
}, {
|
|
key: "choosePage",
|
|
value: function choosePage(page) {
|
|
this.currentPage = '';
|
|
|
|
switch (page) {
|
|
case 'edit':
|
|
case 'add':
|
|
this.currentPage = new _PageEditor.default();
|
|
break;
|
|
|
|
default:
|
|
//just chill
|
|
break;
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return PostIndex;
|
|
}();
|
|
|
|
exports.default = PostIndex;
|
|
},{"./PageEditor":"controllers/PageEditor.js"}],"actions/SettingsActions.js":[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 SettingsActions = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function SettingsActions() {
|
|
_classCallCheck(this, SettingsActions);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(SettingsActions, [{
|
|
key: "getInfo",
|
|
value: function getInfo() {
|
|
var handle = document.getElementById('settings-handle').value;
|
|
var email = document.getElementById('settings-email').value;
|
|
var url = document.getElementById('settings-url').value;
|
|
var title = document.getElementById('settings-title').value;
|
|
var desc = document.getElementById('settings-desc').value; //let privacy = document.getElementById('privacy-toggle').getAttribute('data-private');
|
|
|
|
var render = document.getElementById('render-toggle').getAttribute('data-render');
|
|
var background = document.getElementById('background').src;
|
|
var selected = '';
|
|
var selects = document.querySelectorAll('.theme-select');
|
|
var smtpDomain = document.getElementById('smtp-domain').value;
|
|
var smtpEmail = document.getElementById('smtp-email').value;
|
|
var smtpPass = document.getElementById('smtp-pass').value;
|
|
var mgDomain = document.getElementById('mg-domain').value;
|
|
var mgKey = document.getElementById('mg-key').value;
|
|
var mailActive = '';
|
|
var mailOptions = document.querySelectorAll('.mail-option');
|
|
var i, count;
|
|
|
|
for (i = 0, count = selects.length; i < count; i++) {
|
|
if (selects[i].getAttribute('data-enabled') == 'true') selected = selects[i].id;
|
|
}
|
|
|
|
for (i = 0, count = mailOptions.length; i < count; i++) {
|
|
if (mailOptions[i].getAttribute('data-enabled') == 'true') mailActive = mailOptions[i].id;
|
|
}
|
|
|
|
var settingsData = {
|
|
global: {
|
|
base_url: url,
|
|
title: title,
|
|
descriptions: desc,
|
|
background: background,
|
|
private: false,
|
|
renderOnSave: render,
|
|
theme: selected
|
|
},
|
|
member: {
|
|
handle: handle,
|
|
email: email
|
|
},
|
|
email: {
|
|
active: mailActive,
|
|
smtp: {
|
|
domain: smtpDomain,
|
|
email: smtpEmail,
|
|
password: smtpPass
|
|
},
|
|
mailgun: {
|
|
domain: mgDomain,
|
|
key: mgKey
|
|
}
|
|
}
|
|
};
|
|
return new Promise(function (resolve) {
|
|
resolve(settingsData);
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return SettingsActions;
|
|
}();
|
|
|
|
exports.default = SettingsActions;
|
|
},{}],"actions/Mailer.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _FipamoAdminAPI = _interopRequireDefault(require("../../libraries/FipamoAdminAPI"));
|
|
|
|
var _Notifications = _interopRequireDefault(require("../ui/Notifications"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var admin = new _FipamoAdminAPI.default();
|
|
var notify = new _Notifications.default();
|
|
|
|
var Mailer = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function Mailer() {
|
|
_classCallCheck(this, Mailer);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(Mailer, [{
|
|
key: "sendMail",
|
|
value: function sendMail() {
|
|
var mailData = {
|
|
content: 'This is a test email'
|
|
};
|
|
admin.sendMail(mailData).then(function (result) {
|
|
notify.alert(result.message, true);
|
|
}).catch(function (err) {
|
|
notify.alert(err.message, false);
|
|
});
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return Mailer;
|
|
}();
|
|
|
|
exports.default = Mailer;
|
|
},{"../../libraries/FipamoAdminAPI":"../libraries/FipamoAdminAPI.js","../ui/Notifications":"ui/Notifications.js"}],"controllers/SettingsIndex.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _SettingsActions = _interopRequireDefault(require("../actions/SettingsActions"));
|
|
|
|
var _FipamoAdminAPI = _interopRequireDefault(require("../../libraries/FipamoAdminAPI"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../../../src/com/events/DataEvent"));
|
|
|
|
var _Mailer = _interopRequireDefault(require("../actions/Mailer"));
|
|
|
|
var _Notifications = _interopRequireDefault(require("../ui/Notifications"));
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var admin = new _FipamoAdminAPI.default();
|
|
var notify = new _Notifications.default();
|
|
var mailer = new _Mailer.default();
|
|
|
|
var SettingsIndex = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function SettingsIndex() {
|
|
_classCallCheck(this, SettingsIndex);
|
|
|
|
this.start();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(SettingsIndex, [{
|
|
key: "start",
|
|
value: function start() {
|
|
var _this = this;
|
|
|
|
var self = this; //handle save button
|
|
|
|
document.getElementById('save-toggle').addEventListener('click', function () {
|
|
return new _SettingsActions.default().getInfo().then(function (data) {
|
|
admin.syncSettings(data).then(function (r) {
|
|
if (r.type == DataEvent.SETTINGS_UPDATED) {
|
|
notify.alert(r.message, true);
|
|
} else {
|
|
notify.alert(r.message, true);
|
|
}
|
|
});
|
|
}).catch(function () {//console.log(err);
|
|
});
|
|
}); //handle set up image uploads
|
|
|
|
document.getElementById('avatar').addEventListener('click', function () {
|
|
document.getElementById('avatar-upload').click();
|
|
});
|
|
document.getElementById('background').addEventListener('click', function () {
|
|
document.getElementById('background-upload').click();
|
|
});
|
|
document.getElementById('avatar-upload').addEventListener('change', function (e) {
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
}, false);
|
|
document.getElementById('background-upload').addEventListener('change', function (e) {
|
|
self.handleImageUpload(e.target.id, e.target.files);
|
|
}, false); //handle privacy toggle
|
|
//document
|
|
//.getElementById('privacy-toggle')
|
|
//.addEventListener('click', e => this.togglePrivacy(e));
|
|
|
|
document.getElementById('render-toggle').addEventListener('click', function (e) {
|
|
return _this.toggleRender(e);
|
|
});
|
|
document.getElementById('send-mail').addEventListener('click', function (e) {
|
|
return _this.handleMailer(e);
|
|
});
|
|
document.getElementById('publish-pages').addEventListener('click', function (e) {
|
|
return _this.handlePublished(e);
|
|
}); //handle theme toggle
|
|
|
|
var themeBtns = document.querySelectorAll('.theme-select');
|
|
|
|
for (var i = 0, length = themeBtns.length; i < length; i++) {
|
|
themeBtns[i].addEventListener('click', function (e) {
|
|
return _this.handleThemes(e);
|
|
});
|
|
} //handle mail options
|
|
|
|
|
|
var mailBtn = document.querySelectorAll('.mail-option');
|
|
|
|
for (i = 0, length = mailBtn.length; i < length; i++) {
|
|
mailBtn[i].addEventListener('click', function (e) {
|
|
return _this.handleMailOptions(e);
|
|
});
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "togglePrivacy",
|
|
value: function togglePrivacy(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
|
|
if (e.target.getAttribute('data-private') == 'false') {
|
|
e.target.setAttribute('data-private', 'true');
|
|
e.target.innerHTML = 'SITE IS PUBLIC';
|
|
} else {
|
|
e.target.setAttribute('data-private', 'false');
|
|
e.target.innerHTML = 'SITE IS PRIVATE';
|
|
}
|
|
}
|
|
}, {
|
|
key: "toggleRender",
|
|
value: function toggleRender(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
|
|
if (e.target.getAttribute('data-render') == 'false') {
|
|
e.target.setAttribute('data-render', 'true'); //e.target.innerHTML = 'RENDER PAGES ON SAVE';
|
|
} else {
|
|
e.target.setAttribute('data-render', 'false'); //e.target.innerHTML = "DON'T RENDER PAGES ON SAVE";
|
|
}
|
|
}
|
|
}, {
|
|
key: "handleMailer",
|
|
value: function handleMailer() {
|
|
mailer.sendMail();
|
|
}
|
|
}, {
|
|
key: "handleThemes",
|
|
value: function handleThemes(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
var themes = document.querySelectorAll('.theme-select');
|
|
|
|
for (var i = 0, length = themes.length; i < length; i++) {
|
|
e.target.id == themes[i].id ? themes[i].setAttribute('data-enabled', 'true') : themes[i].setAttribute('data-enabled', 'false');
|
|
}
|
|
}
|
|
}, {
|
|
key: "handleMailOptions",
|
|
value: function handleMailOptions(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
var smtp = document.getElementById('mail-smtp');
|
|
var mailgun = document.getElementById('mail-mg');
|
|
var mail = document.querySelectorAll('.mail-option');
|
|
|
|
for (var i = 0, length = mail.length; i < length; i++) {
|
|
if (e.target.id == mail[i].id) {
|
|
mail[i].setAttribute('data-enabled', 'true');
|
|
|
|
if (e.target.id == 'option-smtp') {
|
|
smtp.setAttribute('data-enabled', 'true');
|
|
mailgun.setAttribute('data-enabled', 'false');
|
|
} else if (e.target.id == 'option-none') {
|
|
smtp.setAttribute('data-enabled', 'false');
|
|
mailgun.setAttribute('data-enabled', 'false');
|
|
} else {
|
|
smtp.setAttribute('data-enabled', 'false');
|
|
mailgun.setAttribute('data-enabled', 'true');
|
|
}
|
|
} else {
|
|
mail[i].setAttribute('data-enabled', 'false');
|
|
}
|
|
}
|
|
}
|
|
}, {
|
|
key: "handleImageUpload",
|
|
value: function handleImageUpload(type, files) {
|
|
admin.imageUpload(type, files).then(function (r) {
|
|
if (r.type == DataEvent.AVATAR_UPLOADED) {
|
|
notify.alert(r.message, true);
|
|
document.getElementById('avatar').src = r.url;
|
|
} else {
|
|
notify.alert(r.message, true);
|
|
document.getElementById('background').src = r.url;
|
|
}
|
|
}).catch(function () {//console.log(err)
|
|
});
|
|
}
|
|
}, {
|
|
key: "handlePublished",
|
|
value: function handlePublished(e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
var task = {
|
|
task: 'publish all pages'
|
|
};
|
|
admin.publishSite(task).then(function (r) {
|
|
notify.alert(r.message, true);
|
|
}).catch(function (err) {
|
|
notify.alert(err, false);
|
|
});
|
|
}
|
|
}]);
|
|
|
|
return SettingsIndex;
|
|
}();
|
|
|
|
exports.default = SettingsIndex;
|
|
},{"../actions/SettingsActions":"actions/SettingsActions.js","../../libraries/FipamoAdminAPI":"../libraries/FipamoAdminAPI.js","../../../src/com/events/DataEvent":"events/DataEvent.js","../actions/Mailer":"actions/Mailer.js","../ui/Notifications":"ui/Notifications.js"}],"actions/NavActions.js":[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 NavActions = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function NavActions() {
|
|
_classCallCheck(this, NavActions);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(NavActions, [{
|
|
key: "syncMenu",
|
|
value: function syncMenu() {
|
|
var navData = [];
|
|
var items = document.getElementById('nav-pages').children;
|
|
|
|
for (var index = 0; index < items.length; index++) {
|
|
navData.push({
|
|
title: items[index].getElementsByTagName('label')[0].innerHTML,
|
|
id: items[index].id,
|
|
slug: items[index].getAttribute('data-slug'),
|
|
uuid: items[index].getAttribute('data-uuid'),
|
|
path: items[index].getAttribute('data-path')
|
|
});
|
|
}
|
|
|
|
var data = {
|
|
nav: navData,
|
|
remove: null
|
|
};
|
|
return new Promise(function (resolve) {
|
|
resolve(data);
|
|
});
|
|
}
|
|
}, {
|
|
key: "removeItem",
|
|
value: function removeItem(id) {
|
|
document.getElementById('nav-pages').removeChild(document.getElementById(id));
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return NavActions;
|
|
}();
|
|
|
|
exports.default = NavActions;
|
|
},{}],"controllers/NavIndex.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _FipamoAdminAPI = _interopRequireDefault(require("../../libraries/FipamoAdminAPI"));
|
|
|
|
var _NavActions = _interopRequireDefault(require("../actions/NavActions"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("../events/DataEvent"));
|
|
|
|
var _Notifications = _interopRequireDefault(require("../ui/Notifications"));
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var notify = new _Notifications.default();
|
|
var admin = new _FipamoAdminAPI.default();
|
|
|
|
var NavIndex = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function NavIndex() {
|
|
_classCallCheck(this, NavIndex);
|
|
|
|
this.start();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(NavIndex, [{
|
|
key: "start",
|
|
value: function start() {
|
|
var _this = this;
|
|
|
|
Sortable.create(document.getElementById('nav-pages'), {
|
|
onUpdate: function onUpdate() {
|
|
new _NavActions.default().syncMenu().then(function (data) {
|
|
admin.syncNav(data).then(function (r) {
|
|
if (r.type == DataEvent.MENU_UPDATED) {
|
|
notify.alert(r.message, true);
|
|
} else {
|
|
notify.alert(r.message, true);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|
|
var nav = document.querySelectorAll('.nav-btn');
|
|
|
|
for (var i = 0, length = nav.length; i < length; i++) {
|
|
nav[i].addEventListener('click', function (e) {
|
|
return _this.handleNavButton(e);
|
|
}, false);
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handleNavButton",
|
|
value: function handleNavButton(e) {
|
|
var id = '';
|
|
|
|
switch (e.target.id) {
|
|
case 'remove-item':
|
|
id = e.target.getAttribute('data-id');
|
|
new _NavActions.default().removeItem(id);
|
|
new _NavActions.default().syncMenu().then(function (data) {
|
|
data.remove = e.target.getAttribute('data-uuid');
|
|
admin.syncNav(data).then(function (r) {
|
|
if (r.type == DataEvent.MENU_UPDATED) {
|
|
notify.alert(r.message, true);
|
|
} else {
|
|
notify.alert(r.message, true);
|
|
}
|
|
});
|
|
});
|
|
break;
|
|
|
|
case 'edit-item':
|
|
window.location = '/@/dashboard/page/edit/' + e.target.getAttribute('data-id');
|
|
break;
|
|
}
|
|
}
|
|
}]);
|
|
|
|
return NavIndex;
|
|
}();
|
|
|
|
exports.default = NavIndex;
|
|
},{"../../libraries/FipamoAdminAPI":"../libraries/FipamoAdminAPI.js","../actions/NavActions":"actions/NavActions.js","../events/DataEvent":"events/DataEvent.js","../ui/Notifications":"ui/Notifications.js"}],"controllers/DashManager.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _PostIndex = _interopRequireDefault(require("./PostIndex"));
|
|
|
|
var _SettingsIndex = _interopRequireDefault(require("./SettingsIndex"));
|
|
|
|
var _NavIndex = _interopRequireDefault(require("./NavIndex"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var DashManager = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function DashManager() {
|
|
_classCallCheck(this, DashManager);
|
|
|
|
this.currentDisplay = '';
|
|
this.urlPieces = document.URL.split('/');
|
|
this.chooseDisplay(this.urlPieces[5], this.urlPieces[6]);
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(DashManager, [{
|
|
key: "start",
|
|
value: function start() {}
|
|
}, {
|
|
key: "chooseDisplay",
|
|
value: function chooseDisplay(section, page) {
|
|
this.currentDisplay = '';
|
|
|
|
switch (section) {
|
|
case 'page':
|
|
this.currentDisplay = new _PostIndex.default(page);
|
|
break;
|
|
|
|
case 'settings':
|
|
this.currentDisplay = new _SettingsIndex.default();
|
|
break;
|
|
|
|
case 'navigation':
|
|
this.currentDisplay = new _NavIndex.default();
|
|
break;
|
|
|
|
default:
|
|
//just chill
|
|
break;
|
|
}
|
|
|
|
this.start();
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}]);
|
|
|
|
return DashManager;
|
|
}();
|
|
|
|
exports.default = DashManager;
|
|
},{"./PostIndex":"controllers/PostIndex.js","./SettingsIndex":"controllers/SettingsIndex.js","./NavIndex":"controllers/NavIndex.js"}],"Base.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = void 0;
|
|
|
|
var _FipamoAPI = _interopRequireDefault(require("../libraries/FipamoAPI"));
|
|
|
|
var _DataUtils = _interopRequireDefault(require("./utils/DataUtils"));
|
|
|
|
var DataEvent = _interopRequireWildcard(require("./events/DataEvent"));
|
|
|
|
var _DashManager = _interopRequireDefault(require("./controllers/DashManager"));
|
|
|
|
var _Notifications = _interopRequireDefault(require("./ui/Notifications"));
|
|
|
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
|
|
|
|
var api = new _FipamoAPI.default();
|
|
var data = new _DataUtils.default();
|
|
var notify = new _Notifications.default();
|
|
|
|
var Base = /*#__PURE__*/function () {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
function Base() {
|
|
_classCallCheck(this, Base);
|
|
|
|
this.start();
|
|
} //--------------------------
|
|
// methods
|
|
//--------------------------
|
|
|
|
|
|
_createClass(Base, [{
|
|
key: "start",
|
|
value: function start() {
|
|
var _this = this;
|
|
|
|
if (document.getElementById('dash-form') || document.getElementById('dash-init')) {
|
|
if (document.getElementById('dash-form')) {
|
|
document.getElementById('login-btn').addEventListener('click', function (e) {
|
|
return _this.handleLogin(e);
|
|
});
|
|
} else {
|
|
document.getElementById('init-blog').addEventListener('click', function (e) {
|
|
return _this.handleSetup(e);
|
|
});
|
|
}
|
|
} else {
|
|
new _DashManager.default();
|
|
}
|
|
} //--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
|
|
}, {
|
|
key: "handleLogin",
|
|
value: function handleLogin(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
var authForm = data.formDataToJSON(document.getElementById('login'));
|
|
api.login(authForm).then(function (response) {
|
|
if (response.type === DataEvent.REQUEST_LAME) {
|
|
notify.alert(response.message, false);
|
|
} else {
|
|
e.target.innerHTML = response.message;
|
|
setTimeout(function () {
|
|
window.location = '/@/dashboard';
|
|
}, 500);
|
|
}
|
|
}).catch(function (err) {
|
|
notify.alert(err, false);
|
|
});
|
|
}
|
|
}, {
|
|
key: "handleSetup",
|
|
value: function handleSetup(e) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
var setUpForm = data.formDataToJSON(document.getElementById('init-form'));
|
|
api.init(setUpForm).then(function (response) {
|
|
if (response.type === DataEvent.API_INIT_LAME) {
|
|
notify.alert(response.message, false);
|
|
} else {
|
|
notify.alert(response.message, true);
|
|
setTimeout(function () {
|
|
window.location = '/@/dashboard';
|
|
}, 700);
|
|
}
|
|
}).catch(function (err) {
|
|
notify.alert(err, false);
|
|
});
|
|
}
|
|
}]);
|
|
|
|
return Base;
|
|
}();
|
|
|
|
exports.default = Base;
|
|
},{"../libraries/FipamoAPI":"../libraries/FipamoAPI.js","./utils/DataUtils":"utils/DataUtils.js","./events/DataEvent":"events/DataEvent.js","./controllers/DashManager":"controllers/DashManager.js","./ui/Notifications":"ui/Notifications.js"}],"Start.js":[function(require,module,exports) {
|
|
"use strict";
|
|
|
|
var _Base = _interopRequireDefault(require("./Base"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
new _Base.default();
|
|
}, false);
|
|
},{"./Base":"Base.js"}],"../../node_modules/parcel/src/builtins/hmr-runtime.js":[function(require,module,exports) {
|
|
var global = arguments[3];
|
|
var OVERLAY_ID = '__parcel__error__overlay__';
|
|
var OldModule = module.bundle.Module;
|
|
|
|
function Module(moduleName) {
|
|
OldModule.call(this, moduleName);
|
|
this.hot = {
|
|
data: module.bundle.hotData,
|
|
_acceptCallbacks: [],
|
|
_disposeCallbacks: [],
|
|
accept: function (fn) {
|
|
this._acceptCallbacks.push(fn || function () {});
|
|
},
|
|
dispose: function (fn) {
|
|
this._disposeCallbacks.push(fn);
|
|
}
|
|
};
|
|
module.bundle.hotData = null;
|
|
}
|
|
|
|
module.bundle.Module = Module;
|
|
var checkedAssets, assetsToAccept;
|
|
var parent = module.bundle.parent;
|
|
|
|
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
|
|
var hostname = "" || location.hostname;
|
|
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
|
|
var ws = new WebSocket(protocol + '://' + hostname + ':' + "52729" + '/');
|
|
|
|
ws.onmessage = function (event) {
|
|
checkedAssets = {};
|
|
assetsToAccept = [];
|
|
var data = JSON.parse(event.data);
|
|
|
|
if (data.type === 'update') {
|
|
var handled = false;
|
|
data.assets.forEach(function (asset) {
|
|
if (!asset.isNew) {
|
|
var didAccept = hmrAcceptCheck(global.parcelRequire, asset.id);
|
|
|
|
if (didAccept) {
|
|
handled = true;
|
|
}
|
|
}
|
|
}); // Enable HMR for CSS by default.
|
|
|
|
handled = handled || data.assets.every(function (asset) {
|
|
return asset.type === 'css' && asset.generated.js;
|
|
});
|
|
|
|
if (handled) {
|
|
console.clear();
|
|
data.assets.forEach(function (asset) {
|
|
hmrApply(global.parcelRequire, asset);
|
|
});
|
|
assetsToAccept.forEach(function (v) {
|
|
hmrAcceptRun(v[0], v[1]);
|
|
});
|
|
} else if (location.reload) {
|
|
// `location` global exists in a web worker context but lacks `.reload()` function.
|
|
location.reload();
|
|
}
|
|
}
|
|
|
|
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 hmrAcceptCheck(bundle, id) {
|
|
var modules = bundle.modules;
|
|
|
|
if (!modules) {
|
|
return;
|
|
}
|
|
|
|
if (!modules[id] && bundle.parent) {
|
|
return hmrAcceptCheck(bundle.parent, id);
|
|
}
|
|
|
|
if (checkedAssets[id]) {
|
|
return;
|
|
}
|
|
|
|
checkedAssets[id] = true;
|
|
var cached = bundle.cache[id];
|
|
assetsToAccept.push([bundle, id]);
|
|
|
|
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
|
|
return true;
|
|
}
|
|
|
|
return getParents(global.parcelRequire, id).some(function (id) {
|
|
return hmrAcceptCheck(global.parcelRequire, id);
|
|
});
|
|
}
|
|
|
|
function hmrAcceptRun(bundle, 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;
|
|
}
|
|
}
|
|
},{}]},{},["../../node_modules/parcel/src/builtins/hmr-runtime.js","Start.js"], null)
|
|
//# sourceMappingURL=/assets/scripts/dash.min.js.map
|