Changeset 15507
- Timestamp:
- 08/18/2010 09:02:24 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/admin-table.dev.js
r15495 r15507 1 1 jQuery(document).ready(function($) { 2 $('form').each(function() { 3 this.reset(); 4 }); 5 6 if ( '' == $.query.GET('paged') )7 $.query.SET('paged', 1); 8 9 var total_pages;10 var set_total_pages = function() {11 total_pages = parseInt($('.total-pages').eq(0).text()); 12 }13 14 set_total_pages();15 16 var loading = false,17 $tbody = $('#the-list, #the-comment-list'), 18 $overlay = $('<div id="loading-items>')2 3 var adminTable = { 4 5 init: function() { 6 this.loading = false; 7 8 $('form').each(function() { 9 this.reset(); 10 }); 11 12 if ( '' == $.query.GET('paged') ) 13 $.query.SET('paged', 1); 14 this.set_total_pages(); 15 16 this.$tbody = $('#the-list, #the-comment-list'); 17 18 this.$overlay = $('<div id="loading-items>') 19 19 .html(adminTableL10n.loading) 20 20 .hide() 21 21 .prependTo($('body')); 22 23 var show_overlay = function() { 24 loading = true; 25 26 $('.error.ajax').remove(); 27 28 $overlay 29 .css({ 30 width: $tbody.width() + 'px', 31 height: $tbody.height() - 20 + 'px' 32 }) 33 .css($tbody.offset()) 34 .show(); 35 } 36 37 var hide_overlay = function() { 38 loading = false; 39 $overlay.hide(); 40 } 41 42 var handle_error = function() { 43 hide_overlay(); 44 45 $('h2').after('<div class="error ajax below-h2"><p>' + adminTableL10n.error + '</p></div>'); 46 } 47 48 var update_rows = function(args, reset_paging, callback) { 49 if ( loading ) 22 }, 23 24 // paging 25 set_total_pages: function() { 26 this.total_pages = parseInt($('.total-pages').eq(0).text()); 27 }, 28 29 get_total_pages: function() { 30 return this.total_pages; 31 }, 32 33 change_page: function(paged) { 34 if ( paged < 1 || paged >this.total_pages ) 35 return false; 36 37 this.update_rows({'paged': paged}); 38 }, 39 40 // searching 41 change_search: function(s) { 42 this.update_rows({'s': s}, true, function() { 43 $('h2 .subtitle').remove(); 44 45 if ( s ) 46 $('h2').eq(0).append($('<span class="subtitle">').html(adminTableL10n.search.replace('%s', this.htmlencode(s)))); 47 }); 48 }, 49 50 htmlencode: function(value) { 51 return $('<div/>').text(value).html(); 52 }, 53 54 update_rows: function(args, reset_paging, callback) { 55 if ( this.loading ) 50 56 return false; 51 57 … … 58 64 } 59 65 }); 60 66 61 67 if ( !different ) 62 68 return false; 63 69 64 show_overlay();70 this.show_overlay(); 65 71 66 72 if ( reset_paging ) … … 71 77 data['action'] = 'fetch-list'; 72 78 data['list_args'] = list_args; 79 80 this._callback = callback; 73 81 74 82 $.ajax({ … … 77 85 dataType: 'json', 78 86 data: data, 79 success: function(response) { 80 if ( 'object' != typeof response ) { 81 handle_error(); 82 } else { 83 hide_overlay(); 84 85 $tbody.html(response.rows); 86 87 $('.displaying-num').html(response.total_items); 88 89 $('.total-pages').html(response.total_pages); 90 set_total_pages(); 91 92 $('.current-page').val($.query.GET('paged')); 93 94 if ( callback ) 95 callback(); 96 } 97 }, 98 error: handle_error 87 success: $.proxy(this, 'handle_success'), 88 error: $.proxy(this, 'handle_error') 99 89 }); 100 90 101 91 return true; 92 }, 93 94 handle_success: function(response) { 95 if ( 'object' != typeof response ) { 96 this.handle_error(); 97 } else { 98 this.hide_overlay(); 99 100 this.$tbody.html(response.rows); 101 102 $('.displaying-num').html(response.total_items); 103 104 $('.total-pages').html(response.total_pages); 105 this.set_total_pages(); 106 107 $('.current-page').val($.query.GET('paged')); 108 109 if ( this._callback ) 110 this._callback(); 111 } 112 }, 113 114 handle_error: function() { 115 this.hide_overlay(); 116 117 $('h2').after('<div class="error ajax below-h2"><p>' + adminTableL10n.error + '</p></div>'); 118 }, 119 120 show_overlay: function() { 121 this.loading = true; 122 123 $('.error.ajax').remove(); 124 125 this.$overlay 126 .css({ 127 width: this.$tbody.width() + 'px', 128 height: this.$tbody.height() - 20 + 'px' 129 }) 130 .css(this.$tbody.offset()) 131 .show(); 132 }, 133 134 hide_overlay: function() { 135 this.loading = false; 136 this.$overlay.hide(); 102 137 } 103 104 // paging 105 var change_page = function(paged) { 106 if ( paged < 1 || paged > total_pages ) 107 return false; 108 109 update_rows({'paged': paged}); 110 } 111 138 } 139 140 adminTable.init(); 141 142 // Ajaxify various UI elements 143 144 // pagination 112 145 $('.tablenav-pages a').click(function() { 113 146 var paged = $.query.GET('paged'); … … 124 157 break; 125 158 case 'last-page': 126 paged = total_pages;127 break; 128 } 129 130 change_page(paged);159 paged = adminTable.get_total_pages(); 160 break; 161 } 162 163 adminTable.change_page(paged); 131 164 132 165 return false; … … 137 170 return; 138 171 139 change_page(parseInt($(this).val()));140 141 return false; 142 }); 143 144 // sort ing172 adminTable.change_page(parseInt($(this).val())); 173 174 return false; 175 }); 176 177 // sortable columns 145 178 $('th a').click(function() { 146 179 var orderby = $.query.GET('orderby'), … … 168 201 } 169 202 170 update_rows({'orderby': orderby, 'order': order}, true); 171 172 return false; 173 }); 174 175 // searching 176 var htmlencode = function(value) { 177 return $('<div/>').text(value).html(); 178 } 179 180 var change_search = function(s) { 181 update_rows({'s': s}, true, function() { 182 $('h2 .subtitle').remove(); 183 184 if ( s ) 185 $('h2').eq(0).append($('<span class="subtitle">').html(adminTableL10n.search.replace('%s', htmlencode(s)))); 186 }); 187 } 188 203 adminTable.update_rows({'orderby': orderby, 'order': order}, true); 204 205 return false; 206 }); 207 208 // searchbox 189 209 $('.search-box :submit').click(function() { 190 change_search($(this).parent('.search-box').find(':text').val());210 adminTable.change_search($(this).parent('.search-box').find(':text').val()); 191 211 192 212 return false; … … 197 217 return; 198 218 199 change_search($(this).val());219 adminTable.change_search($(this).val()); 200 220 201 221 return false; … … 204 224 // tablenav dropdowns 205 225 $('#post-query-submit').click(function() { 206 var $this = $(this), key, val, args = {}; 207 208 $this.parents('.actions').find('select[name!="action"]').each(function() { 209 args[$this.attr('name')] = $this.val(); 210 }); 211 212 update_rows(args, true); 226 var key, val, args = {}; 227 228 $(this).parents('.actions').find('select[name!="action"]').each(function() { 229 var $el = $(this); 230 231 args[$el.attr('name')] = $el.val(); 232 }); 233 234 adminTable.update_rows(args, true); 213 235 214 236 return false; … … 219 241 var $this = $(this); 220 242 221 update_rows({'mode': $.query.load($this.attr('href')).get('mode')}, false, function() {243 adminTable.update_rows({'mode': $.query.load($this.attr('href')).get('mode')}, false, function() { 222 244 $('.view-switch .current').removeClass('current'); 223 245 $this.addClass('current'); … … 226 248 return false; 227 249 }); 228 229 /*230 // problem: when switching from one to the other, columns are not always the same231 $('.subsubsub a').click(function() {232 var $this = $(this);233 234 update_rows($.query.load($this.attr('href')).get(), true, function() {235 $('.subsubsub .current').removeClass('current');236 $this.addClass('current');237 });238 239 return false;240 });241 /**/242 250 }); 243 251 -
trunk/wp-admin/js/admin-table.js
r15495 r15507 1 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})});1 jQuery(document).ready(function(b){var a={init:function(){this.loading=false;b("form").each(function(){this.reset()});if(""==b.query.GET("paged")){b.query.SET("paged",1)}this.set_total_pages();this.$tbody=b("#the-list, #the-comment-list");this.$overlay=b('<div id="loading-items>').html(adminTableL10n.loading).hide().prependTo(b("body"))},set_total_pages:function(){this.total_pages=parseInt(b(".total-pages").eq(0).text())},get_total_pages:function(){return this.total_pages},change_page:function(c){if(c<1||c>this.total_pages){return false}this.update_rows({paged:c})},change_search:function(c){this.update_rows({s:c},true,function(){b("h2 .subtitle").remove();if(c){b("h2").eq(0).append(b('<span class="subtitle">').html(adminTableL10n.search.replace("%s",this.htmlencode(c))))}})},htmlencode:function(c){return b("<div/>").text(c).html()},update_rows:function(d,c,g){if(this.loading){return false}var f=false;b.each(d,function(h,i){if(i!=b.query.GET(h)){b.query.SET(h,i);f=true}});if(!f){return false}this.show_overlay();if(c){b.query.SET("paged",1)}var e=b.query.get();e.action="fetch-list";e.list_args=list_args;this._callback=g;b.ajax({url:ajaxurl,global:false,dataType:"json",data:e,success:b.proxy(this,"handle_success"),error:b.proxy(this,"handle_error")});return true},handle_success:function(c){if("object"!=typeof c){this.handle_error()}else{this.hide_overlay();this.$tbody.html(c.rows);b(".displaying-num").html(c.total_items);b(".total-pages").html(c.total_pages);this.set_total_pages();b(".current-page").val(b.query.GET("paged"));if(this._callback){this._callback()}}},handle_error:function(){this.hide_overlay();b("h2").after('<div class="error ajax below-h2"><p>'+adminTableL10n.error+"</p></div>")},show_overlay:function(){this.loading=true;b(".error.ajax").remove();this.$overlay.css({width:this.$tbody.width()+"px",height:this.$tbody.height()-20+"px"}).css(this.$tbody.offset()).show()},hide_overlay:function(){this.loading=false;this.$overlay.hide()}};a.init();b(".tablenav-pages a").click(function(){var c=b.query.GET("paged");switch(b(this).attr("class")){case"first-page":c=1;break;case"prev-page":c-=1;break;case"next-page":c+=1;break;case"last-page":c=a.get_total_pages();break}a.change_page(c);return false});b(".current-page").keypress(function(c){if(13!=c.keyCode){return}a.change_page(parseInt(b(this).val()));return false});b("th a").click(function(){var e=b.query.GET("orderby"),c=b.query.GET("order"),d=b(this).parent("th");if(d.hasClass("sortable")){e=b.query.load(b(this).attr("href")).get("orderby");c="asc";b("th.sorted-desc, th.sorted-asc").removeClass("sorted-asc").removeClass("sorted-desc").addClass("sortable");d.removeClass("sortable").addClass("sorted-asc")}else{if(d.hasClass("sorted-asc")){c="desc";d.removeClass("sorted-asc").addClass("sorted-desc")}else{if(d.hasClass("sorted-desc")){c="asc";d.removeClass("sorted-desc").addClass("sorted-asc")}}}a.update_rows({orderby:e,order:c},true);return false});b(".search-box :submit").click(function(){a.change_search(b(this).parent(".search-box").find(":text").val());return false});b(".search-box :text").keypress(function(c){if(13!=c.keyCode){return}a.change_search(b(this).val());return false});b("#post-query-submit").click(function(){var d,e,c={};b(this).parents(".actions").find('select[name!="action"]').each(function(){var f=b(this);c[f.attr("name")]=f.val()});a.update_rows(c,true);return false});b(".view-switch a").click(function(){var c=b(this);a.update_rows({mode:b.query.load(c.attr("href")).get("mode")},false,function(){b(".view-switch .current").removeClass("current");c.addClass("current")});return false})}); -
trunk/wp-includes/script-loader.php
r15498 r15507 339 339 $scripts->add_data( 'theme-preview', 'group', 1 ); 340 340 341 $scripts->add( 'admin-table', "/wp-admin/js/admin-table$suffix.js", array( 'jquery', 'jquery-query' ), '2010081 2' );341 $scripts->add( 'admin-table', "/wp-admin/js/admin-table$suffix.js", array( 'jquery', 'jquery-query' ), '20100818' ); 342 342 $scripts->add_data( 'admin-table', 'group', 1 ); 343 343 $scripts->localize( 'admin-table', 'adminTableL10n', array(
Note: See TracChangeset
for help on using the changeset viewer.