1 line
2.9 KiB
JavaScript
1 line
2.9 KiB
JavaScript
jQuery(document).ready(function(g){g("form").each(function(){this.reset()});if(""==g.query.GET("paged")){g.query.SET("paged",1)}var l;var b=function(){l=parseInt(g(".total-pages").eq(0).text())};b();var c=false,f=g("#the-list, #the-comment-list"),m=g('<div id="loading-items>').html(adminTableL10n.loading).hide().prependTo(g("body"));var a=function(){c=true;g(".error.ajax").remove();m.css({width:f.width()+"px",height:f.height()-20+"px"}).css(f.offset()).show()};var i=function(){c=false;m.hide()};var e=function(){i();g("h2").after('<div class="error ajax below-h2"><p>'+adminTableL10n.error+"</p></div>")};var k=function(o,n,r){if(c){return false}var q=false;g.each(o,function(s,t){if(t!=g.query.GET(s)){g.query.SET(s,t);q=true}});if(!q){return false}a();if(n){g.query.SET("paged",1)}var p=g.query.get();p.action="fetch-list";p.list_args=list_args;g.ajax({url:ajaxurl,global:false,dataType:"json",data:p,success:function(s){if("object"!=typeof s){e()}else{i();f.html(s.rows);g(".displaying-num").html(s.total_items);g(".total-pages").html(s.total_pages);b();g(".current-page").val(g.query.GET("paged"));if(r){r()}}},error:e});return true};var d=function(n){if(n<1||n>l){return false}k({paged:n})};g(".tablenav-pages a").click(function(){var n=g.query.GET("paged");switch(g(this).attr("class")){case"first-page":n=1;break;case"prev-page":n-=1;break;case"next-page":n+=1;break;case"last-page":n=l;break}d(n);return false});g(".current-page").keypress(function(n){if(13!=n.keyCode){return}d(parseInt(g(this).val()));return false});g("th a").click(function(){var p=g.query.GET("orderby"),n=g.query.GET("order"),o=g(this).parent("th");if(o.hasClass("sortable")){p=g.query.load(g(this).attr("href")).get("orderby");n="asc";g("th.sorted-desc, th.sorted-asc").removeClass("sorted-asc").removeClass("sorted-desc").addClass("sortable");o.removeClass("sortable").addClass("sorted-asc")}else{if(o.hasClass("sorted-asc")){n="desc";o.removeClass("sorted-asc").addClass("sorted-desc")}else{if(o.hasClass("sorted-desc")){n="asc";o.removeClass("sorted-desc").addClass("sorted-asc")}}}k({orderby:p,order:n},true);return false});var h=function(n){return g("<div/>").text(n).html()};var j=function(n){k({s:n},true,function(){g("h2 .subtitle").remove();if(n){g("h2").eq(0).append(g('<span class="subtitle">').html(adminTableL10n.search.replace("%s",h(n))))}})};g(".search-box :submit").click(function(){j(g(this).parent(".search-box").find(":text").val());return false});g(".search-box :text").keypress(function(n){if(13!=n.keyCode){return}j(g(this).val());return false});g("#post-query-submit").click(function(){var p=g(this),o,q,n={};p.parents(".actions").find('select[name!="action"]').each(function(){n[p.attr("name")]=p.val()});k(n,true);return false});g(".view-switch a").click(function(){var n=g(this);k({mode:g.query.load(n.attr("href")).get("mode")},false,function(){g(".view-switch .current").removeClass("current");n.addClass("current")});return false})}); |