Commit f77faeff authored by Van's avatar Van

🐛 vditor

parent fac9a60c
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
}; };
var Label = { var Label = {
"hljsStyle": "atom-one-light",
"pushSuccLabel": '${pushSuccLabel}', "pushSuccLabel": '${pushSuccLabel}',
"pushToHacpaiLabel": '${pushToHacpaiLabel}', "pushToHacpaiLabel": '${pushToHacpaiLabel}',
"uploadMsg": '${uploadMsg}', "uploadMsg": '${uploadMsg}',
......
Util.htmlDecode=function(t){var e=document.createElement("div");return e.innerHTML=decodeURIComponent(t),e.innerText},Util.proessURL=function(t){return/^\w+:\/\//.test(t)||(t="http://"+t),t};var Admin=function(){this.register={},this.tools=["#page-list","#file-list","#link-list","#preference","#user-list","#plugin-list","#others","#category-list"],this.adTools=["link-list","preference","file-list","page-list","user-list","plugin-list","others","category-list"]};$.extend(Admin.prototype,{logout:function(){window.location.href=latkeConfig.servePath+"/logout"},toggleMenu:function(){"-240px"===$("#tabs").css("left")?($("#tabs").css("left",0),$(".tabs__bg").show()):($("#tabs").css("left","-240px"),$(".tabs__bg").hide())},clearTip:function(){$("#tipMsg").text(""),$("#loadMsg").text("")},setHashByPage:function(t){var e=window.location.hash.split("/");/^\d*$/.test(e[e.length-1])?e[e.length-1]=t:e.push(t),window.location.hash=e.join("/")},selectTab:function(t){window.location.hash="#"+t},analyseHash:function(){for(var t=window.location.hash,e=t.substr(1,t.length-1).split("/"),i={page:1,hashList:[]},a=0;a<e.length;a++)a===e.length-1&&/^\d+$/.test(e[a])?i.page=e[a]:i.hashList.push(e[a]);return i},setCurByHash:function(){$(window).scrollTop(0),$("#tipMsg").text("");var t=admin.analyseHash(),e=t.hashList[1],i=t.hashList[2];if(1===t.hashList.length&&(e=t.hashList[0]),""!==e){"article"!==e?admin.article.clearDraftTimer():"article"===e&&(admin.article.autoSaveDraftTimer=setInterval(function(){admin.article._autoSaveToDraft()},admin.article.AUTOSAVETIME));try{if("article"!==e&&admin.article.isConfirm&&""!==admin.editors.articleEditor.getContent().replace(/\s/g,"")&&admin.article.content!==admin.editors.articleEditor.getContent()&&!confirm(Label.editorLeaveLabel))return void(window.location.hash="#article/article");if("article"===e&&admin.article.isConfirm&&""!==admin.editors.articleEditor.getContent().replace(/\s/g,"")&&admin.article.content!==admin.editors.articleEditor.getContent())return}catch(t){var a=$("#articleContent");if(0<a.length){if("article"!==e&&admin.article.isConfirm&&""!==a.val().replace(/\s/g,"")&&admin.article.content!==a.val()&&!confirm(Label.editorLeaveLabel))return void(window.location.hash="#article/article");if("article"===e&&admin.article.isConfirm&&""!==a.val().replace(/\s/g,"")&&admin.article.content!==a.val())return}}"article"!==e&&admin.editors.articleEditor.setContent&&admin.article.clear(),admin.article.isConfirm=!0,$("#tabs").tabs("setCurrent",e),$("#loadMsg").text(Label.loadingLabel),1===$("#tabsPanel_"+e).length?""===$("#tabsPanel_"+e).html().replace(/\s/g,"")?$("#tabsPanel_"+e).load("admin-"+e+".do",function(){"article"===e&&admin.article.status.id?admin.register[e].init.call(admin.register[e].obj,admin.article.getAndSet):admin.register[e].init.call(admin.register[e].obj,t.page),i&&$("#tab"+e.substring(0,1).toUpperCase()+e.substring(1)).tabs("setCurrent",i),admin.plugin.setCurByHash(t)}):("article"===e&&admin.article.status.id&&admin.article.getAndSet(),admin.register[e]&&admin.register[e].refresh&&admin.register[e].refresh.call(admin.register[e].obj,t.page),i&&$("#tab"+e.substring(0,1).toUpperCase()+e.substring(1)).tabs("setCurrent",i),admin.plugin.setCurByHash(t)):($("#tipMsg").text("Error: No tab! "+Label.reportIssueLabel),$("#loadMsg").text(""))}},init:function(){Util.killIE(),$("#loadMsg").text(Label.loadingLabel),$("#tabs").tabs(),setInterval(function(){""!==$("#tipMsg").text()&&setTimeout(function(){$("#tipMsg").text("")},7e3)},6e3),$("#loadMsg").text("")},collapseNav:function(t){$(t).next().slideToggle("normal",function(){"none"!==this.style.display?($(t).find(".icon-chevron-down")[0].className="icon-chevron-up fn__right",$(t).addClass("tab-current")):($(t).find(".icon-chevron-up")[0].className="icon-chevron-down fn__right",$(t).removeClass("tab-current")),$("#tabs > ul").height("auto"),$("#tabs > ul").height($("#tabs > ul").height()+80)})},inited:function(){if("adminRole"!==Label.userRole)for(var t=0;t<this.adTools.length;t++)$("#tabs").tabs("remove",this.adTools[t]);else for(var e=0;e<this.tools.length;e++)if("#"+window.location.hash.split("/")[1]===this.tools[e]){$("#tabToolsTitle").click();break}this.setCurByHash()}});var admin=new Admin; Util.htmlDecode=function(t){var e=document.createElement("div");return e.innerHTML=decodeURIComponent(t),e.innerText},Util.proessURL=function(t){return/^\w+:\/\//.test(t)||(t="http://"+t),t};var Admin=function(){this.register={},this.tools=["#page-list","#file-list","#link-list","#preference","#user-list","#plugin-list","#others","#category-list"],this.adTools=["link-list","preference","file-list","page-list","user-list","plugin-list","others","category-list"]};$.extend(Admin.prototype,{logout:function(){window.location.href=latkeConfig.servePath+"/logout"},toggleMenu:function(){"-240px"===$("#tabs").css("left")?($("#tabs").css("left",0),$(".tabs__bg").show()):($("#tabs").css("left","-240px"),$(".tabs__bg").hide())},clearTip:function(){$("#tipMsg").text(""),$("#loadMsg").text("")},setHashByPage:function(t){var e=window.location.hash.split("/");/^\d*$/.test(e[e.length-1])?e[e.length-1]=t:e.push(t),window.location.hash=e.join("/")},selectTab:function(t){window.location.hash="#"+t},analyseHash:function(){for(var t=window.location.hash,e=t.substr(1,t.length-1).split("/"),i={page:1,hashList:[]},a=0;a<e.length;a++)a===e.length-1&&/^\d+$/.test(e[a])?i.page=e[a]:i.hashList.push(e[a]);return i},setCurByHash:function(){$(window).scrollTop(0),$("#tipMsg").text("");var t=admin.analyseHash(),e=t.hashList[1],i=t.hashList[2];if(1===t.hashList.length&&(e=t.hashList[0]),""!==e){"article"!==e?admin.article.clearDraftTimer():"article"===e&&(admin.article.autoSaveDraftTimer=setInterval(function(){admin.article._autoSaveToDraft()},admin.article.AUTOSAVETIME));try{if("article"!==e&&admin.article.isConfirm&&""!==admin.editors.articleEditor.getContent().replace(/\s/g,"")&&admin.article.content!==admin.editors.articleEditor.getContent()&&!confirm(Label.editorLeaveLabel))return void(window.location.hash="#article/article");if("article"===e&&admin.article.isConfirm&&""!==admin.editors.articleEditor.getContent().replace(/\s/g,"")&&admin.article.content!==admin.editors.articleEditor.getContent())return}catch(t){var a=$("#articleContent");if(0<a.length){if("article"!==e&&admin.article.isConfirm&&""!==a.val().replace(/\s/g,"")&&admin.article.content!==a.val()&&!confirm(Label.editorLeaveLabel))return void(window.location.hash="#article/article");if("article"===e&&admin.article.isConfirm&&""!==a.val().replace(/\s/g,"")&&admin.article.content!==a.val())return}}"article"!==e&&admin.editors.articleEditor.setContent&&admin.article.clear(),admin.article.isConfirm=!0,$("#tabs").tabs("setCurrent",e),$("#loadMsg").text(Label.loadingLabel),1===$("#tabsPanel_"+e).length?""===$("#tabsPanel_"+e).html().replace(/\s/g,"")?$("#tabsPanel_"+e).load("admin-"+e+".do",function(){"article"===e&&admin.article.status.id?admin.register[e].init.call(admin.register[e].obj,admin.article.getAndSet):admin.register[e].init.call(admin.register[e].obj,t.page),i&&$("#tab"+e.substring(0,1).toUpperCase()+e.substring(1)).tabs("setCurrent",i),admin.plugin.setCurByHash(t)}):("article"===e&&admin.article.status.id&&admin.article.getAndSet(),admin.register[e]&&admin.register[e].refresh&&admin.register[e].refresh.call(admin.register[e].obj,t.page),i&&$("#tab"+e.substring(0,1).toUpperCase()+e.substring(1)).tabs("setCurrent",i),admin.plugin.setCurByHash(t)):($("#tipMsg").text("Error: No tab! "+Label.reportIssueLabel),$("#loadMsg").text(""))}},init:function(){Util.killIE(),$("#loadMsg").text(Label.loadingLabel),$("#tabs").tabs(),setInterval(function(){""!==$("#tipMsg").text()&&setTimeout(function(){$("#tipMsg").text("")},7e3)},6e3),$("#loadMsg").text("")},collapseNav:function(t){$(t).next().slideToggle("normal",function(){"none"!==this.style.display?($(t).find(".icon-chevron-down")[0].className="icon-chevron-up fn__right",$(t).addClass("tab-current")):($(t).find(".icon-chevron-up")[0].className="icon-chevron-down fn__right",$(t).removeClass("tab-current")),$("#tabs > ul").height("auto"),$("#tabs > ul").height($("#tabs > ul").height()+80)})},inited:function(){if("adminRole"!==Label.userRole)for(var t=0;t<this.adTools.length;t++)$("#tabs").tabs("remove",this.adTools[t]);else for(var e=0;e<this.tools.length;e++)if("#"+window.location.hash.split("/")[1]===this.tools[e]){$("#tabToolsTitle").click();break}this.setCurByHash()}});var admin=new Admin;
admin.editors={};var SoloEditor=function(t){this.conf=t,this.init()};$.extend(SoloEditor.prototype,{init:function(){this.editor=new Vditor(this.conf.id,{cache:!0,tab:"\t",hint:{emojiPath:latkeConfig.staticServePath+"/js/lib/emojify.js-1.1.0/images/basic"},preview:{delay:500,show:this.conf.previewShow,url:latkeConfig.servePath+"/console/markdown/2html"},upload:{max:10485760,url:Label.uploadURL,token:Label.uploadToken,filename:function(t){return t.replace(/\?|\\|\/|:|\||<|>|\*|\[|\]|\s+/g,"-")}},height:this.conf.height,counter:102400,resize:{enable:this.conf.resize},lang:Label.localeString}),"function"==typeof this.conf.fun&&this.conf.fun()},getContent:function(){return this.editor.getValue()},setContent:function(t){this.editor.setValue(t)},remove:function(){document.getElementById(this.editor.vditor.id).outerHTML=""}}),admin.editors.articleEditor={},admin.editors.abstractEditor={},admin.editors.pageEditor={}; admin.editors={};var SoloEditor=function(t){this.conf=t,this.init()};$.extend(SoloEditor.prototype,{init:function(){this.editor=new Vditor(this.conf.id,{cache:!0,tab:"\t",hint:{emojiPath:latkeConfig.staticServePath+"/js/lib/emojify.js-1.1.0/images/basic"},preview:{delay:500,show:this.conf.previewShow,url:latkeConfig.servePath+"/console/markdown/2html",parse:function(t){"none"!==t.style.display&&Util.parseLanguage()}},upload:{max:10485760,url:Label.uploadURL,token:Label.uploadToken,filename:function(t){return t.replace(/\?|\\|\/|:|\||<|>|\*|\[|\]|\s+/g,"-")}},height:this.conf.height,counter:102400,resize:{enable:this.conf.resize},lang:Label.localeString}),"function"==typeof this.conf.fun&&this.conf.fun()},getContent:function(){return this.editor.getValue()},setContent:function(t){this.editor.setValue(t)},remove:function(){document.getElementById(this.editor.vditor.id).outerHTML=""}}),admin.editors.articleEditor={},admin.editors.abstractEditor={},admin.editors.pageEditor={};
var TablePaginate=function(a){this.id=a,this.currentPage=1};$.extend(TablePaginate.prototype,{buildTable:function(a,t){var e={colModel:a,noDataTip:Label.noDataLabel};t||(e.expendRow={index:"expendRow"}),$("#"+this.id+"Table").table(e)},initPagination:function(){var a=this.id;$("#"+a+"Pagination").paginate({bind:function(a,t){t?$("#tipMsg").text(t):admin.setHashByPage(a)},currentPage:1,errorMessage:Label.inputErrorLabel,nextPageText:">",previousPageText:"<",goText:Label.gotoLabel,type:"custom",custom:[1],pageCount:1})},initCommentsDialog:function(){var a=this;$("#"+this.id+"Comments").dialog({modal:!0,hideFooter:!0,close:function(){return admin[a.id+"List"].getList(a.currentPage),!0}})},updateTablePagination:function(a,t,e){if((t=parseInt(t))>e.paginationPageCount&&1<t)return $("#tipMsg").text(Label.pageLabel+t+Label.notFoundLabel),void $("#loadMsg").text("");$("#"+this.id+"Table").table("update",{data:[{groupName:"all",groupData:a}]}),0===e.paginationPageCount&&(e.paginationPageCount=1),$("#"+this.id+"Pagination").paginate("update",{pageCount:e.paginationPageCount,currentPage:t,custom:e.paginationPageNums}),this.currentPage=t}}); var TablePaginate=function(a){this.id=a,this.currentPage=1};$.extend(TablePaginate.prototype,{buildTable:function(a,t){var e={colModel:a,noDataTip:Label.noDataLabel};t||(e.expendRow={index:"expendRow"}),$("#"+this.id+"Table").table(e)},initPagination:function(){var a=this.id;$("#"+a+"Pagination").paginate({bind:function(a,t){t?$("#tipMsg").text(t):admin.setHashByPage(a)},currentPage:1,errorMessage:Label.inputErrorLabel,nextPageText:">",previousPageText:"<",goText:Label.gotoLabel,type:"custom",custom:[1],pageCount:1})},initCommentsDialog:function(){var a=this;$("#"+this.id+"Comments").dialog({modal:!0,hideFooter:!0,close:function(){return admin[a.id+"List"].getList(a.currentPage),!0}})},updateTablePagination:function(a,t,e){if((t=parseInt(t))>e.paginationPageCount&&1<t)return $("#tipMsg").text(Label.pageLabel+t+Label.notFoundLabel),void $("#loadMsg").text("");$("#"+this.id+"Table").table("update",{data:[{groupName:"all",groupData:a}]}),0===e.paginationPageCount&&(e.paginationPageCount=1),$("#"+this.id+"Pagination").paginate("update",{pageCount:e.paginationPageCount,currentPage:t,custom:e.paginationPageNums}),this.currentPage=t}});
function getUUID(){var a=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=(a+16*Math.random())%16|0;return a=Math.floor(a/16),("x"==t?e:3&e|8).toString(16)});return t=t.replace(new RegExp("-","g"),"")}admin.article={isConfirm:!0,status:{id:void 0,isArticle:void 0},content:"",autoSaveDraftTimer:"",AUTOSAVETIME:6e4,get:function(t,e){this.status.id=t,this.status.isArticle=e,admin.selectTab("article/article")},getAndSet:function(){$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text(""),$.ajax({url:latkeConfig.servePath+"/console/article/"+admin.article.status.id,type:"GET",cache:!1,success:function(e,t){if($("#tipMsg").text(e.msg),e.sc){$("#title").val(e.article.articleTitle),admin.editors.articleEditor.setContent(e.article.articleContent),admin.editors.abstractEditor.setContent(e.article.articleAbstract),admin.article.content=admin.editors.articleEditor.getContent();for(var a=e.article.articleTags,i="",l=0;l<a.length;l++)0===l?i=a[l].tagTitle:i+=","+a[l].tagTitle;$("#tag").val(i),$("#permalink").val(e.article.articlePermalink),$("#viewPwd").val(e.article.articleViewPwd),$("#articleCommentable").prop("checked",e.article.articleCommentable);var s=e.article.signs;$(".signs button").each(function(t){parseInt(e.article.articleSignId)===parseInt(s[t].oId)?$("#articleSign"+s[t].oId).addClass("selected"):$("#articleSign"+s[t].oId).removeClass("selected")}),admin.article.setStatus(),$("#loadMsg").text("")}else $("#loadMsg").text("")}})},del:function(t,a,e){confirm(Label.confirmRemoveLabel+Label.articleLabel+'"'+Util.htmlDecode(e)+'"?')&&($("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text(""),$.ajax({url:latkeConfig.servePath+"/console/article/"+t,type:"DELETE",cache:!1,success:function(t,e){$("#tipMsg").text(t.msg),t.sc?admin[a+"List"].getList(1):$("#loadMsg").text("")}}))},add:function(a,i){if(admin.article.validate()){var t=this;t._addDisabled(),$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text("");var e="";$(".signs button").each(function(){"selected"===this.className&&(e=this.id.substr(this.id.length-1,1))});var l=admin.editors.articleEditor.getContent(),s=admin.editors.abstractEditor.getContent();if($("#articleThumbnail").prop("checked")){var r=$(".thumbnail__img").css("background-image");l="![]("+r.substring(5,r.length-2).replace("w/768","w/960").replace("h/432","h/540")+")\n\n"+l}var c={article:{articleTitle:$("#title").val(),articleContent:l,articleAbstract:s,articleTags:this.trimUniqueArray($("#tag").val()).toString(),articlePermalink:$("#permalink").val(),articleStatus:a,articleSignId:e,postToCommunity:$("#postToCommunity").prop("checked"),articleCommentable:$("#articleCommentable").prop("checked"),articleViewPwd:$("#viewPwd").val()}};$.ajax({url:latkeConfig.servePath+"/console/article/",type:"POST",cache:!1,data:JSON.stringify(c),success:function(t,e){if(i)return $("#tipMsg").text(Label.autoSaveLabel),void(admin.article.status.id=t.oId);$("#tipMsg").text(t.msg),t.sc&&(0===a?(admin.article.status.id=void 0,admin.selectTab("article/article-list")):admin.selectTab("article/draft-list"),admin.article.isConfirm=!1)},complete:function(){t._removeDisabled(),$("#loadMsg").text("")}})}},update:function(a,i){if(admin.article.validate()){var l=this;l._addDisabled(),$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text("");var t="";$(".signs button").each(function(){"selected"===this.className&&(t=this.id.substr(this.id.length-1,1))});var e=admin.editors.articleEditor.getContent(),s=admin.editors.abstractEditor.getContent();if($("#articleThumbnail").prop("checked")){var r=$(".thumbnail__img").css("background-image");e="![]("+r.substring(5,r.length-2).replace("w/768","w/960").replace("h/432","h/540")+") \n\n"+e}var c={article:{oId:this.status.id,articleTitle:$("#title").val(),articleContent:e,articleAbstract:s,articleTags:this.trimUniqueArray($("#tag").val()).toString(),articlePermalink:$("#permalink").val(),articleStatus:a,articleSignId:t,articleCommentable:$("#articleCommentable").prop("checked"),articleViewPwd:$("#viewPwd").val(),postToCommunity:$("#postToCommunity").prop("checked")}};$.ajax({url:latkeConfig.servePath+"/console/article/",type:"PUT",cache:!1,data:JSON.stringify(c),success:function(t,e){i?$("#tipMsg").text(Label.autoSaveLabel):($("#tipMsg").text(t.msg),t.sc&&(0===a?admin.selectTab("article/article-list"):admin.selectTab("article/draft-list"),$("#tipMsg").text(Label.updateSuccLabel),admin.article.status.id=void 0,admin.article.isConfirm=!1))},complete:function(t,e){l._removeDisabled(),$("#loadMsg").text("")}})}},setStatus:function(){$.ajax({url:latkeConfig.servePath+"/console/tags",type:"GET",cache:!1,success:function(t,e){if($("#tipMsg").text(t.msg),t.sc){if(!(t.tags.length<=0)){$("#tagCheckboxPanel>span").remove("");for(var a="",i=0;i<t.tags.length;i++)a+="<span>"+t.tags[i].tagTitle+"</span>";$("#tagCheckboxPanel").html(a+'<div class="fn__clear"></div>'),$("#loadMsg").text("")}}else $("#loadMsg").text("")}}),this.status?this.status.isArticle?($("#unSubmitArticle").show(),$("#saveArticle").hide(),$("#submitArticle").show()):($("#submitArticle").show(),$("#unSubmitArticle").hide(),$("#saveArticle").show()):($("#submitArticle").show(),$("#unSubmitArticle").hide(),$("#saveArticle").show(),$("#postToCommunityPanel").show())},clear:function(){this.status={id:void 0,isArticle:void 0},this.setStatus(),$("#title").val(""),admin.editors.articleEditor.setContent(""),admin.editors.abstractEditor.setContent(""),$("#tag").val(""),$("#tagCheckboxPanel").hide().find("span").removeClass("selected"),$("#permalink").val(""),$("#articleCammentable").prop("checked",!0),$("#postToCommunity").prop("checked",!0),$(".signs button").each(function(t){this.className=0===t?"selected":""}),$("#articleThumbnail").prop("checked")&&$("#articleThumbnail").click()},init:function(t){$(".signs button").click(function(t){$(".signs button").removeClass("selected"),$(this).addClass("selected")}),$("#tipMsg").text(Label.uploadMsg),$.ajax({url:latkeConfig.servePath+"/console/tags",type:"GET",cache:!1,success:function(t,e){if($("#tipMsg").text(t.msg),t.sc){if(!(t.tags.length<=0)){for(var a=[],i=0;i<t.tags.length;i++)a.push(t.tags[i].tagTitle);$("#tag").completed({height:160,buttonText:Label.selectLabel,data:a}),$("#loadMsg").text("")}}else $("#loadMsg").text("")}}),$("#submitArticle").click(function(){admin.article.status.id?admin.article.update(0):admin.article.add(0)}),$("#saveArticle").click(function(){admin.article.status.id?admin.article.update(admin.article.status.isArticle?0:1):admin.article.add(1)}),admin.editors.articleEditor=new SoloEditor({id:"articleContent",height:500,fun:t,previewShow:!0,resize:!1}),admin.editors.abstractEditor=new SoloEditor({id:"abstract",height:200,previewShow:!1,resize:!0}),admin.article.clearDraftTimer(),admin.article.autoSaveDraftTimer=setInterval(function(){admin.article._autoSaveToDraft()},admin.article.AUTOSAVETIME),$("#articleThumbnailBtn").click(function(){$.ajax({url:latkeConfig.servePath+"/console/thumbs?n=1&w=768&h=432",type:"GET",cache:!1,success:function(t,e){t.sc?$("#articleThumbnailBtn").prev().css("background-image","url("+t.data[0]+")"):$("#loadMsg").text(t.msg)}})}).click()},_autoSaveToDraft:function(){""!==$("#title").val().replace(/\s/g,"")&&""!==admin.editors.articleEditor.getContent().replace(/\s/g,"")&&(admin.article.status.id?admin.article.status.isArticle||admin.article.update(1,!0):(admin.article.add(1,!0),admin.article.status.isArticle=!1))},clearDraftTimer:function(){""!==admin.article.autoSaveDraftTimer&&(window.clearInterval(admin.article.autoSaveDraftTimer),admin.article.autoSaveDraftTimer="")},validate:function(){var t=admin.editors.articleEditor.getContent();if(""===$("#title").val().replace(/\s/g,""))$("#tipMsg").text(Label.titleEmptyLabel),$("#title").focus().val("");else{if(""!==t.replace(/\s/g,""))return!0;$("#tipMsg").text(Label.contentEmptyLabel)}return!1},unPublish:function(a){var i=this;i._addDisabled(),$.ajax({url:latkeConfig.servePath+"/console/article/unpublish/"+admin.article.status.id,type:"PUT",cache:!1,success:function(t,e){a?$("#tipMsg").text(Label.autoSaveLabel):($("#tipMsg").text(t.msg),t.sc&&(admin.selectTab("article/draft-list"),admin.article.status.id=void 0,admin.article.isConfirm=!1))},complete:function(t,e){i._removeDisabled(),$("#loadMsg").text("")}})},trimUniqueArray:function(t){for(var e=(t=t.toString()).split(","),a=0;a<e.length;a++)e[a]=e[a].replace(/(^\s*)|(\s*$)/g,""),""===e[a]&&(e.splice(a,1),a--);return $.unique(e).toString()},prePost:function(){if($("#loadMsg").text(Label.loadingLabel),admin.article.content="",admin.editors.articleEditor.getContent){var t=admin.editors.articleEditor.getContent();"#article/article"===window.location.hash&&""!==t.replace(/\s/g,"")&&confirm(Label.editorPostLabel)&&admin.article.clear(),$("#tipMsg").text(""),$("#loadMsg").text("")}},_addDisabled:function(){$("#unSubmitArticle").attr("disabled","disabled"),$("#saveArticle").attr("disabled","disabled"),$("#submitArticle").attr("disabled","disabled")},_removeDisabled:function(){$("#unSubmitArticle").removeAttr("disabled"),$("#saveArticle").removeAttr("disabled"),$("#submitArticle").removeAttr("disabled")}},admin.register.article={obj:admin.article,init:admin.article.init,refresh:function(){admin.editors.abstractEditor.setContent(""),admin.editors.articleEditor.setContent(""),$("#loadMsg").text(""),$("#tipMsg").text(Label.uploadMsg)}}; function getUUID(){var a=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=(a+16*Math.random())%16|0;return a=Math.floor(a/16),("x"==t?e:3&e|8).toString(16)});return t=t.replace(new RegExp("-","g"),"")}admin.article={isConfirm:!0,status:{id:void 0,isArticle:void 0},content:"",autoSaveDraftTimer:"",AUTOSAVETIME:6e4,get:function(t,e){this.status.id=t,this.status.isArticle=e,admin.selectTab("article/article")},getAndSet:function(){$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text(""),$.ajax({url:latkeConfig.servePath+"/console/article/"+admin.article.status.id,type:"GET",cache:!1,success:function(e,t){if($("#tipMsg").text(e.msg),e.sc){$("#title").val(e.article.articleTitle),admin.editors.articleEditor.setContent(e.article.articleContent),admin.editors.abstractEditor.setContent(e.article.articleAbstract),admin.article.content=admin.editors.articleEditor.getContent();for(var a=e.article.articleTags,i="",l=0;l<a.length;l++)0===l?i=a[l].tagTitle:i+=","+a[l].tagTitle;$("#tag").val(i),$("#permalink").val(e.article.articlePermalink),$("#viewPwd").val(e.article.articleViewPwd),$("#articleCommentable").prop("checked",e.article.articleCommentable);var s=e.article.signs;$(".signs button").each(function(t){parseInt(e.article.articleSignId)===parseInt(s[t].oId)?$("#articleSign"+s[t].oId).addClass("selected"):$("#articleSign"+s[t].oId).removeClass("selected")}),admin.article.setStatus(),$("#loadMsg").text("")}else $("#loadMsg").text("")}})},del:function(t,a,e){confirm(Label.confirmRemoveLabel+Label.articleLabel+'"'+Util.htmlDecode(e)+'"?')&&($("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text(""),$.ajax({url:latkeConfig.servePath+"/console/article/"+t,type:"DELETE",cache:!1,success:function(t,e){$("#tipMsg").text(t.msg),t.sc?admin[a+"List"].getList(1):$("#loadMsg").text("")}}))},add:function(a,i){if(admin.article.validate()){var t=this;t._addDisabled(),$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text("");var e="";$(".signs button").each(function(){"selected"===this.className&&(e=this.id.substr(this.id.length-1,1))});var l=admin.editors.articleEditor.getContent(),s=admin.editors.abstractEditor.getContent();if($("#articleThumbnail").prop("checked")){var r=$(".thumbnail__img").css("background-image");l="![]("+r.substring(5,r.length-2).replace("w/768","w/960").replace("h/432","h/540")+")\n\n"+l}var c={article:{articleTitle:$("#title").val(),articleContent:l,articleAbstract:s,articleTags:this.trimUniqueArray($("#tag").val()).toString(),articlePermalink:$("#permalink").val(),articleStatus:a,articleSignId:e,postToCommunity:$("#postToCommunity").prop("checked"),articleCommentable:$("#articleCommentable").prop("checked"),articleViewPwd:$("#viewPwd").val()}};$.ajax({url:latkeConfig.servePath+"/console/article/",type:"POST",cache:!1,data:JSON.stringify(c),success:function(t,e){if(i)return $("#tipMsg").text(Label.autoSaveLabel),void(admin.article.status.id=t.oId);$("#tipMsg").text(t.msg),t.sc&&(0===a?(admin.article.status.id=void 0,admin.selectTab("article/article-list")):admin.selectTab("article/draft-list"),admin.article.isConfirm=!1)},complete:function(){t._removeDisabled(),$("#loadMsg").text("")}})}},update:function(a,i){if(admin.article.validate()){var l=this;l._addDisabled(),$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text("");var t="";$(".signs button").each(function(){"selected"===this.className&&(t=this.id.substr(this.id.length-1,1))});var e=admin.editors.articleEditor.getContent(),s=admin.editors.abstractEditor.getContent();if($("#articleThumbnail").prop("checked")){var r=$(".thumbnail__img").css("background-image");e="![]("+r.substring(5,r.length-2).replace("w/768","w/960").replace("h/432","h/540")+") \n\n"+e}var c={article:{oId:this.status.id,articleTitle:$("#title").val(),articleContent:e,articleAbstract:s,articleTags:this.trimUniqueArray($("#tag").val()).toString(),articlePermalink:$("#permalink").val(),articleStatus:a,articleSignId:t,articleCommentable:$("#articleCommentable").prop("checked"),articleViewPwd:$("#viewPwd").val(),postToCommunity:$("#postToCommunity").prop("checked")}};$.ajax({url:latkeConfig.servePath+"/console/article/",type:"PUT",cache:!1,data:JSON.stringify(c),success:function(t,e){i?$("#tipMsg").text(Label.autoSaveLabel):($("#tipMsg").text(t.msg),t.sc&&(0===a?admin.selectTab("article/article-list"):admin.selectTab("article/draft-list"),$("#tipMsg").text(Label.updateSuccLabel),admin.article.status.id=void 0,admin.article.isConfirm=!1))},complete:function(t,e){l._removeDisabled(),$("#loadMsg").text("")}})}},setStatus:function(){$.ajax({url:latkeConfig.servePath+"/console/tags",type:"GET",cache:!1,success:function(t,e){if($("#tipMsg").text(t.msg),t.sc){if(!(t.tags.length<=0)){$("#tagCheckboxPanel>span").remove("");for(var a="",i=0;i<t.tags.length;i++)a+="<span>"+t.tags[i].tagTitle+"</span>";$("#tagCheckboxPanel").html(a+'<div class="fn__clear"></div>'),$("#loadMsg").text("")}}else $("#loadMsg").text("")}}),this.status?this.status.isArticle?($("#unSubmitArticle").show(),$("#saveArticle").hide(),$("#submitArticle").show()):($("#submitArticle").show(),$("#unSubmitArticle").hide(),$("#saveArticle").show()):($("#submitArticle").show(),$("#unSubmitArticle").hide(),$("#saveArticle").show(),$("#postToCommunityPanel").show())},clear:function(){this.status={id:void 0,isArticle:void 0},this.setStatus(),$("#title").val(""),admin.editors.articleEditor.setContent(""),admin.editors.abstractEditor.setContent(""),$("#tag").val(""),$("#tagCheckboxPanel").hide().find("span").removeClass("selected"),$("#permalink").val(""),$("#articleCammentable").prop("checked",!0),$("#postToCommunity").prop("checked",!0),$(".signs button").each(function(t){this.className=0===t?"selected":""}),$("#articleThumbnail").prop("checked")&&$("#articleThumbnail").click()},init:function(t){$(".signs button").click(function(t){$(".signs button").removeClass("selected"),$(this).addClass("selected")}),$("#tipMsg").text(Label.uploadMsg),$.ajax({url:latkeConfig.servePath+"/console/tags",type:"GET",cache:!1,success:function(t,e){if($("#tipMsg").text(t.msg),t.sc){if(!(t.tags.length<=0)){for(var a=[],i=0;i<t.tags.length;i++)a.push(t.tags[i].tagTitle);$("#tag").completed({height:160,buttonText:Label.selectLabel,data:a}),$("#loadMsg").text("")}}else $("#loadMsg").text("")}}),$("#submitArticle").click(function(){admin.article.status.id?admin.article.update(0):admin.article.add(0)}),$("#saveArticle").click(function(){admin.article.status.id?admin.article.update(admin.article.status.isArticle?0:1):admin.article.add(1)}),admin.editors.articleEditor=new SoloEditor({id:"articleContent",height:500,fun:t,previewShow:!0,resize:!1}),admin.editors.abstractEditor=new SoloEditor({id:"abstract",height:200,previewShow:!1,resize:!0}),admin.article.clearDraftTimer(),admin.article.autoSaveDraftTimer=setInterval(function(){admin.article._autoSaveToDraft()},admin.article.AUTOSAVETIME),$("#articleThumbnailBtn").click(function(){$.ajax({url:latkeConfig.servePath+"/console/thumbs?n=1&w=768&h=432",type:"GET",cache:!1,success:function(t,e){t.sc?$("#articleThumbnailBtn").prev().css("background-image","url("+t.data[0]+")"):$("#loadMsg").text(t.msg)}})}).click()},_autoSaveToDraft:function(){""!==$("#title").val().replace(/\s/g,"")&&""!==admin.editors.articleEditor.getContent().replace(/\s/g,"")&&(admin.article.status.id?admin.article.status.isArticle||admin.article.update(1,!0):(admin.article.add(1,!0),admin.article.status.isArticle=!1))},clearDraftTimer:function(){""!==admin.article.autoSaveDraftTimer&&(window.clearInterval(admin.article.autoSaveDraftTimer),admin.article.autoSaveDraftTimer="")},validate:function(){var t=admin.editors.articleEditor.getContent();if(""===$("#title").val().replace(/\s/g,""))$("#tipMsg").text(Label.titleEmptyLabel),$("#title").focus().val("");else{if(""!==t.replace(/\s/g,""))return!0;$("#tipMsg").text(Label.contentEmptyLabel)}return!1},unPublish:function(a){var i=this;i._addDisabled(),$.ajax({url:latkeConfig.servePath+"/console/article/unpublish/"+admin.article.status.id,type:"PUT",cache:!1,success:function(t,e){a?$("#tipMsg").text(Label.autoSaveLabel):($("#tipMsg").text(t.msg),t.sc&&(admin.selectTab("article/draft-list"),admin.article.status.id=void 0,admin.article.isConfirm=!1))},complete:function(t,e){i._removeDisabled(),$("#loadMsg").text("")}})},trimUniqueArray:function(t){for(var e=(t=t.toString()).split(","),a=0;a<e.length;a++)e[a]=e[a].replace(/(^\s*)|(\s*$)/g,""),""===e[a]&&(e.splice(a,1),a--);return $.unique(e).toString()},prePost:function(){if($("#loadMsg").text(Label.loadingLabel),admin.article.content="",admin.editors.articleEditor.getContent){var t=admin.editors.articleEditor.getContent();"#article/article"===window.location.hash&&""!==t.replace(/\s/g,"")&&confirm(Label.editorPostLabel)&&admin.article.clear(),$("#tipMsg").text(""),$("#loadMsg").text("")}},_addDisabled:function(){$("#unSubmitArticle").attr("disabled","disabled"),$("#saveArticle").attr("disabled","disabled"),$("#submitArticle").attr("disabled","disabled")},_removeDisabled:function(){$("#unSubmitArticle").removeAttr("disabled"),$("#saveArticle").removeAttr("disabled"),$("#submitArticle").removeAttr("disabled")}},admin.register.article={obj:admin.article,init:admin.article.init,refresh:function(){admin.editors.abstractEditor.setContent(""),admin.editors.articleEditor.setContent(""),$("#loadMsg").text(""),$("#tipMsg").text(Label.uploadMsg)}};
admin.comment={open:function(e,t){this.getList(e,t),$("#"+t+"Comments").dialog("open")},getList:function(i,c){$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text(""),$("#"+c+"Comments").html("");var e="article";"page"===c&&(e="page"),$.ajax({url:latkeConfig.servePath+"/console/comments/"+e+"/"+i,type:"GET",cache:!1,success:function(e,t){if($("#tipMsg").text(e.msg),e.sc){for(var a=e.comments,n="",m=0;m<a.length;m++){var o="<a target='_blank' href='"+a[m].commentURL+"'>",l=a[m].commentContent,s=Util.replaceEmString(l);"http://"===a[m].commentURL&&(o="<a target='_blank'>"),n+="<div class='comment-title'><span class='fn__left'>"+o+a[m].commentName+"</a>",a[m].commentOriginalCommentName&&(n+="@"+a[m].commentOriginalCommentName),n+="</span><a title='"+Label.removeLabel+"' class='fn__right fn__pointer' href=\"javascript:admin.comment.del('"+a[m].oId+"', '"+c+"', '"+i+"')\">"+Label.removeLabel+"</a><span class='fn__right'>&nbsp;&nbsp;"+$.bowknot.getDate(a[m].commentTime)+"&nbsp;</span><div class='fn__clear'></div></div><div class='fn__margin12'>"+s+"</div>"}""===n&&(n=Label.noCommentLabel),$("#"+c+"Comments").html(n),$("#loadMsg").text("")}else $("#loadMsg").text("")}})},del:function(e,a,n){if(confirm(Label.confirmRemoveLabel+Label.commentLabel+"?")){$("#loadMsg").text(Label.loadingLabel);var t="article";"page"===a&&(t="page"),$.ajax({url:latkeConfig.servePath+"/console/"+t+"/comment/"+e,type:"DELETE",cache:!1,success:function(e,t){$("#tipMsg").text(e.msg),e.sc&&admin.comment.getList(n,a),$("#loadMsg").text("")}})}}}; admin.comment={open:function(e,t){this.getList(e,t),$("#"+t+"Comments").dialog("open")},getList:function(i,c){$("#loadMsg").text(Label.loadingLabel),$("#tipMsg").text(""),$("#"+c+"Comments").html("");var e="article";"page"===c&&(e="page"),$.ajax({url:latkeConfig.servePath+"/console/comments/"+e+"/"+i,type:"GET",cache:!1,success:function(e,t){if($("#tipMsg").text(e.msg),e.sc){for(var a=e.comments,n="",m=0;m<a.length;m++){var o="<a target='_blank' href='"+a[m].commentURL+"'>",l=a[m].commentContent,s=Util.replaceEmString(l);"http://"===a[m].commentURL&&(o="<a target='_blank'>"),n+="<div class='comment-title'><span class='fn__left'>"+o+a[m].commentName+"</a>",a[m].commentOriginalCommentName&&(n+="@"+a[m].commentOriginalCommentName),n+="</span><a title='"+Label.removeLabel+"' class='fn__right fn__pointer' href=\"javascript:admin.comment.del('"+a[m].oId+"', '"+c+"', '"+i+"')\">"+Label.removeLabel+"</a><span class='fn__right'>&nbsp;&nbsp;"+$.bowknot.getDate(a[m].commentTime)+"&nbsp;</span><div class='fn__clear'></div></div><div class='fn__margin12'>"+s+"</div>"}""===n&&(n=Label.noCommentLabel),$("#"+c+"Comments").html(n),$("#loadMsg").text("")}else $("#loadMsg").text("")}})},del:function(e,a,n){if(confirm(Label.confirmRemoveLabel+Label.commentLabel+"?")){$("#loadMsg").text(Label.loadingLabel);var t="article";"page"===a&&(t="page"),$.ajax({url:latkeConfig.servePath+"/console/"+t+"/comment/"+e,type:"DELETE",cache:!1,success:function(e,t){$("#tipMsg").text(e.msg),e.sc&&admin.comment.getList(n,a),$("#loadMsg").text("")}})}}};
......
...@@ -51,6 +51,12 @@ $.extend(SoloEditor.prototype, { ...@@ -51,6 +51,12 @@ $.extend(SoloEditor.prototype, {
delay: 500, delay: 500,
show: this.conf.previewShow, show: this.conf.previewShow,
url: latkeConfig.servePath + '/console/markdown/2html', url: latkeConfig.servePath + '/console/markdown/2html',
parse: function(element) {
if (element.style.display === 'none') {
return
}
Util.parseLanguage()
},
}, },
upload: { upload: {
max: 10 * 1024 * 1024, max: 10 * 1024 * 1024,
......
...@@ -81,6 +81,7 @@ var Util = { ...@@ -81,6 +81,7 @@ var Util = {
}, },
callback: function () { callback: function () {
Util.parseMarkdown() Util.parseMarkdown()
Util.parseLanguage()
cb && cb() cb && cb()
}, },
}) })
...@@ -118,12 +119,11 @@ var Util = { ...@@ -118,12 +119,11 @@ var Util = {
parseLanguage: function () { parseLanguage: function () {
Util.addStyle('https://cdn.jsdelivr.net/npm/highlight.js@9.15.6/styles/' + Util.addStyle('https://cdn.jsdelivr.net/npm/highlight.js@9.15.6/styles/' +
Label.hljsStyle + '.min.css', 'vditorHljsStyle') Label.hljsStyle + '.min.css', 'vditorHljsStyle')
Vditor.codeRender(document.body, Label.langLabel)
if (!Label.markedAvailable) { if (!Label.markedAvailable) {
if (typeof hljs === 'undefined') { if (typeof hljs === 'undefined') {
$.ajax({ $.ajax({
url: 'https://cdn.jsdelivr.net/npm/highlight.js@9.15.6/lib/index.min.js', url: 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.6/build/highlight.min.js',
dataType: 'script', dataType: 'script',
cache: true, cache: true,
success: function () { success: function () {
...@@ -157,8 +157,7 @@ var Util = { ...@@ -157,8 +157,7 @@ var Util = {
Vditor.mermaidRender(document.body) Vditor.mermaidRender(document.body)
Vditor.mathRender(document.body) Vditor.mathRender(document.body)
Vditor.codeRender(document.body, Label.langLabel)
this.parseLanguage()
}, },
/** /**
* @description IE6/7,跳转到 kill-browser 页面 * @description IE6/7,跳转到 kill-browser 页面
...@@ -267,6 +266,7 @@ var Util = { ...@@ -267,6 +266,7 @@ var Util = {
init: function () { init: function () {
Util.killIE() Util.killIE()
Util.parseMarkdown() Util.parseMarkdown()
Util.parseLanguage()
Util.initSW() Util.initSW()
Util.previewImg() Util.previewImg()
}, },
......
var Util={isArticlePage:function(e){var t=!0;return-1<e.indexOf(latkeConfig.servePath+"/tags/")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/tags.html")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/category/")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/archives.html")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/archives/")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/links.html")&&(t=!1),e===latkeConfig.servePath&&(t=!1),/^[0-9]*$/.test(e.replace(latkeConfig.servePath+"/",""))&&(t=!1),t},initPjax:function(e){1===$("#pjax").length&&($.pjax({selector:"a",container:"#pjax",show:"",cache:!1,storage:!0,titleSuffix:"",filter:function(e){return e===latkeConfig.servePath+"/rss.xml"||-1<e.indexOf(latkeConfig.servePath+"/admin-index.do")||!(-1<e.indexOf(latkeConfig.servePath))},callback:function(){Util.parseMarkdown(),e&&e()}}),NProgress.configure({showSpinner:!1}),$("#pjax").bind("pjax.start",function(){NProgress.start()}),$("#pjax").bind("pjax.end",function(){window.scroll(window.scrollX,0),NProgress.done()}))},previewImg:function(){$("body").on("click",".vditor-reset img",function(){window.open(this.src)})},addStyle:function(e,t){if(!document.getElementById(t)){var i=document.createElement("link");i.id=t,i.setAttribute("rel","stylesheet"),i.setAttribute("type","text/css"),i.setAttribute("href",e),document.getElementsByTagName("head")[0].appendChild(i)}},parseLanguage:function(){Util.addStyle("https://cdn.jsdelivr.net/npm/highlight.js@9.15.6/styles/"+Label.hljsStyle+".min.css","vditorHljsStyle"),Vditor.codeRender(document.body,Label.langLabel),Label.markedAvailable||("undefined"==typeof hljs?$.ajax({url:"https://cdn.jsdelivr.net/npm/highlight.js@9.15.6/lib/index.min.js",dataType:"script",cache:!0,success:function(){hljs.initHighlighting.called=!1,hljs.initHighlighting()}}):(hljs.initHighlighting.called=!1,hljs.initHighlighting()))},parseMarkdown:function(){if(!window.Vditor){var e=new XMLHttpRequest;e.open("GET",latkeConfig.staticServePath+"/js/lib/vditor-1.1.10/index.min.js",!1),e.setRequestHeader("Accept","text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01"),e.send("");var t=document.createElement("script");t.type="text/javascript",t.text=e.responseText,document.getElementsByTagName("head")[0].appendChild(t)}Vditor.mermaidRender(document.body),Vditor.mathRender(document.body),this.parseLanguage()},killIE:function(e){var t=navigator.userAgent.split("MSIE")[1];t&&(e||(e=7),parseFloat(t.split(";"))<=e&&function(){if(""===Cookie.readCookie("showKill"))try{var t="<div style='display: block; height: 100%; width: 100%; position: fixed; background-color: rgb(0, 0, 0); opacity: 0.6;filter: alpha(opacity=60); top: 0px;z-index:110'></div><iframe style='left:"+($(window).width()-781)/2+"px;z-index:120;top: "+($(window).height()-680)/2+"px; position: fixed; border: 0px none; width: 781px; height: 680px;' src='"+latkeConfig.servePath+"/kill-browser'></iframe>";$("body").append(t)}catch(e){t="<div style='display: block; height: 100%; width: 100%; position: fixed; background-color: rgb(0, 0, 0); opacity: 0.6;filter: alpha(opacity=60); top: 0px;z-index:110'></div><iframe style='left:10px;z-index:120;top: 0px; position: fixed; border: 0px none; width: 781px; height: 680px;' src='"+latkeConfig.servePath+"/kill-browser'></iframe>",document.body.innerHTML=document.body.innerHTML+t}}())},replaceEmString:function(e){var t=e.split("[em");if(1===t.length)return e;e=t[0];for(var i=1;i<t.length;i++){var n=t[i].substr(0,2);e+="<img width='20' src='"+latkeConfig.staticServePath+"/images/emotions/em"+n+".png' alt='"+Label["em"+n+"Label"]+"' title='"+Label["em"+n+"Label"]+"'/> "+t[i].substr(3)}return e},switchMobile:function(e){Cookie.createCookie("btouch_switch_toggle",e,365),setTimeout(function(){location.reload()},1250)},setTopBar:function(){var e=$("#top");if(1===e.length){var t=$("#showTop");t.click(function(){e.slideDown(),t.hide()}),$("#hideTop").click(function(){e.slideUp(),t.show()})}},goTop:function(){$("html, body").animate({scrollTop:0},800)},goBottom:function(e){e||(e=0),$("html, body").animate({scrollTop:$(document).height()-$(window).height()-e},800)},init:function(){Util.killIE(),Util.parseMarkdown(),Util.initSW(),Util.previewImg()},initSW:function(){navigator.serviceWorker&&navigator.serviceWorker.register("/sw.js",{scope:"/"})},replaceSideEm:function(e){for(var t=0;t<e.length;t++){var i=$(e[t]);i.html(Util.replaceEmString(i.html()))}},buildTags:function(e){e=e||"tags";for(var t=["tags1","tags2","tags3","tags4","tags5"],i=$("#"+e+" b").get(),n=parseInt($("#"+e+" b").last().text()),o=Math.ceil(n/t.length),a=0;a<i.length;a++)for(var r=parseInt(i[a].innerHTML),l=0;l<t.length;l++)if(l*o<r&&r<=(l+1)*o){i[a].parentNode.className=t[l];break}$("#"+e).html($("#"+e+" li").get().sort(function(e,t){var i=$(e).find("span").text().toLowerCase(),n=$(t).find("span").text().toLowerCase();return i.localeCompare(n)}))},toDate:function(e,t){var i=new Date(e),n={"M+":i.getMonth()+1,"d+":i.getDate(),"H+":i.getHours(),"m+":i.getMinutes(),"s+":i.getSeconds(),"q+":Math.floor((i.getMonth()+3)/3),S:i.getMilliseconds()};for(var o in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(i.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+o+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?n[o]:("00"+n[o]).substr((""+n[o]).length)));return t}};if(!Cookie)var Cookie={readCookie:function(e){for(var t=e+"=",i=document.cookie.split(";"),n=0;n<i.length;n++){for(var o=i[n];" "==o.charAt(0);)o=o.substring(1,o.length);if(0==o.indexOf(t))return decodeURIComponent(o.substring(t.length,o.length))}return""},eraseCookie:function(e){this.createCookie(e,"",-1)},createCookie:function(e,t,i){var n="";if(i){var o=new Date;o.setTime(o.getTime()+24*i*60*60*1e3),n="; expires="+o.toGMTString()}document.cookie=e+"="+encodeURIComponent(t)+n+"; path=/"}}; var Util={isArticlePage:function(e){var t=!0;return-1<e.indexOf(latkeConfig.servePath+"/tags/")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/tags.html")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/category/")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/archives.html")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/archives/")&&(t=!1),-1<e.indexOf(latkeConfig.servePath+"/links.html")&&(t=!1),e===latkeConfig.servePath&&(t=!1),/^[0-9]*$/.test(e.replace(latkeConfig.servePath+"/",""))&&(t=!1),t},initPjax:function(e){1===$("#pjax").length&&($.pjax({selector:"a",container:"#pjax",show:"",cache:!1,storage:!0,titleSuffix:"",filter:function(e){return e===latkeConfig.servePath+"/rss.xml"||-1<e.indexOf(latkeConfig.servePath+"/admin-index.do")||!(-1<e.indexOf(latkeConfig.servePath))},callback:function(){Util.parseMarkdown(),Util.parseLanguage(),e&&e()}}),NProgress.configure({showSpinner:!1}),$("#pjax").bind("pjax.start",function(){NProgress.start()}),$("#pjax").bind("pjax.end",function(){window.scroll(window.scrollX,0),NProgress.done()}))},previewImg:function(){$("body").on("click",".vditor-reset img",function(){window.open(this.src)})},addStyle:function(e,t){if(!document.getElementById(t)){var i=document.createElement("link");i.id=t,i.setAttribute("rel","stylesheet"),i.setAttribute("type","text/css"),i.setAttribute("href",e),document.getElementsByTagName("head")[0].appendChild(i)}},parseLanguage:function(){Util.addStyle("https://cdn.jsdelivr.net/npm/highlight.js@9.15.6/styles/"+Label.hljsStyle+".min.css","vditorHljsStyle"),Label.markedAvailable||("undefined"==typeof hljs?$.ajax({url:"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.6/build/highlight.min.js",dataType:"script",cache:!0,success:function(){hljs.initHighlighting.called=!1,hljs.initHighlighting()}}):(hljs.initHighlighting.called=!1,hljs.initHighlighting()))},parseMarkdown:function(){if(!window.Vditor){var e=new XMLHttpRequest;e.open("GET",latkeConfig.staticServePath+"/js/lib/vditor-1.1.10/index.min.js",!1),e.setRequestHeader("Accept","text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01"),e.send("");var t=document.createElement("script");t.type="text/javascript",t.text=e.responseText,document.getElementsByTagName("head")[0].appendChild(t)}Vditor.mermaidRender(document.body),Vditor.mathRender(document.body),Vditor.codeRender(document.body,Label.langLabel)},killIE:function(e){var t=navigator.userAgent.split("MSIE")[1];t&&(e||(e=7),parseFloat(t.split(";"))<=e&&function(){if(""===Cookie.readCookie("showKill"))try{var t="<div style='display: block; height: 100%; width: 100%; position: fixed; background-color: rgb(0, 0, 0); opacity: 0.6;filter: alpha(opacity=60); top: 0px;z-index:110'></div><iframe style='left:"+($(window).width()-781)/2+"px;z-index:120;top: "+($(window).height()-680)/2+"px; position: fixed; border: 0px none; width: 781px; height: 680px;' src='"+latkeConfig.servePath+"/kill-browser'></iframe>";$("body").append(t)}catch(e){t="<div style='display: block; height: 100%; width: 100%; position: fixed; background-color: rgb(0, 0, 0); opacity: 0.6;filter: alpha(opacity=60); top: 0px;z-index:110'></div><iframe style='left:10px;z-index:120;top: 0px; position: fixed; border: 0px none; width: 781px; height: 680px;' src='"+latkeConfig.servePath+"/kill-browser'></iframe>",document.body.innerHTML=document.body.innerHTML+t}}())},replaceEmString:function(e){var t=e.split("[em");if(1===t.length)return e;e=t[0];for(var i=1;i<t.length;i++){var n=t[i].substr(0,2);e+="<img width='20' src='"+latkeConfig.staticServePath+"/images/emotions/em"+n+".png' alt='"+Label["em"+n+"Label"]+"' title='"+Label["em"+n+"Label"]+"'/> "+t[i].substr(3)}return e},switchMobile:function(e){Cookie.createCookie("btouch_switch_toggle",e,365),setTimeout(function(){location.reload()},1250)},setTopBar:function(){var e=$("#top");if(1===e.length){var t=$("#showTop");t.click(function(){e.slideDown(),t.hide()}),$("#hideTop").click(function(){e.slideUp(),t.show()})}},goTop:function(){$("html, body").animate({scrollTop:0},800)},goBottom:function(e){e||(e=0),$("html, body").animate({scrollTop:$(document).height()-$(window).height()-e},800)},init:function(){Util.killIE(),Util.parseMarkdown(),Util.parseLanguage(),Util.initSW(),Util.previewImg()},initSW:function(){navigator.serviceWorker&&navigator.serviceWorker.register("/sw.js",{scope:"/"})},replaceSideEm:function(e){for(var t=0;t<e.length;t++){var i=$(e[t]);i.html(Util.replaceEmString(i.html()))}},buildTags:function(e){e=e||"tags";for(var t=["tags1","tags2","tags3","tags4","tags5"],i=$("#"+e+" b").get(),n=parseInt($("#"+e+" b").last().text()),o=Math.ceil(n/t.length),a=0;a<i.length;a++)for(var r=parseInt(i[a].innerHTML),l=0;l<t.length;l++)if(l*o<r&&r<=(l+1)*o){i[a].parentNode.className=t[l];break}$("#"+e).html($("#"+e+" li").get().sort(function(e,t){var i=$(e).find("span").text().toLowerCase(),n=$(t).find("span").text().toLowerCase();return i.localeCompare(n)}))},toDate:function(e,t){var i=new Date(e),n={"M+":i.getMonth()+1,"d+":i.getDate(),"H+":i.getHours(),"m+":i.getMinutes(),"s+":i.getSeconds(),"q+":Math.floor((i.getMonth()+3)/3),S:i.getMilliseconds()};for(var o in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(i.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+o+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?n[o]:("00"+n[o]).substr((""+n[o]).length)));return t}};if(!Cookie)var Cookie={readCookie:function(e){for(var t=e+"=",i=document.cookie.split(";"),n=0;n<i.length;n++){for(var o=i[n];" "==o.charAt(0);)o=o.substring(1,o.length);if(0==o.indexOf(t))return decodeURIComponent(o.substring(t.length,o.length))}return""},eraseCookie:function(e){this.createCookie(e,"",-1)},createCookie:function(e,t,i){var n="";if(i){var o=new Date;o.setTime(o.getTime()+24*i*60*60*1e3),n="; expires="+o.toGMTString()}document.cookie=e+"="+encodeURIComponent(t)+n+"; path=/"}};
\ No newline at end of file \ No newline at end of file
...@@ -87,6 +87,12 @@ $.extend(Page.prototype, { ...@@ -87,6 +87,12 @@ $.extend(Page.prototype, {
enable: true, enable: true,
style: Label.hljsStyle, style: Label.hljsStyle,
}, },
parse: function(element) {
if (element.style.display === 'none') {
return
}
Util.parseLanguage()
},
}, },
counter: 500, counter: 500,
resize: { resize: {
...@@ -356,6 +362,7 @@ $.extend(Page.prototype, { ...@@ -356,6 +362,7 @@ $.extend(Page.prototype, {
$('#comments').html(commentHTML) $('#comments').html(commentHTML)
} }
Util.parseMarkdown() Util.parseMarkdown()
Util.parseLanguage()
window.location.hash = '#comments' window.location.hash = '#comments'
}, },
}) })
\ No newline at end of file
var Page=function(e){this.currentCommentId="",this.tips=e};$.extend(Page.prototype,{replaceCommentsEm:function(e){for(var t=$(e),o=0;o<t.length;o++){var n=t[o].innerHTML;t[o].innerHTML=Util.replaceEmString(n)}},load:function(){var e=this;$("#comment").click(function(){e.toggleEditor()}).attr("readonly","readonly"),$("#soloEditorCancel").click(function(){e.toggleEditor()}),$("#soloEditorAdd").click(function(){e.submitComment()})},toggleEditor:function(e,t){var o=$("#soloEditor");if(0!==o.length){if("undefined"==typeof vditor){window.vditor=new Vditor("soloEditorComment",{placeholder:this.tips.commentContentCannotEmptyLabel,height:180,tab:"\t",hint:{emojiPath:latkeConfig.staticServePath+"/js/lib/emojify.js-1.1.0/images/basic"},esc:function(){$("#soloEditorCancel").click()},ctrlEnter:function(){$("#soloEditorAdd").click()},preview:{delay:500,show:!1,url:latkeConfig.servePath+"/console/markdown/2html",hljs:{enable:!0,style:Label.hljsStyle}},counter:500,resize:{enable:!0,position:"top",after:function(){$("body").css("padding-bottom",$("#soloEditor").outerHeight())}},lang:Label.langLabel,toolbar:["emoji","headings","bold","italic","strike","|","line","quote","|","list","ordered-list","check","|","code","inline-code","|","undo","redo","|","link","table","|","preview","fullscreen","info","help"]}),vditor.focus()}"0px"===$("body").css("padding-bottom")||e?($("#soloEditorError").text(""),o.css({bottom:"0",opacity:1}),$("body").css("padding-bottom","238px"),this.currentCommentId=e,$("#soloEditorReplyTarget").text(t?"@"+t:""),"undefined"!=typeof vditor&&vditor.focus()):(o.css({bottom:"-300px",opacity:0}),$("body").css("padding-bottom",0))}else location.href=latkeConfig.servePath+"/start"},loadRandomArticles:function(s){var c=this.tips.randomArticles1Label;$.ajax({url:latkeConfig.servePath+"/articles/random",type:"POST",success:function(e,t){var o=e.randomArticles;if(o&&0!==o.length){for(var n="",i=0;i<o.length;i++){var l=o[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' href='"+latkeConfig.servePath+l.articlePermalink+"'>"+r+"</a></li>"}var a=(s||"<h4>"+c+"</h4>")+"<ul>"+n+"</ul>";$("#randomArticles").append(a)}else $("#randomArticles").remove()}})},loadRelevantArticles:function(e,s){$.ajax({url:latkeConfig.servePath+"/article/id/"+e+"/relevant/articles",type:"GET",success:function(e,t){var o=e.relevantArticles;if(o&&0!==o.length){for(var n="",i=0;i<o.length;i++){var l=o[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' href='"+latkeConfig.servePath+l.articlePermalink+"'>"+r+"</a></li>"}var a=s+"<ul>"+n+"</ul>";$("#relevantArticles").append(a)}else $("#relevantArticles").remove()},error:function(){$("#relevantArticles").remove()}})},loadExternalRelevantArticles:function(e,s){var c=this.tips;try{$.ajax({url:"https://rhythm.b3log.org/get-articles-by-tags.do?tags="+e+"&blogHost="+c.blogHost+"&paginationPageSize="+c.externalRelevantArticlesDisplayCount,type:"GET",cache:!0,dataType:"jsonp",error:function(){$("#externalRelevantArticles").remove()},success:function(e,t){var o=e.articles;if(o&&0!==o.length){for(var n="",i=0;i<o.length;i++){var l=o[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' target='_blank' href='"+l.articlePermalink+"'>"+r+"</a></li>"}var a=(s||"<h4>"+c.externalRelevantArticles1Label+"</h4>")+"<ul>"+n+"</ul>";$("#externalRelevantArticles").append(a)}else $("#externalRelevantArticles").remove()}})}catch(e){}},submitComment:function(){var t=this,e=this.tips,o="article";if(void 0===e.externalRelevantArticlesDisplayCount&&(o="page"),1<vditor.getValue().length&&vditor.getValue().length<500){$("#soloEditorAdd").attr("disabled","disabled");var n={oId:e.oId,commentContent:vditor.getValue()};this.currentCommentId&&(n.commentOriginalCommentId=this.currentCommentId),$.ajax({type:"POST",url:latkeConfig.servePath+"/"+o+"/comments",cache:!1,contentType:"application/json",data:JSON.stringify(n),success:function(e){$("#soloEditorAdd").removeAttr("disabled"),e.sc?(t.toggleEditor(),vditor.setValue(""),t.addCommentAjax(Util.replaceEmString(e.cmtTpl))):$("#soloEditorError").html(e.msg)}})}else $("#soloEditorError").text(t.tips.commentContentCannotEmptyLabel)},addReplyForm:function(e,t){this.currentCommentId=e,this.toggleEditor(e,t)},hideComment:function(e){$("#commentRef"+e).hide()},showComment:function(e,t,o,n){var i=parseInt($(e).position().top);if(n&&(i=parseInt($(e).parents(n).position().top)),0<$("#commentRef"+t).length)$("#commentRef"+t).show().css("top",i+o+"px");else{var l=$("#"+t).clone();l.addClass("comment-body-ref").attr("id","commentRef"+t),l.find("#replyForm").remove(),$("#comments").append(l),$("#commentRef"+t).css("top",i+o+"px")}},addCommentAjax:function(e){0<$("#comments").children().length?$($("#comments").children()[0]).before(e):$("#comments").html(e),Util.parseMarkdown(),window.location.hash="#comments"}}); var Page=function(e){this.currentCommentId="",this.tips=e};$.extend(Page.prototype,{replaceCommentsEm:function(e){for(var t=$(e),o=0;o<t.length;o++){var n=t[o].innerHTML;t[o].innerHTML=Util.replaceEmString(n)}},load:function(){var e=this;$("#comment").click(function(){e.toggleEditor()}).attr("readonly","readonly"),$("#soloEditorCancel").click(function(){e.toggleEditor()}),$("#soloEditorAdd").click(function(){e.submitComment()})},toggleEditor:function(e,t){var o=$("#soloEditor");if(0!==o.length){if("undefined"==typeof vditor){window.vditor=new Vditor("soloEditorComment",{placeholder:this.tips.commentContentCannotEmptyLabel,height:180,tab:"\t",hint:{emojiPath:latkeConfig.staticServePath+"/js/lib/emojify.js-1.1.0/images/basic"},esc:function(){$("#soloEditorCancel").click()},ctrlEnter:function(){$("#soloEditorAdd").click()},preview:{delay:500,show:!1,url:latkeConfig.servePath+"/console/markdown/2html",hljs:{enable:!0,style:Label.hljsStyle},parse:function(e){"none"!==e.style.display&&Util.parseLanguage()}},counter:500,resize:{enable:!0,position:"top",after:function(){$("body").css("padding-bottom",$("#soloEditor").outerHeight())}},lang:Label.langLabel,toolbar:["emoji","headings","bold","italic","strike","|","line","quote","|","list","ordered-list","check","|","code","inline-code","|","undo","redo","|","link","table","|","preview","fullscreen","info","help"]}),vditor.focus()}"0px"===$("body").css("padding-bottom")||e?($("#soloEditorError").text(""),o.css({bottom:"0",opacity:1}),$("body").css("padding-bottom","238px"),this.currentCommentId=e,$("#soloEditorReplyTarget").text(t?"@"+t:""),"undefined"!=typeof vditor&&vditor.focus()):(o.css({bottom:"-300px",opacity:0}),$("body").css("padding-bottom",0))}else location.href=latkeConfig.servePath+"/start"},loadRandomArticles:function(s){var c=this.tips.randomArticles1Label;$.ajax({url:latkeConfig.servePath+"/articles/random",type:"POST",success:function(e,t){var o=e.randomArticles;if(o&&0!==o.length){for(var n="",i=0;i<o.length;i++){var l=o[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' href='"+latkeConfig.servePath+l.articlePermalink+"'>"+r+"</a></li>"}var a=(s||"<h4>"+c+"</h4>")+"<ul>"+n+"</ul>";$("#randomArticles").append(a)}else $("#randomArticles").remove()}})},loadRelevantArticles:function(e,s){$.ajax({url:latkeConfig.servePath+"/article/id/"+e+"/relevant/articles",type:"GET",success:function(e,t){var o=e.relevantArticles;if(o&&0!==o.length){for(var n="",i=0;i<o.length;i++){var l=o[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' href='"+latkeConfig.servePath+l.articlePermalink+"'>"+r+"</a></li>"}var a=s+"<ul>"+n+"</ul>";$("#relevantArticles").append(a)}else $("#relevantArticles").remove()},error:function(){$("#relevantArticles").remove()}})},loadExternalRelevantArticles:function(e,s){var c=this.tips;try{$.ajax({url:"https://rhythm.b3log.org/get-articles-by-tags.do?tags="+e+"&blogHost="+c.blogHost+"&paginationPageSize="+c.externalRelevantArticlesDisplayCount,type:"GET",cache:!0,dataType:"jsonp",error:function(){$("#externalRelevantArticles").remove()},success:function(e,t){var o=e.articles;if(o&&0!==o.length){for(var n="",i=0;i<o.length;i++){var l=o[i],r=l.articleTitle;n+="<li><a rel='nofollow' title='"+r+"' target='_blank' href='"+l.articlePermalink+"'>"+r+"</a></li>"}var a=(s||"<h4>"+c.externalRelevantArticles1Label+"</h4>")+"<ul>"+n+"</ul>";$("#externalRelevantArticles").append(a)}else $("#externalRelevantArticles").remove()}})}catch(e){}},submitComment:function(){var t=this,e=this.tips,o="article";if(void 0===e.externalRelevantArticlesDisplayCount&&(o="page"),1<vditor.getValue().length&&vditor.getValue().length<500){$("#soloEditorAdd").attr("disabled","disabled");var n={oId:e.oId,commentContent:vditor.getValue()};this.currentCommentId&&(n.commentOriginalCommentId=this.currentCommentId),$.ajax({type:"POST",url:latkeConfig.servePath+"/"+o+"/comments",cache:!1,contentType:"application/json",data:JSON.stringify(n),success:function(e){$("#soloEditorAdd").removeAttr("disabled"),e.sc?(t.toggleEditor(),vditor.setValue(""),t.addCommentAjax(Util.replaceEmString(e.cmtTpl))):$("#soloEditorError").html(e.msg)}})}else $("#soloEditorError").text(t.tips.commentContentCannotEmptyLabel)},addReplyForm:function(e,t){this.currentCommentId=e,this.toggleEditor(e,t)},hideComment:function(e){$("#commentRef"+e).hide()},showComment:function(e,t,o,n){var i=parseInt($(e).position().top);if(n&&(i=parseInt($(e).parents(n).position().top)),0<$("#commentRef"+t).length)$("#commentRef"+t).show().css("top",i+o+"px");else{var l=$("#"+t).clone();l.addClass("comment-body-ref").attr("id","commentRef"+t),l.find("#replyForm").remove(),$("#comments").append(l),$("#commentRef"+t).css("top",i+o+"px")}},addCommentAjax:function(e){0<$("#comments").children().length?$($("#comments").children()[0]).before(e):$("#comments").html(e),Util.parseMarkdown(),Util.parseLanguage(),window.location.hash="#comments"}});
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment