From 45fd8be25f9a50d00388cfe4e7cc6e5a4d8f7229 Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 17 Jun 2021 13:26:04 -0700 Subject: [PATCH] reorganized API methods into new files --- public/assets/scripts/dash.min.js | 8 +- src/com/Base.js | 12 +- src/libraries/FipamoAdminAPI.js | 105 ++----- .../{FipamoAPI.js => FipamoContentAPI.js} | 185 +++++-------- src/libraries/FipamoUtilityAPI.js | 258 ++++++++++++++++++ 5 files changed, 363 insertions(+), 205 deletions(-) rename src/libraries/{FipamoAPI.js => FipamoContentAPI.js} (65%) create mode 100644 src/libraries/FipamoUtilityAPI.js diff --git a/public/assets/scripts/dash.min.js b/public/assets/scripts/dash.min.js index 9cef926..44a7e5b 100644 --- a/public/assets/scripts/dash.min.js +++ b/public/assets/scripts/dash.min.js @@ -1,11 +1,11 @@ -!function(){"use strict";function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:null;e(this,t),this.baseURL=null,n&&(this.baseURL=n)}return n(t,[{key:"login",value:function(e){var t=this;return new Promise((function(n,r){t._request(t.baseURL?t.baseURL+d:d,"getAuthStatus",s,u,e).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"init",value:function(e){var t=this;return new Promise((function(n,r){t._request("/api/v1/init","blogInit",s,u,e).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"handleInitRestore",value:function(e){var t=this;return new Promise((function(n,r){var o;o=new FormData(e),t._request("/api/v1/restore","downloadBackup","POST","x-www-form-urlencoded",o).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"getSecret",value:function(e){var t=this;return new Promise((function(n,r){t._request("/api/v1/get-secret","retrieveSecret",s,u,e).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"setNewPass",value:function(e){var t=this;return new Promise((function(n,r){t._request("/api/v1/reset-password","resetPassword",s,u,e).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"getPages",value:function(e,t){var n=this;return new Promise((function(e,r){n._request(n.baseURL?n.baseURL+f+"?key="+t:f,p,l).then((function(t){e(t)})).catch((function(e){r(e)}))}))}},{key:"getPage",value:function(e,t){var n=this;return new Promise((function(r,o){n._request(n.baseURL?n.baseURL+h+"/"+e+"?key="+t:h,p,l).then((function(e){r(e)})).catch((function(e){o(e)}))}))}},{key:"_request",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:l,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:u,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i=this;return new Promise((function(t,a){var l=new XMLHttpRequest;if(l.upload.onprogress=i.handleLoadProgress,l.open(n,e,!0),l.onload=function(){if(200==l.status){var e=JSON.parse(l.response);t(e)}else{var n=JSON.parse(l.response);a(n)}},"PUT"==n||n==s)switch(r){case u:l.setRequestHeader("Content-type","application/"+r),l.send(JSON.stringify(o));break;case c:l.send(o)}else l.send()}))}},{key:"handleLoadProgress",value:function(e){this.percentComplete=Math.ceil(e.loaded/e.total*100)}}]),t}(),m=function(){function t(){e(this,t)}return n(t,[{key:"imgLoad",value:function(e){return new Promise((function(t,n){var r=new XMLHttpRequest;r.open("GET",e),r.responseType="blob",r.onload=function(){200===r.status?t(r.response):n(new Error("Image didn't load successfully; error code:"+r.statusText))},r.onerror=function(){n(new Error("There was a network error."))},r.send()}))}},{key:"loadImage",value:function(e){var t=this;return new Promise((function(n,r){(new Image).crossOrigin="",t.imgLoad(e).then((function(e){var t=window.URL.createObjectURL(e);n(t)}),(function(e){r(e)}))}))}},{key:"formDataToJSON",value:function(e){var t={};return new FormData(e).forEach((function(e,n){t.hasOwnProperty(n)?(Array.isArray(t[n])||(t[n]=[t[n]]),t[n].push(e)):t[n]=e})),t}}]),t}(),v="requestLame",y="postUpdated",b="writingItDown",w="erasingPage",E="savingSettings",I="createBackup",k="downloadBackup",S="uploadProfileImages",T="renderPages",P="reindexPages";new function t(){e(this,t)};var D="POST",x="createNewPage",_="editPage",B="deletePage",A="json",C="x-www-form-urlencoded",O=function(){function t(){var n=this;e(this,t),this.percentComplete=0,this.token=null,this._request("/api/v1/status").then((function(e){"apiUseAuthorized"===e.type&&(n.token=e.token)}))}return n(t,[{key:"syncSettings",value:function(e){var t=this;return new Promise((function(n,r){t._request("/api/v1/settings/sync",E,D,A,e).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"imageUpload",value:function(e,t){var n=this;return new Promise((function(r,o){var i="";switch(e){case"avatar-upload":i="/api/v1/settings/add-avatar";break;case"background-upload":i="/api/v1/settings/add-feature-background";break;default:i="/api/v1/page/add-entry-image"}for(var a=new FormData,s=0;s2&&void 0!==arguments[2]?arguments[2]:"GET",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:A,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i=this;return new Promise((function(a,s){var l=new XMLHttpRequest;if(l.upload.onprogress=i.handleLoadProgress,l.open(n,e,!0),l.onload=function(){if(200==l.status){var e=JSON.parse(l.response);a(e)}else{var t=JSON.parse(l.response);s(t)}},"PUT"==n||n==D)switch(t!==b&&t!==S&&t!==E&&t!==w&&t!==T&&t!==I&&t!==k&&t!==P||l.setRequestHeader("fipamo-access-token",i.token),r){case A:l.setRequestHeader("Content-type","application/"+r),l.send(JSON.stringify(o));break;case C:l.send(o)}else l.send()}))}},{key:"handleLoadProgress",value:function(e){this.percentComplete=Math.ceil(e.loaded/e.total*100)}}]),t}(),M=function(){function t(){e(this,t)}return n(t,[{key:"cleanString",value:function(e){return e.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g,"").toLowerCase().replace(/[\/_| -]+/g,"-")}},{key:"decodeHTML",value:function(e,t){var n=0,r=0,o=!1;void 0===t&&(t=2),e=e.toString().replace(/</g,"<").replace(/>/g,">");var i={ENT_NOQUOTES:0,ENT_HTML_QUOTE_SINGLE:1,ENT_HTML_QUOTE_DOUBLE:2,ENT_COMPAT:2,ENT_QUOTES:3,ENT_IGNORE:4};if(0===t&&(o=!0),"number"!=typeof t){for(t=[].concat(t),r=0;r]*>/g,"\n"),r.append("id",document.getElementById("post-edit-index").getAttribute("data-index")),r.append("uuid",document.getElementById("post-edit-index").getAttribute("data-uuid")),r.append("layout",document.getElementById("post-edit-index").getAttribute("data-layout")),r.append("current_title",document.getElementById("post-edit-index").getAttribute("data-slug")),r.append("content",i),r.append("title",document.getElementById("post_title").value),r.append("created",document.getElementById("post-date").getAttribute("data-raw")),r.append("slug",(new M).cleanString(document.getElementById("post_title").value)),r.append("tags",document.getElementById("post_tags").value),r.append("menu",document.getElementById("option-menu-pin").getAttribute("data-active")),r.append("featured",document.getElementById("option-feature").getAttribute("data-active")),r.append("published",document.getElementById("option-published").getAttribute("data-active")),null!=e||null!=e)e.type.match("image.*")?r.append("feature_image",e,e.name):n("Not an image file");else{var a=document.getElementById("featured-image").src;null!=a||null!=a?r.append("feature_image",a):r.append("feature_image",null)}t(r)}))}}]),t}(),L="editorDelete",R="editorUploadImage",H="editorSave",U="editorUpdate";new function t(){e(this,t)};var F=["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"],X=function(e,t){var n=document.createElement("div");return function(t){var r=function(){var t={position:"absolute",left:-9999,top:0,zIndex:-2e3};return"TEXTAREA"===e.tagName&&F.push("width"),F.forEach((function(n){t[n]=getComputedStyle(e)[n]})),t}();Object.keys(r).forEach((function(e){n.style[e]=r[e]})),n.innerHTML=t,e.parentNode.insertBefore(n,e.nextSibling)}(t),{rect:function(){var e=n.ownerDocument.getElementById("caret-position-marker"),t={left:e.offsetLeft,top:e.offsetTop,height:e.offsetHeight};return n.parentNode.removeChild(n),t}}};function q(e){return(q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var Y=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.customPos,n=e.iframe,r=e.noShadowCaret;return n?{iframe:n,window:n.contentWindow,document:n.contentDocument||n.contentWindow.document,noShadowCaret:r,customPos:t}:{window:window,document:document,noShadowCaret:r,customPos:t}},j=function(e){return"object"===q(e)&&null!==e},W=function(e,t){var n=function(){return e.selectionStart},r=function(r){var o=function(e){return e.replace(/<|>|`|"|&/g,"?").replace(/\r\n|\r|\n/g,"
")};(t.customPos||0===t.customPos)&&(r=t.customPos);var i=void 0===r?n():r,a=e.value.slice(0,i),s=e.value.slice(i),l=''.concat(o(a),"");l+='|',l+=''.concat(o(s),"");var u=X(e,l).rect();return u.pos=n(),u};return{getPos:n,setPos:function(t){return e.setSelectionRange(t,t),e},getOffset:function(n){var o=function(e,t){var n=t&&t.window||window,r=t&&t.document||document,o=e.getBoundingClientRect(),i=r.documentElement,a=n.pageXOffset||i.scrollLeft,s=n.pageYOffset||i.scrollTop;return{top:o.top+s,left:o.left+a}}(e),i=r(n);return{top:o.top+i.top+t.document.body.scrollTop,left:o.left+i.left+t.document.body.scrollLeft,height:i.height}},getPosition:r}},z=function(e,t){return function(e){return!!(e.contentEditable?"true"===e.contentEditable:"true"===e.getAttribute("contenteditable"))}(e)?function(e,t){var n=function(){var n=r(),o={height:0,left:0,right:0};if(!n)return o;var i=t.customPos||0===t.customPos;if(n.endOffset-1>0&&n.endContainer!==e||i){var a=n.cloneRange(),s=i?t.customPos:n.endOffset;a.setStart(n.endContainer,s-1<0?0:s-1),a.setEnd(n.endContainer,s);var l=a.getBoundingClientRect();o={height:l.height,left:l.left+l.width,top:l.top},a.detach()}if((!o||o&&0===o.height)&&!t.noShadowCaret){var u=n.cloneRange(),c=t.document.createTextNode("|");u.insertNode(c),u.selectNode(c);var d=u.getBoundingClientRect();o={height:d.height,left:d.left,top:d.top},c.parentNode.removeChild(c),u.detach()}if(o){var f=t.document.documentElement;o.top+=t.window.pageYOffset-(f.clientTop||0),o.left+=t.window.pageXOffset-(f.clientLeft||0)}return o},r=function(){if(t.window.getSelection){var e=t.window.getSelection();return e.rangeCount>0?e.getRangeAt(0):null}},o=function(){var t=r(),n=t.cloneRange();n.selectNodeContents(e),n.setEnd(t.endContainer,t.endOffset);var o=n.toString().length;return n.detach(),o};return{getPos:o,setPos:function(n){var r=t.window.getSelection();if(r){var o=0,i=!1;!function e(a,s){for(var l=0;l=a){i=!0;var c=t.document.createRange();c.setStart(u,a-o),r.removeAllRanges(),r.addRange(c);break}o+=u.length}else e(n,u)}}(n,e)}return e},getPosition:function(){var r=n(),i=o(),a=e.getBoundingClientRect(),s=a.top+t.document.body.scrollTop,l=a.left+t.document.body.scrollLeft;return r.left-=l,r.top-=s,r.pos=i,r},getOffset:n,getRange:r}}(e,t):W(e,t)},G=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n;j(t)&&(r=t,t=null);var o=Y(r),i=z(e,o);return t||0===t?i.setPos(t):i.getPosition()},Q=function(t){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(i,t);var r=a(i);function i(t,n){var o;return e(this,i),(o=r.call(this)).textEditor=t,o.fixLimit=n,o.caretPos=null,o.url="",o.setInputs(),window.addEventListener("scroll",(function(){})),o.refresh(),o}return n(i,[{key:"setInputs",value:function(){for(var e=this,t=this,n=document.querySelectorAll(".editor-button"),r=0,o=n.length;r/g)>-1){var o=G(e.textEditor).pos;t.refresh(),G(e.textEditor,o)}}))}},{key:"refresh",value:function(){var e=this.textEditor.innerText;e=e.replace(new RegExp("\r?\n","g"),"
");var t=document.createElement("div");t.innerText=e,this.textEditor.innerHTML=t.innerText,this.textEditor.style.maxWidth="900px"}},{key:"notify",value:function(e,t){switch(e){case y: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")}),2e3);break;case"postAdded":break;case R:var n,r;G(this.textEditor,this.caretPos),(n=window.getSelection()).rangeCount&&((r=n.getRangeAt(0)).deleteContents(),r.insertNode(document.createTextNode("![image alt text]("+t+" 'image title')"))),this.refresh()}}},{key:"handleEditorOption",value:function(e){var t,n,r;if(e.preventDefault(),(t=window.getSelection()).rangeCount)switch(n=t.getRangeAt(0),r=t.getRangeAt(0).toString(),n.deleteContents(),e.target.id){case"edit-bold":n.insertNode(document.createTextNode("**"+r+"**"));break;case"edit-italic":n.insertNode(document.createTextNode("*"+r+"*"));break;case"edit-strikethrough":n.insertNode(document.createTextNode(""+r+""));break;case"edit-header1":n.insertNode(document.createTextNode("# "+r));break;case"edit-header2":n.insertNode(document.createTextNode("## "+r));break;case"edit-header3":n.insertNode(document.createTextNode("### "+r));break;case"edit-image":this.caretPos=G(this.textEditor).pos,this.emitEvent(R);break;case"submit-save":case"edit-save":this.emitEvent(H);break;case"submit-update":case"edit-update":this.emitEvent(U);break;case"edit-link":n.insertNode(document.createTextNode("["+r+"](PASTE URL HERE)"));break;case"edit-delete":this.emitEvent(L)}this.refresh()}}]),i}(function(){function t(){e(this,t),this.listeners=new Map}return n(t,[{key:"addListener",value:function(e,t){this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t)}},{key:"removeListener",value:function(e,t){var n,r=this.listeners.get(e);return!!(r&&r.length&&(n=r.reduce((function(e,n,r){return"function"==typeof n&&n===t?e=r:e}),-1))>-1)&&(r.splice(n,1),this.listeners.set(e,r),!0)}},{key:"emitEvent",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r-1}function te(e,t){return e.apply(null,t)}var ne={arr:function(e){return Array.isArray(e)},obj:function(e){return ee(Object.prototype.toString.call(e),"Object")},pth:function(e){return ne.obj(e)&&e.hasOwnProperty("totalLength")},svg:function(e){return e instanceof SVGElement},inp:function(e){return e instanceof HTMLInputElement},dom:function(e){return e.nodeType||ne.svg(e)},str:function(e){return"string"==typeof e},fnc:function(e){return"function"==typeof e},und:function(e){return void 0===e},nil:function(e){return ne.und(e)||null===e},hex:function(e){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e)},rgb:function(e){return/^rgb/.test(e)},hsl:function(e){return/^hsl/.test(e)},col:function(e){return ne.hex(e)||ne.rgb(e)||ne.hsl(e)},key:function(e){return!V.hasOwnProperty(e)&&!J.hasOwnProperty(e)&&"targets"!==e&&"keyframes"!==e}};function re(e){var t=/\(([^)]+)\)/.exec(e);return t?t[1].split(",").map((function(e){return parseFloat(e)})):[]}function oe(e,t){var n=re(e),r=K(ne.und(n[0])?1:n[0],.1,100),o=K(ne.und(n[1])?100:n[1],.1,100),i=K(ne.und(n[2])?10:n[2],.1,100),a=K(ne.und(n[3])?0:n[3],.1,100),s=Math.sqrt(o/r),l=i/(2*Math.sqrt(o*r)),u=l<1?s*Math.sqrt(1-l*l):0,c=l<1?(l*s-a)/u:-a+s;function d(e){var n=t?t*e/1e3:e;return n=l<1?Math.exp(-n*l*s)*(1*Math.cos(u*n)+c*Math.sin(u*n)):(1+c*n)*Math.exp(-n*s),0===e||1===e?e:1-n}return t?d:function(){var t=Z.springs[e];if(t)return t;for(var n=1/6,r=0,o=0;;)if(1===d(r+=n)){if(++o>=16)break}else o=0;var i=r*n*1e3;return Z.springs[e]=i,i}}function ie(e){return void 0===e&&(e=10),function(t){return Math.ceil(K(t,1e-6,1)*e)*(1/e)}}var ae,se,le=function(){var e=.1;function t(e,t){return 1-3*t+3*e}function n(e,t){return 3*t-6*e}function r(e){return 3*e}function o(e,o,i){return((t(o,i)*e+n(o,i))*e+r(o))*e}function i(e,o,i){return 3*t(o,i)*e*e+2*n(o,i)*e+r(o)}return function(t,n,r,a){if(0<=t&&t<=1&&0<=r&&r<=1){var s=new Float32Array(11);if(t!==n||r!==a)for(var l=0;l<11;++l)s[l]=o(l*e,t,r);return function(e){return t===n&&r===a||0===e||1===e?e:o(u(e),n,a)}}function u(n){for(var a=0,l=1;10!==l&&s[l]<=n;++l)a+=e;--l;var u=a+(n-s[l])/(s[l+1]-s[l])*e,c=i(u,t,r);return c>=.001?function(e,t,n,r){for(var a=0;a<4;++a){var s=i(t,n,r);if(0===s)return t;t-=(o(t,n,r)-e)/s}return t}(n,u,t,r):0===c?u:function(e,t,n,r,i){var a,s,l=0;do{(a=o(s=t+(n-t)/2,r,i)-e)>0?n=s:t=s}while(Math.abs(a)>1e-7&&++l<10);return s}(n,a,a+e,t,r)}}}(),ue=(ae={linear:function(){return function(e){return e}}},se={Sine:function(){return function(e){return 1-Math.cos(e*Math.PI/2)}},Circ:function(){return function(e){return 1-Math.sqrt(1-e*e)}},Back:function(){return function(e){return e*e*(3*e-2)}},Bounce:function(){return function(e){for(var t,n=4;e<((t=Math.pow(2,--n))-1)/11;);return 1/Math.pow(4,3-n)-7.5625*Math.pow((3*t-2)/22-e,2)}},Elastic:function(e,t){void 0===e&&(e=1),void 0===t&&(t=.5);var n=K(e,1,10),r=K(t,.1,2);return function(e){return 0===e||1===e?e:-n*Math.pow(2,10*(e-1))*Math.sin((e-1-r/(2*Math.PI)*Math.asin(1/n))*(2*Math.PI)/r)}}},["Quad","Cubic","Quart","Quint","Expo"].forEach((function(e,t){se[e]=function(){return function(e){return Math.pow(e,t+2)}}})),Object.keys(se).forEach((function(e){var t=se[e];ae["easeIn"+e]=t,ae["easeOut"+e]=function(e,n){return function(r){return 1-t(e,n)(1-r)}},ae["easeInOut"+e]=function(e,n){return function(r){return r<.5?t(e,n)(2*r)/2:1-t(e,n)(-2*r+2)/2}},ae["easeOutIn"+e]=function(e,n){return function(r){return r<.5?(1-t(e,n)(1-2*r))/2:(t(e,n)(2*r-1)+1)/2}}})),ae);function ce(e,t){if(ne.fnc(e))return e;var n=e.split("(")[0],r=ue[n],o=re(e);switch(n){case"spring":return oe(e,t);case"cubicBezier":return te(le,o);case"steps":return te(ie,o);default:return te(r,o)}}function de(e){try{return document.querySelectorAll(e)}catch(e){return}}function fe(e,t){for(var n=e.length,r=arguments.length>=2?t:void 0,o=[],i=0;i1&&(n-=1),n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}if(0==a)t=n=r=s;else{var c=s<.5?s*(1+a):s+a-s*a,d=2*s-c;t=u(d,c,i+1/3),n=u(d,c,i),r=u(d,c,i-1/3)}return"rgba("+255*t+","+255*n+","+255*r+","+l+")"}(e):void 0;var t,n}function we(e){var t=/[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(e);if(t)return t[1]}function Ee(e,t){return ne.fnc(e)?e(t.target,t.id,t.total):e}function Ie(e,t){return e.getAttribute(t)}function ke(e,t,n){if(ge([n,"deg","rad","turn"],we(t)))return t;var r=Z.CSS[t+n];if(!ne.und(r))return r;var o=document.createElement(e.tagName),i=e.parentNode&&e.parentNode!==document?e.parentNode:document.body;i.appendChild(o),o.style.position="absolute",o.style.width=100+n;var a=100/o.offsetWidth;i.removeChild(o);var s=a*parseFloat(t);return Z.CSS[t+n]=s,s}function Se(e,t,n){if(t in e.style){var r=t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),o=e.style[t]||getComputedStyle(e).getPropertyValue(r)||"0";return n?ke(e,o,n):o}}function Te(e,t){return ne.dom(e)&&!ne.inp(e)&&(!ne.nil(Ie(e,t))||ne.svg(e)&&e[t])?"attribute":ne.dom(e)&&ge($,t)?"transform":ne.dom(e)&&"transform"!==t&&Se(e,t)?"css":null!=e[t]?"object":void 0}function Pe(e){if(ne.dom(e)){for(var t,n=e.style.transform||"",r=/(\w+)\(([^)]*)\)/g,o=new Map;t=r.exec(n);)o.set(t[1],t[2]);return o}}function De(e,t,n,r){var o=ee(t,"scale")?1:0+function(e){return ee(e,"translate")||"perspective"===e?"px":ee(e,"rotate")||ee(e,"skew")?"deg":void 0}(t),i=Pe(e).get(t)||o;return n&&(n.transforms.list.set(t,i),n.transforms.last=t),r?ke(e,i,r):i}function xe(e,t,n,r){switch(Te(e,t)){case"transform":return De(e,t,r,n);case"css":return Se(e,t,n);case"attribute":return Ie(e,t);default:return e[t]||0}}function _e(e,t){var n=/^(\*=|\+=|-=)/.exec(e);if(!n)return e;var r=we(e)||0,o=parseFloat(t),i=parseFloat(e.replace(n[0],""));switch(n[0][0]){case"+":return o+i+r;case"-":return o-i+r;case"*":return o*i+r}}function Be(e,t){if(ne.col(e))return be(e);if(/\s/g.test(e))return e;var n=we(e),r=n?e.substr(0,e.length-n.length):e;return t?r+t:r}function Ae(e,t){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function Ce(e){for(var t,n=e.points,r=0,o=0;o0&&(r+=Ae(t,i)),t=i}return r}function Oe(e){if(e.getTotalLength)return e.getTotalLength();switch(e.tagName.toLowerCase()){case"circle":return function(e){return 2*Math.PI*Ie(e,"r")}(e);case"rect":return function(e){return 2*Ie(e,"width")+2*Ie(e,"height")}(e);case"line":return function(e){return Ae({x:Ie(e,"x1"),y:Ie(e,"y1")},{x:Ie(e,"x2"),y:Ie(e,"y2")})}(e);case"polyline":return Ce(e);case"polygon":return function(e){var t=e.points;return Ce(e)+Ae(t.getItem(t.numberOfItems-1),t.getItem(0))}(e)}}function Me(e,t){var n=t||{},r=n.el||function(e){for(var t=e.parentNode;ne.svg(t)&&ne.svg(t.parentNode);)t=t.parentNode;return t}(e),o=r.getBoundingClientRect(),i=Ie(r,"viewBox"),a=o.width,s=o.height,l=n.viewBox||(i?i.split(" "):[0,0,a,s]);return{el:r,viewBox:l,x:l[0]/1,y:l[1]/1,w:a,h:s,vW:l[2],vH:l[3]}}function Ne(e,t,n){function r(n){void 0===n&&(n=0);var r=t+n>=1?t+n:0;return e.el.getPointAtLength(r)}var o=Me(e.el,e.svg),i=r(),a=r(-1),s=r(1),l=n?1:o.w/o.vW,u=n?1:o.h/o.vH;switch(e.property){case"x":return(i.x-o.x)*l;case"y":return(i.y-o.y)*u;case"angle":return 180*Math.atan2(s.y-a.y,s.x-a.x)/Math.PI}}function Le(e,t){var n=/[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g,r=Be(ne.pth(e)?e.totalLength:e,t)+"";return{original:r,numbers:r.match(n)?r.match(n).map(Number):[0],strings:ne.str(e)||t?r.split(n):[]}}function Re(e){return fe(e?he(ne.arr(e)?e.map(pe):pe(e)):[],(function(e,t,n){return n.indexOf(e)===t}))}function He(e){var t=Re(e);return t.map((function(e,n){return{target:e,id:n,total:t.length,transforms:{list:Pe(e)}}}))}function Ue(e,t){var n=me(t);if(/^spring/.test(n.easing)&&(n.duration=oe(n.easing)),ne.arr(e)){var r=e.length;2===r&&!ne.obj(e[0])?e={value:e}:ne.fnc(t.duration)||(n.duration=t.duration/r)}var o=ne.arr(e)?e:[e];return o.map((function(e,n){var r=ne.obj(e)&&!ne.pth(e)?e:{value:e};return ne.und(r.delay)&&(r.delay=n?0:t.delay),ne.und(r.endDelay)&&(r.endDelay=n===o.length-1?t.endDelay:0),r})).map((function(e){return ye(e,n)}))}function Fe(e,t){var n=[],r=t.keyframes;for(var o in r&&(t=ye(function(e){for(var t=fe(he(e.map((function(e){return Object.keys(e)}))),(function(e){return ne.key(e)})).reduce((function(e,t){return e.indexOf(t)<0&&e.push(t),e}),[]),n={},r=function(r){var o=t[r];n[o]=e.map((function(e){var t={};for(var n in e)ne.key(n)?n==o&&(t.value=e[n]):t[n]=e[n];return t}))},o=0;o0?requestAnimationFrame(t):void 0}return"undefined"!=typeof document&&document.addEventListener("visibilitychange",(function(){Je.suspendWhenDocumentHidden&&(Ve()?e=cancelAnimationFrame(e):(Ge.forEach((function(e){return e._onDocumentVisibility()})),Qe()))})),function(){e||Ve()&&Je.suspendWhenDocumentHidden||!(Ge.length>0)||(e=requestAnimationFrame(t))}}();function Ve(){return!!document&&document.hidden}function Je(e){void 0===e&&(e={});var t,n=0,r=0,o=0,i=0,a=null;function s(e){var t=window.Promise&&new Promise((function(e){return a=e}));return e.finished=t,t}var l=function(e){var t=ve(V,e),n=ve(J,e),r=Fe(n,e),o=He(e.targets),i=je(o,r),a=We(i,n),s=ze;return ze++,ye(t,{id:s,children:[],animatables:o,animations:i,duration:a.duration,delay:a.delay,endDelay:a.endDelay})}(e);function u(){var e=l.direction;"alternate"!==e&&(l.direction="normal"!==e?"normal":"reverse"),l.reversed=!l.reversed,t.forEach((function(e){return e.reversed=l.reversed}))}function c(e){return l.reversed?l.duration-e:e}function d(){n=0,r=c(l.currentTime)*(1/Je.speed)}function f(e,t){t&&t.seek(e-t.timelineOffset)}function h(e){for(var t=0,n=l.animations,r=n.length;t2||(y=Math.round(y*h)/h)),p.push(y)}var E=f.length;if(E){m=f[0];for(var I=0;I0&&(l.began=!0,p("begin")),!l.loopBegan&&l.currentTime>0&&(l.loopBegan=!0,p("loopBegin")),v<=g&&0!==l.currentTime&&h(0),(v>=m&&l.currentTime!==d||!d)&&h(d),v>g&&v=d&&(r=0,l.remaining&&!0!==l.remaining&&l.remaining--,l.remaining?(n=o,p("loopComplete"),l.loopBegan=!1,"alternate"===l.direction&&u()):(l.paused=!0,l.completed||(l.completed=!0,p("loopComplete"),p("complete"),!l.passThrough&&"Promise"in window&&(a(),s(l)))))}return s(l),l.reset=function(){var e=l.direction;l.passThrough=!1,l.currentTime=0,l.progress=0,l.paused=!0,l.began=!1,l.loopBegan=!1,l.changeBegan=!1,l.completed=!1,l.changeCompleted=!1,l.reversePlayback=!1,l.reversed="reverse"===e,l.remaining=l.loop,t=l.children;for(var n=i=t.length;n--;)l.children[n].reset();(l.reversed&&!0!==l.loop||"alternate"===e&&1===l.loop)&&l.remaining++,h(l.reversed?l.duration:0)},l._onDocumentVisibility=d,l.set=function(e,t){return Ye(e,t),l},l.tick=function(e){o=e,n||(n=o),g((o+(r-n))*Je.speed)},l.seek=function(e){g(c(e))},l.pause=function(){l.paused=!0,d()},l.play=function(){l.paused&&(l.completed&&l.reset(),l.paused=!1,Ge.push(l),d(),Qe())},l.reverse=function(){u(),l.completed=!l.reversed,d()},l.restart=function(){l.reset(),l.play()},l.remove=function(e){Ze(Re(e),l)},l.reset(),l.autoplay&&l.play(),l}function $e(e,t){for(var n=t.length;n--;)ge(e,t[n].animatable.target)&&t.splice(n,1)}function Ze(e,t){var n=t.animations,r=t.children;$e(e,n);for(var o=r.length;o--;){var i=r[o],a=i.animations;$e(e,a),a.length||i.children.length||r.splice(o,1)}n.length||r.length||t.pause()}Je.version="3.2.1",Je.speed=1,Je.suspendWhenDocumentHidden=!0,Je.running=Ge,Je.remove=function(e){for(var t=Re(e),n=Ge.length;n--;){Ze(t,Ge[n])}},Je.get=xe,Je.set=Ye,Je.convertPx=ke,Je.path=function(e,t){var n=ne.str(e)?de(e)[0]:e,r=t||100;return function(e){return{property:e,el:n,svg:Me(n),totalLength:Oe(n)*(r/100)}}},Je.setDashoffset=function(e){var t=Oe(e);return e.setAttribute("stroke-dasharray",t),t},Je.stagger=function(e,t){void 0===t&&(t={});var n=t.direction||"normal",r=t.easing?ce(t.easing):null,o=t.grid,i=t.axis,a=t.from||0,s="first"===a,l="center"===a,u="last"===a,c=ne.arr(e),d=c?parseFloat(e[0]):parseFloat(e),f=c?parseFloat(e[1]):0,h=we(c?e[1]:e)||0,p=t.start||0+(c?d:0),g=[],m=0;return function(e,t,v){if(s&&(a=0),l&&(a=(v-1)/2),u&&(a=v-1),!g.length){for(var y=0;y-1&&Ge.splice(o,1);for(var s=0;s'].join(""),document.getElementById("featured-image-drop").innerHTML="",document.getElementById("featured-image-drop").appendChild(n)}}(n),o.readAsDataURL(n)}}}},{key:"handleImageUpload",value:function(e,t){var n=this;at.alert("Uploading Image",null),this.admin.imageUpload(e,t).then((function(e){"postImageAdded"==e.type&&n.editor.notify(R,e.url),at.alert("Image Added to Entry",!0)})).catch((function(){at.alert("Uh oh. Image not added",!1)}))}}]),t}();st.uploadFiles=[];var lt=function(){function t(n){e(this,t),this.currentPage=null,this.choosePage(n),this.start()}return n(t,[{key:"start",value:function(){}},{key:"choosePage",value:function(e){switch(this.currentPage="",e){case"edit":case"add":this.currentPage=new st}}}]),t}(),ut=function(){function t(){e(this,t)}return n(t,[{key:"getInfo",value:function(){var e,t,n=document.getElementById("settings-handle").value,r=document.getElementById("settings-email").value,o=document.getElementById("settings-url").value,i=document.getElementById("settings-title").value,a=document.getElementById("settings-desc").value,s=document.getElementById("background").src,l="",u=document.querySelectorAll(".theme-select"),c=document.getElementById("smtp-domain").value,d=document.getElementById("smtp-email").value,f=document.getElementById("smtp-pass").value,h=document.getElementById("mg-domain").value,p=document.getElementById("mg-key").value,g="",m=document.querySelectorAll(".mail-option"),v=document.getElementById("api-access-toggle").getAttribute("data-enabled");for(e=0,t=u.length;e2&&void 0!==arguments[2]?arguments[2]:"GET",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:E,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i=this;return new Promise((function(a,s){var l=new XMLHttpRequest;if(l.upload.onprogress=i.handleLoadProgress,l.open(n,e,!0),l.onload=function(){if(200==l.status){var e=JSON.parse(l.response);a(e)}else{var t=JSON.parse(l.response);s(t)}},"PUT"==n||n==v)switch(t!==u&&t!==h&&t!==d&&t!==c&&t!==g&&t!==f&&t!==p&&t!==m||l.setRequestHeader("fipamo-access-token",i.token),r){case E:l.setRequestHeader("Content-type","application/"+r),l.send(JSON.stringify(o));break;case I:l.send(o)}else l.send()}))}},{key:"handleLoadProgress",value:function(e){this.percentComplete=Math.ceil(e.loaded/e.total*100)}}]),t}(),T="POST",D="json",x="x-www-form-urlencoded",P=function(){function t(){e(this,t)}return n(t,[{key:"initNew",value:function(e){var t=this;return new Promise((function(n,r){t._request("/api/v1/init","blogInit",T,D,e).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"initRestore",value:function(e){var t=this;return new Promise((function(n,r){var o;o=new FormData(e),t._request("/api/v1/restore","downloadBackup","POST","x-www-form-urlencoded",o).then((function(e){n(e)})).catch((function(e){r(e)}))}))}},{key:"backup",value:function(e,t){var n=this;return new Promise((function(r,o){var i,a,s,l,u;if("create-backup"===e)i="/api/v1/backup",a=f,s=T,l=D,u={task:"create_backup"};else{i="/api/v1/backup/restore",a=p,s=T,l=x,u=new FormData;for(var c=0;c2&&void 0!==arguments[2]?arguments[2]:"GET",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:D,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,i=this;return new Promise((function(t,a){var s=new XMLHttpRequest;if(s.upload.onprogress=i.handleLoadProgress,s.open(n,e,!0),s.onload=function(){if(200==s.status){var e=JSON.parse(s.response);t(e)}else{var n=JSON.parse(s.response);a(n)}},"PUT"==n||n==T)switch(r){case D:s.setRequestHeader("Content-type","application/"+r),s.send(JSON.stringify(o));break;case x:s.send(o)}else s.send()}))}},{key:"handleLoadProgress",value:function(e){this.percentComplete=Math.ceil(e.loaded/e.total*100)}}]),t}(),_=function(){function t(){e(this,t)}return n(t,[{key:"imgLoad",value:function(e){return new Promise((function(t,n){var r=new XMLHttpRequest;r.open("GET",e),r.responseType="blob",r.onload=function(){200===r.status?t(r.response):n(new Error("Image didn't load successfully; error code:"+r.statusText))},r.onerror=function(){n(new Error("There was a network error."))},r.send()}))}},{key:"loadImage",value:function(e){var t=this;return new Promise((function(n,r){(new Image).crossOrigin="",t.imgLoad(e).then((function(e){var t=window.URL.createObjectURL(e);n(t)}),(function(e){r(e)}))}))}},{key:"formDataToJSON",value:function(e){var t={};return new FormData(e).forEach((function(e,n){t.hasOwnProperty(n)?(Array.isArray(t[n])||(t[n]=[t[n]]),t[n].push(e)):t[n]=e})),t}}]),t}(),B=function(){function t(){e(this,t)}return n(t,[{key:"cleanString",value:function(e){return e.replace(/(^\-+|[^a-zA-Z0-9\/_| -]+|\-+$)/g,"").toLowerCase().replace(/[\/_| -]+/g,"-")}},{key:"decodeHTML",value:function(e,t){var n=0,r=0,o=!1;void 0===t&&(t=2),e=e.toString().replace(/</g,"<").replace(/>/g,">");var i={ENT_NOQUOTES:0,ENT_HTML_QUOTE_SINGLE:1,ENT_HTML_QUOTE_DOUBLE:2,ENT_COMPAT:2,ENT_QUOTES:3,ENT_IGNORE:4};if(0===t&&(o=!0),"number"!=typeof t){for(t=[].concat(t),r=0;r]*>/g,"\n"),r.append("id",document.getElementById("post-edit-index").getAttribute("data-index")),r.append("uuid",document.getElementById("post-edit-index").getAttribute("data-uuid")),r.append("layout",document.getElementById("post-edit-index").getAttribute("data-layout")),r.append("current_title",document.getElementById("post-edit-index").getAttribute("data-slug")),r.append("content",i),r.append("title",document.getElementById("post_title").value),r.append("created",document.getElementById("post-date").getAttribute("data-raw")),r.append("slug",(new B).cleanString(document.getElementById("post_title").value)),r.append("tags",document.getElementById("post_tags").value),r.append("menu",document.getElementById("option-menu-pin").getAttribute("data-active")),r.append("featured",document.getElementById("option-feature").getAttribute("data-active")),r.append("published",document.getElementById("option-published").getAttribute("data-active")),null!=e||null!=e)e.type.match("image.*")?r.append("feature_image",e,e.name):n("Not an image file");else{var a=document.getElementById("featured-image").src;null!=a||null!=a?r.append("feature_image",a):r.append("feature_image",null)}t(r)}))}}]),t}(),C="editorDelete",O="editorUploadImage",M="editorSave",N="editorUpdate";new function t(){e(this,t)};var L=["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"],R=function(e,t){var n=document.createElement("div");return function(t){var r=function(){var t={position:"absolute",left:-9999,top:0,zIndex:-2e3};return"TEXTAREA"===e.tagName&&L.push("width"),L.forEach((function(n){t[n]=getComputedStyle(e)[n]})),t}();Object.keys(r).forEach((function(e){n.style[e]=r[e]})),n.innerHTML=t,e.parentNode.insertBefore(n,e.nextSibling)}(t),{rect:function(){var e=n.ownerDocument.getElementById("caret-position-marker"),t={left:e.offsetLeft,top:e.offsetTop,height:e.offsetHeight};return n.parentNode.removeChild(n),t}}};function H(e){return(H="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var F=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.customPos,n=e.iframe,r=e.noShadowCaret;return n?{iframe:n,window:n.contentWindow,document:n.contentDocument||n.contentWindow.document,noShadowCaret:r,customPos:t}:{window:window,document:document,noShadowCaret:r,customPos:t}},X=function(e){return"object"===H(e)&&null!==e},U=function(e,t){var n=function(){return e.selectionStart},r=function(r){var o=function(e){return e.replace(/<|>|`|"|&/g,"?").replace(/\r\n|\r|\n/g,"
")};(t.customPos||0===t.customPos)&&(r=t.customPos);var i=void 0===r?n():r,a=e.value.slice(0,i),s=e.value.slice(i),l=''.concat(o(a),"");l+='|',l+=''.concat(o(s),"");var u=R(e,l).rect();return u.pos=n(),u};return{getPos:n,setPos:function(t){return e.setSelectionRange(t,t),e},getOffset:function(n){var o=function(e,t){var n=t&&t.window||window,r=t&&t.document||document,o=e.getBoundingClientRect(),i=r.documentElement,a=n.pageXOffset||i.scrollLeft,s=n.pageYOffset||i.scrollTop;return{top:o.top+s,left:o.left+a}}(e),i=r(n);return{top:o.top+i.top+t.document.body.scrollTop,left:o.left+i.left+t.document.body.scrollLeft,height:i.height}},getPosition:r}},q=function(e,t){return function(e){return!!(e.contentEditable?"true"===e.contentEditable:"true"===e.getAttribute("contenteditable"))}(e)?function(e,t){var n=function(){var n=r(),o={height:0,left:0,right:0};if(!n)return o;var i=t.customPos||0===t.customPos;if(n.endOffset-1>0&&n.endContainer!==e||i){var a=n.cloneRange(),s=i?t.customPos:n.endOffset;a.setStart(n.endContainer,s-1<0?0:s-1),a.setEnd(n.endContainer,s);var l=a.getBoundingClientRect();o={height:l.height,left:l.left+l.width,top:l.top},a.detach()}if((!o||o&&0===o.height)&&!t.noShadowCaret){var u=n.cloneRange(),c=t.document.createTextNode("|");u.insertNode(c),u.selectNode(c);var d=u.getBoundingClientRect();o={height:d.height,left:d.left,top:d.top},c.parentNode.removeChild(c),u.detach()}if(o){var f=t.document.documentElement;o.top+=t.window.pageYOffset-(f.clientTop||0),o.left+=t.window.pageXOffset-(f.clientLeft||0)}return o},r=function(){if(t.window.getSelection){var e=t.window.getSelection();return e.rangeCount>0?e.getRangeAt(0):null}},o=function(){var t=r(),n=t.cloneRange();n.selectNodeContents(e),n.setEnd(t.endContainer,t.endOffset);var o=n.toString().length;return n.detach(),o};return{getPos:o,setPos:function(n){var r=t.window.getSelection();if(r){var o=0,i=!1;!function e(a,s){for(var l=0;l=a){i=!0;var c=t.document.createRange();c.setStart(u,a-o),r.removeAllRanges(),r.addRange(c);break}o+=u.length}else e(n,u)}}(n,e)}return e},getPosition:function(){var r=n(),i=o(),a=e.getBoundingClientRect(),s=a.top+t.document.body.scrollTop,l=a.left+t.document.body.scrollLeft;return r.left-=l,r.top-=s,r.pos=i,r},getOffset:n,getRange:r}}(e,t):U(e,t)},Y=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=n;X(t)&&(r=t,t=null);var o=F(r),i=q(e,o);return t||0===t?i.setPos(t):i.getPosition()},j=function(t){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}(i,t);var r=a(i);function i(t,n){var o;return e(this,i),(o=r.call(this)).textEditor=t,o.fixLimit=n,o.caretPos=null,o.url="",o.setInputs(),window.addEventListener("scroll",(function(){})),o.refresh(),o}return n(i,[{key:"setInputs",value:function(){for(var e=this,t=this,n=document.querySelectorAll(".editor-button"),r=0,o=n.length;r/g)>-1){var o=Y(e.textEditor).pos;t.refresh(),Y(e.textEditor,o)}}))}},{key:"refresh",value:function(){var e=this.textEditor.innerText;e=e.replace(new RegExp("\r?\n","g"),"
");var t=document.createElement("div");t.innerText=e,this.textEditor.innerHTML=t.innerText,this.textEditor.style.maxWidth="900px"}},{key:"notify",value:function(e,t){switch(e){case l: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")}),2e3);break;case"postAdded":break;case O:var n,r;Y(this.textEditor,this.caretPos),(n=window.getSelection()).rangeCount&&((r=n.getRangeAt(0)).deleteContents(),r.insertNode(document.createTextNode("![image alt text]("+t+" 'image title')"))),this.refresh()}}},{key:"handleEditorOption",value:function(e){var t,n,r;if(e.preventDefault(),(t=window.getSelection()).rangeCount)switch(n=t.getRangeAt(0),r=t.getRangeAt(0).toString(),n.deleteContents(),e.target.id){case"edit-bold":n.insertNode(document.createTextNode("**"+r+"**"));break;case"edit-italic":n.insertNode(document.createTextNode("*"+r+"*"));break;case"edit-strikethrough":n.insertNode(document.createTextNode(""+r+""));break;case"edit-header1":n.insertNode(document.createTextNode("# "+r));break;case"edit-header2":n.insertNode(document.createTextNode("## "+r));break;case"edit-header3":n.insertNode(document.createTextNode("### "+r));break;case"edit-image":this.caretPos=Y(this.textEditor).pos,this.emitEvent(O);break;case"submit-save":case"edit-save":this.emitEvent(M);break;case"submit-update":case"edit-update":this.emitEvent(N);break;case"edit-link":n.insertNode(document.createTextNode("["+r+"](PASTE URL HERE)"));break;case"edit-delete":this.emitEvent(C)}this.refresh()}}]),i}(function(){function t(){e(this,t),this.listeners=new Map}return n(t,[{key:"addListener",value:function(e,t){this.listeners.has(e)||this.listeners.set(e,[]),this.listeners.get(e).push(t)}},{key:"removeListener",value:function(e,t){var n,r=this.listeners.get(e);return!!(r&&r.length&&(n=r.reduce((function(e,n,r){return"function"==typeof n&&n===t?e=r:e}),-1))>-1)&&(r.splice(n,1),this.listeners.set(e,r),!0)}},{key:"emitEvent",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r-1}function $(e,t){return e.apply(null,t)}var Z={arr:function(e){return Array.isArray(e)},obj:function(e){return J(Object.prototype.toString.call(e),"Object")},pth:function(e){return Z.obj(e)&&e.hasOwnProperty("totalLength")},svg:function(e){return e instanceof SVGElement},inp:function(e){return e instanceof HTMLInputElement},dom:function(e){return e.nodeType||Z.svg(e)},str:function(e){return"string"==typeof e},fnc:function(e){return"function"==typeof e},und:function(e){return void 0===e},nil:function(e){return Z.und(e)||null===e},hex:function(e){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e)},rgb:function(e){return/^rgb/.test(e)},hsl:function(e){return/^hsl/.test(e)},col:function(e){return Z.hex(e)||Z.rgb(e)||Z.hsl(e)},key:function(e){return!W.hasOwnProperty(e)&&!z.hasOwnProperty(e)&&"targets"!==e&&"keyframes"!==e}};function K(e){var t=/\(([^)]+)\)/.exec(e);return t?t[1].split(",").map((function(e){return parseFloat(e)})):[]}function ee(e,t){var n=K(e),r=V(Z.und(n[0])?1:n[0],.1,100),o=V(Z.und(n[1])?100:n[1],.1,100),i=V(Z.und(n[2])?10:n[2],.1,100),a=V(Z.und(n[3])?0:n[3],.1,100),s=Math.sqrt(o/r),l=i/(2*Math.sqrt(o*r)),u=l<1?s*Math.sqrt(1-l*l):0,c=l<1?(l*s-a)/u:-a+s;function d(e){var n=t?t*e/1e3:e;return n=l<1?Math.exp(-n*l*s)*(1*Math.cos(u*n)+c*Math.sin(u*n)):(1+c*n)*Math.exp(-n*s),0===e||1===e?e:1-n}return t?d:function(){var t=Q.springs[e];if(t)return t;for(var n=1/6,r=0,o=0;;)if(1===d(r+=n)){if(++o>=16)break}else o=0;var i=r*n*1e3;return Q.springs[e]=i,i}}function te(e){return void 0===e&&(e=10),function(t){return Math.ceil(V(t,1e-6,1)*e)*(1/e)}}var ne,re,oe=function(){var e=.1;function t(e,t){return 1-3*t+3*e}function n(e,t){return 3*t-6*e}function r(e){return 3*e}function o(e,o,i){return((t(o,i)*e+n(o,i))*e+r(o))*e}function i(e,o,i){return 3*t(o,i)*e*e+2*n(o,i)*e+r(o)}return function(t,n,r,a){if(0<=t&&t<=1&&0<=r&&r<=1){var s=new Float32Array(11);if(t!==n||r!==a)for(var l=0;l<11;++l)s[l]=o(l*e,t,r);return function(e){return t===n&&r===a||0===e||1===e?e:o(u(e),n,a)}}function u(n){for(var a=0,l=1;10!==l&&s[l]<=n;++l)a+=e;--l;var u=a+(n-s[l])/(s[l+1]-s[l])*e,c=i(u,t,r);return c>=.001?function(e,t,n,r){for(var a=0;a<4;++a){var s=i(t,n,r);if(0===s)return t;t-=(o(t,n,r)-e)/s}return t}(n,u,t,r):0===c?u:function(e,t,n,r,i){var a,s,l=0;do{(a=o(s=t+(n-t)/2,r,i)-e)>0?n=s:t=s}while(Math.abs(a)>1e-7&&++l<10);return s}(n,a,a+e,t,r)}}}(),ie=(ne={linear:function(){return function(e){return e}}},re={Sine:function(){return function(e){return 1-Math.cos(e*Math.PI/2)}},Circ:function(){return function(e){return 1-Math.sqrt(1-e*e)}},Back:function(){return function(e){return e*e*(3*e-2)}},Bounce:function(){return function(e){for(var t,n=4;e<((t=Math.pow(2,--n))-1)/11;);return 1/Math.pow(4,3-n)-7.5625*Math.pow((3*t-2)/22-e,2)}},Elastic:function(e,t){void 0===e&&(e=1),void 0===t&&(t=.5);var n=V(e,1,10),r=V(t,.1,2);return function(e){return 0===e||1===e?e:-n*Math.pow(2,10*(e-1))*Math.sin((e-1-r/(2*Math.PI)*Math.asin(1/n))*(2*Math.PI)/r)}}},["Quad","Cubic","Quart","Quint","Expo"].forEach((function(e,t){re[e]=function(){return function(e){return Math.pow(e,t+2)}}})),Object.keys(re).forEach((function(e){var t=re[e];ne["easeIn"+e]=t,ne["easeOut"+e]=function(e,n){return function(r){return 1-t(e,n)(1-r)}},ne["easeInOut"+e]=function(e,n){return function(r){return r<.5?t(e,n)(2*r)/2:1-t(e,n)(-2*r+2)/2}},ne["easeOutIn"+e]=function(e,n){return function(r){return r<.5?(1-t(e,n)(1-2*r))/2:(t(e,n)(2*r-1)+1)/2}}})),ne);function ae(e,t){if(Z.fnc(e))return e;var n=e.split("(")[0],r=ie[n],o=K(e);switch(n){case"spring":return ee(e,t);case"cubicBezier":return $(oe,o);case"steps":return $(te,o);default:return $(r,o)}}function se(e){try{return document.querySelectorAll(e)}catch(e){return}}function le(e,t){for(var n=e.length,r=arguments.length>=2?t:void 0,o=[],i=0;i1&&(n-=1),n<1/6?e+6*(t-e)*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e}if(0==a)t=n=r=s;else{var c=s<.5?s*(1+a):s+a-s*a,d=2*s-c;t=u(d,c,i+1/3),n=u(d,c,i),r=u(d,c,i-1/3)}return"rgba("+255*t+","+255*n+","+255*r+","+l+")"}(e):void 0;var t,n}function me(e){var t=/[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(e);if(t)return t[1]}function ve(e,t){return Z.fnc(e)?e(t.target,t.id,t.total):e}function ye(e,t){return e.getAttribute(t)}function be(e,t,n){if(de([n,"deg","rad","turn"],me(t)))return t;var r=Q.CSS[t+n];if(!Z.und(r))return r;var o=document.createElement(e.tagName),i=e.parentNode&&e.parentNode!==document?e.parentNode:document.body;i.appendChild(o),o.style.position="absolute",o.style.width=100+n;var a=100/o.offsetWidth;i.removeChild(o);var s=a*parseFloat(t);return Q.CSS[t+n]=s,s}function we(e,t,n){if(t in e.style){var r=t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),o=e.style[t]||getComputedStyle(e).getPropertyValue(r)||"0";return n?be(e,o,n):o}}function Ee(e,t){return Z.dom(e)&&!Z.inp(e)&&(!Z.nil(ye(e,t))||Z.svg(e)&&e[t])?"attribute":Z.dom(e)&&de(G,t)?"transform":Z.dom(e)&&"transform"!==t&&we(e,t)?"css":null!=e[t]?"object":void 0}function Ie(e){if(Z.dom(e)){for(var t,n=e.style.transform||"",r=/(\w+)\(([^)]*)\)/g,o=new Map;t=r.exec(n);)o.set(t[1],t[2]);return o}}function ke(e,t,n,r){var o=J(t,"scale")?1:0+function(e){return J(e,"translate")||"perspective"===e?"px":J(e,"rotate")||J(e,"skew")?"deg":void 0}(t),i=Ie(e).get(t)||o;return n&&(n.transforms.list.set(t,i),n.transforms.last=t),r?be(e,i,r):i}function Se(e,t,n,r){switch(Ee(e,t)){case"transform":return ke(e,t,r,n);case"css":return we(e,t,n);case"attribute":return ye(e,t);default:return e[t]||0}}function Te(e,t){var n=/^(\*=|\+=|-=)/.exec(e);if(!n)return e;var r=me(e)||0,o=parseFloat(t),i=parseFloat(e.replace(n[0],""));switch(n[0][0]){case"+":return o+i+r;case"-":return o-i+r;case"*":return o*i+r}}function De(e,t){if(Z.col(e))return ge(e);if(/\s/g.test(e))return e;var n=me(e),r=n?e.substr(0,e.length-n.length):e;return t?r+t:r}function xe(e,t){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function Pe(e){for(var t,n=e.points,r=0,o=0;o0&&(r+=xe(t,i)),t=i}return r}function _e(e){if(e.getTotalLength)return e.getTotalLength();switch(e.tagName.toLowerCase()){case"circle":return function(e){return 2*Math.PI*ye(e,"r")}(e);case"rect":return function(e){return 2*ye(e,"width")+2*ye(e,"height")}(e);case"line":return function(e){return xe({x:ye(e,"x1"),y:ye(e,"y1")},{x:ye(e,"x2"),y:ye(e,"y2")})}(e);case"polyline":return Pe(e);case"polygon":return function(e){var t=e.points;return Pe(e)+xe(t.getItem(t.numberOfItems-1),t.getItem(0))}(e)}}function Be(e,t){var n=t||{},r=n.el||function(e){for(var t=e.parentNode;Z.svg(t)&&Z.svg(t.parentNode);)t=t.parentNode;return t}(e),o=r.getBoundingClientRect(),i=ye(r,"viewBox"),a=o.width,s=o.height,l=n.viewBox||(i?i.split(" "):[0,0,a,s]);return{el:r,viewBox:l,x:l[0]/1,y:l[1]/1,w:a,h:s,vW:l[2],vH:l[3]}}function Ae(e,t,n){function r(n){void 0===n&&(n=0);var r=t+n>=1?t+n:0;return e.el.getPointAtLength(r)}var o=Be(e.el,e.svg),i=r(),a=r(-1),s=r(1),l=n?1:o.w/o.vW,u=n?1:o.h/o.vH;switch(e.property){case"x":return(i.x-o.x)*l;case"y":return(i.y-o.y)*u;case"angle":return 180*Math.atan2(s.y-a.y,s.x-a.x)/Math.PI}}function Ce(e,t){var n=/[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g,r=De(Z.pth(e)?e.totalLength:e,t)+"";return{original:r,numbers:r.match(n)?r.match(n).map(Number):[0],strings:Z.str(e)||t?r.split(n):[]}}function Oe(e){return le(e?ue(Z.arr(e)?e.map(ce):ce(e)):[],(function(e,t,n){return n.indexOf(e)===t}))}function Me(e){var t=Oe(e);return t.map((function(e,n){return{target:e,id:n,total:t.length,transforms:{list:Ie(e)}}}))}function Ne(e,t){var n=fe(t);if(/^spring/.test(n.easing)&&(n.duration=ee(n.easing)),Z.arr(e)){var r=e.length;2===r&&!Z.obj(e[0])?e={value:e}:Z.fnc(t.duration)||(n.duration=t.duration/r)}var o=Z.arr(e)?e:[e];return o.map((function(e,n){var r=Z.obj(e)&&!Z.pth(e)?e:{value:e};return Z.und(r.delay)&&(r.delay=n?0:t.delay),Z.und(r.endDelay)&&(r.endDelay=n===o.length-1?t.endDelay:0),r})).map((function(e){return he(e,n)}))}function Le(e,t){var n=[],r=t.keyframes;for(var o in r&&(t=he(function(e){for(var t=le(ue(e.map((function(e){return Object.keys(e)}))),(function(e){return Z.key(e)})).reduce((function(e,t){return e.indexOf(t)<0&&e.push(t),e}),[]),n={},r=function(r){var o=t[r];n[o]=e.map((function(e){var t={};for(var n in e)Z.key(n)?n==o&&(t.value=e[n]):t[n]=e[n];return t}))},o=0;o0?requestAnimationFrame(t):void 0}return"undefined"!=typeof document&&document.addEventListener("visibilitychange",(function(){ze.suspendWhenDocumentHidden&&(We()?e=cancelAnimationFrame(e):(Ye.forEach((function(e){return e._onDocumentVisibility()})),je()))})),function(){e||We()&&ze.suspendWhenDocumentHidden||!(Ye.length>0)||(e=requestAnimationFrame(t))}}();function We(){return!!document&&document.hidden}function ze(e){void 0===e&&(e={});var t,n=0,r=0,o=0,i=0,a=null;function s(e){var t=window.Promise&&new Promise((function(e){return a=e}));return e.finished=t,t}var l=function(e){var t=pe(W,e),n=pe(z,e),r=Le(n,e),o=Me(e.targets),i=Xe(o,r),a=Ue(i,n),s=qe;return qe++,he(t,{id:s,children:[],animatables:o,animations:i,duration:a.duration,delay:a.delay,endDelay:a.endDelay})}(e);function u(){var e=l.direction;"alternate"!==e&&(l.direction="normal"!==e?"normal":"reverse"),l.reversed=!l.reversed,t.forEach((function(e){return e.reversed=l.reversed}))}function c(e){return l.reversed?l.duration-e:e}function d(){n=0,r=c(l.currentTime)*(1/ze.speed)}function f(e,t){t&&t.seek(e-t.timelineOffset)}function p(e){for(var t=0,n=l.animations,r=n.length;t2||(y=Math.round(y*p)/p)),h.push(y)}var E=f.length;if(E){m=f[0];for(var I=0;I0&&(l.began=!0,h("begin")), +!l.loopBegan&&l.currentTime>0&&(l.loopBegan=!0,h("loopBegin")),v<=g&&0!==l.currentTime&&p(0),(v>=m&&l.currentTime!==d||!d)&&p(d),v>g&&v=d&&(r=0,l.remaining&&!0!==l.remaining&&l.remaining--,l.remaining?(n=o,h("loopComplete"),l.loopBegan=!1,"alternate"===l.direction&&u()):(l.paused=!0,l.completed||(l.completed=!0,h("loopComplete"),h("complete"),!l.passThrough&&"Promise"in window&&(a(),s(l)))))}return s(l),l.reset=function(){var e=l.direction;l.passThrough=!1,l.currentTime=0,l.progress=0,l.paused=!0,l.began=!1,l.loopBegan=!1,l.changeBegan=!1,l.completed=!1,l.changeCompleted=!1,l.reversePlayback=!1,l.reversed="reverse"===e,l.remaining=l.loop,t=l.children;for(var n=i=t.length;n--;)l.children[n].reset();(l.reversed&&!0!==l.loop||"alternate"===e&&1===l.loop)&&l.remaining++,p(l.reversed?l.duration:0)},l._onDocumentVisibility=d,l.set=function(e,t){return Fe(e,t),l},l.tick=function(e){o=e,n||(n=o),g((o+(r-n))*ze.speed)},l.seek=function(e){g(c(e))},l.pause=function(){l.paused=!0,d()},l.play=function(){l.paused&&(l.completed&&l.reset(),l.paused=!1,Ye.push(l),d(),je())},l.reverse=function(){u(),l.completed=!l.reversed,d()},l.restart=function(){l.reset(),l.play()},l.remove=function(e){Qe(Oe(e),l)},l.reset(),l.autoplay&&l.play(),l}function Ge(e,t){for(var n=t.length;n--;)de(e,t[n].animatable.target)&&t.splice(n,1)}function Qe(e,t){var n=t.animations,r=t.children;Ge(e,n);for(var o=r.length;o--;){var i=r[o],a=i.animations;Ge(e,a),a.length||i.children.length||r.splice(o,1)}n.length||r.length||t.pause()}ze.version="3.2.1",ze.speed=1,ze.suspendWhenDocumentHidden=!0,ze.running=Ye,ze.remove=function(e){for(var t=Oe(e),n=Ye.length;n--;){Qe(t,Ye[n])}},ze.get=Se,ze.set=Fe,ze.convertPx=be,ze.path=function(e,t){var n=Z.str(e)?se(e)[0]:e,r=t||100;return function(e){return{property:e,el:n,svg:Be(n),totalLength:_e(n)*(r/100)}}},ze.setDashoffset=function(e){var t=_e(e);return e.setAttribute("stroke-dasharray",t),t},ze.stagger=function(e,t){void 0===t&&(t={});var n=t.direction||"normal",r=t.easing?ae(t.easing):null,o=t.grid,i=t.axis,a=t.from||0,s="first"===a,l="center"===a,u="last"===a,c=Z.arr(e),d=c?parseFloat(e[0]):parseFloat(e),f=c?parseFloat(e[1]):0,p=me(c?e[1]:e)||0,h=t.start||0+(c?d:0),g=[],m=0;return function(e,t,v){if(s&&(a=0),l&&(a=(v-1)/2),u&&(a=v-1),!g.length){for(var y=0;y-1&&Ye.splice(o,1);for(var s=0;s'].join(""),document.getElementById("featured-image-drop").innerHTML="",document.getElementById("featured-image-drop").appendChild(n)}}(n),o.readAsDataURL(n)}}}},{key:"handleImageUpload",value:function(e,t){var n=this;nt.alert("Uploading Image",null),this.admin.imageUpload(e,t).then((function(e){"postImageAdded"==e.type&&n.editor.notify(O,e.url),nt.alert("Image Added to Entry",!0)})).catch((function(){nt.alert("Uh oh. Image not added",!1)}))}}]),t}();rt.uploadFiles=[];var ot=function(){function t(n){e(this,t),this.currentPage=null,this.choosePage(n),this.start()}return n(t,[{key:"start",value:function(){}},{key:"choosePage",value:function(e){switch(this.currentPage="",e){case"edit":case"add":this.currentPage=new rt}}}]),t}(),it=function(){function t(){e(this,t)}return n(t,[{key:"getInfo",value:function(){var e,t,n=document.getElementById("settings-handle").value,r=document.getElementById("settings-email").value,o=document.getElementById("settings-url").value,i=document.getElementById("settings-title").value,a=document.getElementById("settings-desc").value,s=document.getElementById("background").src,l="",u=document.querySelectorAll(".theme-select"),c=document.getElementById("smtp-domain").value,d=document.getElementById("smtp-email").value,f=document.getElementById("smtp-pass").value,p=document.getElementById("mg-domain").value,h=document.getElementById("mg-key").value,g="",m=document.querySelectorAll(".mail-option"),v=document.getElementById("api-access-toggle").getAttribute("data-enabled");for(e=0,t=u.length;e * @author owenm * @license MIT */ -function gt(e){return(gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function mt(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vt(){return(vt=Object.assign||function(e){for(var t=1;t=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function wt(e){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(e)}var Et=wt(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),It=wt(/Edge/i),kt=wt(/firefox/i),St=wt(/safari/i)&&!wt(/chrome/i)&&!wt(/android/i),Tt=wt(/iP(ad|od|hone)/i),Pt=wt(/chrome/i)&&wt(/android/i),Dt={capture:!1,passive:!1};function xt(e,t,n){e.addEventListener(t,n,!Et&&Dt)}function _t(e,t,n){e.removeEventListener(t,n,!Et&&Dt)}function Bt(e,t){if(t){if(">"===t[0]&&(t=t.substring(1)),e)try{if(e.matches)return e.matches(t);if(e.msMatchesSelector)return e.msMatchesSelector(t);if(e.webkitMatchesSelector)return e.webkitMatchesSelector(t)}catch(e){return!1}return!1}}function At(e){return e.host&&e!==document&&e.host.nodeType?e.host:e.parentNode}function Ct(e,t,n,r){if(e){n=n||document;do{if(null!=t&&(">"===t[0]?e.parentNode===n&&Bt(e,t):Bt(e,t))||r&&e===n)return e;if(e===n)break}while(e=At(e))}return null}var Ot,Mt=/\s+/g;function Nt(e,t,n){if(e&&t)if(e.classList)e.classList[n?"add":"remove"](t);else{var r=(" "+e.className+" ").replace(Mt," ").replace(" "+t+" "," ");e.className=(r+(n?" "+t:"")).replace(Mt," ")}}function Lt(e,t,n){var r=e&&e.style;if(r){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(e,""):e.currentStyle&&(n=e.currentStyle),void 0===t?n:n[t];t in r||-1!==t.indexOf("webkit")||(t="-webkit-"+t),r[t]=n+("string"==typeof n?"":"px")}}function Rt(e,t){var n="";if("string"==typeof e)n=e;else do{var r=Lt(e,"transform");r&&"none"!==r&&(n=r+" "+n)}while(!t&&(e=e.parentNode));var o=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return o&&new o(n)}function Ht(e,t,n){if(e){var r=e.getElementsByTagName(t),o=0,i=r.length;if(n)for(;o=i:o<=i))return r;if(r===Ut())break;r=zt(r,!1)}return!1}function qt(e,t,n){for(var r=0,o=0,i=e.children;o2&&void 0!==arguments[2]?arguments[2]:{},r=n.evt,o=bt(n,["evt"]);tn.pluginEvent.bind(Vn)(e,t,yt({dragEl:on,parentEl:an,ghostEl:sn,rootEl:ln,nextEl:un,lastDownEl:cn,cloneEl:dn,cloneHidden:fn,dragStarted:Tn,putSortable:yn,activeSortable:Vn.active,originalEvent:r,oldIndex:hn,oldDraggableIndex:gn,newIndex:pn,newDraggableIndex:mn,hideGhostForTarget:Wn,unhideGhostForTarget:zn,cloneNowHidden:function(){fn=!0},cloneNowShown:function(){fn=!1},dispatchSortableEvent:function(e){rn({sortable:t,name:e,originalEvent:r})}},o))};function rn(e){!function(e){var t=e.sortable,n=e.rootEl,r=e.name,o=e.targetEl,i=e.cloneEl,a=e.toEl,s=e.fromEl,l=e.oldIndex,u=e.newIndex,c=e.oldDraggableIndex,d=e.newDraggableIndex,f=e.originalEvent,h=e.putSortable,p=e.extraEventProperties;if(t=t||n&&n[$t]){var g,m=t.options,v="on"+r.charAt(0).toUpperCase()+r.substr(1);!window.CustomEvent||Et||It?(g=document.createEvent("Event")).initEvent(r,!0,!0):g=new CustomEvent(r,{bubbles:!0,cancelable:!0}),g.to=a||n,g.from=s||n,g.item=o||n,g.clone=i,g.oldIndex=l,g.newIndex=u,g.oldDraggableIndex=c,g.newDraggableIndex=d,g.originalEvent=f,g.pullMode=h?h.lastPutMode:void 0;var y=yt({},p,tn.getEventProperties(r,t));for(var b in y)g[b]=y[b];n&&n.dispatchEvent(g),m[v]&&m[v].call(t,g)}}(yt({putSortable:yn,cloneEl:dn,targetEl:on,rootEl:ln,oldIndex:hn,oldDraggableIndex:gn,newIndex:pn,newDraggableIndex:mn},e))}var on,an,sn,ln,un,cn,dn,fn,hn,pn,gn,mn,vn,yn,bn,wn,En,In,kn,Sn,Tn,Pn,Dn,xn,_n,Bn=!1,An=!1,Cn=[],On=!1,Mn=!1,Nn=[],Ln=!1,Rn=[],Hn="undefined"!=typeof document,Un=Tt,Fn=It||Et?"cssFloat":"float",Xn=Hn&&!Pt&&!Tt&&"draggable"in document.createElement("div"),qn=function(){if(Hn){if(Et)return!1;var e=document.createElement("x");return e.style.cssText="pointer-events:auto","auto"===e.style.pointerEvents}}(),Yn=function(e,t){var n=Lt(e),r=parseInt(n.width)-parseInt(n.paddingLeft)-parseInt(n.paddingRight)-parseInt(n.borderLeftWidth)-parseInt(n.borderRightWidth),o=qt(e,0,t),i=qt(e,1,t),a=o&&Lt(o),s=i&&Lt(i),l=a&&parseInt(a.marginLeft)+parseInt(a.marginRight)+Ft(o).width,u=s&&parseInt(s.marginLeft)+parseInt(s.marginRight)+Ft(i).width;if("flex"===n.display)return"column"===n.flexDirection||"column-reverse"===n.flexDirection?"vertical":"horizontal";if("grid"===n.display)return n.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(o&&a.float&&"none"!==a.float){var c="left"===a.float?"left":"right";return!i||"both"!==s.clear&&s.clear!==c?"horizontal":"vertical"}return o&&("block"===a.display||"flex"===a.display||"table"===a.display||"grid"===a.display||l>=r&&"none"===n[Fn]||i&&"none"===n[Fn]&&l+u>r)?"vertical":"horizontal"},jn=function(e){function t(e,n){return function(r,o,i,a){var s=r.options.group.name&&o.options.group.name&&r.options.group.name===o.options.group.name;if(null==e&&(n||s))return!0;if(null==e||!1===e)return!1;if(n&&"clone"===e)return e;if("function"==typeof e)return t(e(r,o,i,a),n)(r,o,i,a);var l=(n?r:o).options.group.name;return!0===e||"string"==typeof e&&e===l||e.join&&e.indexOf(l)>-1}}var n={},r=e.group;r&&"object"==gt(r)||(r={name:r}),n.name=r.name,n.checkPull=t(r.pull,!0),n.checkPut=t(r.put),n.revertClone=r.revertClone,e.group=n},Wn=function(){!qn&&sn&&Lt(sn,"display","none")},zn=function(){!qn&&sn&&Lt(sn,"display","")};Hn&&document.addEventListener("click",(function(e){if(An)return e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),An=!1,!1}),!0);var Gn=function(e){if(on){e=e.touches?e.touches[0]:e;var t=(o=e.clientX,i=e.clientY,Cn.some((function(e){if(!Yt(e)){var t=Ft(e),n=e[$t].options.emptyInsertThreshold,r=o>=t.left-n&&o<=t.right+n,s=i>=t.top-n&&i<=t.bottom+n;return n&&r&&s?a=e:void 0}})),a);if(t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);n.target=n.rootEl=t,n.preventDefault=void 0,n.stopPropagation=void 0,t[$t]._onDragOver(n)}}var o,i,a},Qn=function(e){on&&on.parentNode[$t]._isOutsideThisEl(e.target)};function Vn(e,t){if(!e||!e.nodeType||1!==e.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(e));this.el=e,this.options=t=vt({},t),e[$t]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(e.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return Yn(e,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(e,t){e.setData("Text",t.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==Vn.supportPointer&&"PointerEvent"in window&&!St,emptyInsertThreshold:5};for(var r in tn.initializePlugins(this,e,n),n)!(r in t)&&(t[r]=n[r]);for(var o in jn(t),this)"_"===o.charAt(0)&&"function"==typeof this[o]&&(this[o]=this[o].bind(this));this.nativeDraggable=!t.forceFallback&&Xn,this.nativeDraggable&&(this.options.touchStartThreshold=1),t.supportPointer?xt(e,"pointerdown",this._onTapStart):(xt(e,"mousedown",this._onTapStart),xt(e,"touchstart",this._onTapStart)),this.nativeDraggable&&(xt(e,"dragover",this),xt(e,"dragenter",this)),Cn.push(this.el),t.store&&t.store.get&&this.sort(t.store.get(this)||[]),vt(this,Zt())}function Jn(e,t,n,r,o,i,a,s){var l,u,c=e[$t],d=c.options.onMove;return!window.CustomEvent||Et||It?(l=document.createEvent("Event")).initEvent("move",!0,!0):l=new CustomEvent("move",{bubbles:!0,cancelable:!0}),l.to=t,l.from=e,l.dragged=n,l.draggedRect=r,l.related=o||t,l.relatedRect=i||Ft(t),l.willInsertAfter=s,l.originalEvent=a,e.dispatchEvent(l),d&&(u=d.call(c,l,a)),u}function $n(e){e.draggable=!1}function Zn(){Ln=!1}function Kn(e){for(var t=e.tagName+e.className+e.src+e.href+e.textContent,n=t.length,r=0;n--;)r+=t.charCodeAt(n);return r.toString(36)}function er(e){return setTimeout(e,0)}function tr(e){return clearTimeout(e)}Vn.prototype={constructor:Vn,_isOutsideThisEl:function(e){this.el.contains(e)||e===this.el||(Pn=null)},_getDirection:function(e,t){return"function"==typeof this.options.direction?this.options.direction.call(this,e,t,on):this.options.direction},_onTapStart:function(e){if(e.cancelable){var t=this,n=this.el,r=this.options,o=r.preventOnFilter,i=e.type,a=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,s=(a||e).target,l=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||s,u=r.filter;if(function(e){Rn.length=0;var t=e.getElementsByTagName("input"),n=t.length;for(;n--;){var r=t[n];r.checked&&Rn.push(r)}}(n),!on&&!(/mousedown|pointerdown/.test(i)&&0!==e.button||r.disabled)&&!l.isContentEditable&&(this.nativeDraggable||!St||!s||"SELECT"!==s.tagName.toUpperCase())&&!((s=Ct(s,r.draggable,n,!1))&&s.animated||cn===s)){if(hn=jt(s),gn=jt(s,r.draggable),"function"==typeof u){if(u.call(this,e,s,this))return rn({sortable:t,rootEl:l,name:"filter",targetEl:s,toEl:n,fromEl:n}),nn("filter",t,{evt:e}),void(o&&e.cancelable&&e.preventDefault())}else if(u&&(u=u.split(",").some((function(r){if(r=Ct(l,r.trim(),n,!1))return rn({sortable:t,rootEl:r,name:"filter",targetEl:s,fromEl:n,toEl:n}),nn("filter",t,{evt:e}),!0}))))return void(o&&e.cancelable&&e.preventDefault());r.handle&&!Ct(l,r.handle,n,!1)||this._prepareDragStart(e,a,s)}}},_prepareDragStart:function(e,t,n){var r,o=this,i=o.el,a=o.options,s=i.ownerDocument;if(n&&!on&&n.parentNode===i){var l=Ft(n);if(ln=i,an=(on=n).parentNode,un=on.nextSibling,cn=n,vn=a.group,Vn.dragged=on,bn={target:on,clientX:(t||e).clientX,clientY:(t||e).clientY},kn=bn.clientX-l.left,Sn=bn.clientY-l.top,this._lastX=(t||e).clientX,this._lastY=(t||e).clientY,on.style["will-change"]="all",r=function(){nn("delayEnded",o,{evt:e}),Vn.eventCanceled?o._onDrop():(o._disableDelayedDragEvents(),!kt&&o.nativeDraggable&&(on.draggable=!0),o._triggerDragStart(e,t),rn({sortable:o,name:"choose",originalEvent:e}),Nt(on,a.chosenClass,!0))},a.ignore.split(",").forEach((function(e){Ht(on,e.trim(),$n)})),xt(s,"dragover",Gn),xt(s,"mousemove",Gn),xt(s,"touchmove",Gn),xt(s,"mouseup",o._onDrop),xt(s,"touchend",o._onDrop),xt(s,"touchcancel",o._onDrop),kt&&this.nativeDraggable&&(this.options.touchStartThreshold=4,on.draggable=!0),nn("delayStart",this,{evt:e}),!a.delay||a.delayOnTouchOnly&&!t||this.nativeDraggable&&(It||Et))r();else{if(Vn.eventCanceled)return void this._onDrop();xt(s,"mouseup",o._disableDelayedDrag),xt(s,"touchend",o._disableDelayedDrag),xt(s,"touchcancel",o._disableDelayedDrag),xt(s,"mousemove",o._delayedDragTouchMoveHandler),xt(s,"touchmove",o._delayedDragTouchMoveHandler),a.supportPointer&&xt(s,"pointermove",o._delayedDragTouchMoveHandler),o._dragStartTimer=setTimeout(r,a.delay)}}},_delayedDragTouchMoveHandler:function(e){var t=e.touches?e.touches[0]:e;Math.max(Math.abs(t.clientX-this._lastX),Math.abs(t.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){on&&$n(on),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;_t(e,"mouseup",this._disableDelayedDrag),_t(e,"touchend",this._disableDelayedDrag),_t(e,"touchcancel",this._disableDelayedDrag),_t(e,"mousemove",this._delayedDragTouchMoveHandler),_t(e,"touchmove",this._delayedDragTouchMoveHandler),_t(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,t){t=t||"touch"==e.pointerType&&e,!this.nativeDraggable||t?this.options.supportPointer?xt(document,"pointermove",this._onTouchMove):xt(document,t?"touchmove":"mousemove",this._onTouchMove):(xt(on,"dragend",this),xt(ln,"dragstart",this._onDragStart));try{document.selection?er((function(){document.selection.empty()})):window.getSelection().removeAllRanges()}catch(e){}},_dragStarted:function(e,t){if(Bn=!1,ln&&on){nn("dragStarted",this,{evt:t}),this.nativeDraggable&&xt(document,"dragover",Qn);var n=this.options;!e&&Nt(on,n.dragClass,!1),Nt(on,n.ghostClass,!0),Vn.active=this,e&&this._appendGhost(),rn({sortable:this,name:"start",originalEvent:t})}else this._nulling()},_emulateDragOver:function(){if(wn){this._lastX=wn.clientX,this._lastY=wn.clientY,Wn();for(var e=document.elementFromPoint(wn.clientX,wn.clientY),t=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(wn.clientX,wn.clientY))!==t;)t=e;if(on.parentNode[$t]._isOutsideThisEl(e),t)do{if(t[$t]){if(t[$t]._onDragOver({clientX:wn.clientX,clientY:wn.clientY,target:e,rootEl:t})&&!this.options.dragoverBubble)break}e=t}while(t=t.parentNode);zn()}},_onTouchMove:function(e){if(bn){var t=this.options,n=t.fallbackTolerance,r=t.fallbackOffset,o=e.touches?e.touches[0]:e,i=sn&&Rt(sn,!0),a=sn&&i&&i.a,s=sn&&i&&i.d,l=Un&&_n&&Wt(_n),u=(o.clientX-bn.clientX+r.x)/(a||1)+(l?l[0]-Nn[0]:0)/(a||1),c=(o.clientY-bn.clientY+r.y)/(s||1)+(l?l[1]-Nn[1]:0)/(s||1);if(!Vn.active&&!Bn){if(n&&Math.max(Math.abs(o.clientX-this._lastX),Math.abs(o.clientY-this._lastY))r.right+o||e.clientX<=r.right&&e.clientY>r.bottom&&e.clientX>=r.left:e.clientX>r.right&&e.clientY>r.top||e.clientX<=r.right&&e.clientY>r.bottom+o}(e,o,this)&&!g.animated){if(g===on)return B(!1);if(g&&i===e.target&&(a=g),a&&(n=Ft(a)),!1!==Jn(ln,i,on,t,a,n,e,!!a))return _(),i.appendChild(on),an=i,A(),B(!0)}else if(a.parentNode===i){n=Ft(a);var m,v,y,b=on.parentNode!==i,w=!function(e,t,n){var r=n?e.left:e.top,o=n?e.right:e.bottom,i=n?e.width:e.height,a=n?t.left:t.top,s=n?t.right:t.bottom,l=n?t.width:t.height;return r===a||o===s||r+i/2===a+l/2}(on.animated&&on.toRect||t,a.animated&&a.toRect||n,o),E=o?"top":"left",I=Xt(a,"top","top")||Xt(on,"top","top"),k=I?I.scrollTop:void 0;if(Pn!==a&&(v=n[E],On=!1,Mn=!w&&s.invertSwap||b),0!==(m=function(e,t,n,r,o,i,a,s){var l=r?e.clientY:e.clientX,u=r?n.height:n.width,c=r?n.top:n.left,d=r?n.bottom:n.right,f=!1;if(!a)if(s&&xnc+u*i/2:ld-xn)return-Dn}else if(l>c+u*(1-o)/2&&ld-u*i/2))return l>c+u/2?1:-1;return 0}(e,a,n,o,w?1:s.swapThreshold,null==s.invertedSwapThreshold?s.swapThreshold:s.invertedSwapThreshold,Mn,Pn===a))){var S=jt(on);do{S-=m,y=an.children[S]}while(y&&("none"===Lt(y,"display")||y===sn))}if(0===m||y===a)return B(!1);Pn=a,Dn=m;var T=a.nextElementSibling,P=!1,D=Jn(ln,i,on,t,a,n,e,P=1===m);if(!1!==D)return 1!==D&&-1!==D||(P=1===D),Ln=!0,setTimeout(Zn,30),_(),P&&!T?i.appendChild(on):a.parentNode.insertBefore(on,P?T:a),I&&Vt(I,0,k-I.scrollTop),an=on.parentNode,void 0===v||Mn||(xn=Math.abs(v-Ft(a)[E])),A(),B(!0)}if(i.contains(on))return B(!1)}return!1}function x(s,l){nn(s,h,yt({evt:e,isOwner:c,axis:o?"vertical":"horizontal",revert:r,dragRect:t,targetRect:n,canSort:d,fromSortable:f,target:a,completed:B,onMove:function(n,r){return Jn(ln,i,on,t,n,Ft(n),e,r)},changed:A},l))}function _(){x("dragOverAnimationCapture"),h.captureAnimationState(),h!==f&&f.captureAnimationState()}function B(t){return x("dragOverCompleted",{insertion:t}),t&&(c?u._hideClone():u._showClone(h),h!==f&&(Nt(on,yn?yn.options.ghostClass:u.options.ghostClass,!1),Nt(on,s.ghostClass,!0)),yn!==h&&h!==Vn.active?yn=h:h===Vn.active&&yn&&(yn=null),f===h&&(h._ignoreWhileAnimating=a),h.animateAll((function(){x("dragOverAnimationComplete"),h._ignoreWhileAnimating=null})),h!==f&&(f.animateAll(),f._ignoreWhileAnimating=null)),(a===on&&!on.animated||a===i&&!a.animated)&&(Pn=null),s.dragoverBubble||e.rootEl||a===document||(on.parentNode[$t]._isOutsideThisEl(e.target),!t&&Gn(e)),!s.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),p=!0}function A(){pn=jt(on),mn=jt(on,s.draggable),rn({sortable:h,name:"change",toEl:i,newIndex:pn,newDraggableIndex:mn,originalEvent:e})}},_ignoreWhileAnimating:null,_offMoveEvents:function(){_t(document,"mousemove",this._onTouchMove),_t(document,"touchmove",this._onTouchMove),_t(document,"pointermove",this._onTouchMove),_t(document,"dragover",Gn),_t(document,"mousemove",Gn),_t(document,"touchmove",Gn)},_offUpEvents:function(){var e=this.el.ownerDocument;_t(e,"mouseup",this._onDrop),_t(e,"touchend",this._onDrop),_t(e,"pointerup",this._onDrop),_t(e,"touchcancel",this._onDrop),_t(document,"selectstart",this)},_onDrop:function(e){var t=this.el,n=this.options;pn=jt(on),mn=jt(on,n.draggable),nn("drop",this,{evt:e}),an=on&&on.parentNode,pn=jt(on),mn=jt(on,n.draggable),Vn.eventCanceled||(Bn=!1,Mn=!1,On=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),tr(this.cloneId),tr(this._dragStartId),this.nativeDraggable&&(_t(document,"drop",this),_t(t,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),St&&Lt(document.body,"user-select",""),Lt(on,"transform",""),e&&(Tn&&(e.cancelable&&e.preventDefault(),!n.dropBubble&&e.stopPropagation()),sn&&sn.parentNode&&sn.parentNode.removeChild(sn),(ln===an||yn&&"clone"!==yn.lastPutMode)&&dn&&dn.parentNode&&dn.parentNode.removeChild(dn),on&&(this.nativeDraggable&&_t(on,"dragend",this),$n(on),on.style["will-change"]="",Tn&&!Bn&&Nt(on,yn?yn.options.ghostClass:this.options.ghostClass,!1),Nt(on,this.options.chosenClass,!1),rn({sortable:this,name:"unchoose",toEl:an,newIndex:null,newDraggableIndex:null,originalEvent:e}),ln!==an?(pn>=0&&(rn({rootEl:an,name:"add",toEl:an,fromEl:ln,originalEvent:e}),rn({sortable:this,name:"remove",toEl:an,originalEvent:e}),rn({rootEl:an,name:"sort",toEl:an,fromEl:ln,originalEvent:e}),rn({sortable:this,name:"sort",toEl:an,originalEvent:e})),yn&&yn.save()):pn!==hn&&pn>=0&&(rn({sortable:this,name:"update",toEl:an,originalEvent:e}),rn({sortable:this,name:"sort",toEl:an,originalEvent:e})),Vn.active&&(null!=pn&&-1!==pn||(pn=hn,mn=gn),rn({sortable:this,name:"end",toEl:an,originalEvent:e}),this.save())))),this._nulling()},_nulling:function(){nn("nulling",this),ln=on=an=sn=un=dn=cn=fn=bn=wn=Tn=pn=mn=hn=gn=Pn=Dn=yn=vn=Vn.dragged=Vn.ghost=Vn.clone=Vn.active=null,Rn.forEach((function(e){e.checked=!0})),Rn.length=En=In=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":on&&(this._onDragOver(e),function(e){e.dataTransfer&&(e.dataTransfer.dropEffect="move");e.cancelable&&e.preventDefault()}(e));break;case"selectstart":e.preventDefault()}},toArray:function(){for(var e,t=[],n=this.el.children,r=0,o=n.length,i=this.options;r=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function mt(e){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(e)}var vt=mt(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),yt=mt(/Edge/i),bt=mt(/firefox/i),wt=mt(/safari/i)&&!mt(/chrome/i)&&!mt(/android/i),Et=mt(/iP(ad|od|hone)/i),It=mt(/chrome/i)&&mt(/android/i),kt={capture:!1,passive:!1};function St(e,t,n){e.addEventListener(t,n,!vt&&kt)}function Tt(e,t,n){e.removeEventListener(t,n,!vt&&kt)}function Dt(e,t){if(t){if(">"===t[0]&&(t=t.substring(1)),e)try{if(e.matches)return e.matches(t);if(e.msMatchesSelector)return e.msMatchesSelector(t);if(e.webkitMatchesSelector)return e.webkitMatchesSelector(t)}catch(e){return!1}return!1}}function xt(e){return e.host&&e!==document&&e.host.nodeType?e.host:e.parentNode}function Pt(e,t,n,r){if(e){n=n||document;do{if(null!=t&&(">"===t[0]?e.parentNode===n&&Dt(e,t):Dt(e,t))||r&&e===n)return e;if(e===n)break}while(e=xt(e))}return null}var _t,Bt=/\s+/g;function At(e,t,n){if(e&&t)if(e.classList)e.classList[n?"add":"remove"](t);else{var r=(" "+e.className+" ").replace(Bt," ").replace(" "+t+" "," ");e.className=(r+(n?" "+t:"")).replace(Bt," ")}}function Ct(e,t,n){var r=e&&e.style;if(r){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(e,""):e.currentStyle&&(n=e.currentStyle),void 0===t?n:n[t];t in r||-1!==t.indexOf("webkit")||(t="-webkit-"+t),r[t]=n+("string"==typeof n?"":"px")}}function Ot(e,t){var n="";if("string"==typeof e)n=e;else do{var r=Ct(e,"transform");r&&"none"!==r&&(n=r+" "+n)}while(!t&&(e=e.parentNode));var o=window.DOMMatrix||window.WebKitCSSMatrix||window.CSSMatrix||window.MSCSSMatrix;return o&&new o(n)}function Mt(e,t,n){if(e){var r=e.getElementsByTagName(t),o=0,i=r.length;if(n)for(;o=i:o<=i))return r;if(r===Nt())break;r=qt(r,!1)}return!1}function Ht(e,t,n){for(var r=0,o=0,i=e.children;o2&&void 0!==arguments[2]?arguments[2]:{},r=n.evt,o=gt(n,["evt"]);$t.pluginEvent.bind(Wn)(e,t,ht({dragEl:en,parentEl:tn,ghostEl:nn,rootEl:rn,nextEl:on,lastDownEl:an,cloneEl:sn,cloneHidden:ln,dragStarted:En,putSortable:hn,activeSortable:Wn.active,originalEvent:r,oldIndex:un,oldDraggableIndex:dn,newIndex:cn,newDraggableIndex:fn,hideGhostForTarget:Un,unhideGhostForTarget:qn,cloneNowHidden:function(){ln=!0},cloneNowShown:function(){ln=!1},dispatchSortableEvent:function(e){Kt({sortable:t,name:e,originalEvent:r})}},o))};function Kt(e){!function(e){var t=e.sortable,n=e.rootEl,r=e.name,o=e.targetEl,i=e.cloneEl,a=e.toEl,s=e.fromEl,l=e.oldIndex,u=e.newIndex,c=e.oldDraggableIndex,d=e.newDraggableIndex,f=e.originalEvent,p=e.putSortable,h=e.extraEventProperties;if(t=t||n&&n[Gt]){var g,m=t.options,v="on"+r.charAt(0).toUpperCase()+r.substr(1);!window.CustomEvent||vt||yt?(g=document.createEvent("Event")).initEvent(r,!0,!0):g=new CustomEvent(r,{bubbles:!0,cancelable:!0}),g.to=a||n,g.from=s||n,g.item=o||n,g.clone=i,g.oldIndex=l,g.newIndex=u,g.oldDraggableIndex=c,g.newDraggableIndex=d,g.originalEvent=f,g.pullMode=p?p.lastPutMode:void 0;var y=ht({},h,$t.getEventProperties(r,t));for(var b in y)g[b]=y[b];n&&n.dispatchEvent(g),m[v]&&m[v].call(t,g)}}(ht({putSortable:hn,cloneEl:sn,targetEl:en,rootEl:rn,oldIndex:un,oldDraggableIndex:dn,newIndex:cn,newDraggableIndex:fn},e))}var en,tn,nn,rn,on,an,sn,ln,un,cn,dn,fn,pn,hn,gn,mn,vn,yn,bn,wn,En,In,kn,Sn,Tn,Dn=!1,xn=!1,Pn=[],_n=!1,Bn=!1,An=[],Cn=!1,On=[],Mn="undefined"!=typeof document,Nn=Et,Ln=yt||vt?"cssFloat":"float",Rn=Mn&&!It&&!Et&&"draggable"in document.createElement("div"),Hn=function(){if(Mn){if(vt)return!1;var e=document.createElement("x");return e.style.cssText="pointer-events:auto","auto"===e.style.pointerEvents}}(),Fn=function(e,t){var n=Ct(e),r=parseInt(n.width)-parseInt(n.paddingLeft)-parseInt(n.paddingRight)-parseInt(n.borderLeftWidth)-parseInt(n.borderRightWidth),o=Ht(e,0,t),i=Ht(e,1,t),a=o&&Ct(o),s=i&&Ct(i),l=a&&parseInt(a.marginLeft)+parseInt(a.marginRight)+Lt(o).width,u=s&&parseInt(s.marginLeft)+parseInt(s.marginRight)+Lt(i).width;if("flex"===n.display)return"column"===n.flexDirection||"column-reverse"===n.flexDirection?"vertical":"horizontal";if("grid"===n.display)return n.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(o&&a.float&&"none"!==a.float){var c="left"===a.float?"left":"right";return!i||"both"!==s.clear&&s.clear!==c?"horizontal":"vertical"}return o&&("block"===a.display||"flex"===a.display||"table"===a.display||"grid"===a.display||l>=r&&"none"===n[Ln]||i&&"none"===n[Ln]&&l+u>r)?"vertical":"horizontal"},Xn=function(e){function t(e,n){return function(r,o,i,a){var s=r.options.group.name&&o.options.group.name&&r.options.group.name===o.options.group.name;if(null==e&&(n||s))return!0;if(null==e||!1===e)return!1;if(n&&"clone"===e)return e;if("function"==typeof e)return t(e(r,o,i,a),n)(r,o,i,a);var l=(n?r:o).options.group.name;return!0===e||"string"==typeof e&&e===l||e.join&&e.indexOf(l)>-1}}var n={},r=e.group;r&&"object"==dt(r)||(r={name:r}),n.name=r.name,n.checkPull=t(r.pull,!0),n.checkPut=t(r.put),n.revertClone=r.revertClone,e.group=n},Un=function(){!Hn&&nn&&Ct(nn,"display","none")},qn=function(){!Hn&&nn&&Ct(nn,"display","")};Mn&&document.addEventListener("click",(function(e){if(xn)return e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.stopImmediatePropagation&&e.stopImmediatePropagation(),xn=!1,!1}),!0);var Yn=function(e){if(en){e=e.touches?e.touches[0]:e;var t=(o=e.clientX,i=e.clientY,Pn.some((function(e){if(!Ft(e)){var t=Lt(e),n=e[Gt].options.emptyInsertThreshold,r=o>=t.left-n&&o<=t.right+n,s=i>=t.top-n&&i<=t.bottom+n;return n&&r&&s?a=e:void 0}})),a);if(t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=e[r]);n.target=n.rootEl=t,n.preventDefault=void 0,n.stopPropagation=void 0,t[Gt]._onDragOver(n)}}var o,i,a},jn=function(e){en&&en.parentNode[Gt]._isOutsideThisEl(e.target)};function Wn(e,t){if(!e||!e.nodeType||1!==e.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(e));this.el=e,this.options=t=pt({},t),e[Gt]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,draggable:/^[uo]l$/i.test(e.nodeName)?">li":">*",swapThreshold:1,invertSwap:!1,invertedSwapThreshold:null,removeCloneOnHide:!0,direction:function(){return Fn(e,this.options)},ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,easing:null,setData:function(e,t){e.setData("Text",t.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==Wn.supportPointer&&"PointerEvent"in window&&!wt,emptyInsertThreshold:5};for(var r in $t.initializePlugins(this,e,n),n)!(r in t)&&(t[r]=n[r]);for(var o in Xn(t),this)"_"===o.charAt(0)&&"function"==typeof this[o]&&(this[o]=this[o].bind(this));this.nativeDraggable=!t.forceFallback&&Rn,this.nativeDraggable&&(this.options.touchStartThreshold=1),t.supportPointer?St(e,"pointerdown",this._onTapStart):(St(e,"mousedown",this._onTapStart),St(e,"touchstart",this._onTapStart)),this.nativeDraggable&&(St(e,"dragover",this),St(e,"dragenter",this)),Pn.push(this.el),t.store&&t.store.get&&this.sort(t.store.get(this)||[]),pt(this,Qt())}function zn(e,t,n,r,o,i,a,s){var l,u,c=e[Gt],d=c.options.onMove;return!window.CustomEvent||vt||yt?(l=document.createEvent("Event")).initEvent("move",!0,!0):l=new CustomEvent("move",{bubbles:!0,cancelable:!0}),l.to=t,l.from=e,l.dragged=n,l.draggedRect=r,l.related=o||t,l.relatedRect=i||Lt(t),l.willInsertAfter=s,l.originalEvent=a,e.dispatchEvent(l),d&&(u=d.call(c,l,a)),u}function Gn(e){e.draggable=!1}function Qn(){Cn=!1}function Vn(e){for(var t=e.tagName+e.className+e.src+e.href+e.textContent,n=t.length,r=0;n--;)r+=t.charCodeAt(n);return r.toString(36)}function Jn(e){return setTimeout(e,0)}function $n(e){return clearTimeout(e)}Wn.prototype={constructor:Wn,_isOutsideThisEl:function(e){this.el.contains(e)||e===this.el||(In=null)},_getDirection:function(e,t){return"function"==typeof this.options.direction?this.options.direction.call(this,e,t,en):this.options.direction},_onTapStart:function(e){if(e.cancelable){var t=this,n=this.el,r=this.options,o=r.preventOnFilter,i=e.type,a=e.touches&&e.touches[0]||e.pointerType&&"touch"===e.pointerType&&e,s=(a||e).target,l=e.target.shadowRoot&&(e.path&&e.path[0]||e.composedPath&&e.composedPath()[0])||s,u=r.filter;if(function(e){On.length=0;var t=e.getElementsByTagName("input"),n=t.length;for(;n--;){var r=t[n];r.checked&&On.push(r)}}(n),!en&&!(/mousedown|pointerdown/.test(i)&&0!==e.button||r.disabled)&&!l.isContentEditable&&(this.nativeDraggable||!wt||!s||"SELECT"!==s.tagName.toUpperCase())&&!((s=Pt(s,r.draggable,n,!1))&&s.animated||an===s)){if(un=Xt(s),dn=Xt(s,r.draggable),"function"==typeof u){if(u.call(this,e,s,this))return Kt({sortable:t,rootEl:l,name:"filter",targetEl:s,toEl:n,fromEl:n}),Zt("filter",t,{evt:e}),void(o&&e.cancelable&&e.preventDefault())}else if(u&&(u=u.split(",").some((function(r){if(r=Pt(l,r.trim(),n,!1))return Kt({sortable:t,rootEl:r,name:"filter",targetEl:s,fromEl:n,toEl:n}),Zt("filter",t,{evt:e}),!0}))))return void(o&&e.cancelable&&e.preventDefault());r.handle&&!Pt(l,r.handle,n,!1)||this._prepareDragStart(e,a,s)}}},_prepareDragStart:function(e,t,n){var r,o=this,i=o.el,a=o.options,s=i.ownerDocument;if(n&&!en&&n.parentNode===i){var l=Lt(n);if(rn=i,tn=(en=n).parentNode,on=en.nextSibling,an=n,pn=a.group,Wn.dragged=en,gn={target:en,clientX:(t||e).clientX,clientY:(t||e).clientY},bn=gn.clientX-l.left,wn=gn.clientY-l.top,this._lastX=(t||e).clientX,this._lastY=(t||e).clientY,en.style["will-change"]="all",r=function(){Zt("delayEnded",o,{evt:e}),Wn.eventCanceled?o._onDrop():(o._disableDelayedDragEvents(),!bt&&o.nativeDraggable&&(en.draggable=!0),o._triggerDragStart(e,t),Kt({sortable:o,name:"choose",originalEvent:e}),At(en,a.chosenClass,!0))},a.ignore.split(",").forEach((function(e){Mt(en,e.trim(),Gn)})),St(s,"dragover",Yn),St(s,"mousemove",Yn),St(s,"touchmove",Yn),St(s,"mouseup",o._onDrop),St(s,"touchend",o._onDrop),St(s,"touchcancel",o._onDrop),bt&&this.nativeDraggable&&(this.options.touchStartThreshold=4,en.draggable=!0),Zt("delayStart",this,{evt:e}),!a.delay||a.delayOnTouchOnly&&!t||this.nativeDraggable&&(yt||vt))r();else{if(Wn.eventCanceled)return void this._onDrop();St(s,"mouseup",o._disableDelayedDrag),St(s,"touchend",o._disableDelayedDrag),St(s,"touchcancel",o._disableDelayedDrag),St(s,"mousemove",o._delayedDragTouchMoveHandler),St(s,"touchmove",o._delayedDragTouchMoveHandler),a.supportPointer&&St(s,"pointermove",o._delayedDragTouchMoveHandler),o._dragStartTimer=setTimeout(r,a.delay)}}},_delayedDragTouchMoveHandler:function(e){var t=e.touches?e.touches[0]:e;Math.max(Math.abs(t.clientX-this._lastX),Math.abs(t.clientY-this._lastY))>=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){en&&Gn(en),clearTimeout(this._dragStartTimer),this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var e=this.el.ownerDocument;Tt(e,"mouseup",this._disableDelayedDrag),Tt(e,"touchend",this._disableDelayedDrag),Tt(e,"touchcancel",this._disableDelayedDrag),Tt(e,"mousemove",this._delayedDragTouchMoveHandler),Tt(e,"touchmove",this._delayedDragTouchMoveHandler),Tt(e,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(e,t){t=t||"touch"==e.pointerType&&e,!this.nativeDraggable||t?this.options.supportPointer?St(document,"pointermove",this._onTouchMove):St(document,t?"touchmove":"mousemove",this._onTouchMove):(St(en,"dragend",this),St(rn,"dragstart",this._onDragStart));try{document.selection?Jn((function(){document.selection.empty()})):window.getSelection().removeAllRanges()}catch(e){}},_dragStarted:function(e,t){if(Dn=!1,rn&&en){Zt("dragStarted",this,{evt:t}),this.nativeDraggable&&St(document,"dragover",jn);var n=this.options;!e&&At(en,n.dragClass,!1),At(en,n.ghostClass,!0),Wn.active=this,e&&this._appendGhost(),Kt({sortable:this,name:"start",originalEvent:t})}else this._nulling()},_emulateDragOver:function(){if(mn){this._lastX=mn.clientX,this._lastY=mn.clientY,Un();for(var e=document.elementFromPoint(mn.clientX,mn.clientY),t=e;e&&e.shadowRoot&&(e=e.shadowRoot.elementFromPoint(mn.clientX,mn.clientY))!==t;)t=e;if(en.parentNode[Gt]._isOutsideThisEl(e),t)do{if(t[Gt]){if(t[Gt]._onDragOver({clientX:mn.clientX,clientY:mn.clientY,target:e,rootEl:t})&&!this.options.dragoverBubble)break}e=t}while(t=t.parentNode);qn()}},_onTouchMove:function(e){if(gn){var t=this.options,n=t.fallbackTolerance,r=t.fallbackOffset,o=e.touches?e.touches[0]:e,i=nn&&Ot(nn,!0),a=nn&&i&&i.a,s=nn&&i&&i.d,l=Nn&&Tn&&Ut(Tn),u=(o.clientX-gn.clientX+r.x)/(a||1)+(l?l[0]-An[0]:0)/(a||1),c=(o.clientY-gn.clientY+r.y)/(s||1)+(l?l[1]-An[1]:0)/(s||1);if(!Wn.active&&!Dn){if(n&&Math.max(Math.abs(o.clientX-this._lastX),Math.abs(o.clientY-this._lastY))r.right+o||e.clientX<=r.right&&e.clientY>r.bottom&&e.clientX>=r.left:e.clientX>r.right&&e.clientY>r.top||e.clientX<=r.right&&e.clientY>r.bottom+o}(e,o,this)&&!g.animated){if(g===en)return B(!1);if(g&&i===e.target&&(a=g),a&&(n=Lt(a)),!1!==zn(rn,i,en,t,a,n,e,!!a))return _(),i.appendChild(en),tn=i,A(),B(!0)}else if(a.parentNode===i){n=Lt(a);var m,v,y,b=en.parentNode!==i,w=!function(e,t,n){var r=n?e.left:e.top,o=n?e.right:e.bottom,i=n?e.width:e.height,a=n?t.left:t.top,s=n?t.right:t.bottom,l=n?t.width:t.height;return r===a||o===s||r+i/2===a+l/2}(en.animated&&en.toRect||t,a.animated&&a.toRect||n,o),E=o?"top":"left",I=Rt(a,"top","top")||Rt(en,"top","top"),k=I?I.scrollTop:void 0;if(In!==a&&(v=n[E],_n=!1,Bn=!w&&s.invertSwap||b),0!==(m=function(e,t,n,r,o,i,a,s){var l=r?e.clientY:e.clientX,u=r?n.height:n.width,c=r?n.top:n.left,d=r?n.bottom:n.right,f=!1;if(!a)if(s&&Snc+u*i/2:ld-Sn)return-kn}else if(l>c+u*(1-o)/2&&ld-u*i/2))return l>c+u/2?1:-1;return 0}(e,a,n,o,w?1:s.swapThreshold,null==s.invertedSwapThreshold?s.swapThreshold:s.invertedSwapThreshold,Bn,In===a))){var S=Xt(en);do{S-=m,y=tn.children[S]}while(y&&("none"===Ct(y,"display")||y===nn))}if(0===m||y===a)return B(!1);In=a,kn=m;var T=a.nextElementSibling,D=!1,x=zn(rn,i,en,t,a,n,e,D=1===m);if(!1!==x)return 1!==x&&-1!==x||(D=1===x),Cn=!0,setTimeout(Qn,30),_(),D&&!T?i.appendChild(en):a.parentNode.insertBefore(en,D?T:a),I&&Wt(I,0,k-I.scrollTop),tn=en.parentNode,void 0===v||Bn||(Sn=Math.abs(v-Lt(a)[E])),A(),B(!0)}if(i.contains(en))return B(!1)}return!1}function P(s,l){Zt(s,p,ht({evt:e,isOwner:c,axis:o?"vertical":"horizontal",revert:r,dragRect:t,targetRect:n,canSort:d,fromSortable:f,target:a,completed:B,onMove:function(n,r){return zn(rn,i,en,t,n,Lt(n),e,r)},changed:A},l))}function _(){P("dragOverAnimationCapture"),p.captureAnimationState(),p!==f&&f.captureAnimationState()}function B(t){return P("dragOverCompleted",{insertion:t}),t&&(c?u._hideClone():u._showClone(p),p!==f&&(At(en,hn?hn.options.ghostClass:u.options.ghostClass,!1),At(en,s.ghostClass,!0)),hn!==p&&p!==Wn.active?hn=p:p===Wn.active&&hn&&(hn=null),f===p&&(p._ignoreWhileAnimating=a),p.animateAll((function(){P("dragOverAnimationComplete"),p._ignoreWhileAnimating=null})),p!==f&&(f.animateAll(),f._ignoreWhileAnimating=null)),(a===en&&!en.animated||a===i&&!a.animated)&&(In=null),s.dragoverBubble||e.rootEl||a===document||(en.parentNode[Gt]._isOutsideThisEl(e.target),!t&&Yn(e)),!s.dragoverBubble&&e.stopPropagation&&e.stopPropagation(),h=!0}function A(){cn=Xt(en),fn=Xt(en,s.draggable),Kt({sortable:p,name:"change",toEl:i,newIndex:cn,newDraggableIndex:fn,originalEvent:e})}},_ignoreWhileAnimating:null,_offMoveEvents:function(){Tt(document,"mousemove",this._onTouchMove),Tt(document,"touchmove",this._onTouchMove),Tt(document,"pointermove",this._onTouchMove),Tt(document,"dragover",Yn),Tt(document,"mousemove",Yn),Tt(document,"touchmove",Yn)},_offUpEvents:function(){var e=this.el.ownerDocument;Tt(e,"mouseup",this._onDrop),Tt(e,"touchend",this._onDrop),Tt(e,"pointerup",this._onDrop),Tt(e,"touchcancel",this._onDrop),Tt(document,"selectstart",this)},_onDrop:function(e){var t=this.el,n=this.options;cn=Xt(en),fn=Xt(en,n.draggable),Zt("drop",this,{evt:e}),tn=en&&en.parentNode,cn=Xt(en),fn=Xt(en,n.draggable),Wn.eventCanceled||(Dn=!1,Bn=!1,_n=!1,clearInterval(this._loopId),clearTimeout(this._dragStartTimer),$n(this.cloneId),$n(this._dragStartId),this.nativeDraggable&&(Tt(document,"drop",this),Tt(t,"dragstart",this._onDragStart)),this._offMoveEvents(),this._offUpEvents(),wt&&Ct(document.body,"user-select",""),Ct(en,"transform",""),e&&(En&&(e.cancelable&&e.preventDefault(),!n.dropBubble&&e.stopPropagation()),nn&&nn.parentNode&&nn.parentNode.removeChild(nn),(rn===tn||hn&&"clone"!==hn.lastPutMode)&&sn&&sn.parentNode&&sn.parentNode.removeChild(sn),en&&(this.nativeDraggable&&Tt(en,"dragend",this),Gn(en),en.style["will-change"]="",En&&!Dn&&At(en,hn?hn.options.ghostClass:this.options.ghostClass,!1),At(en,this.options.chosenClass,!1),Kt({sortable:this,name:"unchoose",toEl:tn,newIndex:null,newDraggableIndex:null,originalEvent:e}),rn!==tn?(cn>=0&&(Kt({rootEl:tn,name:"add",toEl:tn,fromEl:rn,originalEvent:e}),Kt({sortable:this,name:"remove",toEl:tn,originalEvent:e}),Kt({rootEl:tn,name:"sort",toEl:tn,fromEl:rn,originalEvent:e}),Kt({sortable:this,name:"sort",toEl:tn,originalEvent:e})),hn&&hn.save()):cn!==un&&cn>=0&&(Kt({sortable:this,name:"update",toEl:tn,originalEvent:e}),Kt({sortable:this,name:"sort",toEl:tn,originalEvent:e})),Wn.active&&(null!=cn&&-1!==cn||(cn=un,fn=dn),Kt({sortable:this,name:"end",toEl:tn,originalEvent:e}),this.save())))),this._nulling()},_nulling:function(){Zt("nulling",this),rn=en=tn=nn=on=sn=an=ln=gn=mn=En=cn=fn=un=dn=In=kn=hn=pn=Wn.dragged=Wn.ghost=Wn.clone=Wn.active=null,On.forEach((function(e){e.checked=!0})),On.length=vn=yn=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragenter":case"dragover":en&&(this._onDragOver(e),function(e){e.dataTransfer&&(e.dataTransfer.dropEffect="move");e.cancelable&&e.preventDefault()}(e));break;case"selectstart":e.preventDefault()}},toArray:function(){for(var e,t=[],n=this.el.children,r=0,o=n.length,i=this.options;r { + this._request( + this.baseURL ? this.baseURL + API_LOGIN : API_LOGIN, + AUTH_STATUS, + REQUEST_TYPE_POST, + CONTENT_TYPE_JSON, + data + ) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } syncSettings(data) { return new Promise((resolve, reject) => { this._request( @@ -61,50 +75,7 @@ export default class APIUtils { }); }); } - imageUpload(type, files) { - return new Promise((resolve, reject) => { - let 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); - } - } - this._request( - url, - DataEvent.API_IMAGES_UPLOAD, - REQUEST_TYPE_POST, - CONTENT_TYPE_FORM, - imageData - ) - .then((r) => { - resolve(r); - }) - .catch((err) => { - reject(err); - }); - }); - } + publishSite(data) { return new Promise((resolve, reject) => { this._request( @@ -192,40 +163,6 @@ export default class APIUtils { }); }); } - handleBackup(id, files) { - return new Promise((resolve, reject) => { - var url, event, method, type, data; - - if (id === "create-backup") { - url = API_CREATE_BACKUP; - event = DataEvent.API_BACKUP_CREATE; - method = REQUEST_TYPE_POST; - type = CONTENT_TYPE_JSON; - data = { task: "create_backup" }; - } else { - url = API_RESTORE_BACKUP; - event = DataEvent.API_BACKUP_RESTORE; - method = REQUEST_TYPE_POST; - type = CONTENT_TYPE_FORM; - data = new FormData(); - for (var i = 0; i < files.length; i++) { - var file = files[i]; - // Check the file type. - if (!file.type.match("application.zip")) { - continue; - } - data.append("backup_upload", file, file.name); - } - } - this._request(url, event, method, type, data) - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }); - } handleReindex(data) { return new Promise((resolve, reject) => { diff --git a/src/libraries/FipamoAPI.js b/src/libraries/FipamoContentAPI.js similarity index 65% rename from src/libraries/FipamoAPI.js rename to src/libraries/FipamoContentAPI.js index 39c808d..1b704c0 100644 --- a/src/libraries/FipamoAPI.js +++ b/src/libraries/FipamoContentAPI.js @@ -3,136 +3,45 @@ export const REQUEST_TYPE_POST = "POST"; export const REQUEST_TYPE_GET = "GET"; export const REQUEST_TYPE_PUT = "PUT"; export const REQUEST_TYPE_DELETE = "DELETE"; + //** POST CONTENT TYPES **// export const CONTENT_TYPE_JSON = "json"; export const CONTENT_TYPE_FORM = "x-www-form-urlencoded"; + //** API URLS **// -export const API_STATUS = "/api/v1/status"; -export const API_INIT = "/api/v1/init"; -export const API_RESTORE = "/api/v1/restore"; -export const API_LOGIN = "/api/v1/login"; export const API_GET_PAGES = "/api/v1/page/published"; +export const API_GET_FEATURED = "/api/v1/page/featured"; +export const API_GET_MENU = "/api/v1/page/menu"; export const API_GET_PAGE = "/api/v1/page/single"; -export const API_GET_SECRET = "/api/v1/get-secret"; -export const API_RESET_PASS = "/api/v1/reset-password"; +export const API_GET_TAGS = "/api/v1/page/tags"; + //** API TASKS **// -export const AUTH_STATUS = "getAuthStatus"; -export const TASK_SITE_INIT = "blogInit"; -export const TASK_BACKUP_RESTORE = "downloadBackup"; -export const TASK_GET_SECRET = "retrieveSecret"; -export const TASK_RESET_PASS = "resetPassword"; export const TASK_GET_CONTENT = "retrieveContent"; +/** + * FipamoContentAPI + */ export default class FipamoAPI { //-------------------------- // constructor //-------------------------- - constructor(baseURL = null) { + + /** + * @constructor + * @param {string} baseURL - url of site + * @param {string} key - user api key + */ + constructor(baseURL = null, key = null) { this.baseURL = null; - if (baseURL) { - this.baseURL = baseURL; - } + this.key = null; + if (key) this.key = key; + if (baseURL) this.baseURL = baseURL; } //-------------------------- // methods //-------------------------- - //** MEMBER AUTH METHODS **// - login(data) { - return new Promise((resolve, reject) => { - this._request( - this.baseURL ? this.baseURL + API_LOGIN : API_LOGIN, - AUTH_STATUS, - REQUEST_TYPE_POST, - CONTENT_TYPE_JSON, - data - ) - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }); - } - init(data) { - return new Promise((resolve, reject) => { - this._request( - API_INIT, - TASK_SITE_INIT, - REQUEST_TYPE_POST, - CONTENT_TYPE_JSON, - data - ) - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }); - } - - handleInitRestore(form) { - return new Promise((resolve, reject) => { - var url, event, method, type, data; - - url = API_RESTORE; - event = TASK_BACKUP_RESTORE; - method = REQUEST_TYPE_POST; - type = CONTENT_TYPE_FORM; - data = new FormData(form); - this._request(url, event, method, type, data) - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }); - } - - getSecret(data) { - return new Promise((resolve, reject) => { - this._request( - API_GET_SECRET, - TASK_GET_SECRET, - REQUEST_TYPE_POST, - CONTENT_TYPE_JSON, - data - ) - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }); - } - - setNewPass(data) { - return new Promise((resolve, reject) => { - this._request( - API_RESET_PASS, - TASK_RESET_PASS, - REQUEST_TYPE_POST, - CONTENT_TYPE_JSON, - data - ) - .then((result) => { - resolve(result); - }) - .catch((err) => { - reject(err); - }); - }); - } - - //** CONTENT API METHODS **// - - getPages(num, key) { - let pageNum = num; - if (pageNum === null || pageNum === "" || !pageNum) pageNum = 1; + getPages(key) { return new Promise((resolve, reject) => { this._request( this.baseURL @@ -150,6 +59,60 @@ export default class FipamoAPI { }); } + getFeatured(key) { + return new Promise((resolve, reject) => { + this._request( + this.baseURL + ? this.baseURL + API_GET_FEATURED + "?key=" + key + : API_GET_FEATURED, + TASK_GET_CONTENT, + REQUEST_TYPE_GET + ) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + + getMenu(key) { + return new Promise((resolve, reject) => { + this._request( + this.baseURL + ? this.baseURL + API_GET_MENU + "?key=" + key + : API_GET_MENU, + TASK_GET_CONTENT, + REQUEST_TYPE_GET + ) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + + getTags(key) { + return new Promise((resolve, reject) => { + this._request( + this.baseURL + ? this.baseURL + API_GET_TAGS + "?key=" + key + : API_GET_TAGS, + TASK_GET_CONTENT, + REQUEST_TYPE_GET + ) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + getPage(id, key) { return new Promise((resolve, reject) => { this._request( diff --git a/src/libraries/FipamoUtilityAPI.js b/src/libraries/FipamoUtilityAPI.js new file mode 100644 index 0000000..41a64e5 --- /dev/null +++ b/src/libraries/FipamoUtilityAPI.js @@ -0,0 +1,258 @@ +//** REQUEST TYPES **// +export const REQUEST_TYPE_POST = "POST"; +export const REQUEST_TYPE_GET = "GET"; +export const REQUEST_TYPE_PUT = "PUT"; +export const REQUEST_TYPE_DELETE = "DELETE"; +//** POST CONTENT TYPES **// +export const CONTENT_TYPE_JSON = "json"; +export const CONTENT_TYPE_FORM = "x-www-form-urlencoded"; +//** API URLS **// +export const API_STATUS = "/api/v1/status"; +export const API_INIT = "/api/v1/init"; +export const API_RESTORE = "/api/v1/restore"; +export const API_GET_SECRET = "/api/v1/get-secret"; +export const API_RESET_PASS = "/api/v1/reset-password"; +export const API_CREATE_BACKUP = "/api/v1/backup"; +export const API_DOWNLOAD_BACKUP = "/api/v1/backup/download"; +export const API_RESTORE_BACKUP = "/api/v1/backup/restore"; +export const API_UPLOAD_AVATAR = "/api/v1/settings/add-avatar"; +export const API_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background"; +export const API_IMAGE_UPLOAD = "/api/v1/page/add-entry-image"; +//** API TASKS **// +export const AUTH_STATUS = "getAuthStatus"; +export const TASK_SITE_INIT = "blogInit"; +export const TASK_BACKUP_RESTORE = "downloadBackup"; +export const TASK_GET_SECRET = "retrieveSecret"; +export const TASK_RESET_PASS = "resetPassword"; +export const TASK_GET_CONTENT = "retrieveContent"; + +import * as DataEvent from "../com/events/DataEvent"; + +/** + * FipamoUtilityAPI + */ +export default class FipamoUtilityAPI { + //-------------------------- + // constructor + //-------------------------- + + /** + * @constructor + */ + constructor() {} + //-------------------------- + // methods + //-------------------------- + + //** MEMBER AUTH METHODS **// + + initNew(data) { + return new Promise((resolve, reject) => { + this._request( + API_INIT, + TASK_SITE_INIT, + REQUEST_TYPE_POST, + CONTENT_TYPE_JSON, + data + ) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + + initRestore(form) { + return new Promise((resolve, reject) => { + var url, event, method, type, data; + + url = API_RESTORE; + event = TASK_BACKUP_RESTORE; + method = REQUEST_TYPE_POST; + type = CONTENT_TYPE_FORM; + data = new FormData(form); + this._request(url, event, method, type, data) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + + backup(id, files) { + return new Promise((resolve, reject) => { + var url, event, method, type, data; + + if (id === "create-backup") { + url = API_CREATE_BACKUP; + event = DataEvent.API_BACKUP_CREATE; + method = REQUEST_TYPE_POST; + type = CONTENT_TYPE_JSON; + data = { task: "create_backup" }; + } else { + url = API_RESTORE_BACKUP; + event = DataEvent.API_BACKUP_RESTORE; + method = REQUEST_TYPE_POST; + type = CONTENT_TYPE_FORM; + data = new FormData(); + for (var i = 0; i < files.length; i++) { + var file = files[i]; + // Check the file type. + if (!file.type.match("application.zip")) { + continue; + } + data.append("backup_upload", file, file.name); + } + } + this._request(url, event, method, type, data) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + + secret(data) { + return new Promise((resolve, reject) => { + this._request( + API_GET_SECRET, + TASK_GET_SECRET, + REQUEST_TYPE_POST, + CONTENT_TYPE_JSON, + data + ) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + + newPass(data) { + return new Promise((resolve, reject) => { + this._request( + API_RESET_PASS, + TASK_RESET_PASS, + REQUEST_TYPE_POST, + CONTENT_TYPE_JSON, + data + ) + .then((result) => { + resolve(result); + }) + .catch((err) => { + reject(err); + }); + }); + } + + imageUpload(type, files) { + return new Promise((resolve, reject) => { + let 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); + } + } + this._request( + url, + DataEvent.API_IMAGES_UPLOAD, + REQUEST_TYPE_POST, + CONTENT_TYPE_FORM, + imageData + ) + .then((r) => { + resolve(r); + }) + .catch((err) => { + reject(err); + }); + }); + } + + //-------------------------- + // private + //-------------------------- + _request( + requestURL, + eventType, + requestType = REQUEST_TYPE_GET, + contentType = CONTENT_TYPE_JSON, + requestData = 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 = () => { + if (request.status == 200) { + let response = JSON.parse(request["response"]); + resolve(response); + } else { + let 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.setRequestHeader( + "Access-Control-Allow-Origin", + self.baseURL + ); + **/ + request.send(JSON.stringify(requestData)); + break; + case CONTENT_TYPE_FORM: + request.send(requestData); + break; + } + } else { + request.send(); + } + }); + } + + //-------------------------- + // event handlers + //-------------------------- + handleLoadProgress(e) { + this.percentComplete = Math.ceil((e.loaded / e.total) * 100); + //pass element to display request progress + } +}