"use strict";function _classCallCheck(e,o){if(!(e instanceof o))throw new TypeError("Cannot call a class as a function")}function setInputSelection(e,o,t){if(e.focus(),void 0!==e.selectionStart)e.selectionStart=o,e.selectionEnd=t;else if(document.selection&&document.selection.createRange){e.select();var n=document.selection.createRange();n.collapse(!0),n.moveEnd("character",t),n.moveStart("character",o),n.select()}}function makeSafePath(e){var o=_.split(_.trim(e),"/");return o=_.map(o,function(e){return _.kebabCase(_.deburr(_.trim(e)))}),_.join(_.filter(o,function(e){return!_.isEmpty(e)}),"/")}var _createClass=function(){function e(e,o){for(var t=0;t=3?(i.searchactive=!0,i.searchload++,n.emit("search",{terms:e},function(e){i.searchres=e.match,i.searchsuggest=e.suggest,i.searchmovearr=_.concat([],i.searchres,i.searchsuggest),i.searchload>0&&i.searchload--})):(i.searchactive=!1,i.searchres=[],i.searchsuggest=[],i.searchmovearr=[],i.searchload=0)},searchmoveidx:function(e,o){i.searchmovekey=e>0?i.searchmovearr[e-1]?"res."+i.searchmovearr[e-1].entryPath:"sug."+i.searchmovearr[e-1]:""}},methods:{useSuggestion:function(e){i.searchq=e},closeSearch:function(){i.searchq=""},moveSelectSearch:function(){if(!(i.searchmoveidx<1)){var e=i.searchmoveidx-1;i.searchmovearr[e]?window.location.assign("/"+i.searchmovearr[e].entryPath):i.searchq=i.searchmovearr[e]}},moveDownSearch:function(){i.searchmoveidx0&&i.searchmoveidx--}}});e("main").on("click",i.closeSearch)}if(e("#page-type-view").length){var a="home"!==e("#page-type-view").data("entrypath")?e("#page-type-view").data("entrypath"):"",r=a+"/new-page";e(".btn-create-prompt").on("click",function(o){e("#txt-create-prompt").val(r),e("#modal-create-prompt").toggleClass("is-active"),setInputSelection(e("#txt-create-prompt").get(0),a.length+1,r.length),e("#txt-create-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-create-prompt").on("keypress",function(o){13===o.which&&e(".btn-create-go").trigger("click")}),e(".btn-create-go").on("click",function(o){var t=makeSafePath(e("#txt-create-prompt").val());_.isEmpty(t)?e("#txt-create-prompt").addClass("is-danger").next().removeClass("is-hidden"):(e("#txt-create-prompt").parent().addClass("is-loading"),window.location.assign("/create/"+t))}),""!==a&&e(".btn-move-prompt").removeClass("is-hidden");var l=_.lastIndexOf(a,"/")+1;e(".btn-move-prompt").on("click",function(o){e("#txt-move-prompt").val(a),e("#modal-move-prompt").toggleClass("is-active"),setInputSelection(e("#txt-move-prompt").get(0),l,a.length),e("#txt-move-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-move-prompt").on("keypress",function(o){13===o.which&&e(".btn-move-go").trigger("click")}),e(".btn-move-go").on("click",function(o){var n=makeSafePath(e("#txt-move-prompt").val());_.isEmpty(n)||n===a||"home"===n?e("#txt-move-prompt").addClass("is-danger").next().removeClass("is-hidden"):(e("#txt-move-prompt").parent().addClass("is-loading"),e.ajax(window.location.href,{data:{move:n},dataType:"json",method:"PUT"}).then(function(e,o,i){e.ok?window.location.assign("/"+n):t.pushError("Something went wrong",e.error)},function(e,o,n){t.pushError("Something went wrong","Save operation failed.")}))})}if(e("#page-type-create").length){var d=e("#page-type-create").data("entrypath");if(e(".btn-create-discard").on("click",function(o){e("#modal-create-discard").toggleClass("is-active")}),1===e("#mk-editor").length){var s=!1;Vue.filter("filesize",function(e){return _.toUpper(filesize(e))});var c=new Vue({el:"#modal-editor-image",data:{isLoading:!1,isLoadingText:"",newFolderName:"",newFolderShow:!1,newFolderError:!1,fetchFromUrlURL:"",fetchFromUrlShow:!1,folders:[],currentFolder:"",currentImage:"",currentAlign:"left",images:[],uploadSucceeded:!1,postUploadChecks:0,renameImageShow:!1,renameImageId:"",renameImageFilename:"",deleteImageShow:!1,deleteImageId:"",deleteImageFilename:""},methods:{open:function(){s=!0,e("#modal-editor-image").addClass("is-active"),c.refreshFolders()},cancel:function(o){s=!1,e("#modal-editor-image").removeClass("is-active")},selectImage:function(e){c.currentImage=e},insertImage:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.find(c.images,["_id",c.currentImage]);o.normalizedPath="f:"===o.folder?o.filename:o.folder.slice(2)+"/"+o.filename,o.titleGuess=_.startCase(o.basename);var t="!["+o.titleGuess+"](/uploads/"+o.normalizedPath+' "'+o.titleGuess+'")';switch(c.currentAlign){case"center":t+="{.align-center}";break;case"right":t+="{.align-right}";break;case"logo":t+="{.pagelogo}"}F.codemirror.doc.replaceSelection(t),c.cancel()},newFolder:function(o){c.newFolderName="",c.newFolderError=!1,c.newFolderShow=!0,_.delay(function(){e("#txt-editor-image-newfoldername").focus()},400)},newFolderDiscard:function(e){c.newFolderShow=!1},newFolderCreate:function(e){var o=new RegExp("^[a-z0-9][a-z0-9-]*[a-z0-9]$");if(c.newFolderName=_.kebabCase(_.trim(c.newFolderName)),_.isEmpty(c.newFolderName)||!o.test(c.newFolderName))return void(c.newFolderError=!0);c.newFolderDiscard(),c.isLoadingText="Creating new folder...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsCreateFolder",{foldername:c.newFolderName},function(e){c.folders=e,c.currentFolder=c.newFolderName,c.images=[],c.isLoading=!1})})},fetchFromUrl:function(o){c.fetchFromUrlURL="",c.fetchFromUrlShow=!0,_.delay(function(){e("#txt-editor-image-fetchurl").focus()},400)},fetchFromUrlDiscard:function(e){c.fetchFromUrlShow=!1},fetchFromUrlGo:function(e){c.fetchFromUrlDiscard(),c.isLoadingText="Fetching image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsFetchFileFromURL",{folder:c.currentFolder,fetchUrl:c.fetchFromUrlURL},function(e){e.ok?c.waitChangeComplete(c.images.length,!0):(c.isLoading=!1,t.pushError("Upload error",e.msg))})})},renameImage:function(){var o=_.find(c.images,["_id",c.renameImageId]);c.renameImageFilename=o.basename||"",c.renameImageShow=!0,_.delay(function(){e("#txt-editor-image-rename").focus(),_.defer(function(){e("#txt-editor-image-rename").select()})},400)},renameImageDiscard:function(){c.renameImageShow=!1},renameImageGo:function(){c.renameImageDiscard(),c.isLoadingText="Renaming image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsRenameFile",{uid:c.renameImageId,folder:c.currentFolder,filename:c.renameImageFilename},function(e){e.ok?c.waitChangeComplete(c.images.length,!1):(c.isLoading=!1,t.pushError("Rename error",e.msg))})})},moveImage:function(e,o){c.isLoadingText="Moving image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsMoveFile",{uid:e,folder:o},function(e){e.ok?c.loadImages():(c.isLoading=!1,t.pushError("Rename error",e.msg))})})},deleteImageWarn:function(e){if(e){var o=_.find(c.images,["_id",c.deleteImageId]);c.deleteImageFilename=o.filename||"this image"}c.deleteImageShow=e},deleteImageGo:function(){c.deleteImageWarn(!1),c.isLoadingText="Deleting image...",c.isLoading=!0,Vue.nextTick(function(){n.emit("uploadsDeleteFile",{uid:c.deleteImageId},function(e){c.loadImages()})})},selectFolder:function(e){c.currentFolder=e,c.loadImages()},refreshFolders:function(){c.isLoadingText="Fetching folders list...",c.isLoading=!0,c.currentFolder="",c.currentImage="",Vue.nextTick(function(){n.emit("uploadsGetFolders",{},function(e){c.folders=e,c.loadImages()})})},loadImages:function(e){return e||(c.isLoadingText="Fetching images...",c.isLoading=!0),new Promise(function(o,t){Vue.nextTick(function(){n.emit("uploadsGetImages",{folder:c.currentFolder},function(t){c.images=t,e||(c.isLoading=!1),c.attachContextMenus(),o(!0)})})})},waitChangeComplete:function(e,o){o=!_.isBoolean(o)||o,c.postUploadChecks++,c.isLoadingText="Processing...",Vue.nextTick(function(){c.loadImages(!0).then(function(){c.images.length!==e===o?(c.postUploadChecks=0,c.isLoading=!1):c.postUploadChecks>5?(c.postUploadChecks=0,c.isLoading=!1,t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){c.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(c.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(c.folders,o);c.moveImage(n,i)}}});e.contextMenu("destroy",".editor-modal-image-choices > figure"),e.contextMenu({selector:".editor-modal-image-choices > figure",appendTo:".editor-modal-image-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/2,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){c.renameImageId=_.toString(o.$trigger[0].dataset.uid),c.renameImage()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){c.deleteImageId=_.toString(o.$trigger[0].dataset.uid),c.deleteImageWarn(!0)}}}})}}});e("#btn-editor-image-upload input").on("change",function(n){var i=c.images.length;e(n.currentTarget).simpleUpload("/uploads/img",{name:"imgfile",data:{folder:c.currentFolder},limit:20,expect:"json",allowedExts:["jpg","jpeg","gif","png","webp"],allowedTypes:["image/png","image/jpeg","image/gif","image/webp"],maxFileSize:3145728,init:function(e){c.uploadSucceeded=!1,c.isLoadingText="Preparing to upload...",c.isLoading=!0},progress:function(e){c.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length5?(m.postUploadChecks=0,m.isLoading=!1,t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){m.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(m.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(m.folders,o);m.moveFile(n,i)}}});e.contextMenu("destroy",".editor-modal-file-choices > figure"),e.contextMenu({selector:".editor-modal-file-choices > figure",appendTo:".editor-modal-file-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/5,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){m.renameFileId=_.toString(o.$trigger[0].dataset.uid),m.renameFile()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){m.deleteFileId=_.toString(o.$trigger[0].dataset.uid),m.deleteFileWarn(!0)}}}})}}});e("#btn-editor-file-upload input").on("change",function(o){var n=m.files.length;e(o.currentTarget).simpleUpload("/uploads/file",{name:"binfile",data:{folder:m.currentFolder},limit:20,expect:"json",maxFileSize:0,init:function(e){m.uploadSucceeded=!1,m.isLoadingText="Preparing to upload...",m.isLoading=!0},progress:function(e){m.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length5?(C.postUploadChecks=0,C.isLoading=!1,t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){C.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(C.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(C.folders,o);C.moveImage(n,i)}}});e.contextMenu("destroy",".editor-modal-image-choices > figure"),e.contextMenu({selector:".editor-modal-image-choices > figure",appendTo:".editor-modal-image-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/2,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){C.renameImageId=_.toString(o.$trigger[0].dataset.uid),C.renameImage()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){C.deleteImageId=_.toString(o.$trigger[0].dataset.uid),C.deleteImageWarn(!0)}}}})}}});e("#btn-editor-image-upload input").on("change",function(n){var i=C.images.length;e(n.currentTarget).simpleUpload("/uploads/img",{name:"imgfile",data:{folder:C.currentFolder},limit:20,expect:"json",allowedExts:["jpg","jpeg","gif","png","webp"],allowedTypes:["image/png","image/jpeg","image/gif","image/webp"],maxFileSize:3145728,init:function(e){C.uploadSucceeded=!1,C.isLoadingText="Preparing to upload...",C.isLoading=!0},progress:function(e){C.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length5?(I.postUploadChecks=0,I.isLoading=!1, t.pushError("Unable to fetch updated listing","Try again later")):_.delay(function(){I.waitChangeComplete(e,o)},1500)})})},attachContextMenus:function(){var o=_.map(I.folders,function(o){return{name:""!==o?o:"/ (root)",icon:"fa-folder",callback:function(o,t){var n=_.toString(e(t.$trigger).data("uid")),i=_.nth(I.folders,o);I.moveFile(n,i)}}});e.contextMenu("destroy",".editor-modal-file-choices > figure"),e.contextMenu({selector:".editor-modal-file-choices > figure",appendTo:".editor-modal-file-choices",position:function(o,t,n){e(o.$trigger).addClass("is-contextopen");var i=e(o.$trigger).position(),a={w:e(o.$trigger).width()/5,h:e(o.$trigger).height()/2};o.$menu.css({top:i.top+a.h,left:i.left+a.w})},events:{hide:function(o){e(o.$trigger).removeClass("is-contextopen")}},items:{rename:{name:"Rename",icon:"fa-edit",callback:function(e,o){I.renameFileId=_.toString(o.$trigger[0].dataset.uid),I.renameFile()}},move:{name:"Move to...",icon:"fa-folder-open-o",items:o},delete:{name:"Delete",icon:"fa-trash",callback:function(e,o){I.deleteFileId=_.toString(o.$trigger[0].dataset.uid),I.deleteFileWarn(!0)}}}})}}});e("#btn-editor-file-upload input").on("change",function(o){var n=I.files.length;e(o.currentTarget).simpleUpload("/uploads/file",{name:"binfile",data:{folder:I.currentFolder},limit:20,expect:"json",maxFileSize:0,init:function(e){I.uploadSucceeded=!1,I.isLoadingText="Preparing to upload...",I.isLoading=!0},progress:function(e){I.isLoadingText="Uploading..."+Math.round(e)+"%"},success:function(e){if(e.ok){var o=_.filter(e.results,["ok",!1]);o.length?(_.forEach(o,function(e){t.pushError("Upload error",e.msg)}),o.length=0&&n&&(n.class+=" exit",Vue.set(o.mdl.children,t,n),_.delay(function(){o.mdl.children.splice(t,1)},500))}}]),e}();