var nowpage = 1, perpage = 50, maxpage = 1, orderway, thispage = 1; maxpage = Math.ceil($('#chapterlist li').length/perpage); $(function(){ $('#loadingbg').on('click', function(){ $('#loadingbg').hide(); }); $('.pt-card-7 li').on('click', function(){ var burl = $(this).find('a:eq(0)').attr('href'); if(burl){ window.location.href = burl; } }); $('[rel^=chapterstat]').html(''+nowpage+'/'+maxpage+'椤袋/span>'); $('a .fa-search').on('click', function(){ $('.ptm-search').toggle(); $('.searchinput').focus(); }); $('form[name=searchinline],form[name=searchbtm]').submit(function(){ if(!$(this).children('.searchinput').val()){ alert('璇疯緭鍏ヨ鎼滅储鐨勪綔鍝佸悕鎴栦綔鑰呭悕锛屽畞鍙皯瀛椾笉鑳介敊瀛楀摝锛?); return false; } else { $('#loadingbg').show(); return true; } }); if($('#chapterlist li').length > 0 || $('.searchbtn').length > 0){ $('body').append('
'); } $('[rel^=nextpage]').on('click', function(){ $('#loadingbg').show(); setTimeout("showChapterByPage(nowpage+1)", 1000); }); $('[rel^=prevpage]').on('click', function(){ $('#loadingbg').show(); setTimeout("showChapterByPage(nowpage-1)", 1000); }); $('[rel^=allchapter]').on('click', function(){ if($('#chapterlist').css('height') != 'auto'){ $('#chapterlist').css('height', 'auto'); $('#chapterlist li').show(); $(this).text('閮ㄥ垎'); maxpage = 1; } else { $('#chapterlist').css('height', '1749px'); maxpage = Math.ceil($('#chapterlist li').length/perpage); $(this).text('鍏ㄩ儴'); } }); $('[rel^=reversechapter]').on('click', function(){ $('#loadingbg').show(); if(orderway == 'desc'){ $(this).text('姝e簭'); setTimeout("showChapterByOrder('asc')", 1000); } else { $(this).text('鍊掑簭'); setTimeout("showChapterByOrder('desc')", 1000); } setTimeout("showChapterByPage(1)", 1000); }); $('[rel^=chapterstat]').on('click',function(){ var selhtml = ''; for (var i = 0; i < maxpage; i++) { if(i == nowpage - 1){ var current_li = ' class="active"'; } selhtml += '
  • '+(i * perpage + 1)+'绔 - '+((i + 1) * perpage)+'绔燑/li>'; current_li = ''; } $('.pt-dir-sel ul').html(selhtml); $('.sel').removeClass('ptm-hide'); }) $('.ptm-alert-shade').on('click',function(){ $('.sel').addClass('ptm-hide'); }) $('.pt-dir-sel').on('click', 'li', function(){ thispage = parseInt($(this).data('cpage')); if(thispage != nowpage){ $('.sel').addClass('ptm-hide'); $('#loadingbg').show(); setTimeout("showChapterByPage(thispage)", 1000); } }); if("undefined" != typeof bookid){ setTimeout(updatecache, 2000); } }); function showChapterByPage(page){ if(page > maxpage){ alert('鍒版渶鍚庝竴椤典簡'); showChapterByPage(maxpage); return; } else if(page < 1) { alert('鍒扮涓€椤典簡'); showChapterByPage(1); return; } $('#chapterlist li').each(function(i){ if(i>page*perpage-1 || i<(page-1)*perpage){ $(this).hide(); } else { $(this).show(); } }); nowpage = page; $('[rel^=chapterstat]').html(''+page+'/'+maxpage+'椤袋/span>'); $('#loadingbg').hide(); } function showChapterByOrder(sc){ orderway = sc; $('#chapterlist li').each(function(){ $(this).prependTo('#chapterlist'); }); $('#loadingbg').hide(); } function updatecache(){ $.ajax({ type: 'get', url: '/home/index/updatecache', data: {id: bookid, hash: hash}, dataType: 'json', success: function(data){ if(data.status == 'error'){ layer.open({content: '宸叉槸鏈€鏂扮珷鑺傦紝鏆傛棤鏇存柊锛?,skin: 'msg',time: 2}); } if(data.status == 'success'){ layer.open({content: '鏈€鏂扮珷鑺傛姄鍙栨垚鍔燂紒',skin: 'msg',time: 2}); var newlisthtml=listhtml=''; var chapterhtml = $('#chapterhtml').html(); $.each(data.content, function(i, item){ if(item.title){ listhtml = chapterhtml.replace('{}', ''); listhtml = listhtml.replace('{subid}', Math.floor(item.id/1000)); listhtml = listhtml.replace('{id}', parseInt(item.id) + parseInt(index_rule)); listhtml = listhtml.replace('{cid}', parseInt(item.cid) + parseInt(cindex_rule)); listhtml = listhtml.replace('{dir}', item.cate); listhtml = listhtml.replace('{title}', item.title); newlisthtml += listhtml; } }); $('#newchaperlist').html(newlisthtml); } $('#loading-tip').html(' 鏈哄櫒浜哄凡涓烘偍鎶撳彇鏈€鏂扮珷鑺侟/span>'); $('#loading-tip1').html(' 宸叉槸鏈€鏂?); $('#loading-tip1').addClass('ptm-text-success'); }, complete : function(xhr,status){ if(status == 'timeout'){ $('#loading-tip').html('鎶撳彇瓒呮椂锛岀綉缁滅箒蹇欙紝璇风◢鍚庨噸璇曪紒'); $('#loading-tip1').html(' 鏇存柊澶辫触'); $('#loading-tip1').addClass('ptm-text-warning'); layer.open({content: '鎶撳彇瓒呮椂锛岀綉缁滅箒蹇欙紝璇风◢鍚庨噸璇曪紒',skin: 'msg',time: 2}); } } }); }