Commit d2c8588e authored by Vanessa's avatar Vanessa

fixed #12360

parent 8e8565d0
......@@ -18,7 +18,7 @@
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</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,277 +26,358 @@
* @static
*/
var Util = {
/**
* @description 是否登录
* @returns {Boolean} 是否登录
*/
isLoggedIn: function () {
if (($("#admin").length === 1 && $("#admin").data("login")) || latkeConfig.isLoggedIn === "true") {
return true;
} else {
return false;
}
},
/**
* @description 获取用户名称
* @returns {String} 用户名称
*/
getUserName: function () {
if ($("#adminName").length === 1) {
return $("#adminName").text();
} else {
return latkeConfig.userName;
/**
* 按需加载 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;
}
},
/**
* @description 检测页面错误
*/
error: function() {
$("#tipMsg").text("Error: " + arguments[0] +
" File: " + arguments[1] + "\nLine: " + arguments[2] +
" please report this issue on https://github.com/b3log/solo/issues/new");
$("#loadMsg").text("");
},
/**
* @description IE6/7,跳转到 kill-browser 页面
*/
killIE: function() {
var addKillPanel = function() {
if (Cookie.readCookie("showKill") === "") {
var left = ($(window).width() - 701) / 2,
top1 = ($(window).height() - 420) / 2;
$("body").append("<div style='display: block; height: 100%; width: 100%; position: fixed; background-color: rgb(0, 0, 0); opacity: 0.6; top: 0px;z-index:11'></div>"
+ "<iframe style='left:" + left + "px;z-index:20;top: " + top1 + "px; position: fixed; border: 0px none; width: 701px; height: 420px;' src='" + latkeConfig.servePath + "/kill-browser'></iframe>");
}
};
});
if ($(this).find('code.lang-flow, code.language-flow').length > 0) {
hasFlow = true
}
});
if ($.browser.msie) {
// kill IE6 and IE7
if ($.browser.version === "6.0" || $.browser.version === "7.0") {
addKillPanel();
return;
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';
}
}
});
};
// 后台页面 kill 360
if (window.external && window.external.twGetRunPath) {
var path = external.twGetRunPath();
if (path && path.toLowerCase().indexOf("360se") > -1 &&
window.location.href.indexOf("admin-index") > -1) {
addKillPanel();
return;
}
}
}
},
/**
* @description 替换[emXX] 为图片
* @param {String} str 替换字符串
* @returns {String} 替换后的字符
*/
replaceEmString: function(str) {
var commentSplited = str.split("[em");
if (commentSplited.length === 1) {
return str;
}
if (typeof MathJax !== 'undefined') {
initMathJax();
return;
}
str = commentSplited[0];
for (var j = 1; j < commentSplited.length; j++) {
var key = commentSplited[j].substr(0, 2);
str += "<img width='20' src='" + latkeConfig.staticServePath + "/images/emotions/em" + key + ".png' alt='" +
Label["em" + key + "Label"] + "' title='" +
Label["em" + key + "Label"] + "'/> " + commentSplited[j].substr(3);
}
return str;
},
/**
* @description URL 没有协议头,则自动加上 http://
* @param {String} url URL 地址
* @returns {String} 添加后的URL
*/
proessURL: function(url) {
if (!/^\w+:\/\//.test(url)) {
url = "http://" + url;
}
return url;
},
/**
* @description 切换到手机版
* @param {String} skin 切换前的皮肤名称
*/
switchMobile: function(skin) {
Cookie.createCookie("btouch_switch_toggle", skin, 365);
setTimeout(function() {
location.reload();
}, 1250);
},
/**
* @description topbar 相关事件
*/
setTopBar: function() {
var $top = $("#top");
if ($top.length === 1) {
var $showTop = $("#showTop");
$showTop.click(function() {
$top.slideDown();
$showTop.hide();
});
$("#hideTop").click(function() {
$top.slideUp();
$showTop.show();
});
}
},
/**
* @description 回到顶部
*/
goTop: function() {
$('html, body').animate({scrollTop : 0},800);
},
/**
* @description 回到底部
*/
goBottom: function(bottom) {
if (!bottom) {
bottom = 0;
$.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 是否登录
* @returns {Boolean} 是否登录
*/
isLoggedIn: function () {
if (($("#admin").length === 1 && $("#admin").data("login")) || latkeConfig.isLoggedIn === "true") {
return true;
} else {
return false;
}
},
/**
* @description 获取用户名称
* @returns {String} 用户名称
*/
getUserName: function () {
if ($("#adminName").length === 1) {
return $("#adminName").text();
} else {
return latkeConfig.userName;
}
},
/**
* @description 检测页面错误
*/
error: function () {
$("#tipMsg").text("Error: " + arguments[0] +
" File: " + arguments[1] + "\nLine: " + arguments[2] +
" please report this issue on https://github.com/b3log/solo/issues/new");
$("#loadMsg").text("");
},
/**
* @description IE6/7,跳转到 kill-browser 页面
*/
killIE: function () {
var addKillPanel = function () {
if (Cookie.readCookie("showKill") === "") {
var left = ($(window).width() - 701) / 2,
top1 = ($(window).height() - 420) / 2;
$("body").append("<div style='display: block; height: 100%; width: 100%; position: fixed; background-color: rgb(0, 0, 0); opacity: 0.6; top: 0px;z-index:11'></div>"
+ "<iframe style='left:" + left + "px;z-index:20;top: " + top1 + "px; position: fixed; border: 0px none; width: 701px; height: 420px;' src='" + latkeConfig.servePath + "/kill-browser'></iframe>");
}
};
if ($.browser.msie) {
// kill IE6 and IE7
if ($.browser.version === "6.0" || $.browser.version === "7.0") {
addKillPanel();
return;
}
// 后台页面 kill 360
if (window.external && window.external.twGetRunPath) {
var path = external.twGetRunPath();
if (path && path.toLowerCase().indexOf("360se") > -1 &&
window.location.href.indexOf("admin-index") > -1) {
addKillPanel();
return;
}
var wHeight = $("body").height() > $(document).height() ? $("body").height() : $(document).height();
window.scrollTo(0, wHeight - $(window).height() - bottom);
},
/**
* @description 页面初始化执行的函数
*/
init: function() {
}
}
},
/**
* @description 替换[emXX] 为图片
* @param {String} str 替换字符串
* @returns {String} 替换后的字符
*/
replaceEmString: function (str) {
var commentSplited = str.split("[em");
if (commentSplited.length === 1) {
return str;
}
str = commentSplited[0];
for (var j = 1; j < commentSplited.length; j++) {
var key = commentSplited[j].substr(0, 2);
str += "<img width='20' src='" + latkeConfig.staticServePath + "/images/emotions/em" + key + ".png' alt='" +
Label["em" + key + "Label"] + "' title='" +
Label["em" + key + "Label"] + "'/> " + commentSplited[j].substr(3);
}
return str;
},
/**
* @description URL 没有协议头,则自动加上 http://
* @param {String} url URL 地址
* @returns {String} 添加后的URL
*/
proessURL: function (url) {
if (!/^\w+:\/\//.test(url)) {
url = "http://" + url;
}
return url;
},
/**
* @description 切换到手机版
* @param {String} skin 切换前的皮肤名称
*/
switchMobile: function (skin) {
Cookie.createCookie("btouch_switch_toggle", skin, 365);
setTimeout(function () {
location.reload();
}, 1250);
},
/**
* @description topbar 相关事件
*/
setTopBar: function () {
var $top = $("#top");
if ($top.length === 1) {
var $showTop = $("#showTop");
$showTop.click(function () {
$top.slideDown();
$showTop.hide();
});
$("#hideTop").click(function () {
$top.slideUp();
$showTop.show();
});
}
},
/**
* @description 回到顶部
*/
goTop: function () {
$('html, body').animate({scrollTop: 0}, 800);
},
/**
* @description 回到底部
*/
goBottom: function (bottom) {
if (!bottom) {
bottom = 0;
}
var wHeight = $("body").height() > $(document).height() ? $("body").height() : $(document).height();
window.scrollTo(0, wHeight - $(window).height() - bottom);
},
/**
* @description 页面初始化执行的函数
*/
init: function () {
//window.onerror = Util.error;
Util.killIE();
Util.setTopBar();
},
/**
* @description 替换侧边栏表情为图片
* @param {Dom} comments 评论内容元素
*/
replaceSideEm: function(comments) {
for (var i = 0; i < comments.length; i++) {
var $comment = $(comments[i]);
$comment.html(Util.replaceEmString($comment.html()));
Util.killIE();
Util.setTopBar();
},
/**
* @description 替换侧边栏表情为图片
* @param {Dom} comments 评论内容元素
*/
replaceSideEm: function (comments) {
for (var i = 0; i < comments.length; i++) {
var $comment = $(comments[i]);
$comment.html(Util.replaceEmString($comment.html()));
}
},
/**
* @description 根据 tags,穿件云效果
* @param {String} [id] tags 根元素 id,默认为 tags
*/
buildTags: function (id) {
id = id || "tags";
// 根据引用次数添加样式,产生云效果
var classes = ["tags1", "tags2", "tags3", "tags4", "tags5"],
bList = $("#" + id + " b").get();
var max = parseInt($("#" + id + " b").last().text());
var distance = Math.ceil(max / classes.length);
for (var i = 0; i < bList.length; i++) {
var num = parseInt(bList[i].innerHTML);
// 算出当前 tag 数目所在的区间,加上 class
for (var j = 0; j < classes.length; j++) {
if (num > j * distance && num <= (j + 1) * distance) {
bList[i].parentNode.className = classes[j];
break;
}
},
}
}
// 按字母或者中文拼音进行排序
$("#" + id).html($("#" + id + " li").get().sort(function (a, b) {
var valA = $(a).find("span").text().toLowerCase();
var valB = $(b).find("span").text().toLowerCase();
// 对中英文排序的处理
return valA.localeCompare(valB);
}));
},
/**
* @description 时间戳转化为时间格式
* @param {String} time 时间
* @param {String} format 格式化后日期格式
* @returns {String} 格式化后的时间
*/
toDate: function (time, format) {
var dateTime = new Date(time);
var o = {
"M+": dateTime.getMonth() + 1, //month
"d+": dateTime.getDate(), //day
"H+": dateTime.getHours(), //hour
"m+": dateTime.getMinutes(), //minute
"s+": dateTime.getSeconds(), //second
"q+": Math.floor((dateTime.getMonth() + 3) / 3), //quarter
"S": dateTime.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (dateTime.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
},
/**
* @description 获取窗口高度
* @returns {Inter} 窗口高度
*/
getWinHeight: function () {
if (window.innerHeight) {
return window.innerHeight;
}
if (document.compatMode === "CSS1Compat") {
return window.document.documentElement.clientHeight;
}
return window.document.body.clientHeight;
}
};
if (!Cookie) {
/**
* @description Cookie 相关操作
* @static
*/
var Cookie = {
/**
* @description 根据 tags,穿件云效果
* @param {String} [id] tags 根元素 id,默认为 tags
* @description 读取 cookie
* @param {String} name cookie key
* @returns {String} 对应 key 的值,如 key 不存在则返回 ""
*/
buildTags: function(id) {
id = id || "tags";
// 根据引用次数添加样式,产生云效果
var classes = ["tags1", "tags2", "tags3", "tags4", "tags5"],
bList = $("#" + id + " b").get();
var max = parseInt($("#" + id + " b").last().text());
var distance = Math.ceil(max / classes.length);
for (var i = 0; i < bList.length; i++) {
var num = parseInt(bList[i].innerHTML);
// 算出当前 tag 数目所在的区间,加上 class
for (var j = 0; j < classes.length; j++) {
if (num > j * distance && num <= (j + 1) * distance) {
bList[i].parentNode.className = classes[j];
break;
}
}
}
// 按字母或者中文拼音进行排序
$("#" + id).html($("#" + id + " li").get().sort(function(a, b) {
var valA = $(a).find("span").text().toLowerCase();
var valB = $(b).find("span").text().toLowerCase();
// 对中英文排序的处理
return valA.localeCompare(valB);
}));
readCookie: function (name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0)
return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return "";
},
/**
* @description 时间戳转化为时间格式
* @param {String} time 时间
* @param {String} format 格式化后日期格式
* @returns {String} 格式化后的时间
* @description 清除 Cookie
* @param {String} name 清除 key 为 name 的该条 Cookie
*/
toDate: function(time, format) {
var dateTime = new Date(time);
var o = {
"M+": dateTime.getMonth() + 1, //month
"d+": dateTime.getDate(), //day
"H+": dateTime.getHours(), //hour
"m+": dateTime.getMinutes(), //minute
"s+": dateTime.getSeconds(), //second
"q+": Math.floor((dateTime.getMonth() + 3) / 3), //quarter
"S": dateTime.getMilliseconds() //millisecond
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (dateTime.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
eraseCookie: function (name) {
this.createCookie(name, "", -1);
},
/**
* @description 获取窗口高度
* @returns {Inter} 窗口高度
* @description 创建 Cookie
* @param {String} name 每条 Cookie 唯一的 key
* @param {String} value 每条 Cookie 对应的值,将被 UTF-8 编码
* @param {Int} days Cookie 保存时间
*/
getWinHeight: function() {
if (window.innerHeight) {
return window.innerHeight;
}
if (document.compatMode === "CSS1Compat") {
return window.document.documentElement.clientHeight;
}
return window.document.body.clientHeight;
createCookie: function (name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
}
};
if (!Cookie) {
/**
* @description Cookie 相关操作
* @static
*/
var Cookie = {
/**
* @description 读取 cookie
* @param {String} name cookie key
* @returns {String} 对应 key 的值,如 key 不存在则返回 ""
*/
readCookie: function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0)
return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
return "";
},
/**
* @description 清除 Cookie
* @param {String} name 清除 key 为 name 的该条 Cookie
*/
eraseCookie: function(name) {
this.createCookie(name, "", -1);
},
/**
* @description 创建 Cookie
* @param {String} name 每条 Cookie 唯一的 key
* @param {String} value 每条 Cookie 对应的值,将被 UTF-8 编码
* @param {Int} days Cookie 保存时间
*/
createCookie: function(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
}
};
};
}
\ No newline at end of file
.CodeMirror{font-family:monospace;height:300px;color:#000}.CodeMirror-lines{padding:4px 0}.CodeMirror-lines pre{padding:0 4px}.CodeMirror-gutter-filler,.CodeMirror-scrollbar-filler{background-color:#fff}.CodeMirror-gutters{border-right:1px solid #ddd;background-color:#f7f7f7;white-space:nowrap}.CodeMirror-linenumber{padding:0 3px 0 5px;min-width:20px;text-align:right;color:#999;white-space:nowrap}.CodeMirror-guttermarker{color:#000}.CodeMirror-guttermarker-subtle{color:#999}.CodeMirror-cursor{border-left:1px solid #000;border-right:none;width:0}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.cm-fat-cursor .CodeMirror-cursor{width:auto;border:0;background:#7e7}.cm-fat-cursor div.CodeMirror-cursors{z-index:1}.cm-animate-fat-cursor{width:auto;border:0;-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite;background-color:#7e7}@-moz-keyframes blink{50%{background-color:transparent}}@-webkit-keyframes blink{50%{background-color:transparent}}@keyframes blink{50%{background-color:transparent}}.cm-tab{display:inline-block;text-decoration:inherit}.CodeMirror-ruler{border-left:1px solid #ccc;position:absolute}.cm-s-default .cm-header{color:#00f}.cm-s-default .cm-quote{color:#090}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:700}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-strikethrough{text-decoration:line-through}.cm-s-default .cm-keyword{color:#708}.cm-s-default .cm-atom{color:#219}.cm-s-default .cm-number{color:#164}.cm-s-default .cm-def{color:#00f}.cm-s-default .cm-variable-2{color:#05a}.cm-s-default .cm-variable-3{color:#085}.cm-s-default .cm-comment{color:#a50}.cm-s-default .cm-string{color:#a11}.cm-s-default .cm-string-2{color:#f50}.cm-s-default .cm-meta,.cm-s-default .cm-qualifier{color:#555}.cm-s-default .cm-builtin{color:#30a}.cm-s-default .cm-bracket{color:#997}.cm-s-default .cm-tag{color:#170}.cm-s-default .cm-attribute{color:#00c}.cm-s-default .cm-hr{color:#999}.cm-s-default .cm-link{color:#00c}.cm-invalidchar,.cm-s-default .cm-error{color:red}.CodeMirror-composing{border-bottom:2px solid}div.CodeMirror span.CodeMirror-matchingbracket{color:#0f0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#f22}.CodeMirror-matchingtag{background:rgba(255,150,0,.3)}.CodeMirror-activeline-background{background:#e8f2ff}.CodeMirror{position:relative;overflow:hidden;background:#fff}.CodeMirror-scroll{overflow:scroll!important;margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;height:100%;outline:0;position:relative}.CodeMirror-sizer{position:relative;border-right:30px solid transparent}.CodeMirror-gutter-filler,.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-vscrollbar{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0}.CodeMirror-gutter-filler{left:0;bottom:0}.CodeMirror-gutters{position:absolute;left:0;top:0;z-index:3}.CodeMirror-gutter{white-space:normal;height:100%;display:inline-block;margin-bottom:-30px}.CodeMirror-gutter-wrapper{position:absolute;z-index:4;background:0 0!important;border:none!important;-webkit-user-select:none;-moz-user-select:none;user-select:none}.CodeMirror-gutter-background{position:absolute;top:0;bottom:0;z-index:4}.CodeMirror-gutter-elt{position:absolute;cursor:default;z-index:4}.CodeMirror-lines{cursor:text;min-height:1px}.CodeMirror-lines pre{-moz-border-radius:0;-webkit-border-radius:0;border-radius:0;border-width:0;background:0 0;font-family:inherit;font-size:inherit;margin:0;white-space:pre;word-wrap:normal;line-height:inherit;color:inherit;z-index:2;position:relative;overflow:visible;-webkit-tap-highlight-color:transparent}.CodeMirror-wrap pre{word-wrap:break-word;white-space:pre-wrap;word-break:normal}.CodeMirror-linebackground{position:absolute;left:0;right:0;top:0;bottom:0;z-index:0}.CodeMirror-linewidget{position:relative;z-index:2;overflow:auto}.CodeMirror-code{outline:0}.CodeMirror-gutter,.CodeMirror-gutters,.CodeMirror-linenumber,.CodeMirror-scroll,.CodeMirror-sizer{-moz-box-sizing:content-box;box-sizing:content-box}.CodeMirror-measure{position:absolute;width:100%;height:0;overflow:hidden;visibility:hidden}.CodeMirror-cursor{position:absolute}.CodeMirror-measure pre{position:static}div.CodeMirror-cursors{visibility:hidden;position:relative;z-index:3}.CodeMirror-focused div.CodeMirror-cursors,div.CodeMirror-dragcursors{visibility:visible}.CodeMirror-selected{background:#d9d9d9}.CodeMirror-focused .CodeMirror-selected{background:#d7d4f0}.CodeMirror-crosshair{cursor:crosshair}.CodeMirror-line::selection,.CodeMirror-line>span::selection,.CodeMirror-line>span>span::selection{background:#d7d4f0}.CodeMirror-line::-moz-selection,.CodeMirror-line>span::-moz-selection,.CodeMirror-line>span>span::-moz-selection{background:#d7d4f0}.cm-searching{background:#ffa;background:rgba(255,255,0,.4)}.cm-force-border{padding-right:.1px}.CodeMirror-hints{position:absolute;z-index:100;overflow:hidden;list-style:none;margin:0;padding:2px;-webkit-box-shadow:2px 3px 5px rgba(0,0,0,.2);-moz-box-shadow:2px 3px 5px rgba(0,0,0,.2);box-shadow:2px 3px 5px rgba(0,0,0,.2);border-radius:3px;border:1px solid silver;background:#fff;font-size:90%;font-family:monospace;max-height:20em;overflow-y:auto}.CodeMirror-preview,.editor-toolbar{box-shadow:0 1px 2px rgba(0,0,0,.075) inset}.CodeMirror-hint{margin:0;padding:0 4px;border-radius:2px;max-width:19em;overflow:hidden;white-space:pre;color:#000;cursor:pointer}li.CodeMirror-hint-active{background:#08f;color:#fff}.CodeMirror-fullscreen{position:fixed;top:0;left:0;right:0;bottom:0;height:auto;z-index:9}@media print{.CodeMirror div.CodeMirror-cursors{visibility:hidden}}.CodeMirror-merge-2pane .CodeMirror-merge-pane{width:49%;border:1px solid #CCC;border-radius:3px}.CodeMirror-merge-2pane .CodeMirror-merge-gap{width:0;display:none}.CodeMirror-merge-3pane .CodeMirror-merge-pane{width:31%}.CodeMirror-merge-3pane .CodeMirror-merge-gap{width:3.5%}.CodeMirror-merge-pane{display:inline-block;white-space:normal;vertical-align:top}.CodeMirror-merge-pane-rightmost{float:right}.CodeMirror-merge-gap{z-index:2;display:inline-block;height:100%;-moz-box-sizing:border-box;box-sizing:border-box;overflow:hidden;border-left:1px solid #ddd;border-right:1px solid #ddd;position:relative;background:#f8f8f8}.CodeMirror-merge-scrolllock-wrap{position:absolute;bottom:0;left:50%}.CodeMirror-merge-scrolllock{position:relative;left:-50%;cursor:pointer;color:#555;line-height:1;display:none}.CodeMirror-merge-copy,.CodeMirror-merge-copy-reverse{position:absolute;color:#44c;cursor:pointer}.CodeMirror-merge-copybuttons-left,.CodeMirror-merge-copybuttons-right{position:absolute;left:0;top:0;right:0;bottom:0;line-height:1}.CodeMirror-merge-copy{z-index:3}.CodeMirror-merge-copybuttons-left .CodeMirror-merge-copy{left:2px}.CodeMirror-merge-copybuttons-right .CodeMirror-merge-copy{right:2px}.CodeMirror-merge-l-inserted,.CodeMirror-merge-r-inserted{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12MwuCXy3+CWyH8GBgYGJgYkAABZbAQ9ELXurwAAAABJRU5ErkJggg==);background-position:bottom left;background-repeat:repeat-x}.CodeMirror-merge-l-deleted,.CodeMirror-merge-r-deleted{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12M4Kyb2/6yY2H8GBgYGJgYkAABURgPz6Ks7wQAAAABJRU5ErkJggg==);background-position:bottom left;background-repeat:repeat-x}.CodeMirror-merge-r-chunk{background:#ffffe0}.CodeMirror-merge-r-chunk-start{border-top:1px solid #ee8}.CodeMirror-merge-r-chunk-end{border-bottom:1px solid #ee8}.CodeMirror-merge-r-connect{fill:#ffffe0;stroke:#ee8;stroke-width:1px}.CodeMirror-merge-l-chunk{background:#eef}.CodeMirror-merge-l-chunk-start{border-top:1px solid #88e}.CodeMirror-merge-l-chunk-end{border-bottom:1px solid #88e}.CodeMirror-merge-l-connect{fill:#eef;stroke:#88e;stroke-width:1px}.CodeMirror-merge-l-chunk.CodeMirror-merge-r-chunk{background:#dfd}.CodeMirror-merge-l-chunk-start.CodeMirror-merge-r-chunk-start{border-top:1px solid #4e4}.CodeMirror-merge-l-chunk-end.CodeMirror-merge-r-chunk-end{border-bottom:1px solid #4e4}.CodeMirror-merge-collapsed-widget:before{content:"(...)"}.CodeMirror-merge-collapsed-widget{cursor:pointer;color:#88b;background:#eef;border:1px solid #ddf;font-size:90%;padding:0 3px;border-radius:4px}.CodeMirror-merge-collapsed-line .CodeMirror-gutter-elt{display:none}.cm-tab-wrap-hack:after{content:''}span.CodeMirror-selectedtext{background:0 0}:-webkit-full-screen{background:#f9f9f5;padding:.5em 1em;width:100%;height:100%}:-moz-full-screen{padding:.5em 1em;background:#f9f9f5;width:100%;height:100%}.editor-wrapper{font:16px/1.62 "Helvetica Neue","Xin Gothic","Hiragino Sans GB","WenQuanYi Micro Hei","Microsoft YaHei",sans-serif;color:#2c3e50}.editor-toolbar{position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;border:1px solid #CCC;background-color:#FAFAFA;border-bottom-width:0;border-radius:3px 3px 0 0;height:34px}.editor-toolbar a,.editor-toolbar label{text-decoration:none!important;font-size:16px;color:#666;padding:5px 10px;cursor:pointer;line-height:24px;display:inline-block;top:-1px}.editor-toolbar a.active,.editor-toolbar a.focus,.editor-toolbar a:hover,.editor-toolbar label.active,.editor-toolbar label:hover{background:#666;color:#fff}.editor-toolbar a:before,.editor-toolbar label:before{line-height:24px}.editor-toolbar label.icon-upload{margin:0;position:relative}.editor-toolbar input{height:1px;position:absolute;left:0;top:0;opacity:.001}.editor-toolbar form{overflow:hidden;display:initial}.CodeMirror-preview,.editor-preview{position:absolute;box-sizing:border-box;overflow:auto}.editor-toolbar i.separator{display:inline-block;width:0;border-left:1px solid #d9d9d9;border-right:1px solid #fff;color:transparent;text-indent:-10px;margin:0 5px}.editor-toolbar a.icon-contract,.editor-toolbar a.icon-fullscreen{position:absolute;right:0}.editor-statusbar{border-top:1px solid #ece9e9;padding:8px 10px;font-size:12px;color:#959694;text-align:right}.editor-statusbar span{display:inline-block;min-width:4em;margin-left:1em}.editor-statusbar .lines:before{content:'lines: '}.editor-statusbar .words:before{content:'words: '}.editor-preview{width:100%;height:100%;top:1px;padding:0 4px;left:100%;background:#FDFDFD;z-index:10;-webkit-transition:left .2s ease;-moz-transition:left .2s ease;-ms-transition:left .2s ease;transition:left .2s ease}.editor-preview-active{left:0}.editor-preview>p{margin-top:0}.CodeMirror-preview{background-color:#FFF;width:50%;top:30px;border-left:1px solid #ccc;border-radius:0 0 3px;border-top:0;right:0;padding:4px}
\ No newline at end of file
.CodeMirror{font-family:monospace;height:300px;color:#000}.CodeMirror-lines{padding:4px 0}.CodeMirror-lines pre{padding:0 4px}.CodeMirror-gutter-filler,.CodeMirror-scrollbar-filler{background-color:#fff}.CodeMirror-gutters{border-right:1px solid #ddd;background-color:#f7f7f7;white-space:nowrap}.CodeMirror-linenumber{padding:0 3px 0 5px;min-width:20px;text-align:right;color:#999;white-space:nowrap}.CodeMirror-guttermarker{color:#000}.CodeMirror-guttermarker-subtle{color:#999}.CodeMirror-cursor{border-left:1px solid #000;border-right:none;width:0}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.cm-fat-cursor .CodeMirror-cursor{width:auto;border:0;background:#7e7}.cm-fat-cursor div.CodeMirror-cursors{z-index:1}.cm-animate-fat-cursor{width:auto;border:0;-webkit-animation:blink 1.06s steps(1) infinite;-moz-animation:blink 1.06s steps(1) infinite;animation:blink 1.06s steps(1) infinite;background-color:#7e7}@-moz-keyframes blink{50%{background-color:transparent}}@-webkit-keyframes blink{50%{background-color:transparent}}@keyframes blink{50%{background-color:transparent}}.cm-tab{display:inline-block;text-decoration:inherit}.CodeMirror-ruler{border-left:1px solid #ccc;position:absolute}.cm-s-default .cm-header{color:#00f}.cm-s-default .cm-quote{color:#090}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:700}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-strikethrough{text-decoration:line-through}.cm-s-default .cm-keyword{color:#708}.cm-s-default .cm-atom{color:#219}.cm-s-default .cm-number{color:#164}.cm-s-default .cm-def{color:#00f}.cm-s-default .cm-variable-2{color:#05a}.cm-s-default .cm-variable-3{color:#085}.cm-s-default .cm-comment{color:#a50}.cm-s-default .cm-string{color:#a11}.cm-s-default .cm-string-2{color:#f50}.cm-s-default .cm-meta{color:#555}.cm-s-default .cm-qualifier{color:#555}.cm-s-default .cm-builtin{color:#30a}.cm-s-default .cm-bracket{color:#997}.cm-s-default .cm-tag{color:#170}.cm-s-default .cm-attribute{color:#00c}.cm-s-default .cm-hr{color:#999}.cm-s-default .cm-link{color:#00c}.cm-s-default .cm-error{color:red}.cm-invalidchar{color:red}.CodeMirror-composing{border-bottom:2px solid}div.CodeMirror span.CodeMirror-matchingbracket{color:#0f0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#f22}.CodeMirror-matchingtag{background:rgba(255,150,0,.3)}.CodeMirror-activeline-background{background:#e8f2ff}.CodeMirror{position:relative;overflow:hidden;background:#fff}.CodeMirror-scroll{overflow:scroll!important;margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;height:100%;outline:0;position:relative}.CodeMirror-sizer{position:relative;border-right:30px solid transparent}.CodeMirror-gutter-filler,.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-vscrollbar{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0}.CodeMirror-gutter-filler{left:0;bottom:0}.CodeMirror-gutters{position:absolute;left:0;top:0;z-index:3}.CodeMirror-gutter{white-space:normal;height:100%;display:inline-block;margin-bottom:-30px}.CodeMirror-gutter-wrapper{position:absolute;z-index:4;background:0 0!important;border:none!important}.CodeMirror-gutter-background{position:absolute;top:0;bottom:0;z-index:4}.CodeMirror-gutter-elt{position:absolute;cursor:default;z-index:4}.CodeMirror-gutter-wrapper{-webkit-user-select:none;-moz-user-select:none;user-select:none}.CodeMirror-lines{cursor:text;min-height:1px}.CodeMirror-lines pre{-moz-border-radius:0;-webkit-border-radius:0;border-radius:0;border-width:0;background:0 0;font-family:inherit;font-size:inherit;margin:0;white-space:pre;word-wrap:normal;line-height:inherit;color:inherit;z-index:2;position:relative;overflow:visible;-webkit-tap-highlight-color:transparent}.CodeMirror-wrap pre{word-wrap:break-word;white-space:pre-wrap;word-break:normal}.CodeMirror-linebackground{position:absolute;left:0;right:0;top:0;bottom:0;z-index:0}.CodeMirror-linewidget{position:relative;z-index:2;overflow:auto}.CodeMirror-code{outline:0}.CodeMirror-gutter,.CodeMirror-gutters,.CodeMirror-linenumber,.CodeMirror-scroll,.CodeMirror-sizer{-moz-box-sizing:content-box;box-sizing:content-box}.CodeMirror-measure{position:absolute;width:100%;height:0;overflow:hidden;visibility:hidden}.CodeMirror-cursor{position:absolute}.CodeMirror-measure pre{position:static}div.CodeMirror-cursors{visibility:hidden;position:relative;z-index:3}div.CodeMirror-dragcursors{visibility:visible}.CodeMirror-focused div.CodeMirror-cursors{visibility:visible}.CodeMirror-selected{background:#d9d9d9}.CodeMirror-focused .CodeMirror-selected{background:#d7d4f0}.CodeMirror-crosshair{cursor:crosshair}.CodeMirror-line::selection,.CodeMirror-line>span::selection,.CodeMirror-line>span>span::selection{background:#d7d4f0}.CodeMirror-line::-moz-selection,.CodeMirror-line>span::-moz-selection,.CodeMirror-line>span>span::-moz-selection{background:#d7d4f0}.cm-searching{background:#ffa;background:rgba(255,255,0,.4)}.cm-force-border{padding-right:.1px}.CodeMirror-hints{position:absolute;z-index:100;overflow:hidden;list-style:none;margin:0;padding:2px;-webkit-box-shadow:2px 3px 5px rgba(0,0,0,.2);-moz-box-shadow:2px 3px 5px rgba(0,0,0,.2);box-shadow:2px 3px 5px rgba(0,0,0,.2);border-radius:3px;border:1px solid silver;background:#fff;font-size:90%;font-family:monospace;max-height:20em;overflow-y:auto}.CodeMirror-hint{margin:0;padding:0 4px;border-radius:2px;max-width:19em;overflow:hidden;white-space:pre;color:#000;cursor:pointer}li.CodeMirror-hint-active{background:#08f;color:#fff}.CodeMirror-fullscreen{position:fixed;top:0;left:0;right:0;bottom:0;height:auto;z-index:9}@media print{.CodeMirror div.CodeMirror-cursors{visibility:hidden}}.CodeMirror-merge-2pane .CodeMirror-merge-pane{width:49%;border:1px solid #ccc;border-radius:3px}.CodeMirror-merge-2pane .CodeMirror-merge-gap{width:0;display:none}.CodeMirror-merge-3pane .CodeMirror-merge-pane{width:31%}.CodeMirror-merge-3pane .CodeMirror-merge-gap{width:3.5%}.CodeMirror-merge-pane{display:inline-block;white-space:normal;vertical-align:top}.CodeMirror-merge-pane-rightmost{float:right}.CodeMirror-merge-gap{z-index:2;display:inline-block;height:100%;-moz-box-sizing:border-box;box-sizing:border-box;overflow:hidden;border-left:1px solid #ddd;border-right:1px solid #ddd;position:relative;background:#f8f8f8}.CodeMirror-merge-scrolllock-wrap{position:absolute;bottom:0;left:50%}.CodeMirror-merge-scrolllock{position:relative;left:-50%;cursor:pointer;color:#555;line-height:1;display:none}.CodeMirror-merge-copybuttons-left,.CodeMirror-merge-copybuttons-right{position:absolute;left:0;top:0;right:0;bottom:0;line-height:1}.CodeMirror-merge-copy{position:absolute;cursor:pointer;color:#44c;z-index:3}.CodeMirror-merge-copy-reverse{position:absolute;cursor:pointer;color:#44c}.CodeMirror-merge-copybuttons-left .CodeMirror-merge-copy{left:2px}.CodeMirror-merge-copybuttons-right .CodeMirror-merge-copy{right:2px}.CodeMirror-merge-l-inserted,.CodeMirror-merge-r-inserted{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12MwuCXy3+CWyH8GBgYGJgYkAABZbAQ9ELXurwAAAABJRU5ErkJggg==);background-position:bottom left;background-repeat:repeat-x}.CodeMirror-merge-l-deleted,.CodeMirror-merge-r-deleted{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAAAGUlEQVQI12M4Kyb2/6yY2H8GBgYGJgYkAABURgPz6Ks7wQAAAABJRU5ErkJggg==);background-position:bottom left;background-repeat:repeat-x}.CodeMirror-merge-r-chunk{background:#ffffe0}.CodeMirror-merge-r-chunk-start{border-top:1px solid #ee8}.CodeMirror-merge-r-chunk-end{border-bottom:1px solid #ee8}.CodeMirror-merge-r-connect{fill:#ffffe0;stroke:#ee8;stroke-width:1px}.CodeMirror-merge-l-chunk{background:#eef}.CodeMirror-merge-l-chunk-start{border-top:1px solid #88e}.CodeMirror-merge-l-chunk-end{border-bottom:1px solid #88e}.CodeMirror-merge-l-connect{fill:#eef;stroke:#88e;stroke-width:1px}.CodeMirror-merge-l-chunk.CodeMirror-merge-r-chunk{background:#dfd}.CodeMirror-merge-l-chunk-start.CodeMirror-merge-r-chunk-start{border-top:1px solid #4e4}.CodeMirror-merge-l-chunk-end.CodeMirror-merge-r-chunk-end{border-bottom:1px solid #4e4}.CodeMirror-merge-collapsed-widget:before{content:"(...)"}.CodeMirror-merge-collapsed-widget{cursor:pointer;color:#88b;background:#eef;border:1px solid #ddf;font-size:90%;padding:0 3px;border-radius:4px}.CodeMirror-merge-collapsed-line .CodeMirror-gutter-elt{display:none}.cm-tab-wrap-hack:after{content:''}span.CodeMirror-selectedtext{background:0 0}:-webkit-full-screen{background:#f9f9f5;padding:.5em 1em;width:100%;height:100%}:-moz-full-screen{padding:.5em 1em;background:#f9f9f5;width:100%;height:100%}.editor-wrapper{font:16px/1.62 "Helvetica Neue","Xin Gothic","Hiragino Sans GB","WenQuanYi Micro Hei","Microsoft YaHei",sans-serif;color:#2c3e50}.editor-toolbar{position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;border:1px solid #ccc;background-color:#fafafa;box-shadow:0 1px 2px rgba(0,0,0,.075) inset;border-bottom-width:0;border-radius:3px 3px 0 0;height:34px}.editor-toolbar a,.editor-toolbar label{text-decoration:none!important;font-size:16px;color:#666;padding:5px 10px;cursor:pointer;line-height:24px;display:inline-block;top:-1px}.editor-toolbar a.active,.editor-toolbar a.focus,.editor-toolbar a:hover,.editor-toolbar label.active,.editor-toolbar label:hover{background:#666;color:#fff}.editor-toolbar a:before,.editor-toolbar label:before{line-height:24px}.editor-toolbar label.icon-upload{margin:0;position:relative}.editor-toolbar input{height:1px;position:absolute;left:0;top:0;opacity:.001}.editor-toolbar form{overflow:hidden;display:initial}.editor-toolbar i.separator{display:inline-block;width:0;border-left:1px solid #d9d9d9;border-right:1px solid #fff;color:transparent;text-indent:-10px;margin:0 5px}.editor-toolbar a.icon-contract,.editor-toolbar a.icon-fullscreen{position:absolute;right:0}.editor-statusbar{border-top:1px solid #ece9e9;padding:8px 10px;font-size:12px;color:#959694;text-align:right}.editor-statusbar span{display:inline-block;min-width:4em;margin-left:1em}.editor-statusbar .lines:before{content:'lines: '}.editor-statusbar .words:before{content:'words: '}.editor-preview{position:absolute;width:100%;height:100%;top:1px;padding:0 4px;left:100%;background:#fdfdfd;z-index:10;overflow:auto;-webkit-transition:left .2s ease;-moz-transition:left .2s ease;-ms-transition:left .2s ease;transition:left .2s ease;box-sizing:border-box}.editor-preview-active{left:0}.editor-preview>p{margin-top:0}.CodeMirror-preview{background-color:#fff;width:50%;top:30px;border-left:1px solid #ccc;border-radius:0 0 3px;border-top:0;overflow:hidden;right:0;position:absolute;box-shadow:0 1px 2px rgba(0,0,0,.075) inset;padding:4px;box-sizing:border-box;overflow:auto}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -18,729 +18,728 @@
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</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) {
this.currentCommentId = "";
this.tips = tips;
this.currentCommentId = "";
this.tips = tips;
};
$.extend(Page.prototype, {
/*
* @description 评论时点击表情,在评论内容中插入相关代码
* @param {String} name 用于区别回复评论还是对文章的评论
*/
insertEmotions: function (name) {
var _it = this;
if (name === undefined) {
name = "";
}
/*
* @description 评论时点击表情,在评论内容中插入相关代码
* @param {String} name 用于区别回复评论还是对文章的评论
*/
insertEmotions: function (name) {
var _it = this;
if (name === undefined) {
name = "";
}
$("#emotions" + name + " span").click(function () {
var $comment = $("#comment" + name);
var endPosition = _it._getCursorEndPosition($comment[0]);
var key = this.title + ' ',
textValue = $comment[0].value;
textValue = textValue.substring(0, endPosition) + key + textValue.substring(endPosition, textValue.length);
$("#comment" + name).val(textValue);
if ($.browser.msie) {
endPosition -= textValue.split('\n').length - 1;
var oR = $comment[0].createTextRange();
oR.collapse(true);
oR.moveStart('character', endPosition + key.length);
oR.select();
} else {
$comment[0].setSelectionRange(endPosition + key.length, endPosition + key.length);
}
});
},
/**
* @description 获取当前光标最后位置
* @param {Dom} textarea 评论框对象
* @returns {Num} 光标位置
*/
_getCursorEndPosition: function (textarea) {
textarea.focus();
if (textarea.setSelectionRange) { // W3C
return textarea.selectionEnd;
} else if (document.selection) { // IE
var i = 0,
oS = document.selection.createRange(),
oR = document.body.createTextRange();
oR.moveToElementText(textarea);
oS.getBookmark();
for (i = 0; oR.compareEndPoints('StartToStart', oS) < 0 && oS.moveStart("character", -1) !== 0; i++) {
if (textarea.value.charAt(i) === '\n') {
i++;
}
}
return i;
}
},
/*
* @description 评论校验
* @param {String} state 用于区别回复评论还是对文章的评论
*/
validateComment: function (state) {
if (Util.isLoggedIn()) {
var commenterContent = $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, "");
if (2 > commenterContent.length || commenterContent.length > 500) {
$("#commentErrorTip" + state).html(this.tips.commentContentCannotEmptyLabel);
$("#comment" + state).focus();
} else {
return true;
}
$("#commentErrorTip" + state).show();
return false;
$("#emotions" + name + " span").click(function () {
var $comment = $("#comment" + name);
var endPosition = _it._getCursorEndPosition($comment[0]);
var key = this.title + ' ',
textValue = $comment[0].value;
textValue = textValue.substring(0, endPosition) + key + textValue.substring(endPosition, textValue.length);
$("#comment" + name).val(textValue);
if ($.browser.msie) {
endPosition -= textValue.split('\n').length - 1;
var oR = $comment[0].createTextRange();
oR.collapse(true);
oR.moveStart('character', endPosition + key.length);
oR.select();
} else {
$comment[0].setSelectionRange(endPosition + key.length, endPosition + key.length);
}
});
},
/**
* @description 获取当前光标最后位置
* @param {Dom} textarea 评论框对象
* @returns {Num} 光标位置
*/
_getCursorEndPosition: function (textarea) {
textarea.focus();
if (textarea.setSelectionRange) { // W3C
return textarea.selectionEnd;
} else if (document.selection) { // IE
var i = 0,
oS = document.selection.createRange(),
oR = document.body.createTextRange();
oR.moveToElementText(textarea);
oS.getBookmark();
for (i = 0; oR.compareEndPoints('StartToStart', oS) < 0 && oS.moveStart("character", -1) !== 0; i++) {
if (textarea.value.charAt(i) === '\n') {
i++;
}
}
return i;
}
},
/*
* @description 评论校验
* @param {String} state 用于区别回复评论还是对文章的评论
*/
validateComment: function (state) {
if (Util.isLoggedIn()) {
var commenterContent = $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, "");
if (2 > commenterContent.length || commenterContent.length > 500) {
$("#commentErrorTip" + state).html(this.tips.commentContentCannotEmptyLabel);
$("#comment" + state).focus();
} else {
return true;
}
$("#commentErrorTip" + state).show();
return false;
}
var commentName = $("#commentName" + state).val().replace(/(^\s*)|(\s*$)/g, ""),
commenterContent = $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, "");
if (2 > commentName.length || commentName.length > 20) {
$("#commentErrorTip" + state).html(this.tips.nameTooLongLabel);
$("#commentName" + state).focus();
} else if ($("#commentEmail" + state).val().replace(/\s/g, "") === "") {
$("#commentErrorTip" + state).html(this.tips.mailCannotEmptyLabel);
$("#commentEmail" + state).focus();
} else if (!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($("#commentEmail" + state).val())) {
$("#commentErrorTip" + state).html(this.tips.mailInvalidLabel);
$("#commentEmail" + state).focus();
} else if (2 > commenterContent.length || commenterContent.length > 500) {
$("#commentErrorTip" + state).html(this.tips.commentContentCannotEmptyLabel);
$("#comment" + state).focus();
} else if ($("#commentValidate" + state).val().replace(/\s/g, "") === "") {
$("#commentErrorTip" + state).html(this.tips.captchaCannotEmptyLabel);
$("#commentValidate" + state).focus();
} else {
return true;
}
$("#commentErrorTip" + state).show();
return false;
},
/*
* @description 把评论中的标识替换为图片
* @param {Dom} selector
*/
replaceCommentsEm: function (selector) {
var $commentContents = $(selector);
for (var i = 0; i < $commentContents.length; i++) {
var str = $commentContents[i].innerHTML;
$commentContents[i].innerHTML = Util.replaceEmString(str);
}
},
/*
* @description 初始化 SyantaxHighlighter
* @param {Array} languages 需要加载的语言
*/
_initSyntaxHighlighter: function (languages) {
// load brush js
for (var i = 0; i < languages.length; i++) {
switch (languages[i]) {
case "groovy":
languages[i] = 'groovy ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushGroovy.js';
break;
case "java":
languages[i] = 'java ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushJava.js';
break;
case "php":
languages[i] = 'php ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPhp.js';
break;
case "scala":
languages[i] = 'scala ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushScala.js';
break;
case "sql":
languages[i] = 'sql ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushSql.js';
break;
case "applescript":
languages[i] = 'applescript ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushAppleScript.js';
break;
case "as3":
case "actionscript3":
languages[i] = 'actionscript3 as3 ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushAS3.js';
break;
case "bash":
case "shell":
languages[i] = 'bash shell ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushBash.js';
break;
case "coldfusion":
case "cf":
languages[i] = 'coldfusion cf ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushColdFusion.js';
break;
case "c#":
case "c-sharp":
case "csharp":
languages[i] = 'c# c-sharp csharp ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushCSharp.js';
break;
case "cpp":
case "c":
languages[i] = 'cpp c ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushCpp.js';
break;
case "css":
languages[i] = 'css ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushCss.js';
break;
case "delphi":
case "pascal":
languages[i] = 'delphi pascal ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushDelphi.js';
break;
case "diff":
case "patch":
case "pas":
languages[i] = 'diff patch pas ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushDiff.js';
break;
case "erl":
case "erlang":
languages[i] = 'erl erlang ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushErlang.js';
break;
case "js":
case "jscript":
case "javascript":
languages[i] = 'js jscript javascript ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushJScript.js';
break;
case "jfx":
case "javafx":
languages[i] = 'jfx javafx ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushJavaFX.js';
break;
case "perl":
case "pl":
languages[i] = 'perl pl ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPerl.js';
break;
case "plain":
case "text":
languages[i] = 'text plain ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPlain.js';
break;
case "ps":
case "powershell":
languages[i] = 'ps powershell ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPowerShell.js';
break;
case "py":
case "python":
languages[i] = 'py python ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPython.js';
break;
case "rails":
case "ror":
case "ruby":
case "rb":
languages[i] = 'ruby rails ror rb ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushRuby.js';
break;
case "sass":
case "scss":
languages[i] = 'sass scss ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushSass.js';
break;
case "vb":
case "vbnet":
languages[i] = 'vb vbnet ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushVb.js';
break;
case "xml":
case "xhtml":
case "xslt":
case "html":
languages[i] = 'xml xhtml xslt html ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushXml.js';
break;
default:
break;
}
}
var commentName = $("#commentName" + state).val().replace(/(^\s*)|(\s*$)/g, ""),
commenterContent = $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, "");
if (2 > commentName.length || commentName.length > 20) {
$("#commentErrorTip" + state).html(this.tips.nameTooLongLabel);
$("#commentName" + state).focus();
} else if ($("#commentEmail" + state).val().replace(/\s/g, "") === "") {
$("#commentErrorTip" + state).html(this.tips.mailCannotEmptyLabel);
$("#commentEmail" + state).focus();
} else if (!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($("#commentEmail" + state).val())) {
$("#commentErrorTip" + state).html(this.tips.mailInvalidLabel);
$("#commentEmail" + state).focus();
} else if (2 > commenterContent.length || commenterContent.length > 500) {
$("#commentErrorTip" + state).html(this.tips.commentContentCannotEmptyLabel);
$("#comment" + state).focus();
} else if ($("#commentValidate" + state).val().replace(/\s/g, "") === "") {
$("#commentErrorTip" + state).html(this.tips.captchaCannotEmptyLabel);
$("#commentValidate" + state).focus();
} else {
return true;
}
$("#commentErrorTip" + state).show();
return false;
},
/*
* @description 把评论中的标识替换为图片
* @param {Dom} selector
*/
replaceCommentsEm: function (selector) {
var $commentContents = $(selector);
for (var i = 0; i < $commentContents.length; i++) {
var str = $commentContents[i].innerHTML;
$commentContents[i].innerHTML = Util.replaceEmString(str);
}
},
/*
* @description 初始化 SyantaxHighlighter
* @param {Array} languages 需要加载的语言
*/
_initSyntaxHighlighter: function (languages) {
// load brush js
for (var i = 0; i < languages.length; i++) {
switch (languages[i]) {
case "groovy":
languages[i] = 'groovy ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushGroovy.js';
break;
case "java":
languages[i] = 'java ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushJava.js';
break;
case "php":
languages[i] = 'php ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPhp.js';
break;
case "scala":
languages[i] = 'scala ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushScala.js';
break;
case "sql":
languages[i] = 'sql ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushSql.js';
break;
case "applescript":
languages[i] = 'applescript ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushAppleScript.js';
break;
case "as3":
case "actionscript3":
languages[i] = 'actionscript3 as3 ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushAS3.js';
break;
case "bash":
case "shell":
languages[i] = 'bash shell ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushBash.js';
break;
case "coldfusion":
case "cf":
languages[i] = 'coldfusion cf ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushColdFusion.js';
break;
case "c#":
case "c-sharp":
case "csharp":
languages[i] = 'c# c-sharp csharp ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushCSharp.js';
break;
case "cpp":
case "c":
languages[i] = 'cpp c ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushCpp.js';
break;
case "css":
languages[i] = 'css ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushCss.js';
break;
case "delphi":
case "pascal":
languages[i] = 'delphi pascal ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushDelphi.js';
break;
case "diff":
case "patch":
case "pas":
languages[i] = 'diff patch pas ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushDiff.js';
break;
case "erl":
case "erlang":
languages[i] = 'erl erlang ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushErlang.js';
break;
case "js":
case "jscript":
case "javascript":
languages[i] = 'js jscript javascript ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushJScript.js';
break;
case "jfx":
case "javafx":
languages[i] = 'jfx javafx ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushJavaFX.js';
break;
case "perl":
case "pl":
languages[i] = 'perl pl ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPerl.js';
break;
case "plain":
case "text":
languages[i] = 'text plain ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPlain.js';
break;
case "ps":
case "powershell":
languages[i] = 'ps powershell ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPowerShell.js';
break;
case "py":
case "python":
languages[i] = 'py python ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushPython.js';
break;
case "rails":
case "ror":
case "ruby":
case "rb":
languages[i] = 'ruby rails ror rb ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushRuby.js';
break;
case "sass":
case "scss":
languages[i] = 'sass scss ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushSass.js';
break;
case "vb":
case "vbnet":
languages[i] = 'vb vbnet ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushVb.js';
break;
case "xml":
case "xhtml":
case "xslt":
case "html":
languages[i] = 'xml xhtml xslt html ' +
latkeConfig.staticServePath + '/js/lib/SyntaxHighlighter/scripts/shBrushXml.js';
break;
default:
break;
}
}
// code high lighter
SyntaxHighlighter.autoloader.apply(null, languages);
SyntaxHighlighter.config.stripBrs = true;
SyntaxHighlighter.all();
},
/*
* @description 加载 SyntaxHighlighter
* @param {String} SHTheme SyntaxHighLighter 样式
*/
_loadSyntaxHighlighter: function (SHTheme) {
var cssName = SHTheme ? SHTheme : "shCoreEclipse",
that = this;
// load css
if (document.createStyleSheet) {
document.createStyleSheet(latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/styles/" + cssName + ".css");
} else {
$("head").append($("<link rel='stylesheet' href='" + latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/styles/"
+ cssName + ".css' type='text/css' charset='utf-8' />"));
}
// code high lighter
SyntaxHighlighter.autoloader.apply(null, languages);
SyntaxHighlighter.config.stripBrs = true;
SyntaxHighlighter.all();
},
/*
* @description 加载 SyntaxHighlighter
* @param {String} SHTheme SyntaxHighLighter 样式
*/
_loadSyntaxHighlighter: function (SHTheme) {
var cssName = SHTheme ? SHTheme : "shCoreEclipse",
that = this;
// load css
if (document.createStyleSheet) {
document.createStyleSheet(latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/styles/" + cssName + ".css");
} else {
$("head").append($("<link rel='stylesheet' href='" + latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/styles/"
+ cssName + ".css' type='text/css' charset='utf-8' />"));
}
// load js
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/scripts/shCore.js",
dataType: "script",
cache: true,
success: function () {
// get brush settings
var languages = [],
isScrip = false;
$(".article-body pre, .code-highlight pre").each(function () {
var name = this.className.split(";")[0];
var language = name.substr(7, name.length - 1);
if (this.className.indexOf("html-script: true") > -1 &&
(language !== "xml" && language !== "xhtml" &&
language !== "xslt" && language != "html")) {
isScrip = true;
}
// load js
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/scripts/shCore.js",
languages.push(language);
});
// when html-script is true, need shBrushXml.js
if (isScrip) {
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/scripts/shBrushXml.js",
dataType: "script",
cache: true,
success: function () {
// get brush settings
var languages = [],
isScrip = false;
$(".article-body pre, .code-highlight pre").each(function () {
var name = this.className.split(";")[0];
var language = name.substr(7, name.length - 1);
if (this.className.indexOf("html-script: true") > -1 &&
(language !== "xml" && language !== "xhtml" &&
language !== "xslt" && language != "html")) {
isScrip = true;
}
languages.push(language);
});
// when html-script is true, need shBrushXml.js
if (isScrip) {
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/SyntaxHighlighter/scripts/shBrushXml.js",
dataType: "script",
cache: true,
success: function () {
that._initSyntaxHighlighter(languages);
}
});
} else {
that._initSyntaxHighlighter(languages);
}
}
});
},
/*
* @description 解析语法高亮
* @param {Obj} obj 语法高亮配置参数
* @param {Obj} obj.SHTheme 语法高亮 SyntaxHighLighter 样式
*/
parseLanguage: function (obj) {
var isPrettify = false,
isSH = false;
$(".article-body pre, .code-highlight pre").each(function () {
if (this.className.indexOf("brush") > -1) {
isSH = true;
that._initSyntaxHighlighter(languages);
}
});
} else {
that._initSyntaxHighlighter(languages);
}
}
});
},
/*
* @description 解析语法高亮
* @param {Obj} obj 语法高亮配置参数
* @param {Obj} obj.SHTheme 语法高亮 SyntaxHighLighter 样式
*/
parseLanguage: function (obj) {
var isPrettify = false,
isSH = false;
$(".article-body pre, .code-highlight pre").each(function () {
if (this.className.indexOf("brush") > -1) {
isSH = true;
}
if (this.className.indexOf("prettyprint") > -1) {
isPrettify = true;
}
});
if (this.className.indexOf("prettyprint") > -1) {
isPrettify = true;
}
});
if (isSH) {
this._loadSyntaxHighlighter(obj ? (obj.SHTheme ? obj.SHTheme : undefined) : undefined);
return false;
}
if (isSH) {
this._loadSyntaxHighlighter(obj ? (obj.SHTheme ? obj.SHTheme : undefined) : undefined);
return false;
}
if (isPrettify) {
// load css
if (document.createStyleSheet) {
document.createStyleSheet(latkeConfig.staticServePath + "/js/lib/google-code-prettify/prettify.css");
} else {
$("head").append($("<link rel='stylesheet' href='" + latkeConfig.staticServePath + "/js/lib/google-code-prettify/prettify.css'>"));
}
if (isPrettify) {
// load css
if (document.createStyleSheet) {
document.createStyleSheet(latkeConfig.staticServePath + "/js/lib/google-code-prettify/prettify.css");
} else {
$("head").append($("<link rel='stylesheet' href='" + latkeConfig.staticServePath + "/js/lib/google-code-prettify/prettify.css'>"));
}
// load js
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/google-code-prettify/prettify.js",
dataType: "script",
cache: true,
success: function () {
prettyPrint();
}
});
return false;
// load js
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/google-code-prettify/prettify.js",
dataType: "script",
cache: true,
success: function () {
prettyPrint();
}
});
return false;
}
// otherelse use highlight
// load css
if (document.createStyleSheet) {
document.createStyleSheet(latkeConfig.staticServePath + "/js/lib/highlight.js-9.6.0/styles/default.css");
} else {
$("head").append($("<link rel='stylesheet' href='" + latkeConfig.staticServePath + "/js/lib/highlight.js-9.6.0/styles/github.css'>"));
}
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/highlight.js-9.6.0/highlight.pack.js",
dataType: "script",
cache: true,
success: function () {
hljs.initHighlighting.called = false;
hljs.initHighlighting();
}
});
// otherelse use highlight
// load css
if (document.createStyleSheet) {
document.createStyleSheet(latkeConfig.staticServePath + "/js/lib/highlight.js-9.6.0/styles/default.css");
} else {
$("head").append($("<link rel='stylesheet' href='" + latkeConfig.staticServePath + "/js/lib/highlight.js-9.6.0/styles/github.css'>"));
}
$.ajax({
url: latkeConfig.staticServePath + "/js/lib/highlight.js-9.6.0/highlight.pack.js",
dataType: "script",
cache: true,
success: function () {
hljs.initHighlighting.called = false;
hljs.initHighlighting();
}
});
},
/*
* @description 文章/自定义页面加载
* @param {Obj} obj 配置设定
* @param {Obj} obj.language 代码高亮配置
*/
load: function (obj) {
var that = this;
// emotions
that.insertEmotions();
// language
that.parseLanguage(obj ? (obj.language ? obj.language : undefined) : undefined);
// submit comment
$("#commentValidate").keypress(function (event) {
if (event.keyCode === 13) {
that.submitComment();
}
});
},
/*
* @description 文章/自定义页面加载
* @param {Obj} obj 配置设定
* @param {Obj} obj.language 代码高亮配置
*/
load: function (obj) {
var that = this;
// emotions
that.insertEmotions();
// language
that.parseLanguage(obj ? (obj.language ? obj.language : undefined) : undefined);
// submit comment
$("#commentValidate").keypress(function (event) {
if (event.keyCode === 13) {
that.submitComment();
}
});
$("#comment").keypress(function (event) {
if (event.keyCode === 13 && event.ctrlKey) {
that.submitComment();
}
});
// captcha
$("#captcha").click(function () {
$(this).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
});
// cookie
if (!Util.isLoggedIn()) {
$("#commentEmail").val(Cookie.readCookie("commentEmail"));
$("#commentURL").val(Cookie.readCookie("commentURL"));
$("#commentName").val(Cookie.readCookie("commentName"));
$("#comment").keypress(function (event) {
if (event.keyCode === 13 && event.ctrlKey) {
that.submitComment();
}
});
// captcha
$("#captcha").click(function () {
$(this).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
});
// cookie
if (!Util.isLoggedIn()) {
$("#commentEmail").val(Cookie.readCookie("commentEmail"));
$("#commentURL").val(Cookie.readCookie("commentURL"));
$("#commentName").val(Cookie.readCookie("commentName"));
}
// if no JSON, add it.
try {
JSON
} catch (e) {
document.write("<script src=\"" + latkeConfig.staticServePath + "/js/lib/json2.js\"><\/script>");
}
Util.parseMarkdown();
},
/*
* @description 加载随机文章
* @param {String} headTitle 随机文章标题
*/
loadRandomArticles: function (headTitle) {
var randomArticles1Label = this.tips.randomArticles1Label;
// getRandomArticles
$.ajax({
url: latkeConfig.servePath + "/get-random-articles.do",
type: "POST",
success: function (result, textStatus) {
var randomArticles = result.randomArticles;
if (!randomArticles || 0 === randomArticles.length) {
$("#randomArticles").remove();
return;
}
// if no JSON, add it.
try {
JSON
} catch (e) {
document.write("<script src=\"" + latkeConfig.staticServePath + "/js/lib/json2.js\"><\/script>");
var listHtml = "";
for (var i = 0; i < randomArticles.length; i++) {
var article = randomArticles[i];
var title = article.articleTitle;
var randomArticleLiHtml = "<li>" + "<a rel='nofollow' title='" + title + "' href='" + latkeConfig.servePath +
article.articlePermalink + "'>" + title + "</a></li>";
listHtml += randomArticleLiHtml;
}
},
/*
* @description 加载随机文章
* @param {String} headTitle 随机文章标题
*/
loadRandomArticles: function (headTitle) {
var randomArticles1Label = this.tips.randomArticles1Label;
// getRandomArticles
$.ajax({
url: latkeConfig.servePath + "/get-random-articles.do",
type: "POST",
success: function (result, textStatus) {
var randomArticles = result.randomArticles;
if (!randomArticles || 0 === randomArticles.length) {
$("#randomArticles").remove();
return;
}
var titleHTML = headTitle ? headTitle : "<h4>" + randomArticles1Label + "</h4>";
var randomArticleListHtml = titleHTML + "<ul class='marginLeft12'>" + listHtml + "</ul>";
$("#randomArticles").append(randomArticleListHtml);
}
});
},
/*
* @description 加载相关文章
* @param {String} id 文章 id
* @param {String} headTitle 相关文章标题
*/
loadRelevantArticles: function (id, headTitle) {
$.ajax({
url: latkeConfig.servePath + "/article/id/" + id + "/relevant/articles",
type: "GET",
success: function (data, textStatus) {
var articles = data.relevantArticles;
if (!articles || 0 === articles.length) {
$("#relevantArticles").remove();
return;
}
var listHtml = "";
for (var i = 0; i < articles.length; i++) {
var article = articles[i];
var title = article.articleTitle;
var articleLiHtml = "<li>"
+ "<a rel='nofollow' title='" + title + "' href='" + latkeConfig.servePath + article.articlePermalink + "'>"
+ title + "</a></li>"
listHtml += articleLiHtml
}
var listHtml = "";
for (var i = 0; i < randomArticles.length; i++) {
var article = randomArticles[i];
var title = article.articleTitle;
var randomArticleLiHtml = "<li>" + "<a rel='nofollow' title='" + title + "' href='" + latkeConfig.servePath +
article.articlePermalink + "'>" + title + "</a></li>";
listHtml += randomArticleLiHtml;
}
var relevantArticleListHtml = headTitle
+ "<ul class='marginLeft12'>"
+ listHtml + "</ul>";
$("#relevantArticles").append(relevantArticleListHtml);
},
error: function () {
$("#relevantArticles").remove();
}
});
},
/*
* @description 加载站外相关文章
* @param {String} tags 文章 tags
* @param {String} headTitle 站外相关文章标题
*/
loadExternalRelevantArticles: function (tags, headTitle) {
var tips = this.tips;
try {
$.ajax({
url: "https://rhythm.b3log.org/get-articles-by-tags.do?tags=" + tags
+ "&blogHost=" + tips.blogHost + "&paginationPageSize=" + tips.externalRelevantArticlesDisplayCount,
type: "GET",
cache: true,
dataType: "jsonp",
error: function () {
$("#externalRelevantArticles").remove();
},
success: function (data, textStatus) {
var articles = data.articles;
if (!articles || 0 === articles.length) {
$("#externalRelevantArticles").remove();
return;
}
var listHtml = "";
for (var i = 0; i < articles.length; i++) {
var article = articles[i];
var title = article.articleTitle;
var articleLiHtml = "<li>"
+ "<a rel='nofollow' title='" + title + "' target='_blank' href='" + article.articlePermalink + "'>"
+ title + "</a></li>"
listHtml += articleLiHtml
}
var titleHTML = headTitle ? headTitle : "<h4>" + randomArticles1Label + "</h4>";
var randomArticleListHtml = titleHTML + "<ul class='marginLeft12'>" + listHtml + "</ul>";
$("#randomArticles").append(randomArticleListHtml);
}
});
},
/*
* @description 加载相关文章
* @param {String} id 文章 id
* @param {String} headTitle 相关文章标题
*/
loadRelevantArticles: function (id, headTitle) {
$.ajax({
url: latkeConfig.servePath + "/article/id/" + id + "/relevant/articles",
type: "GET",
success: function (data, textStatus) {
var articles = data.relevantArticles;
if (!articles || 0 === articles.length) {
$("#relevantArticles").remove();
return;
}
var listHtml = "";
for (var i = 0; i < articles.length; i++) {
var article = articles[i];
var title = article.articleTitle;
var articleLiHtml = "<li>"
+ "<a rel='nofollow' title='" + title + "' href='" + latkeConfig.servePath + article.articlePermalink + "'>"
+ title + "</a></li>"
listHtml += articleLiHtml
}
var titleHTML = headTitle ? headTitle : "<h4>" + tips.externalRelevantArticles1Label + "</h4>";
var randomArticleListHtml = titleHTML
+ "<ul class='marginLeft12'>"
+ listHtml + "</ul>";
$("#externalRelevantArticles").append(randomArticleListHtml);
}
});
} catch (e) {
// 忽略相关文章加载异常:load script error
}
},
/*
* @description 提交评论
* @param {String} commentId 回复评论时的评论 id
* @param {String} state 区分回复文章还是回复评论的标识
*/
submitComment: function (commentId, state) {
if (!state) {
state = '';
}
var that = this,
tips = this.tips,
type = "article";
if (tips.externalRelevantArticlesDisplayCount === undefined) {
type = "page";
}
var relevantArticleListHtml = headTitle
+ "<ul class='marginLeft12'>"
+ listHtml + "</ul>";
$("#relevantArticles").append(relevantArticleListHtml);
},
error: function () {
$("#relevantArticles").remove();
}
});
},
/*
* @description 加载站外相关文章
* @param {String} tags 文章 tags
* @param {String} headTitle 站外相关文章标题
*/
loadExternalRelevantArticles: function (tags, headTitle) {
var tips = this.tips;
try {
$.ajax({
url: "https://rhythm.b3log.org/get-articles-by-tags.do?tags=" + tags
+ "&blogHost=" + tips.blogHost + "&paginationPageSize=" + tips.externalRelevantArticlesDisplayCount,
type: "GET",
cache: true,
dataType: "jsonp",
error: function () {
$("#externalRelevantArticles").remove();
},
success: function (data, textStatus) {
var articles = data.articles;
if (!articles || 0 === articles.length) {
$("#externalRelevantArticles").remove();
return;
}
var listHtml = "";
for (var i = 0; i < articles.length; i++) {
var article = articles[i];
var title = article.articleTitle;
var articleLiHtml = "<li>"
+ "<a rel='nofollow' title='" + title + "' target='_blank' href='" + article.articlePermalink + "'>"
+ title + "</a></li>"
listHtml += articleLiHtml
}
if (this.validateComment(state)) {
$("#submitCommentButton" + state).attr("disabled", "disabled");
$("#commentErrorTip" + state).show().html(this.tips.loadingLabel);
var requestJSONObject = {
"oId": tips.oId,
"commentContent": $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, "")
};
var titleHTML = headTitle ? headTitle : "<h4>" + tips.externalRelevantArticles1Label + "</h4>";
var randomArticleListHtml = titleHTML
+ "<ul class='marginLeft12'>"
+ listHtml + "</ul>";
$("#externalRelevantArticles").append(randomArticleListHtml);
}
});
} catch (e) {
// 忽略相关文章加载异常:load script error
}
},
/*
* @description 提交评论
* @param {String} commentId 回复评论时的评论 id
* @param {String} state 区分回复文章还是回复评论的标识
*/
submitComment: function (commentId, state) {
if (!state) {
state = '';
}
var that = this,
tips = this.tips,
type = "article";
if (tips.externalRelevantArticlesDisplayCount === undefined) {
type = "page";
}
if (!Util.isLoggedIn()) {
requestJSONObject = {
"oId": tips.oId,
"commentContent": $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, ""),
"commentEmail": $("#commentEmail" + state).val(),
"commentURL": Util.proessURL($("#commentURL" + state).val().replace(/(^\s*)|(\s*$)/g, "")),
"commentName": $("#commentName" + state).val().replace(/(^\s*)|(\s*$)/g, ""),
"captcha": $("#commentValidate" + state).val()
};
Cookie.createCookie("commentName", requestJSONObject.commentName, 365);
Cookie.createCookie("commentEmail", requestJSONObject.commentEmail, 365);
Cookie.createCookie("commentURL", $("#commentURL" + state).val().replace(/(^\s*)|(\s*$)/g, ""), 365);
}
if (this.validateComment(state)) {
$("#submitCommentButton" + state).attr("disabled", "disabled");
$("#commentErrorTip" + state).show().html(this.tips.loadingLabel);
var requestJSONObject = {
"oId": tips.oId,
"commentContent": $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, "")
};
if (state === "Reply") {
requestJSONObject.commentOriginalCommentId = commentId;
}
$.ajax({
type: "POST",
url: latkeConfig.servePath + "/add-" + type + "-comment.do",
cache: false,
contentType: "application/json",
data: JSON.stringify(requestJSONObject),
success: function (result) {
$("#submitCommentButton" + state).removeAttr("disabled");
if (!result.sc) {
$("#commentErrorTip" + state).html(result.msg);
$("#commentValidate" + state).val('');
$("#captcha" + state).click();
if (!Util.isLoggedIn()) {
requestJSONObject = {
"oId": tips.oId,
"commentContent": $("#comment" + state).val().replace(/(^\s*)|(\s*$)/g, ""),
"commentEmail": $("#commentEmail" + state).val(),
"commentURL": Util.proessURL($("#commentURL" + state).val().replace(/(^\s*)|(\s*$)/g, "")),
"commentName": $("#commentName" + state).val().replace(/(^\s*)|(\s*$)/g, ""),
"captcha": $("#commentValidate" + state).val()
};
Cookie.createCookie("commentName", requestJSONObject.commentName, 365);
Cookie.createCookie("commentEmail", requestJSONObject.commentEmail, 365);
Cookie.createCookie("commentURL", $("#commentURL" + state).val().replace(/(^\s*)|(\s*$)/g, ""), 365);
$("#captcha" + state).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
}
if (state === "Reply") {
requestJSONObject.commentOriginalCommentId = commentId;
}
$.ajax({
type: "POST",
url: latkeConfig.servePath + "/add-" + type + "-comment.do",
cache: false,
contentType: "application/json",
data: JSON.stringify(requestJSONObject),
success: function (result) {
$("#submitCommentButton" + state).removeAttr("disabled");
if (!result.sc) {
$("#commentErrorTip" + state).html(result.msg);
$("#commentValidate" + state).val('');
$("#captcha" + state).click();
if (!Util.isLoggedIn()) {
$("#captcha" + state).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
}
return;
}
$("#comment" + state).val(result.commentContent); // Server processed XSS
$("#commentName" + state).val(result.commentName); // Server processed XSS
return;
}
result.replyNameHTML = "";
if (!Util.isLoggedIn()) {
$("#captcha" + state).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
if ($("#commentURL" + state).val().replace(/\s/g, "") === "") {
result.replyNameHTML = '<a>' + $("#commentName" + state).val() + '</a>';
} else {
result.replyNameHTML = '<a href="' + Util.proessURL($("#commentURL" + state).val()) +
'" target="_blank">' + $("#commentName" + state).val() + '</a>';
}
result.userName = result.commentName;
} else {
result.replyNameHTML = '<a href="' + window.location.host +
'" target="_blank">' + Util.getUserName() + '</a>';
result.userName = Util.getUserName();
}
$("#comment" + state).val(result.commentContent); // Server processed XSS
$("#commentName" + state).val(result.commentName); // Server processed XSS
that.addCommentAjax(Util.replaceEmString(result.cmtTpl), state);
}
});
}
},
/*
* @description 添加回复评论表单
* @param {String} id 被回复的评论 id
* @param {String} commentFormHTML 评论表单HTML
* @param {String} endHTML 判断该表单使用 table 还是 div 标签,然后进行构造
*/
addReplyForm: function (id, commentFormHTML, endHTML) {
var that = this;
if (id === this.currentCommentId) {
if ($("#commentNameReply").val() === "") {
$("#commentNameReply").focus();
} else if ($("#commentEmailReply").val() === "") {
$("#commentEmailReply").focus();
result.replyNameHTML = "";
if (!Util.isLoggedIn()) {
$("#captcha" + state).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
if ($("#commentURL" + state).val().replace(/\s/g, "") === "") {
result.replyNameHTML = '<a>' + $("#commentName" + state).val() + '</a>';
} else {
$("#commentReply").focus();
result.replyNameHTML = '<a href="' + Util.proessURL($("#commentURL" + state).val()) +
'" target="_blank">' + $("#commentName" + state).val() + '</a>';
}
return;
}
$("#replyForm").remove();
endHTML = endHTML ? endHTML : "";
if (endHTML === "</div>") {
$("#" + id).append(commentFormHTML + $("#commentForm").html() + endHTML);
} else {
$("#" + id).append(commentFormHTML + $("#commentForm").html() + "</table>" + endHTML);
}
result.userName = result.commentName;
} else {
result.replyNameHTML = '<a href="' + window.location.host +
'" target="_blank">' + Util.getUserName() + '</a>';
result.userName = Util.getUserName();
}
// change id, bind event and set value
$("#replyForm input, #replyForm textarea").each(function () {
this.id = this.id + "Reply";
});
$("#commentNameReply").val(Cookie.readCookie("commentName"));
$("#commentEmailReply").val(Cookie.readCookie("commentEmail"));
var $label = $("#replyForm #commentURLLabel");
if ($label.length === 1) {
$label.attr("id", "commentURLLabelReply");
that.addCommentAjax(Util.replaceEmString(result.cmtTpl), state);
}
});
}
},
/*
* @description 添加回复评论表单
* @param {String} id 被回复的评论 id
* @param {String} commentFormHTML 评论表单HTML
* @param {String} endHTML 判断该表单使用 table 还是 div 标签,然后进行构造
*/
addReplyForm: function (id, commentFormHTML, endHTML) {
var that = this;
if (id === this.currentCommentId) {
if ($("#commentNameReply").val() === "") {
$("#commentNameReply").focus();
} else if ($("#commentEmailReply").val() === "") {
$("#commentEmailReply").focus();
} else {
$("#commentReply").focus();
}
return;
}
$("#replyForm").remove();
endHTML = endHTML ? endHTML : "";
if (endHTML === "</div>") {
$("#" + id).append(commentFormHTML + $("#commentForm").html() + endHTML);
} else {
$("#" + id).append(commentFormHTML + $("#commentForm").html() + "</table>" + endHTML);
}
$("#commentURLReply").val(Cookie.readCookie("commentURL"));
$("#replyForm #emotions").attr("id", "emotionsReply");
this.insertEmotions("Reply");
$("#commentReply").unbind().keypress(function (event) {
if (event.keyCode === 13 && event.ctrlKey) {
that.submitComment(id, 'Reply');
event.preventDefault();
}
});
$("#commentValidateReply").unbind().keypress(function (event) {
if (event.keyCode === 13) {
that.submitComment(id, 'Reply');
event.preventDefault();
}
});
$("#replyForm #captcha").attr("id", "captchaReply").
attr("src", latkeConfig.servePath + "/captcha.do?" + new Date().getTime()).click(function () {
$(this).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
});
$("#replyForm #commentErrorTip").attr("id", "commentErrorTipReply").html("").hide();
$("#replyForm #submitCommentButton").attr("id", "submitCommentButtonReply");
$("#replyForm #submitCommentButtonReply").unbind("click").removeAttr("onclick").click(function () {
that.submitComment(id, 'Reply');
});
if ($("#commentNameReply").val() === "") {
$("#commentNameReply").focus();
} else if ($("#commentEmailReply").val() === "") {
$("#commentEmailReply").focus();
} else {
$("#commentReply").focus();
}
// change id, bind event and set value
$("#replyForm input, #replyForm textarea").each(function () {
this.id = this.id + "Reply";
});
$("#commentNameReply").val(Cookie.readCookie("commentName"));
$("#commentEmailReply").val(Cookie.readCookie("commentEmail"));
var $label = $("#replyForm #commentURLLabel");
if ($label.length === 1) {
$label.attr("id", "commentURLLabelReply");
}
this.currentCommentId = id;
},
/*
* @description 隐藏回复评论的浮出层
* @parma {String} id 被回复的评论 id
*/
hideComment: function (id) {
$("#commentRef" + id).hide();
},
/*
* @description 显示回复评论的浮出层
* @parma {Dom} it 触发事件的 dom
* @param {String} id 被回复的评论 id
* @param {Int} top 位置相对浮出层的高度
* @param {String} [parentTag] it 如果嵌入在 position 为 relative 的元素 A 中时,需取到 A 元素
*/
showComment: function (it, id, top, parentTag) {
var positionTop = parseInt($(it).position().top);
if (parentTag) {
positionTop = parseInt($(it).parents(parentTag).position().top);
}
if ($("#commentRef" + id).length > 0) {
// 此处重复设置 top 是由于评论为异步,原有回复评论的显示位置应往下移动
$("#commentRef" + id).show().css("top", (positionTop + top) + "px");
} else {
var $refComment = $("#" + id).clone();
$refComment.addClass("comment-body-ref").attr("id", "commentRef" + id);
$refComment.find("#replyForm").remove();
$("#comments").append($refComment);
$("#commentRef" + id).css("top", (positionTop + top) + "px");
}
},
/*
* @description 回复不刷新,将回复内容异步添加到评论列表中
* @parma {String} commentHTML 回复内容 HTML
* @param {String} state 用于区分评论文章还是回复评论
*/
addCommentAjax: function (commentHTML, state) {
if ($("#comments").children().length > 0) {
$($("#comments").children()[0]).before(commentHTML);
} else {
$("#comments").html(commentHTML);
}
$("#commentURLReply").val(Cookie.readCookie("commentURL"));
$("#replyForm #emotions").attr("id", "emotionsReply");
this.insertEmotions("Reply");
$("#commentReply").unbind().keypress(function (event) {
if (event.keyCode === 13 && event.ctrlKey) {
that.submitComment(id, 'Reply');
event.preventDefault();
}
});
$("#commentValidateReply").unbind().keypress(function (event) {
if (event.keyCode === 13) {
that.submitComment(id, 'Reply');
event.preventDefault();
}
});
$("#replyForm #captcha").attr("id", "captchaReply").attr("src", latkeConfig.servePath + "/captcha.do?" + new Date().getTime()).click(function () {
$(this).attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
});
$("#replyForm #commentErrorTip").attr("id", "commentErrorTipReply").html("").hide();
$("#replyForm #submitCommentButton").attr("id", "submitCommentButtonReply");
$("#replyForm #submitCommentButtonReply").unbind("click").removeAttr("onclick").click(function () {
that.submitComment(id, 'Reply');
});
if ($("#commentNameReply").val() === "") {
$("#commentNameReply").focus();
} else if ($("#commentEmailReply").val() === "") {
$("#commentEmailReply").focus();
} else {
$("#commentReply").focus();
}
if (state === "") {
$("#commentErrorTip").html("").hide();
$("#comment").val("");
$("#commentValidate").val("");
$("#captcha").attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
} else {
$("#replyForm").remove();
}
window.location.hash = "#comments";
this.currentCommentId = id;
},
/*
* @description 隐藏回复评论的浮出层
* @parma {String} id 被回复的评论 id
*/
hideComment: function (id) {
$("#commentRef" + id).hide();
},
/*
* @description 显示回复评论的浮出层
* @parma {Dom} it 触发事件的 dom
* @param {String} id 被回复的评论 id
* @param {Int} top 位置相对浮出层的高度
* @param {String} [parentTag] it 如果嵌入在 position 为 relative 的元素 A 中时,需取到 A 元素
*/
showComment: function (it, id, top, parentTag) {
var positionTop = parseInt($(it).position().top);
if (parentTag) {
positionTop = parseInt($(it).parents(parentTag).position().top);
}
if ($("#commentRef" + id).length > 0) {
// 此处重复设置 top 是由于评论为异步,原有回复评论的显示位置应往下移动
$("#commentRef" + id).show().css("top", (positionTop + top) + "px");
} else {
var $refComment = $("#" + id).clone();
$refComment.addClass("comment-body-ref").attr("id", "commentRef" + id);
$refComment.find("#replyForm").remove();
$("#comments").append($refComment);
$("#commentRef" + id).css("top", (positionTop + top) + "px");
}
},
/*
* @description 回复不刷新,将回复内容异步添加到评论列表中
* @parma {String} commentHTML 回复内容 HTML
* @param {String} state 用于区分评论文章还是回复评论
*/
addCommentAjax: function (commentHTML, state) {
if ($("#comments").children().length > 0) {
$($("#comments").children()[0]).before(commentHTML);
} else {
$("#comments").html(commentHTML);
}
if (state === "") {
$("#commentErrorTip").html("").hide();
$("#comment").val("");
$("#commentValidate").val("");
$("#captcha").attr("src", latkeConfig.servePath + "/captcha.do?code=" + Math.random());
} else {
$("#replyForm").remove();
}
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