Commit d2c8588e authored by Vanessa's avatar Vanessa

fixed #12360

parent 8e8565d0
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, May 21, 2017 * @version 1.2.0.0, Nov 10, 2017
*/ */
/** /**
...@@ -26,6 +26,87 @@ ...@@ -26,6 +26,87 @@
* @static * @static
*/ */
var Util = { var Util = {
/**
* 按需加载 MathJax 及 flow
* @returns {undefined}
*/
parseMarkdown: function () {
var hasMathJax = false;
var hasFlow = false;
$('.content-reset').each(function () {
$(this).find('p').each(function () {
if ($(this).text().indexOf('$/') > -1 || $(this).text().indexOf('$$') > -1) {
hasMathJax = true;
return false;
}
});
if ($(this).find('code.lang-flow, code.language-flow').length > 0) {
hasFlow = true
}
});
if (hasMathJax) {
var initMathJax = function () {
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$', '$'], ["\\(", "\\)"]],
displayMath: [['$$', '$$']],
processEscapes: true,
processEnvironments: true,
skipTags: ['pre', 'code']
}
});
MathJax.Hub.Queue(function () {
var all = MathJax.Hub.getAllJax(), i;
for (i = 0; i < all.length; i += 1) {
if ($(all[i].SourceElement().parentNode).closest('.content-reset') === 1) {
all[i].SourceElement().parentNode.className += 'has-jax';
}
}
});
};
if (typeof MathJax !== 'undefined') {
initMathJax();
return;
}
$.ajax({
method: "GET",
url: "https://cdn.staticfile.org/MathJax/MathJax-2.6-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&_=1473258780393",
dataType: "script"
}).done(function () {
initMathJax();
});
}
if (hasFlow) {
var initFlow = function () {
$('.content-reset code.lang-flow, .content-reset code.language-flow').each(function (index) {
var $it = $(this);
var id = 'symFlow' + (new Date()).getTime() + index;
$it.hide();
var diagram = flowchart.parse($.trim($it.text()));
$it.parent().after('<div style="text-align: center" id="' + id + '"></div>')
diagram.drawSVG(id);
$it.parent().remove();
$('#' + id).find('svg').height('auto').width('auto');
});
};
if (typeof (flowchart) !== 'undefined') {
initFlow();
return;
}
$.ajax({
method: "GET",
url: latkeConfig.staticServePath + '/js/lib/flowchart/flowchart.min.js',
dataType: "script"
}).done(function () {
initFlow()
});
}
},
/** /**
* @description 是否登录 * @description 是否登录
* @returns {Boolean} 是否登录 * @returns {Boolean} 是否登录
...@@ -51,7 +132,7 @@ var Util = { ...@@ -51,7 +132,7 @@ var Util = {
/** /**
* @description 检测页面错误 * @description 检测页面错误
*/ */
error: function() { error: function () {
$("#tipMsg").text("Error: " + arguments[0] + $("#tipMsg").text("Error: " + arguments[0] +
" File: " + arguments[1] + "\nLine: " + arguments[2] + " File: " + arguments[1] + "\nLine: " + arguments[2] +
" please report this issue on https://github.com/b3log/solo/issues/new"); " please report this issue on https://github.com/b3log/solo/issues/new");
...@@ -60,8 +141,8 @@ var Util = { ...@@ -60,8 +141,8 @@ var Util = {
/** /**
* @description IE6/7,跳转到 kill-browser 页面 * @description IE6/7,跳转到 kill-browser 页面
*/ */
killIE: function() { killIE: function () {
var addKillPanel = function() { var addKillPanel = function () {
if (Cookie.readCookie("showKill") === "") { if (Cookie.readCookie("showKill") === "") {
var left = ($(window).width() - 701) / 2, var left = ($(window).width() - 701) / 2,
top1 = ($(window).height() - 420) / 2; top1 = ($(window).height() - 420) / 2;
...@@ -93,7 +174,7 @@ var Util = { ...@@ -93,7 +174,7 @@ var Util = {
* @param {String} str 替换字符串 * @param {String} str 替换字符串
* @returns {String} 替换后的字符 * @returns {String} 替换后的字符
*/ */
replaceEmString: function(str) { replaceEmString: function (str) {
var commentSplited = str.split("[em"); var commentSplited = str.split("[em");
if (commentSplited.length === 1) { if (commentSplited.length === 1) {
return str; return str;
...@@ -113,7 +194,7 @@ var Util = { ...@@ -113,7 +194,7 @@ var Util = {
* @param {String} url URL 地址 * @param {String} url URL 地址
* @returns {String} 添加后的URL * @returns {String} 添加后的URL
*/ */
proessURL: function(url) { proessURL: function (url) {
if (!/^\w+:\/\//.test(url)) { if (!/^\w+:\/\//.test(url)) {
url = "http://" + url; url = "http://" + url;
} }
...@@ -123,24 +204,24 @@ var Util = { ...@@ -123,24 +204,24 @@ var Util = {
* @description 切换到手机版 * @description 切换到手机版
* @param {String} skin 切换前的皮肤名称 * @param {String} skin 切换前的皮肤名称
*/ */
switchMobile: function(skin) { switchMobile: function (skin) {
Cookie.createCookie("btouch_switch_toggle", skin, 365); Cookie.createCookie("btouch_switch_toggle", skin, 365);
setTimeout(function() { setTimeout(function () {
location.reload(); location.reload();
}, 1250); }, 1250);
}, },
/** /**
* @description topbar 相关事件 * @description topbar 相关事件
*/ */
setTopBar: function() { setTopBar: function () {
var $top = $("#top"); var $top = $("#top");
if ($top.length === 1) { if ($top.length === 1) {
var $showTop = $("#showTop"); var $showTop = $("#showTop");
$showTop.click(function() { $showTop.click(function () {
$top.slideDown(); $top.slideDown();
$showTop.hide(); $showTop.hide();
}); });
$("#hideTop").click(function() { $("#hideTop").click(function () {
$top.slideUp(); $top.slideUp();
$showTop.show(); $showTop.show();
}); });
...@@ -149,13 +230,13 @@ var Util = { ...@@ -149,13 +230,13 @@ var Util = {
/** /**
* @description 回到顶部 * @description 回到顶部
*/ */
goTop: function() { goTop: function () {
$('html, body').animate({scrollTop : 0},800); $('html, body').animate({scrollTop: 0}, 800);
}, },
/** /**
* @description 回到底部 * @description 回到底部
*/ */
goBottom: function(bottom) { goBottom: function (bottom) {
if (!bottom) { if (!bottom) {
bottom = 0; bottom = 0;
} }
...@@ -165,7 +246,7 @@ var Util = { ...@@ -165,7 +246,7 @@ var Util = {
/** /**
* @description 页面初始化执行的函数 * @description 页面初始化执行的函数
*/ */
init: function() { init: function () {
//window.onerror = Util.error; //window.onerror = Util.error;
Util.killIE(); Util.killIE();
Util.setTopBar(); Util.setTopBar();
...@@ -174,7 +255,7 @@ var Util = { ...@@ -174,7 +255,7 @@ var Util = {
* @description 替换侧边栏表情为图片 * @description 替换侧边栏表情为图片
* @param {Dom} comments 评论内容元素 * @param {Dom} comments 评论内容元素
*/ */
replaceSideEm: function(comments) { replaceSideEm: function (comments) {
for (var i = 0; i < comments.length; i++) { for (var i = 0; i < comments.length; i++) {
var $comment = $(comments[i]); var $comment = $(comments[i]);
$comment.html(Util.replaceEmString($comment.html())); $comment.html(Util.replaceEmString($comment.html()));
...@@ -184,7 +265,7 @@ var Util = { ...@@ -184,7 +265,7 @@ var Util = {
* @description 根据 tags,穿件云效果 * @description 根据 tags,穿件云效果
* @param {String} [id] tags 根元素 id,默认为 tags * @param {String} [id] tags 根元素 id,默认为 tags
*/ */
buildTags: function(id) { buildTags: function (id) {
id = id || "tags"; id = id || "tags";
// 根据引用次数添加样式,产生云效果 // 根据引用次数添加样式,产生云效果
var classes = ["tags1", "tags2", "tags3", "tags4", "tags5"], var classes = ["tags1", "tags2", "tags3", "tags4", "tags5"],
...@@ -203,7 +284,7 @@ var Util = { ...@@ -203,7 +284,7 @@ var Util = {
} }
// 按字母或者中文拼音进行排序 // 按字母或者中文拼音进行排序
$("#" + id).html($("#" + id + " li").get().sort(function(a, b) { $("#" + id).html($("#" + id + " li").get().sort(function (a, b) {
var valA = $(a).find("span").text().toLowerCase(); var valA = $(a).find("span").text().toLowerCase();
var valB = $(b).find("span").text().toLowerCase(); var valB = $(b).find("span").text().toLowerCase();
// 对中英文排序的处理 // 对中英文排序的处理
...@@ -216,7 +297,7 @@ var Util = { ...@@ -216,7 +297,7 @@ var Util = {
* @param {String} format 格式化后日期格式 * @param {String} format 格式化后日期格式
* @returns {String} 格式化后的时间 * @returns {String} 格式化后的时间
*/ */
toDate: function(time, format) { toDate: function (time, format) {
var dateTime = new Date(time); var dateTime = new Date(time);
var o = { var o = {
"M+": dateTime.getMonth() + 1, //month "M+": dateTime.getMonth() + 1, //month
...@@ -243,7 +324,7 @@ var Util = { ...@@ -243,7 +324,7 @@ var Util = {
* @description 获取窗口高度 * @description 获取窗口高度
* @returns {Inter} 窗口高度 * @returns {Inter} 窗口高度
*/ */
getWinHeight: function() { getWinHeight: function () {
if (window.innerHeight) { if (window.innerHeight) {
return window.innerHeight; return window.innerHeight;
} }
...@@ -264,7 +345,7 @@ if (!Cookie) { ...@@ -264,7 +345,7 @@ if (!Cookie) {
* @param {String} name cookie key * @param {String} name cookie key
* @returns {String} 对应 key 的值,如 key 不存在则返回 "" * @returns {String} 对应 key 的值,如 key 不存在则返回 ""
*/ */
readCookie: function(name) { readCookie: function (name) {
var nameEQ = name + "="; var nameEQ = name + "=";
var ca = document.cookie.split(';'); var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) { for (var i = 0; i < ca.length; i++) {
...@@ -280,7 +361,7 @@ if (!Cookie) { ...@@ -280,7 +361,7 @@ if (!Cookie) {
* @description 清除 Cookie * @description 清除 Cookie
* @param {String} name 清除 key 为 name 的该条 Cookie * @param {String} name 清除 key 为 name 的该条 Cookie
*/ */
eraseCookie: function(name) { eraseCookie: function (name) {
this.createCookie(name, "", -1); this.createCookie(name, "", -1);
}, },
/** /**
...@@ -289,7 +370,7 @@ if (!Cookie) { ...@@ -289,7 +370,7 @@ if (!Cookie) {
* @param {String} value 每条 Cookie 对应的值,将被 UTF-8 编码 * @param {String} value 每条 Cookie 对应的值,将被 UTF-8 编码
* @param {Int} days Cookie 保存时间 * @param {Int} days Cookie 保存时间
*/ */
createCookie: function(name, value, days) { createCookie: function (name, value, days) {
var expires = ""; var expires = "";
if (days) { if (days) {
var date = new Date(); var date = new Date();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.0.0, May 21, 2017 * @version 1.4.0.0, Nov 10, 2017
*/ */
var Page = function (tips) { var Page = function (tips) {
this.currentCommentId = ""; this.currentCommentId = "";
...@@ -422,7 +422,7 @@ $.extend(Page.prototype, { ...@@ -422,7 +422,7 @@ $.extend(Page.prototype, {
} catch (e) { } catch (e) {
document.write("<script src=\"" + latkeConfig.staticServePath + "/js/lib/json2.js\"><\/script>"); document.write("<script src=\"" + latkeConfig.staticServePath + "/js/lib/json2.js\"><\/script>");
} }
Util.parseMarkdown();
}, },
/* /*
* @description 加载随机文章 * @description 加载随机文章
...@@ -672,8 +672,7 @@ $.extend(Page.prototype, { ...@@ -672,8 +672,7 @@ $.extend(Page.prototype, {
event.preventDefault(); event.preventDefault();
} }
}); });
$("#replyForm #captcha").attr("id", "captchaReply"). $("#replyForm #captcha").attr("id", "captchaReply").attr("src", latkeConfig.servePath + "/captcha.do?" + new Date().getTime()).click(function () {
attr("src", latkeConfig.servePath + "/captcha.do?" + new Date().getTime()).click(function () {
$(this).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random()); $(this).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
}); });
$("#replyForm #commentErrorTip").attr("id", "commentErrorTipReply").html("").hide(); $("#replyForm #commentErrorTip").attr("id", "commentErrorTipReply").html("").hide();
......
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