wikijs-fork/assets/js/app.js

2 lines
44 KiB
JavaScript
Raw Normal View History

"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(),"undefined"!=typeof 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<o.length;t++){var n=o[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(o,t,n){return t&&e(o.prototype,t),n&&e(o,n),o}}();jQuery(document).ready(function(e){var o=this;e("a").smoothScroll({speed:400,offset:-70});new Sticky(".stickyscroll");e(window).bind("beforeunload",function(){e("#notifload").addClass("active")}),e(document).ajaxSend(function(){e("#notifload").addClass("active")}).ajaxComplete(function(){e("#notifload").removeClass("active")});var t=new Alerts;alertsData&&_.forEach(alertsData,function(e){t.push(e)});var n=io(window.location.origin);if(e("#search-input").length){e("#search-input").focus(),e(".searchresults").css("display","block");var i=new Vue({el:"#header-container",data:{searchq:"",searchres:[],searchsuggest:[],searchload:0,searchactive:!1,searchmoveidx:0,searchmovekey:"",searchmovearr:[]},watch:{searchq:function(e,o){i.searchmoveidx=0,e.length>=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){e>0?i.searchmovekey=i.searchmovearr[e-1]?"res."+i.searchmovearr[e-1].entryPath:"sug."+i.searchmovearr[e-1]:i.searchmovekey=""}},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.searchmoveidx<i.searchmovearr.length&&i.searchmoveidx++},moveUpSearch:function(){i.searchmoveidx>0&&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:
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(n){var i=I.files.length;e(n.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<e.results.length&&(t.push({title:"Some uploads succeeded",message:"Files that are not mentionned in the errors above were uploaded successfully."}),I.uploadSucceeded=!0)):I.uploadSucceeded=!0}else t.pushError("Upload error",e.msg)},error:function(e){t.pushError(e.message,o.upload.file.name)},finish:function(){I.uploadSucceeded?I.waitChangeComplete(i,!0):I.isLoading=!1}})});var y={youtube:new RegExp(/(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|&v(?:i)?=))([^#&?]*).*/,"i"),vimeo:new RegExp(/vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|)(\d+)(?:$|\/|\?)/,"i"),dailymotion:new RegExp(/(?:dailymotion\.com(?:\/embed)?(?:\/video|\/hub)|dai\.ly)\/([0-9a-z]+)(?:[-_0-9a-zA-Z]+(?:#video=)?([a-z0-9]+)?)?/,"i")},L=new Vue({el:"#modal-editor-video",data:{link:""},methods:{open:function(o){e("#modal-editor-video").addClass("is-active"),e("#modal-editor-video input").focus()},cancel:function(o){k=!1,e("#modal-editor-video").removeClass("is-active"),L.link=""},insertVideo:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o=_.findKey(y,function(e){return e.test(L.link)});_.isNil(o)&&(o="video");var t="[video]("+L.link+"){."+o+"}\n";F.codemirror.doc.replaceSelection(t),L.cancel()}}}),b=ace.require("ace/ext/modelist"),E=null,T=[],U=function(o){return e.ajax({url:"/js/ace/mode-"+o+".js",dataType:"script",cache:!0,beforeSend:function(){if(_.includes(T,o))return!1},success:function(){T.push(o)}})},N=new Vue({el:"#modal-editor-codeblock",data:{modes:b.modesByName,modeSelected:"text",initContent:""},watch:{modeSelected:function(e,o){U(e).done(function(){ace.require("ace/mode/"+e),E.getSession().setMode("ace/mode/"+e)})}},methods:{open:function(o){e("#modal-editor-codeblock").addClass("is-active"),_.delay(function(){E=ace.edit("codeblock-editor"),E.setTheme("ace/theme/tomorrow_night"),E.getSession().setMode("ace/mode/"+N.modeSelected),E.setOption("fontSize","14px"),E.setOption("hScrollBarAlwaysVisible",!1),E.setOption("wrap",!0),E.setValue(N.initContent),E.focus(),E.renderer.updateFull()},300)},cancel:function(o){k=!1,e("#modal-editor-codeblock").removeClass("is-active"),N.initContent=""},insertCode:function(e){F.codemirror.doc.somethingSelected()&&F.codemirror.execCommand("singleSelection");var o="\n```"+N.modeSelected+"\n"+E.getValue()+"\n```\n";F.codemirror.doc.replaceSelection(o),N.cancel()}}}),F=new SimpleMDE({autofocus:!0,autoDownloadFontAwesome:!1,element:e("#mk-editor").get(0),placeholder:"Enter Markdown