Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.92 KB | None | 0 0
  1. //functions
  2. (function(){
  3. 'use strict';
  4. var shareMenu = function(){
  5. $(document).on('click','.Share',function(){
  6. $('.share-wrap').fadeToggle('slow');
  7. });
  8. }
  9. var sidebaraffix = function(){
  10. if($('#sidebar').height()&&xb.site_sh){
  11. if($('#main').height()>$('#sidebar').height()){
  12. var footerHeight = 0;
  13. if($('#page-footer').length>0){
  14. footerHeight = $('#page-footer').outerHeight(true);
  15. }
  16. $('#sidebar').affix({
  17. offset:{
  18. top:$('#sidebar').offset().top-xb.site_sh,
  19. bottom:$('#footer').outerHeight(true)+footerHeight+6
  20. }
  21. });
  22. }
  23. }
  24. }
  25. var toSearch = function(){
  26. $('.search-box').on('click',function(e){
  27. $('#searchform').animate({width:'200px'},200),
  28. $('#searchform input').css('display','block');
  29. $(document).one('click', function(){
  30. $('#searchform').animate({width:'0'},100),
  31. $('#searchform input').hide();
  32. });
  33. e.stopPropagation();
  34. });
  35. $('#searchform').on('click',function(e){e.stopPropagation();})
  36. }
  37. var showlove = function(){
  38. $.fn.postLike = function(){
  39. if($(this).hasClass('done')){
  40. layer.msg('您已經支持過了',function(){});
  41. return false;
  42. }else{
  43. $(this).addClass('done');
  44. layer.msg('感謝您的支持');
  45. var id = $(this).data('id'),
  46. action = $(this).data('action'),
  47. rateHolder = $(this).children('.count');
  48. var ajax_data = {
  49. action:'love',
  50. um_id:id,
  51. um_action:action
  52. };
  53. $.post(xb.ajax_url,ajax_data,function(data){
  54. $(rateHolder).html(data);
  55. });
  56. return false;
  57. }
  58. };
  59. $(document).on('click','.Love',function(){$(this).postLike();});
  60. }
  61. var gotop = function(){
  62. $('.gotop-box').on('click',function(event){
  63. event.preventDefault();
  64. $('html, body').animate({
  65. scrollTop:$('html').offset().top
  66. },500);
  67. return false;
  68. });
  69. $(window).scroll(function(){
  70. var $win = $(window);
  71. if ($win.scrollTop()>200){
  72. $('.gotop-box').addClass('active');
  73. }else{
  74. $('.gotop-box').removeClass('active');
  75. }
  76. });
  77. }
  78. var wechatpic = function(){
  79. $('#wechat-img').mouseout(function(){
  80. $('#wechat-pic')[0].style.display = 'none';
  81. })
  82. $('#wechat-img').mouseover(function(){
  83. $('#wechat-pic')[0].style.display = 'block';
  84. })
  85. }
  86. var showPhotos = function(){
  87. layer.photos({
  88. photos:'.kratos-post-content p,.kratos-status-post p',
  89. anim: 0
  90. });
  91. }
  92. var offcanvas = function(){
  93. var $clone = $('#kratos-menu-wrap').clone();
  94. $clone.attr({
  95. 'id':'offcanvas-menu'
  96. });
  97. $clone.find('> ul').attr({
  98. 'class':'ul-me',
  99. 'id':''
  100. });
  101. $('#kratos-page').prepend($clone);
  102. $('.js-kratos-nav-toggle').on('click',function(){
  103. if($('.nav-toggle').hasClass('toon')){
  104. $('.nav-toggle').removeClass('toon');
  105. $('#offcanvas-menu').css('right','-240px');
  106. }else{
  107. $('.nav-toggle').addClass('toon');
  108. $('#offcanvas-menu').css('right','0px');
  109. }
  110. });
  111. $('#offcanvas-menu a').on('click',function(){
  112. $('.nav-toggle').removeClass('toon');
  113. $('#offcanvas-menu').css('right','-240px');
  114. });
  115. $('#offcanvas-menu').css('height',$(window).height());
  116. $('#offcanvas-menu').css('right','-240px');
  117. $(window).resize(function(){
  118. var w = $(window);
  119. $('#offcanvas-menu').css('height',w.height());
  120. if(w.width()>769){
  121. if($('.nav-toggle').hasClass('toon')){
  122. $('.nav-toggle').removeClass('toon');
  123. $('#offcanvas-menu').css('right','-240px');
  124. }
  125. }
  126. });
  127. }
  128. var menu = function(){
  129. $(document).click(function(e){
  130. var container = $('#offcanvas-menu,.js-kratos-nav-toggle');
  131. if(!container.is(e.target)&&container.has(e.target).length===0){
  132. if($('.nav-toggle').hasClass('toon')){
  133. $('.nav-toggle').removeClass('toon');
  134. $('#offcanvas-menu').css('right','-240px');
  135. }
  136. }
  137. });
  138. $('#kratos-header-section:not(.color-banner) ul>li').hover(function(){
  139. $(this).children('ul').slideDown(150)
  140. },function(){$(this).children('ul').stop(true,false).slideUp(200)});
  141. }
  142. var xControl = function(){
  143. $(document).on('click','.xHeading',function(event){
  144. var $this = $(this);
  145. $this.closest('.xControl').find('.xContent').slideToggle(300);
  146. if ($this.closest('.xControl').hasClass('active')){
  147. $this.closest('.xControl').removeClass('active');
  148. }else{
  149. $this.closest('.xControl').addClass('active');
  150. }
  151. event.preventDefault();
  152. });
  153. }
  154. var donateConfig = function(){
  155. $(document).on('click','.Donate',function(){
  156. layer.open({
  157. type:1,
  158. area:['300px', '370px'],
  159. title:'打賞作者',
  160. resize:false,
  161. scrollbar:false,
  162. content:'<div class="donate-box"><div class="meta-pay text-center"><strong>掃一掃支付</strong></div><div class="qr-pay text-center"><img class="pay-img" id="alipay_qr" src="'+xb.alipay+'"><img class="pay-img d-none" id="wechat_qr" src="'+xb.wechat+'"></div><div class="choose-pay text-center mt-2"><input id="alipay" type="radio" name="pay-method" checked><label for="alipay" class="pay-button"><img src="'+xb.thome+'/static/images/alipay.png"></label><input id="wechatpay" type="radio" name="pay-method"><label for="wechatpay" class="pay-button"><img src="'+xb.thome+'/static/images/wechat.png"></label></div></div>'
  163. });
  164. $('.choose-pay input[type="radio"]').click(function(){
  165. var id= $(this).attr('id');
  166. if(id=='alipay'){$('.qr-pay #alipay_qr').removeClass('d-none');$('.qr-pay #wechat_qr').addClass('d-none')};
  167. if(id=='wechatpay'){$('.qr-pay #alipay_qr').addClass('d-none');$('.qr-pay #wechat_qr').removeClass('d-none')};
  168. });
  169. });
  170. }
  171. var OwOcfg = function(){
  172. if($('#commentform').height()){
  173. var OwO_demo = new OwO({
  174. logo:'OωO表情',
  175. container:document.getElementsByClassName('OwO')[0],
  176. target:document.getElementsByClassName('OwO')[0],
  177. api:xb.thome+'/inc/OwO.json',
  178. position:'down',
  179. width:'90%',
  180. maxHeight:'250px'
  181. });
  182. }
  183. }
  184. var APF = function(){
  185. var $this = $('#ap-footer');
  186. $.ajax({
  187. url:$this.attr('data-json'),
  188. success:function(e){
  189. var a = new APlayer({
  190. element:document.getElementById('ap-footer'),
  191. autoplay:$this.attr('data-autoplay'),
  192. fixed:true,
  193. loop:$this.attr('data-loop'),
  194. order:$this.attr('data-order'),
  195. listFolded:true,
  196. showlrc:3,
  197. theme:'#e6d0b2',
  198. listmaxheight:'200px',
  199. music:eval(e)
  200. });
  201. window.aplayers || (window.aplayers = []),
  202. window.aplayers.push(a)
  203. }
  204. })
  205. }
  206. var SnowF = function(){
  207. var requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(callback){window.setTimeout(callback,1000/60);};
  208. window.requestAnimationFrame=requestAnimationFrame;
  209. var flakes=[],canvas=document.getElementById("Snow"),ctx=canvas.getContext("2d"),flakeCount=parseInt($('#Snow').attr('data-count')),mX=-100,mY=-100;
  210. canvas.width=window.innerWidth;
  211. canvas.height=window.innerHeight;
  212. function snow(){
  213. ctx.clearRect(0,0,canvas.width,canvas.height);
  214. for(var i=0;i<flakeCount;i++){
  215. var flake=flakes[i],x=mX,y=mY,minDist=parseInt($('#Snow').attr('data-dist')),x2=flake.x,y2=flake.y;
  216. var dist=Math.sqrt((x2-x)*(x2-x)+(y2-y)*(y2-y)),dx=x2-x,dy=y2-y;
  217. if(dist<minDist){
  218. var force=minDist/(dist*dist),xcomp=(x-x2)/dist,ycomp=(y-y2)/dist,deltaV=force/2;
  219. flake.velX-=deltaV*xcomp;
  220. flake.velY-=deltaV*ycomp;
  221. }else{
  222. flake.velX*=0.98;
  223. if(flake.velY<=flake.speed){flake.velY = flake.speed;}
  224. flake.velX+=Math.cos(flake.step+=.05)*flake.stepSize;
  225. }
  226. ctx.fillStyle="rgba("+$('#Snow').attr('data-color')+","+flake.opacity+")";
  227. flake.y+=flake.velY;
  228. flake.x+=flake.velX;
  229. if(flake.y>=canvas.height||flake.y<=0){reset(flake);}
  230. if(flake.x>=canvas.width||flake.x<=0){reset(flake);}
  231. ctx.beginPath();
  232. ctx.arc(flake.x,flake.y,flake.size,0,Math.PI*2);
  233. ctx.fill();
  234. }
  235. requestAnimationFrame(snow);
  236. };
  237. function reset(flake){
  238. flake.x=Math.floor(Math.random()*canvas.width);
  239. flake.y=0;
  240. flake.size=(Math.random()*3)+parseInt($('#Snow').attr('data-size'));
  241. flake.speed=(Math.random()*1)+parseInt($('#Snow').attr('data-speed'));
  242. flake.velY=flake.speed;
  243. flake.velX=0;
  244. flake.opacity=(Math.random()*0.5)+parseInt($('#Snow').attr('data-opacity'));
  245. }
  246. function init(){
  247. for(var i=0;i<flakeCount;i++){
  248. var x=Math.floor(Math.random()*canvas.width),y=Math.floor(Math.random()*canvas.height),size=(Math.random()*3)+parseInt($('#Snow').attr('data-size')),speed=(Math.random()*1)+parseInt($('#Snow').attr('data-speed')),opacity=(Math.random()*0.5)+parseInt($('#Snow').attr('data-opacity'));
  249. flakes.push({speed:speed,velY:speed,velX:0,x:x,y:y,size:size,stepSize:(Math.random())/30*parseInt($('#Snow').attr('data-step')),step:0,angle:180,opacity:opacity});
  250. }
  251. snow();
  252. };
  253. document.addEventListener('mousemove',function(e){mX=e.clientX,mY=e.clientY});
  254. window.addEventListener('resize',function(){canvas.width=window.innerWidth;canvas.height=window.innerHeight;});
  255. init();
  256. }
  257. //pjax reload
  258. $.fn.kratos_pjax_reload = function(){
  259. sidebaraffix();
  260. showPhotos();
  261. OwOcfg();
  262. }
  263. $(function(){
  264. gotop();
  265. sidebaraffix();
  266. offcanvas();
  267. menu();
  268. toSearch();
  269. xControl();
  270. showPhotos();
  271. donateConfig();
  272. showlove();
  273. shareMenu();
  274. OwOcfg();
  275. wechatpic();
  276. if($('div').hasClass('aplayer-footer')) APF();
  277. if($('div').hasClass('xb-snow')) SnowF();
  278. });
  279. }());
  280. //comment ajax
  281. $('body').on('click','.comment-reply-link',function(){
  282. if($(this).attr('onclick')) return;
  283. addComment.moveForm($(this).attr('data-belowelement'),$(this).attr('data-commentid'),$(this).attr('data-respondelement'),$(this).attr('data-postid'));
  284. return false;
  285. });
  286. jQuery(document).ready(function(jQuery) {
  287. var __cancel = jQuery('#cancel-comment-reply-link'),
  288. __cancel_text = __cancel.text(),
  289. __list = 'comment-list';
  290. jQuery(document).on('submit','#commentform',function(){
  291. jQuery.ajax({
  292. url:xb.ajax_url,
  293. data:jQuery(this).serialize()+'&action=ajax_comment',
  294. type:jQuery(this).attr('method'),
  295. beforeSend:addComment.createButterbar('正在提交'),
  296. error:function(request){
  297. var t = addComment;
  298. t.createButterbar(request.responseText)
  299. },
  300. success:function(data){
  301. jQuery('textarea').each(function(){this.value = ''});
  302. var t = addComment,cancel = t.I('cancel-comment-reply-link'),temp = t.I('wp-temp-form-div'),respond = t.I(t.respondId),post = t.I('comment_post_ID').value,parent = t.I('comment_parent').value;
  303. if(parent!='0'){
  304. jQuery('#respond').before('<ol class="children">'+data+'</ol>')
  305. }else if(!jQuery('.'+__list).length){
  306. jQuery('#comments-nav').before('<ol class="'+__list+'">'+data+'</ol>')
  307. }else{
  308. if(xb.order=='asc'){
  309. jQuery('.'+__list).append(data)
  310. }else{
  311. jQuery('.'+__list).prepend(data)
  312. }
  313. }
  314. t.createButterbar('提交成功');
  315. cancel.style.display = 'none';
  316. cancel.onclick = null;
  317. t.I('comment_parent').value = '0';
  318. if(temp&&respond){
  319. temp.parentNode.insertBefore(respond,temp);
  320. temp.parentNode.removeChild(temp)
  321. }
  322. }
  323. });
  324. return false
  325. });
  326. addComment = {
  327. moveForm:function(commId,parentId,respondId){
  328. var t = this,div,comm = t.I(commId),respond = t.I(respondId),cancel = t.I('cancel-comment-reply-link'),parent = t.I('comment_parent'),post = t.I('comment_post_ID');
  329. __cancel.text(__cancel_text);
  330. t.respondId = respondId;
  331. if(!t.I('wp-temp-form-div')){
  332. div = document.createElement('div');
  333. div.id = 'wp-temp-form-div';
  334. div.style.display = 'none';
  335. respond.parentNode.insertBefore(div,respond)
  336. }!comm?(temp = t.I('wp-temp-form-div'),t.I('comment_parent').value = '0',temp.parentNode.insertBefore(respond,temp),temp.parentNode.removeChild(temp)):comm.parentNode.insertBefore(respond,comm.nextSibling);
  337. jQuery('body').animate({
  338. scrollTop:jQuery('#respond').offset().top-180
  339. },400);
  340. parent.value = parentId;
  341. cancel.style.display = '';
  342. cancel.onclick = function(){
  343. var t = addComment,temp = t.I('wp-temp-form-div'),respond = t.I(t.respondId);
  344. t.I('comment_parent').value = '0';
  345. if(temp&&respond){
  346. temp.parentNode.insertBefore(respond,temp);
  347. temp.parentNode.removeChild(temp)
  348. }
  349. this.style.display = 'none';
  350. this.onclick = null;
  351. return false
  352. };
  353. try{t.I('comment').focus()}catch(e){}
  354. return false
  355. },
  356. I:function(e){
  357. return document.getElementById(e)
  358. },
  359. createButterbar:function(message){
  360. var t = this;
  361. layer.msg(message)
  362. }
  363. }
  364. });
  365. //highlight
  366. hljs.initHighlightingOnLoad();
  367. //time
  368. var now = new Date();
  369. function createtime(){
  370. var grt = new Date(xb.ctime);
  371. now.setTime(now.getTime()+250);
  372. days = (now-grt)/1000/60/60/24;dnum = Math.floor(days);
  373. hours = (now-grt)/1000/60/60-(24*dnum);hnum = Math.floor(hours);
  374. if(String(hnum).length==1){hnum = '0'+hnum;}
  375. minutes = (now-grt)/1000/60-(24*60*dnum)-(60*hnum);mnum = Math.floor(minutes);
  376. if(String(mnum).length==1){mnum = '0'+mnum;}
  377. seconds = (now-grt)/1000-(24*60*60*dnum)-(60*60*hnum)-(60*mnum);snum = Math.round(seconds);
  378. if(String(snum).length==1){snum = '0'+snum;}
  379. document.getElementById('span_dt_dt').innerHTML = dnum+'天'+hnum+'小時'+mnum+'分'+snum+'秒';
  380. }
  381. setInterval('createtime()',250);
  382. //copy
  383. if(xb.copy) document.body.oncopy=function(){alert('已複製');}
  384. //console
  385. window.onload = function(){
  386. var now = new Date().getTime();
  387. var page_load_time = now-performance.timing.navigationStart;
  388. console.clear();
  389. console.log('https://github.com/xb2016/kratos-pjax');
  390. console.log('%cmoedog.org','font-size:2em');
  391. console.log('%c頁面載入完畢消耗了'+Math.round(performance.now()*100)/100+'ms','background:#fff;color:#333;text-shadow:0 0 2px #eee,0 0 3px #eee,0 0 3px #eee,0 0 2px #eee,0 0 3px #eee;');
  392. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement