WordPress.org

Make WordPress Core

Changeset 16602


Ignore:
Timestamp:
11/28/10 19:05:12 (3 years ago)
Author:
scribu
Message:

Make bottom admin pagination scroll to the top after rows are updated. See #15580

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-list-table.php

    r16594 r16602  
    720720            wp_nonce_field( 'bulk-' . $this->_args['plural'] ); 
    721721?> 
    722     <div class="tablenav"> 
     722    <div class="tablenav <?php echo esc_attr( $which ); ?>"> 
    723723 
    724724        <div class="alignleft actions"> 
  • trunk/wp-admin/js/list-table.dev.js

    r16593 r16602  
    3232    get_total_pages: function() { 
    3333        return this.total_pages; 
    34     }, 
    35  
    36     change_page: function(paged) { 
    37         if ( paged < 1 || paged > this.total_pages ) 
    38             return false; 
    39  
    40         this.update_rows({'paged': paged}); 
    4134    }, 
    4235 
     
    152145// Ajaxify various UI elements 
    153146 
     147    function change_page(paged, $el) { 
     148        if ( paged < 1 || paged > listTable.get_total_pages() ) 
     149            return false; 
     150 
     151        listTable.update_rows({'paged': paged}, false, function() { 
     152            if ( $el.parents('.tablenav.bottom').length ) 
     153                window.scrollTo(0, 0); 
     154        }); 
     155    } 
     156 
    154157    // pagination 
    155158    $('.tablenav-pages a').click(function() { 
    156         var paged = $.query.GET('paged'); 
    157  
    158         switch ( $(this).attr('class') ) { 
     159        var $el = $(this), 
     160            paged = $.query.GET('paged'); 
     161 
     162        switch ( $el.attr('class') ) { 
    159163            case 'first-page': 
    160164                paged = 1; 
     
    171175        } 
    172176 
    173         listTable.change_page(paged); 
     177        change_page(paged, $el); 
    174178 
    175179        return false; 
     
    180184            return; 
    181185 
    182         listTable.change_page(parseInt($(this).val())); 
     186        var $el = $(this); 
     187 
     188        change_page(parseInt($el.val()), $el); 
    183189 
    184190        return false; 
  • trunk/wp-admin/js/list-table.js

    r16593 r16602  
    1 jQuery(document).ready(function(a){window.listTable={init:function(){this.loading=false;a("form").each(function(){this.reset()});if(""==a.query.GET("paged")){a.query.SET("paged",1)}this.set_total_pages();this.$tbody=a("#the-list, #the-comment-list");this.$overlay=a('<div id="loading-items>').html(listTableL10n.loading).hide().prependTo(a("body"))},set_total_pages:function(d){var c=a(".last-page").attr("href");if(c){this.total_pages=d||a.query.load(c).get("paged")}},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})},htmlencode:function(c){return a("<div/>").text(c).html()},update_rows:function(d,c,g){if(this.loading){return false}var f=false,e={};a.each(d,function(h,i){if(i!=a.query.GET(h)){a.query.SET(h,i);f=true}});if(!f){return false}this.show_overlay();if(c){a.query.SET("paged",1)}a.each(a.query.get(),function(h,i){if(true===i){e[h]=""}else{e[h]=i}});this._callback=g;this.fetch_list(e,a.proxy(this,"handle_success"),a.proxy(this,"handle_error"));return true},fetch_list:function(d,e,c){d=a.extend(d,{action:"fetch-list",list_args:list_args});a.ajax({url:ajaxurl,global:false,dataType:"json",data:d,success:e,error:c})},handle_success:function(c){if("object"!=typeof c){this.handle_error()}else{this.hide_overlay();this.$tbody.html(c.rows);a(".displaying-num").html(c.total_items_i18n);a(".total-pages").html(c.total_pages_i18n);this.set_total_pages(c.total_pages);a(".current-page").val(a.query.GET("paged"));a("th.column-cb :input").attr("checked",false);if(this._callback){this._callback()}}},handle_error:function(){this.hide_overlay();a("h2").after('<div class="error ajax below-h2"><p>'+listTableL10n.error+"</p></div>")},show_overlay:function(){this.loading=true;a(".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()}};listTable.init();a(".tablenav-pages a").click(function(){var c=a.query.GET("paged");switch(a(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=listTable.get_total_pages();break}listTable.change_page(c);return false});a(".current-page").keypress(function(c){if(13!=c.keyCode){return}listTable.change_page(parseInt(a(this).val()));return false});a("th.sortable a, th.sorted a").click(function(){function g(i){return a.query.load(i.find("a").attr("href")).get("order")}var e=a(this),f=e.parent("th"),h=a.query.load(e.attr("href")).get("orderby"),d;if(h==a.query.get("orderby")){d=("asc"==a.query.get("order"))?"desc":"asc"}else{d=g(f);var c=a("th.sorted");if(c.length){c.removeClass("sorted").addClass("sortable");c.removeClass("desc").removeClass("asc").addClass("asc"==g(c)?"desc":"asc")}f.removeClass("sortable").addClass("sorted")}f.removeClass("desc").removeClass("asc").addClass(d);listTable.update_rows({orderby:h,order:d},true);return false});function b(c){if("keypress"==c.type&&13!=c.keyCode){return}c.preventDefault();c.stopImmediatePropagation();var d=a(this).parent(".search-box").find(":input").serializeObject();listTable.update_rows(d,true,function(){if(a("h2.nav-tab-wrapper").length){return}a("h2 .subtitle").remove();if(d.s){a("h2").append(a('<span class="subtitle">').html(listTableL10n.search.replace("%s",this.htmlencode(d.s))))}})}a(".search-box :submit").click(b);a(".search-box :text").keypress(b);a("#post-query-submit").click(function(){var c={};a(this).parents(".actions").find('select[name!="action"]').each(function(){var d=a(this);c[d.attr("name")]=d.val()});listTable.update_rows(c,true);return false});a(".view-switch a").click(function(){var c=a(this);listTable.update_rows({mode:a.query.load(c.attr("href")).get("mode")},false,function(){a(".view-switch .current").removeClass("current");c.addClass("current")});return false})}); 
     1jQuery(document).ready(function(a){window.listTable={init:function(){this.loading=false;a("form").each(function(){this.reset()});if(""==a.query.GET("paged")){a.query.SET("paged",1)}this.set_total_pages();this.$tbody=a("#the-list, #the-comment-list");this.$overlay=a('<div id="loading-items>').html(listTableL10n.loading).hide().prependTo(a("body"))},set_total_pages:function(e){var d=a(".last-page").attr("href");if(d){this.total_pages=e||a.query.load(d).get("paged")}},get_total_pages:function(){return this.total_pages},htmlencode:function(d){return a("<div/>").text(d).html()},update_rows:function(e,d,h){if(this.loading){return false}var g=false,f={};a.each(e,function(i,j){if(j!=a.query.GET(i)){a.query.SET(i,j);g=true}});if(!g){return false}this.show_overlay();if(d){a.query.SET("paged",1)}a.each(a.query.get(),function(i,j){if(true===j){f[i]=""}else{f[i]=j}});this._callback=h;this.fetch_list(f,a.proxy(this,"handle_success"),a.proxy(this,"handle_error"));return true},fetch_list:function(e,f,d){e=a.extend(e,{action:"fetch-list",list_args:list_args});a.ajax({url:ajaxurl,global:false,dataType:"json",data:e,success:f,error:d})},handle_success:function(d){if("object"!=typeof d){this.handle_error()}else{this.hide_overlay();this.$tbody.html(d.rows);a(".displaying-num").html(d.total_items_i18n);a(".total-pages").html(d.total_pages_i18n);this.set_total_pages(d.total_pages);a(".current-page").val(a.query.GET("paged"));a("th.column-cb :input").attr("checked",false);if(this._callback){this._callback()}}},handle_error:function(){this.hide_overlay();a("h2").after('<div class="error ajax below-h2"><p>'+listTableL10n.error+"</p></div>")},show_overlay:function(){this.loading=true;a(".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()}};listTable.init();function b(e,d){if(e<1||e>listTable.get_total_pages()){return false}listTable.update_rows({paged:e},false,function(){if(d.parents(".tablenav.bottom").length){window.scrollTo(0,0)}})}a(".tablenav-pages a").click(function(){var e=a(this),d=a.query.GET("paged");switch(e.attr("class")){case"first-page":d=1;break;case"prev-page":d-=1;break;case"next-page":d+=1;break;case"last-page":d=listTable.get_total_pages();break}b(d,e);return false});a(".current-page").keypress(function(f){if(13!=f.keyCode){return}var d=a(this);b(parseInt(d.val()),d);return false});a("th.sortable a, th.sorted a").click(function(){function h(j){return a.query.load(j.find("a").attr("href")).get("order")}var f=a(this),g=f.parent("th"),i=a.query.load(f.attr("href")).get("orderby"),e;if(i==a.query.get("orderby")){e=("asc"==a.query.get("order"))?"desc":"asc"}else{e=h(g);var d=a("th.sorted");if(d.length){d.removeClass("sorted").addClass("sortable");d.removeClass("desc").removeClass("asc").addClass("asc"==h(d)?"desc":"asc")}g.removeClass("sortable").addClass("sorted")}g.removeClass("desc").removeClass("asc").addClass(e);listTable.update_rows({orderby:i,order:e},true);return false});function c(d){if("keypress"==d.type&&13!=d.keyCode){return}d.preventDefault();d.stopImmediatePropagation();var e=a(this).parent(".search-box").find(":input").serializeObject();listTable.update_rows(e,true,function(){if(a("h2.nav-tab-wrapper").length){return}a("h2 .subtitle").remove();if(e.s){a("h2").append(a('<span class="subtitle">').html(listTableL10n.search.replace("%s",this.htmlencode(e.s))))}})}a(".search-box :submit").click(c);a(".search-box :text").keypress(c);a("#post-query-submit").click(function(){var d={};a(this).parents(".actions").find('select[name!="action"]').each(function(){var e=a(this);d[e.attr("name")]=e.val()});listTable.update_rows(d,true);return false});a(".view-switch a").click(function(){var d=a(this);listTable.update_rows({mode:a.query.load(d.attr("href")).get("mode")},false,function(){a(".view-switch .current").removeClass("current");d.addClass("current")});return false})}); 
  • trunk/wp-includes/script-loader.php

    r16598 r16602  
    305305        $scripts->add_data( 'admin-custom-fields', 'group', 1 ); 
    306306 
    307         $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20101126' ); 
     307        $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20101128' ); 
    308308        $scripts->add_data( 'list-table', 'group', 1 ); 
    309309        $scripts->localize( 'list-table', 'listTableL10n', array( 
Note: See TracChangeset for help on using the changeset viewer.