Commit 09b5b88d authored by Van's avatar Van

vditor

parent 230450f2
...@@ -3024,9 +3024,9 @@ ...@@ -3024,9 +3024,9 @@
} }
}, },
"electron-to-chromium": { "electron-to-chromium": {
"version": "1.3.260", "version": "1.3.261",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.260.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.261.tgz",
"integrity": "sha512-wGt+OivF1C1MPwaSv3LJ96ebNbLAWlx3HndivDDWqwIVSQxmhL17Y/YmwUdEMtS/bPyommELt47Dct0/VZNQBQ==" "integrity": "sha512-nA9xFj1SgHXlW/6T4+udW2u/Ic/bne25UoFsddoNM7Ut2bgNGLLQUhLhk+vQlbKh9WiRgDDlHaC36Oy7AgRR9w=="
}, },
"emoji-regex": { "emoji-regex": {
"version": "6.1.1", "version": "6.1.1",
...@@ -8097,9 +8097,9 @@ ...@@ -8097,9 +8097,9 @@
"integrity": "sha1-HCQ6ULWVwb5Up1S/7OhWO5/42BM=" "integrity": "sha1-HCQ6ULWVwb5Up1S/7OhWO5/42BM="
}, },
"vditor": { "vditor": {
"version": "1.8.8", "version": "1.8.9",
"resolved": "https://registry.npmjs.org/vditor/-/vditor-1.8.8.tgz", "resolved": "https://registry.npmjs.org/vditor/-/vditor-1.8.9.tgz",
"integrity": "sha512-mMILlCHJHrtlbWyLU2xswzVFkTtA1FvO2wtvDio6/vAOvCt2nr4DGn2CVzgZZxAd45/EwXfzADzlY87q4utMSQ==", "integrity": "sha512-WetgTcj5lDwA+BDkSDnwqZfXYwL4YbAEHLZfU3pFvyhhTagq3Hw4CTO4aZaq0d5q4g37nzADNjL3BpZVuVQpnA==",
"requires": { "requires": {
"abcjs": "^5.8.0", "abcjs": "^5.8.0",
"diff-match-patch": "^1.0.4", "diff-match-patch": "^1.0.4",
......
...@@ -36,6 +36,6 @@ ...@@ -36,6 +36,6 @@
"gulp-uglify": "^3.0.2" "gulp-uglify": "^3.0.2"
}, },
"dependencies": { "dependencies": {
"vditor": "^1.8.8" "vditor": "^1.8.9"
} }
} }
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
</div> </div>
</div> </div>
<script src="${staticServePath}/js/lib/compress/admin-lib.min.js"></script> <script src="${staticServePath}/js/lib/compress/admin-lib.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vditor@1.8.8/dist/index.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/vditor@1.8.9/dist/index.min.js"></script>
<script src="${staticServePath}/js/common${miniPostfix}.js"></script> <script src="${staticServePath}/js/common${miniPostfix}.js"></script>
<#if "" == miniPostfix> <#if "" == miniPostfix>
<script src="${staticServePath}/js/admin/admin.js"></script> <script src="${staticServePath}/js/admin/admin.js"></script>
......
...@@ -157,7 +157,7 @@ var Util = { ...@@ -157,7 +157,7 @@ var Util = {
if (typeof Vditor === 'undefined') { if (typeof Vditor === 'undefined') {
Util.addScript( Util.addScript(
'https://cdn.jsdelivr.net/npm/vditor@1.8.8/dist/method.min.js', 'https://cdn.jsdelivr.net/npm/vditor@1.8.9/dist/method.min.js',
'vditorPreviewScript') 'vditorPreviewScript')
} }
......
var Util={isArticlePage:function(e){var t=!0;return-1<e.indexOf(Label.servePath+"/tags/")&&(t=!1),-1<e.indexOf(Label.servePath+"/tags.html")&&(t=!1),-1<e.indexOf(Label.servePath+"/category/")&&(t=!1),-1<e.indexOf(Label.servePath+"/archives.html")&&(t=!1),-1<e.indexOf(Label.servePath+"/archives/")&&(t=!1),-1<e.indexOf(Label.servePath+"/links.html")&&(t=!1),e===Label.servePath&&(t=!1),/^[0-9]*$/.test(e.replace(Label.servePath+"/",""))&&(t=!1),t},initPjax:function(e){1===$("#pjax").length&&($.pjax({selector:"a",container:"#pjax",show:"",cache:!1,storage:!0,titleSuffix:"",filter:function(e,t){return"_blank"===t.getAttribute("target")||(e===Label.servePath+"/rss.xml"||-1<e.indexOf(Label.servePath+"/admin-index.do")||!(-1<e.indexOf(Label.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(){$(this).hasClass("prevent")||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)}},addScript:function(e,t){if(!document.getElementById(t)){var i=new XMLHttpRequest;i.open("GET",e,!1),i.setRequestHeader("Accept","text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01"),i.send("");var n=document.createElement("script");n.id=t,n.type="text/javascript",n.text=i.responseText,document.getElementsByTagName("head")[0].appendChild(n)}},parseLanguage:function(){Vditor.highlightRender(Label.hljsStyle,!Label.luteAvailable,document)},parseMarkdown:function(){"undefined"==typeof Vditor&&Util.addScript("https://cdn.jsdelivr.net/npm/vditor@1.8.8/dist/method.min.js","vditorPreviewScript"),Vditor.codeRender(document.body,Label.langLabel),Label.luteAvailable?Vditor.mathRenderByLute(document.body):Vditor.mathRender(document.body),Vditor.abcRender(),Vditor.chartRender(),Vditor.mediaRender(document.body),Vditor.mermaidRender(document.body)},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='"+Label.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='"+Label.servePath+"/kill-browser'></iframe>",document.body.innerHTML=document.body.innerHTML+t}}())},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(),Util.initDebugInfo()},initDebugInfo:function(){console.log("%cSolo%c\n 🎸一款小而美的博客系统,专为程序员设计。"+Label.version+" © "+(new Date).getFullYear(),"font-size:96px;color:#3b3e43","font-size:12px;color:rgba(0,0,0,0.38);")},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(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(Label.servePath+"/tags/")&&(t=!1),-1<e.indexOf(Label.servePath+"/tags.html")&&(t=!1),-1<e.indexOf(Label.servePath+"/category/")&&(t=!1),-1<e.indexOf(Label.servePath+"/archives.html")&&(t=!1),-1<e.indexOf(Label.servePath+"/archives/")&&(t=!1),-1<e.indexOf(Label.servePath+"/links.html")&&(t=!1),e===Label.servePath&&(t=!1),/^[0-9]*$/.test(e.replace(Label.servePath+"/",""))&&(t=!1),t},initPjax:function(e){1===$("#pjax").length&&($.pjax({selector:"a",container:"#pjax",show:"",cache:!1,storage:!0,titleSuffix:"",filter:function(e,t){return"_blank"===t.getAttribute("target")||(e===Label.servePath+"/rss.xml"||-1<e.indexOf(Label.servePath+"/admin-index.do")||!(-1<e.indexOf(Label.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(){$(this).hasClass("prevent")||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)}},addScript:function(e,t){if(!document.getElementById(t)){var i=new XMLHttpRequest;i.open("GET",e,!1),i.setRequestHeader("Accept","text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01"),i.send("");var n=document.createElement("script");n.id=t,n.type="text/javascript",n.text=i.responseText,document.getElementsByTagName("head")[0].appendChild(n)}},parseLanguage:function(){Vditor.highlightRender(Label.hljsStyle,!Label.luteAvailable,document)},parseMarkdown:function(){"undefined"==typeof Vditor&&Util.addScript("https://cdn.jsdelivr.net/npm/vditor@1.8.9/dist/method.min.js","vditorPreviewScript"),Vditor.codeRender(document.body,Label.langLabel),Label.luteAvailable?Vditor.mathRenderByLute(document.body):Vditor.mathRender(document.body),Vditor.abcRender(),Vditor.chartRender(),Vditor.mediaRender(document.body),Vditor.mermaidRender(document.body)},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='"+Label.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='"+Label.servePath+"/kill-browser'></iframe>",document.body.innerHTML=document.body.innerHTML+t}}())},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(),Util.initDebugInfo()},initDebugInfo:function(){console.log("%cSolo%c\n 🎸一款小而美的博客系统,专为程序员设计。"+Label.version+" © "+(new Date).getFullYear(),"font-size:96px;color:#3b3e43","font-size:12px;color:rgba(0,0,0,0.38);")},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(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
...@@ -103,7 +103,7 @@ $.extend(Page.prototype, { ...@@ -103,7 +103,7 @@ $.extend(Page.prototype, {
if (!$('#soloEditorComment').hasClass('vditor')) { if (!$('#soloEditorComment').hasClass('vditor')) {
var that = this var that = this
Util.addScript( Util.addScript(
'https://cdn.jsdelivr.net/npm/vditor@1.8.8/dist/index.min.js', 'https://cdn.jsdelivr.net/npm/vditor@1.8.9/dist/index.min.js',
'vditorScript') 'vditorScript')
var toolbar = [ var toolbar = [
'emoji', 'emoji',
......
var Page=function(t){this.currentCommentId="",this.tips=t};$.extend(Page.prototype,{share:function(){var t=$(".article__share");if(0!==t.length){var e=t.find(".item__qr"),o=t.data("url"),i=t.data("avatar"),r=encodeURIComponent(t.data("title")+" - "+t.data("blogtitle")),n=encodeURIComponent(o),l={};l.tencent="http://share.v.t.qq.com/index.php?c=share&a=index&title="+r+"&url="+n+"&pic="+i,l.weibo="http://v.t.sina.com.cn/share/share.php?title="+r+"&url="+n+"&pic="+i,l.qqz="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+n+"&sharesource=qzone&title="+r+"&pics="+i,l.twitter="https://twitter.com/intent/tweet?status="+r+" "+n,t.find("span").click(function(){var t=$(this).data("type");if(t)return"wechat"===t?(0===e.find("canvas").length?(Util.addScript(Label.staticServePath+"/js/lib/jquery.qrcode.min.js","qrcodeScript"),e.qrcode({width:128,height:128,text:o})):e.slideToggle(),!1):void window.open(l[t],"_blank","top=100,left=200,width=648,height=618")})}},load:function(){var t=this;$("#comment").click(function(){t.toggleEditor()}).attr("readonly","readonly"),$("#soloEditorCancel").click(function(){t.toggleEditor()}),$("#soloEditorAdd").click(function(){t.submitComment()})},toggleEditor:function(t,e){var o=$("#soloEditor");if(0!==o.length){if(!$("#soloEditorComment").hasClass("vditor")){Util.addScript("https://cdn.jsdelivr.net/npm/vditor@1.8.8/dist/index.min.js","vditorScript");var i=["emoji","headings","bold","italic","strike","|","line","quote","|","list","ordered-list","check","|","code","inline-code","|","undo","redo","|","link","table","|","both","preview","format","|","devtools","fullscreen","info","help"],r=!0;$(window).width()<768&&(r=!(i=["emoji","line","quote","list","ordered-list","check","link","preview","format","info","help"])),window.vditor=new Vditor("soloEditorComment",{placeholder:this.tips.commentContentCannotEmptyLabel,height:180,tab:"\t",esc:function(){$("#soloEditorCancel").click()},ctrlEnter:function(){$("#soloEditorAdd").click()},preview:{delay:500,mode:"editor",url:Label.servePath+"/console/markdown/2html",hljs:{enable:!Label.luteAvailable,style:Label.hljsStyle},parse:function(t){"none"!==t.style.display&&Util.parseLanguage()}},counter:500,resize:{enable:r,position:"top"},lang:Label.langLabel,toolbar:i}),vditor.focus()}"-300px"===o.css("bottom")||t?($("#soloEditorError").text(""),$(window).width()<768?o.css({top:"0",bottom:"auto",opacity:1}):o.css({bottom:"0",top:"auto",opacity:1}),this.currentCommentId=t,$("#soloEditorReplyTarget").text(e?"@"+e:""),"undefined"!=typeof vditor&&vditor.focus()):o.css({bottom:"-300px",top:"auto",opacity:0})}else location.href=Label.servePath+"/start"},loadRandomArticles:function(s){var c=this.tips.randomArticles1Label;$.ajax({url:Label.servePath+"/articles/random",type:"POST",success:function(t,e){var o=t.randomArticles;if(o&&0!==o.length){for(var i="",r=0;r<o.length;r++){var n=o[r],l=n.articleTitle;i+="<li><a rel='nofollow' title='"+l+"' href='"+Label.servePath+n.articlePermalink+"'>"+l+"</a></li>"}var a=(s||"<h4>"+c+"</h4>")+"<ul>"+i+"</ul>";$("#randomArticles").append(a)}else $("#randomArticles").remove()}})},loadRelevantArticles:function(t,s){$.ajax({url:Label.servePath+"/article/id/"+t+"/relevant/articles",type:"GET",success:function(t,e){var o=t.relevantArticles;if(o&&0!==o.length){for(var i="",r=0;r<o.length;r++){var n=o[r],l=n.articleTitle;i+="<li><a rel='nofollow' title='"+l+"' href='"+Label.servePath+n.articlePermalink+"'>"+l+"</a></li>"}var a=s+"<ul>"+i+"</ul>";$("#relevantArticles").append(a)}else $("#relevantArticles").remove()},error:function(){$("#relevantArticles").remove()}})},loadExternalRelevantArticles:function(t,s){var c=this.tips;try{$.ajax({url:"https://rhythm.b3log.org/get-articles-by-tags.do?tags="+t+"&blogHost="+c.blogHost+"&paginationPageSize="+c.externalRelevantArticlesDisplayCount,type:"GET",cache:!0,dataType:"jsonp",error:function(){$("#externalRelevantArticles").remove()},success:function(t,e){var o=t.articles;if(o&&0!==o.length){for(var i="",r=0;r<o.length;r++){var n=o[r],l=n.articleTitle;i+="<li><a rel='nofollow' title='"+l+"' target='_blank' href='"+n.articlePermalink+"'>"+l+"</a></li>"}var a=(s||"<h4>"+c.externalRelevantArticles1Label+"</h4>")+"<ul>"+i+"</ul>";$("#externalRelevantArticles").append(a)}else $("#externalRelevantArticles").remove()}})}catch(t){}},submitComment:function(){var e=this,t=this.tips;if(1<vditor.getValue().length&&vditor.getValue().length<500){$("#soloEditorAdd").attr("disabled","disabled");var o={oId:t.oId,commentContent:vditor.getValue()};this.currentCommentId&&(o.commentOriginalCommentId=this.currentCommentId),$.ajax({type:"POST",url:Label.servePath+"/article/comments",cache:!1,contentType:"application/json",data:JSON.stringify(o),success:function(t){$("#soloEditorAdd").removeAttr("disabled"),t.sc?(e.toggleEditor(),vditor.setValue(""),e.addCommentAjax(t.cmtTpl)):$("#soloEditorError").html(t.msg)}})}else $("#soloEditorError").text(e.tips.commentContentCannotEmptyLabel)},addReplyForm:function(t,e){this.currentCommentId=t,this.toggleEditor(t,e)},hideComment:function(t){$("#commentRef"+t).hide()},showComment:function(t,e,o,i){var r=parseInt($(t).position().top);if(i&&(r=parseInt($(t).parents(i).position().top)),0<$("#commentRef"+e).length)$("#commentRef"+e).show().css("top",r+o+"px");else{var n=$("#"+e).clone();n.addClass("comment-body-ref").attr("id","commentRef"+e),n.find("#replyForm").remove(),$("#comments").append(n),$("#commentRef"+e).css("top",r+o+"px")}},addCommentAjax:function(t){0<$("#comments").children().length?$($("#comments").children()[0]).before(t):$("#comments").html(t),Util.parseMarkdown(),Util.parseLanguage(),window.location.hash="#comments"}}); var Page=function(t){this.currentCommentId="",this.tips=t};$.extend(Page.prototype,{share:function(){var t=$(".article__share");if(0!==t.length){var e=t.find(".item__qr"),o=t.data("url"),i=t.data("avatar"),r=encodeURIComponent(t.data("title")+" - "+t.data("blogtitle")),n=encodeURIComponent(o),l={};l.tencent="http://share.v.t.qq.com/index.php?c=share&a=index&title="+r+"&url="+n+"&pic="+i,l.weibo="http://v.t.sina.com.cn/share/share.php?title="+r+"&url="+n+"&pic="+i,l.qqz="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+n+"&sharesource=qzone&title="+r+"&pics="+i,l.twitter="https://twitter.com/intent/tweet?status="+r+" "+n,t.find("span").click(function(){var t=$(this).data("type");if(t)return"wechat"===t?(0===e.find("canvas").length?(Util.addScript(Label.staticServePath+"/js/lib/jquery.qrcode.min.js","qrcodeScript"),e.qrcode({width:128,height:128,text:o})):e.slideToggle(),!1):void window.open(l[t],"_blank","top=100,left=200,width=648,height=618")})}},load:function(){var t=this;$("#comment").click(function(){t.toggleEditor()}).attr("readonly","readonly"),$("#soloEditorCancel").click(function(){t.toggleEditor()}),$("#soloEditorAdd").click(function(){t.submitComment()})},toggleEditor:function(t,e){var o=$("#soloEditor");if(0!==o.length){if(!$("#soloEditorComment").hasClass("vditor")){Util.addScript("https://cdn.jsdelivr.net/npm/vditor@1.8.9/dist/index.min.js","vditorScript");var i=["emoji","headings","bold","italic","strike","|","line","quote","|","list","ordered-list","check","|","code","inline-code","|","undo","redo","|","link","table","|","both","preview","format","|","devtools","fullscreen","info","help"],r=!0;$(window).width()<768&&(r=!(i=["emoji","line","quote","list","ordered-list","check","link","preview","format","info","help"])),window.vditor=new Vditor("soloEditorComment",{placeholder:this.tips.commentContentCannotEmptyLabel,height:180,tab:"\t",esc:function(){$("#soloEditorCancel").click()},ctrlEnter:function(){$("#soloEditorAdd").click()},preview:{delay:500,mode:"editor",url:Label.servePath+"/console/markdown/2html",hljs:{enable:!Label.luteAvailable,style:Label.hljsStyle},parse:function(t){"none"!==t.style.display&&Util.parseLanguage()}},counter:500,resize:{enable:r,position:"top"},lang:Label.langLabel,toolbar:i}),vditor.focus()}"-300px"===o.css("bottom")||t?($("#soloEditorError").text(""),$(window).width()<768?o.css({top:"0",bottom:"auto",opacity:1}):o.css({bottom:"0",top:"auto",opacity:1}),this.currentCommentId=t,$("#soloEditorReplyTarget").text(e?"@"+e:""),"undefined"!=typeof vditor&&vditor.focus()):o.css({bottom:"-300px",top:"auto",opacity:0})}else location.href=Label.servePath+"/start"},loadRandomArticles:function(s){var c=this.tips.randomArticles1Label;$.ajax({url:Label.servePath+"/articles/random",type:"POST",success:function(t,e){var o=t.randomArticles;if(o&&0!==o.length){for(var i="",r=0;r<o.length;r++){var n=o[r],l=n.articleTitle;i+="<li><a rel='nofollow' title='"+l+"' href='"+Label.servePath+n.articlePermalink+"'>"+l+"</a></li>"}var a=(s||"<h4>"+c+"</h4>")+"<ul>"+i+"</ul>";$("#randomArticles").append(a)}else $("#randomArticles").remove()}})},loadRelevantArticles:function(t,s){$.ajax({url:Label.servePath+"/article/id/"+t+"/relevant/articles",type:"GET",success:function(t,e){var o=t.relevantArticles;if(o&&0!==o.length){for(var i="",r=0;r<o.length;r++){var n=o[r],l=n.articleTitle;i+="<li><a rel='nofollow' title='"+l+"' href='"+Label.servePath+n.articlePermalink+"'>"+l+"</a></li>"}var a=s+"<ul>"+i+"</ul>";$("#relevantArticles").append(a)}else $("#relevantArticles").remove()},error:function(){$("#relevantArticles").remove()}})},loadExternalRelevantArticles:function(t,s){var c=this.tips;try{$.ajax({url:"https://rhythm.b3log.org/get-articles-by-tags.do?tags="+t+"&blogHost="+c.blogHost+"&paginationPageSize="+c.externalRelevantArticlesDisplayCount,type:"GET",cache:!0,dataType:"jsonp",error:function(){$("#externalRelevantArticles").remove()},success:function(t,e){var o=t.articles;if(o&&0!==o.length){for(var i="",r=0;r<o.length;r++){var n=o[r],l=n.articleTitle;i+="<li><a rel='nofollow' title='"+l+"' target='_blank' href='"+n.articlePermalink+"'>"+l+"</a></li>"}var a=(s||"<h4>"+c.externalRelevantArticles1Label+"</h4>")+"<ul>"+i+"</ul>";$("#externalRelevantArticles").append(a)}else $("#externalRelevantArticles").remove()}})}catch(t){}},submitComment:function(){var e=this,t=this.tips;if(1<vditor.getValue().length&&vditor.getValue().length<500){$("#soloEditorAdd").attr("disabled","disabled");var o={oId:t.oId,commentContent:vditor.getValue()};this.currentCommentId&&(o.commentOriginalCommentId=this.currentCommentId),$.ajax({type:"POST",url:Label.servePath+"/article/comments",cache:!1,contentType:"application/json",data:JSON.stringify(o),success:function(t){$("#soloEditorAdd").removeAttr("disabled"),t.sc?(e.toggleEditor(),vditor.setValue(""),e.addCommentAjax(t.cmtTpl)):$("#soloEditorError").html(t.msg)}})}else $("#soloEditorError").text(e.tips.commentContentCannotEmptyLabel)},addReplyForm:function(t,e){this.currentCommentId=t,this.toggleEditor(t,e)},hideComment:function(t){$("#commentRef"+t).hide()},showComment:function(t,e,o,i){var r=parseInt($(t).position().top);if(i&&(r=parseInt($(t).parents(i).position().top)),0<$("#commentRef"+e).length)$("#commentRef"+e).show().css("top",r+o+"px");else{var n=$("#"+e).clone();n.addClass("comment-body-ref").attr("id","commentRef"+e),n.find("#replyForm").remove(),$("#comments").append(n),$("#commentRef"+e).css("top",r+o+"px")}},addCommentAjax:function(t){0<$("#comments").children().length?$($("#comments").children()[0]).before(t):$("#comments").html(t),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