<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[16602] trunk:
Make bottom admin pagination scroll to the top after rows are updated.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16602">16602</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-11-28 19:05:12 +0000 (Sun, 28 Nov 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Make bottom admin pagination scroll to the top after rows are updated. See <a href="http://trac.wordpress.org/ticket/15580">#15580</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswplisttablephp">trunk/wp-admin/includes/class-wp-list-table.php</a></li>
<li><a href="#trunkwpadminjslisttabledevjs">trunk/wp-admin/js/list-table.dev.js</a></li>
<li><a href="#trunkwpadminjslisttablejs">trunk/wp-admin/js/list-table.js</a></li>
<li><a href="#trunkwpincludesscriptloaderphp">trunk/wp-includes/script-loader.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswplisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-list-table.php (16601 => 16602)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-list-table.php        2010-11-28 17:39:44 UTC (rev 16601)
+++ trunk/wp-admin/includes/class-wp-list-table.php        2010-11-28 19:05:12 UTC (rev 16602)
</span><span class="lines">@@ -719,7 +719,7 @@
</span><span class="cx">                 if ( 'top' == $which )
</span><span class="cx">                         wp_nonce_field( 'bulk-' . $this->_args['plural'] );
</span><span class="cx"> ?>
</span><del>-        <div class="tablenav">
</del><ins>+        <div class="tablenav <?php echo esc_attr( $which ); ?>">
</ins><span class="cx">
</span><span class="cx">                 <div class="alignleft actions">
</span><span class="cx">                         <?php $this->bulk_actions( $which ); ?>
</span></span></pre></div>
<a id="trunkwpadminjslisttabledevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/list-table.dev.js (16601 => 16602)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/list-table.dev.js        2010-11-28 17:39:44 UTC (rev 16601)
+++ trunk/wp-admin/js/list-table.dev.js        2010-11-28 19:05:12 UTC (rev 16602)
</span><span class="lines">@@ -33,13 +33,6 @@
</span><span class="cx">                 return this.total_pages;
</span><span class="cx">         },
</span><span class="cx">
</span><del>-        change_page: function(paged) {
-                if ( paged < 1 || paged > this.total_pages )
-                        return false;
-
-                this.update_rows({'paged': paged});
-        },
-
</del><span class="cx">         htmlencode: function(value) {
</span><span class="cx">                 return $('<div/>').text(value).html();
</span><span class="cx">         },
</span><span class="lines">@@ -151,11 +144,22 @@
</span><span class="cx">
</span><span class="cx"> // Ajaxify various UI elements
</span><span class="cx">
</span><ins>+        function change_page(paged, $el) {
+                if ( paged < 1 || paged > listTable.get_total_pages() )
+                        return false;
+
+                listTable.update_rows({'paged': paged}, false, function() {
+                        if ( $el.parents('.tablenav.bottom').length )
+                                window.scrollTo(0, 0);
+                });
+        }
+
</ins><span class="cx">         // pagination
</span><span class="cx">         $('.tablenav-pages a').click(function() {
</span><del>-                var paged = $.query.GET('paged');
</del><ins>+                var $el = $(this),
+                        paged = $.query.GET('paged');
</ins><span class="cx">
</span><del>-                switch ( $(this).attr('class') ) {
</del><ins>+                switch ( $el.attr('class') ) {
</ins><span class="cx">                         case 'first-page':
</span><span class="cx">                                 paged = 1;
</span><span class="cx">                                 break;
</span><span class="lines">@@ -170,7 +174,7 @@
</span><span class="cx">                                 break;
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                listTable.change_page(paged);
</del><ins>+                change_page(paged, $el);
</ins><span class="cx">
</span><span class="cx">                 return false;
</span><span class="cx">         });
</span><span class="lines">@@ -179,8 +183,10 @@
</span><span class="cx">                 if ( 13 != e.keyCode )
</span><span class="cx">                         return;
</span><span class="cx">
</span><del>-                listTable.change_page(parseInt($(this).val()));
</del><ins>+                var $el = $(this);
</ins><span class="cx">
</span><ins>+                change_page(parseInt($el.val()), $el);
+
</ins><span class="cx">                 return false;
</span><span class="cx">         });
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadminjslisttablejs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/list-table.js (16601 => 16602)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/list-table.js        2010-11-28 17:39:44 UTC (rev 16601)
+++ trunk/wp-admin/js/list-table.js        2010-11-28 19:05:12 UTC (rev 16602)
</span><span class="lines">@@ -1 +1 @@
</span><del>-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})});
</del><span class="cx">\ No newline at end of file
</span><ins>+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(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})});
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesscriptloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/script-loader.php (16601 => 16602)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/script-loader.php        2010-11-28 17:39:44 UTC (rev 16601)
+++ trunk/wp-includes/script-loader.php        2010-11-28 19:05:12 UTC (rev 16602)
</span><span class="lines">@@ -304,7 +304,7 @@
</span><span class="cx">                 $scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' );
</span><span class="cx">                 $scripts->add_data( 'admin-custom-fields', 'group', 1 );
</span><span class="cx">
</span><del>-                $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20101126' );
</del><ins>+                $scripts->add( 'list-table', "/wp-admin/js/list-table$suffix.js", array( 'jquery-query', 'jquery-serialize-object' ), '20101128' );
</ins><span class="cx">                 $scripts->add_data( 'list-table', 'group', 1 );
</span><span class="cx">                 $scripts->localize( 'list-table', 'listTableL10n', array(
</span><span class="cx">                         'loading' => __('Loading...'),
</span></span></pre>
</div>
</div>
</body>
</html>