18 lines
5.7 KiB
JavaScript

/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
var Util={parseMarkdown:function(e){var t=!1,i=!1;e=e||"article-body";if($("."+e).each(function(){$(this).find("p").each(function(){(-1<$(this).text().indexOf("$\\")||-1<$(this).text().indexOf("$$"))&&(t=!0)}),0<$(this).find("code.lang-flow, code.language-flow").length&&(i=!0)}),t){var n=function(){MathJax.Hub.Config({tex2jax:{inlineMath:[["$","$"],["\\(","\\)"]],displayMath:[["$$","$$"]],processEscapes:!0,processEnvironments:!0,skipTags:["pre","code","script"]}}),MathJax.Hub.Typeset()};"undefined"!=typeof MathJax?n():$.ajax({method:"GET",url:"https://cdn.staticfile.org/MathJax/MathJax-2.6-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&_=1473258780393",dataType:"script",cache:!0}).done(function(){n()})}if(i){var o=function(){$("."+e+" code.lang-flow, ."+e+" code.language-flow").each(function(e){var t=$(this),i="symFlow"+(new Date).getTime()+e;t.hide();var n=flowchart.parse($.trim(t.text()));t.parent().after('<div style="text-align: center" id="'+i+'"></div>'),n.drawSVG(i),t.parent().remove(),$("#"+i).find("svg").height("auto").width("auto")})};"undefined"!=typeof flowchart?o():$.ajax({method:"GET",url:latkeConfig.staticServePath+"/js/lib/flowchart/flowchart.min.js",dataType:"script",cache:!0}).done(function(){o()})}},isLoggedIn:function(){return!!(1===$("#admin").length&&$("#admin").data("login")||"true"===latkeConfig.isLoggedIn)},getUserName:function(){return 1===$("#adminName").length?$("#adminName").text():latkeConfig.userName},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("")},killIE:function(){var e=function(){if(""===Cookie.readCookie("showKill")){var e=($(window).width()-701)/2,t=($(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:"+e+"px;z-index:20;top: "+t+"px; position: fixed; border: 0px none; width: 701px; height: 420px;' src='"+latkeConfig.servePath+"/kill-browser'></iframe>")}};if($.browser.msie){if("6.0"===$.browser.version||"7.0"===$.browser.version)return void e();if(window.external&&window.external.twGetRunPath){var t=external.twGetRunPath();if(t&&-1<t.toLowerCase().indexOf("360se")&&-1<window.location.href.indexOf("admin-index"))return void e()}}},replaceEmString:function(e){var t=e.split("[em");if(1===t.length)return e;e=t[0];for(var i=1;i<t.length;i++){var n=t[i].substr(0,2);e+="<img width='20' src='"+latkeConfig.staticServePath+"/images/emotions/em"+n+".png' alt='"+Label["em"+n+"Label"]+"' title='"+Label["em"+n+"Label"]+"'/> "+t[i].substr(3)}return e},proessURL:function(e){return/^\w+:\/\//.test(e)||(e="http://"+e),e},switchMobile:function(e){Cookie.createCookie("btouch_switch_toggle",e,365),setTimeout(function(){location.reload()},1250)},setTopBar:function(){var e=$("#top");if(1===e.length){var t=$("#showTop");t.click(function(){e.slideDown(),t.hide()}),$("#hideTop").click(function(){e.slideUp(),t.show()})}},goTop:function(){$("html, body").animate({scrollTop:0},500)},goBottom:function(e){e||(e=0);var t=$("body").height()>$(document).height()?$("body").height():$(document).height();$("html, body").animate({scrollTop:t-$(window).height()-e},500)},init:function(){Util.killIE(),Util.setTopBar(),Util.parseMarkdown()},replaceSideEm:function(e){for(var t=0;t<e.length;t++){var i=$(e[t]);i.html(Util.replaceEmString(i.html()))}},buildTags:function(e){e=e||"tags";for(var t=["tags1","tags2","tags3","tags4","tags5"],i=$("#"+e+" b").get(),n=parseInt($("#"+e+" b").last().text()),o=Math.ceil(n/t.length),a=0;a<i.length;a++)for(var r=parseInt(i[a].innerHTML),s=0;s<t.length;s++)if(s*o<r&&r<=(s+1)*o){i[a].parentNode.className=t[s];break}$("#"+e).html($("#"+e+" li").get().sort(function(e,t){var i=$(e).find("span").text().toLowerCase(),n=$(t).find("span").text().toLowerCase();return i.localeCompare(n)}))},toDate:function(e,t){var i=new Date(e),n={"M+":i.getMonth()+1,"d+":i.getDate(),"H+":i.getHours(),"m+":i.getMinutes(),"s+":i.getSeconds(),"q+":Math.floor((i.getMonth()+3)/3),S:i.getMilliseconds()};for(var o in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(i.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+o+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?n[o]:("00"+n[o]).substr((""+n[o]).length)));return t},getWinHeight:function(){return window.innerHeight?window.innerHeight:"CSS1Compat"===document.compatMode?window.document.documentElement.clientHeight:window.document.body.clientHeight}};if(!Cookie)var Cookie={readCookie:function(e){for(var t=e+"=",i=document.cookie.split(";"),n=0;n<i.length;n++){for(var o=i[n];" "==o.charAt(0);)o=o.substring(1,o.length);if(0==o.indexOf(t))return decodeURIComponent(o.substring(t.length,o.length))}return""},eraseCookie:function(e){this.createCookie(e,"",-1)},createCookie:function(e,t,i){var n="";if(i){var o=new Date;o.setTime(o.getTime()+24*i*60*60*1e3),n="; expires="+o.toGMTString()}document.cookie=e+"="+encodeURIComponent(t)+n+"; path=/"}};