Commit f77faeff authored by Van's avatar Van

🐛 vditor

parent fac9a60c
......@@ -25,6 +25,7 @@
};
var Label = {
"hljsStyle": "atom-one-light",
"pushSuccLabel": '${pushSuccLabel}',
"pushToHacpaiLabel": '${pushToHacpaiLabel}',
"uploadMsg": '${uploadMsg}',
......
This diff is collapsed.
......@@ -51,6 +51,12 @@ $.extend(SoloEditor.prototype, {
delay: 500,
show: this.conf.previewShow,
url: latkeConfig.servePath + '/console/markdown/2html',
parse: function(element) {
if (element.style.display === 'none') {
return
}
Util.parseLanguage()
},
},
upload: {
max: 10 * 1024 * 1024,
......
......@@ -81,6 +81,7 @@ var Util = {
},
callback: function () {
Util.parseMarkdown()
Util.parseLanguage()
cb && cb()
},
})
......@@ -118,12 +119,11 @@ var Util = {
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)
if (!Label.markedAvailable) {
if (typeof hljs === 'undefined') {
$.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',
cache: true,
success: function () {
......@@ -157,8 +157,7 @@ var Util = {
Vditor.mermaidRender(document.body)
Vditor.mathRender(document.body)
this.parseLanguage()
Vditor.codeRender(document.body, Label.langLabel)
},
/**
* @description IE6/7,跳转到 kill-browser 页面
......@@ -267,6 +266,7 @@ var Util = {
init: function () {
Util.killIE()
Util.parseMarkdown()
Util.parseLanguage()
Util.initSW()
Util.previewImg()
},
......
This diff is collapsed.
......@@ -87,6 +87,12 @@ $.extend(Page.prototype, {
enable: true,
style: Label.hljsStyle,
},
parse: function(element) {
if (element.style.display === 'none') {
return
}
Util.parseLanguage()
},
},
counter: 500,
resize: {
......@@ -356,6 +362,7 @@ $.extend(Page.prototype, {
$('#comments').html(commentHTML)
}
Util.parseMarkdown()
Util.parseLanguage()
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"}});
\ 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},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
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