You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wiki/assets/js/app.js

1 line
27 KiB

8 years ago
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function setInputSelection(e,t,a){if(e.focus(),"undefined"!=typeof e.selectionStart)e.selectionStart=t,e.selectionEnd=a;else if(document.selection&&document.selection.createRange){e.select();var o=document.selection.createRange();o.collapse(!0),o.moveEnd("character",a),o.moveStart("character",t),o.select()}}function makeSafePath(e){var t=_.split(_.trim(e),"/");return t=_.map(t,function(e){return _.kebabCase(_.deburr(_.trim(e)))}),_.join(_.filter(t,function(e){return!_.isEmpty(e)}),"/")}var _createClass=function(){function e(e,t){for(var a=0;a<t.length;a++){var o=t[a];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,a,o){return a&&e(t.prototype,a),o&&e(t,o),t}}();jQuery(document).ready(function(e){var t=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 a=new Alerts;alertsData&&_.forEach(alertsData,function(e){a.push(e)});var o=io(window.location.origin);if(e("#search-input").length){e("#search-input").focus(),e(".searchresults").css("display","block");var n=new Vue({el:"#header-container",data:{searchq:"",searchres:[],searchsuggest:[],searchload:0,searchactive:!1,searchmoveidx:0,searchmovekey:"",searchmovearr:[]},watch:{searchq:function(e,t){n.searchmoveidx=0,e.length>=3?(n.searchactive=!0,n.searchload++,o.emit("search",{terms:e},function(e){n.searchres=e.match,n.searchsuggest=e.suggest,n.searchmovearr=_.concat([],n.searchres,n.searchsuggest),n.searchload>0&&n.searchload--})):(n.searchactive=!1,n.searchres=[],n.searchsuggest=[],n.searchmovearr=[],n.searchload=0)},searchmoveidx:function(e,t){e>0?n.searchmovekey=n.searchmovearr[e-1]?"res."+n.searchmovearr[e-1]._id:"sug."+n.searchmovearr[e-1]:n.searchmovekey=""}},methods:{useSuggestion:function(e){n.searchq=e},closeSearch:function(){n.searchq=""},moveSelectSearch:function(){if(!(n.searchmoveidx<1)){var e=n.searchmoveidx-1;n.searchmovearr[e]?window.location.assign("/"+n.searchmovearr[e]._id):n.searchq=n.searchmovearr[e]}},moveDownSearch:function(){n.searchmoveidx<n.searchmovearr.length&&n.searchmoveidx++},moveUpSearch:function(){n.searchmoveidx>0&&n.searchmoveidx--}}});e("main").on("click",n.closeSearch)}if(e("#page-type-view").length&&!function(){var t="home"!==e("#page-type-view").data("entrypath")?e("#page-type-view").data("entrypath"):"",o=t+"/new-page";e(".btn-create-prompt").on("click",function(a){e("#txt-create-prompt").val(o),e("#modal-create-prompt").toggleClass("is-active"),setInputSelection(e("#txt-create-prompt").get(0),t.length+1,o.length),e("#txt-create-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-create-prompt").on("keypress",function(t){13===t.which&&e(".btn-create-go").trigger("click")}),e(".btn-create-go").on("click",function(t){var a=makeSafePath(e("#txt-create-prompt").val());_.isEmpty(a)?e("#txt-create-prompt").addClass("is-danger").next().removeClass("is-hidden"):(e("#txt-create-prompt").parent().addClass("is-loading"),window.location.assign("/create/"+a))}),""!==t&&e(".btn-move-prompt").removeClass("is-hidden");var n=_.lastIndexOf(t,"/")+1;e(".btn-move-prompt").on("click",function(a){e("#txt-move-prompt").val(t),e("#modal-move-prompt").toggleClass("is-active"),setInputSelection(e("#txt-move-prompt").get(0),n,t.length),e("#txt-move-prompt").removeClass("is-danger").next().addClass("is-hidden")}),e("#txt-move-prompt").on("keypress",function(t){13===t.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===t||"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: