Ticket #39074: 39074.8.diff
| File 39074.8.diff, 14.6 KB (added by , 6 years ago) |
|---|
-
src/js/_enqueues/admin/postbox.js
diff --git a/src/js/_enqueues/admin/postbox.js b/src/js/_enqueues/admin/postbox.js index 919ac92659..82c9b0644c 100644
a b 10 10 /* global ajaxurl, postBoxL10n, postboxes */ 11 11 12 12 (function($) { 13 var $document = $( document ); 13 var $document = $( document ), 14 __ = wp.i18n.__; 14 15 15 16 /** 16 17 * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see … … 41 42 */ 42 43 handle_click : function () { 43 44 var $el = $( this ), 44 p = $el. parent( '.postbox' ),45 p = $el.closest( '.postbox' ), 45 46 id = p.attr( 'id' ), 46 47 ariaExpandedValue; 47 48 … … 88 89 $document.trigger( 'postbox-toggled', p ); 89 90 }, 90 91 92 /** 93 * Handles clicks on the order up/down icons inside the postbox heading. 94 * 95 * @since 5.4.0 96 * @memberof postboxes 97 * 98 * @return {void} 99 */ 100 handle_order: function() { 101 var el = $( this ), 102 closestPostbox = el.closest( '.postbox' ), 103 closestPostboxId = closestPostbox.attr( 'id' ), 104 closestPostboxIndex = closestPostbox.index(), 105 closestPostboxesCount = closestPostbox.siblings().length; 106 107 if ( 'dashboard_browser_nag' === closestPostboxId ) { 108 return; 109 } 110 111 // If any of the order buttons are disabled do nothing. 112 if ( el.hasClass( 'handle-order-higher' ) && 'true' === el.attr( 'aria-disabled' ) ) { 113 wp.a11y.speak( __( 'The postbox is already on the first position.' ) ); 114 return; 115 } else if ( el.hasClass( 'handle-order-lower' ) && 'true' === el.attr( 'aria-disabled' ) ) { 116 wp.a11y.speak( __( 'The postbox is already on the last position.' ) ); 117 return; 118 } 119 120 // Move the postboxes to the needed positions depending on their index within a sortable area. 121 if ( el.hasClass( 'handle-order-higher' ) && 0 === closestPostboxIndex ) { 122 postboxes.handle_order_between_sortables( 'previous', el ); 123 } else if ( el.hasClass( 'handle-order-higher' ) ) { 124 closestPostbox.prev().before( closestPostbox ); 125 126 el.focus(); 127 128 postboxes.adjust_order_buttons_css( el ); 129 130 postboxes.save_order( postboxes.page ); 131 } else if ( el.hasClass( 'handle-order-lower' ) && closestPostboxIndex === closestPostboxesCount ) { 132 postboxes.handle_order_between_sortables( 'next', el ); 133 } else if ( el.hasClass( 'handle-order-lower' ) ) { 134 closestPostbox.next().after( closestPostbox ); 135 136 el.focus(); 137 138 postboxes.adjust_order_buttons_css( el ); 139 140 postboxes.save_order( postboxes.page ); 141 } 142 143 }, 144 145 /** 146 * Handles clicks on the move between sortables icon inside the postbox heading. 147 * 148 * @since 5.4.0 149 * @memberof postboxes 150 * 151 * @param {string} position "previous" or "next" sortables area. 152 * @param {object} el The element that was clicked. 153 * 154 * @return {void} 155 */ 156 handle_order_between_sortables : function( position, el ) { 157 var closestPostbox = el.closest( '.postbox' ), 158 closestPostboxId = closestPostbox.attr( 'id' ), 159 closestSortables = el.closest( '.meta-box-sortables' ).attr( 'id' ), 160 sortablesArray = [], 161 sortablesIndex, 162 goToSortables, 163 goToSortablesId, 164 detachedPostbox; 165 166 if ( 'dashboard_browser_nag' === closestPostboxId ) { 167 return; 168 } 169 170 // Get the list of sortables within page. 171 $( '.meta-box-sortables').each( function() { 172 sortablesArray.push( $( this ).attr( 'id' ) ); 173 }); 174 175 // Find the index of the current sortables within the sortablesArray. 176 sortablesIndex = $.inArray( closestSortables, sortablesArray ); 177 178 // Depending on the position requested we need to get the id of the Sortables. 179 if ( 'previous' === position ) { 180 goToSortables = sortablesIndex - 1; 181 } else if ( 'next' === position ) { 182 goToSortables = sortablesIndex + 1; 183 } 184 185 // Find the ID of the next Sortables. 186 goToSortablesId = sortablesArray[ goToSortables ]; 187 188 // Move the Postbox to the first position of the next Sortables. 189 detachedPostbox = closestPostbox.detach(); 190 191 if ( 'previous' === position ) { 192 $( detachedPostbox ).appendTo( '#' + goToSortablesId ); 193 } else if ( 'next' === position ) { 194 $( detachedPostbox ).prependTo( '#' + goToSortablesId ); 195 } 196 197 // Refresh marked areas. 198 postboxes._mark_area(); 199 200 // Keep the buttons clicked focused. 201 el.focus(); 202 203 // Enable disable move buttons. 204 postboxes.adjust_order_buttons_css( el ); 205 206 // Save the order of postboxes. 207 postboxes.save_order( postboxes.page ); 208 }, 209 210 /** 211 * Enables or disables the order buttons depending on the postbox index. 212 * 213 * @since 5.4.0 214 * @memberof postboxes 215 * 216 * @param {object} el The element that was clicked. 217 * 218 * @return {void} 219 */ 220 adjust_order_buttons_css : function ( el ) { 221 var firstPostbox = $( '.meta-box-sortables .postbox:not(.hide-if-js):first' ), 222 lastPostbox = $( '.meta-box-sortables .postbox:not(.hide-if-js):last' ), 223 firstPostboxParentId = firstPostbox.parent().attr( 'id' ), 224 lastPostboxParentId = lastPostbox.parent().attr( 'id' ), 225 firstSortablesId = $( '.meta-box-sortables:first' ).attr( 'id' ), 226 lastSortablesId = $( '.meta-box-sortables:last' ).attr( 'id' ); 227 228 // Enable all buttons as a reset first. 229 $( '.meta-box-sortables .postbox:not(.hide-if-js)' ).each( function() { 230 $( this ).find( '.handle-order-higher' ).attr( 'aria-disabled', 'false' ); 231 $( this ).find( '.handle-order-lower' ).attr( 'aria-disabled', 'false' ); 232 }); 233 234 // The first postbox of the first sorables should have the "higher" button disabled and higher enabled. 235 if ( firstPostboxParentId === firstSortablesId ) { 236 $( firstPostbox ).find( '.handle-order-higher' ).attr( 'aria-disabled', 'true' ); 237 $( firstPostbox ).find( '.handle-order-lower' ).attr( 'aria-disabled', 'false' ); 238 } 239 240 // The last postbox of the last sortables should have the "lower" button disabled and higher enabled. 241 if ( lastPostboxParentId === lastSortablesId ) { 242 $( lastPostbox ).find( '.handle-order-higher' ).attr( 'aria-disabled', 'false' ); 243 $( lastPostbox ).find( '.handle-order-lower' ).attr( 'aria-disabled', 'true' ); 244 } 245 246 // Keep the opacity at 1 on the focused order buttons. 247 if ( $( el ).hasClass( 'handle-order-higher' ) || $( el ).hasClass( 'handle-order-lower' ) ) { 248 $( el ).parent().addClass( 'show' ); 249 } 250 }, 251 91 252 /** 92 253 * Adds event handlers to all postboxes and screen option on the current page. 93 254 * … … 102 263 * @return {void} 103 264 */ 104 265 add_postbox_toggles : function (page, args) { 105 var $handles = $( '.postbox .hndle, .postbox .handlediv' ); 266 var $handles = $( '.postbox .hndle, .postbox .handlediv' ), 267 $order_buttons = $( '.postbox .handle-order-higher, .postbox .handle-order-lower' ); 106 268 107 269 this.page = page; 108 270 this.init( page, args ); 109 271 110 272 $handles.on( 'click.postboxes', this.handle_click ); 111 273 274 /** 275 * Handles the order of the postboxes. 276 * 277 * @since 5.4.0 278 */ 279 $order_buttons.on( 'click.postboxes', this.handle_order ); 280 112 281 /** 113 282 * @since 2.7.0 114 283 */ … … 244 413 return; 245 414 } 246 415 416 /** 417 * Enable or disable the order buttons. 418 * 419 * @since 5.4.0 420 */ 421 postboxes.adjust_order_buttons_css(); 422 247 423 postboxes.save_order(page); 248 424 }, 249 425 receive: function(e,ui) { … … 262 438 263 439 this._mark_area(); 264 440 441 /** 442 * Enable or disable the order buttons. 443 * 444 * @since 5.4.0 445 */ 446 this.adjust_order_buttons_css(); 447 265 448 // Set the handle buttons `aria-expanded` attribute initial value on page load. 266 449 $handleButtons.each( function () { 267 450 var $el = $( this ); 268 451 $el.attr( 'aria-expanded', ! $el.parent( '.postbox' ).hasClass( 'closed' ) ); 269 452 }); 453 454 /** 455 * Change the opacity of order buttons. 456 * 457 * @since 5.4.0 458 */ 459 $( 'body' ).on( 'keyup', function( e ) { 460 var keyCode = e.keyCode || e.which; 461 462 // We only need to check on a Tab keyup. 463 if ( 9 === keyCode ) { 464 var target = $( e.target ); 465 466 $( '.handle-order-higher, .handle-order-lower' ).each( function() { 467 $( this ).removeClass( 'show' ); 468 }); 469 470 if ( $( target ).hasClass( 'handle-order-higher' ) || $( target ).hasClass( 'handle-order-lower' ) ) { 471 $( target ).parent().addClass( 'show' ); 472 } 473 } 474 }); 475 476 $( '.meta-box-sortables .postbox' ) 477 .mouseenter( function() { 478 $( this ).find( '.order-buttons-group' ).addClass( 'show' ); 479 }) 480 .mouseleave( function() { 481 $( this ).find( '.order-buttons-group' ).removeClass( 'show' ); 482 }); 270 483 }, 271 484 272 485 /** … … 328 541 postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' ); 329 542 } ); 330 543 331 $.post( ajaxurl, postVars ); 544 $.post( 545 ajaxurl, 546 postVars, 547 function( response ) { 548 if ( response.success ) { 549 wp.a11y.speak( __( 'The postboxes order has been saved.' ) ); 550 } 551 } 552 ); 332 553 }, 333 554 334 555 /** -
src/wp-admin/css/common.css
diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css index 5c97f14453..d3235b01f0 100644
a b html.wp-toolbar { 2057 2057 font-weight: 400; 2058 2058 } 2059 2059 2060 .postbox .handle-actions { 2061 float: right; 2062 display: inline-block; 2063 height: 36px; 2064 } 2065 2066 .postbox .order-buttons-group { 2067 display: inline-block; 2068 opacity: 0; 2069 transition: all .1s ease; 2070 } 2071 2072 .postbox .order-buttons-group.show { 2073 opacity: 1; 2074 } 2075 2076 .postbox .handle-order-higher, 2077 .postbox .handle-order-lower, 2060 2078 .postbox .handlediv { 2061 2079 display: none; 2062 float: right;2063 2080 width: 36px; 2064 2081 height: 36px; 2065 2082 margin: 0; … … html.wp-toolbar { 2069 2086 cursor: pointer; 2070 2087 } 2071 2088 2089 .js .postbox .handle-order-higher, 2090 .js .postbox .handle-order-lower, 2072 2091 .js .postbox .handlediv { 2073 display: block;2092 display: inline-block; 2074 2093 } 2075 2094 2076 2095 .sortable-placeholder { … … img { 3031 3050 /* Metabox collapse arrow indicators */ 3032 3051 .sidebar-name .toggle-indicator:before, 3033 3052 .js .meta-box-sortables .postbox .toggle-indicator:before, 3053 .js .meta-box-sortables .postbox .order-higher-indicator:before, 3054 .js .meta-box-sortables .postbox .order-lower-indicator:before, 3034 3055 .bulk-action-notice .toggle-indicator:before, 3035 3056 .privacy-text-box .toggle-indicator:before { 3036 3057 content: "\f142"; … … img { 3049 3070 content: "\f140"; 3050 3071 } 3051 3072 3073 .js .postbox .handle-order-higher .order-higher-indicator:before { 3074 content: "\f343"; 3075 } 3076 3077 .js .postbox .handle-order-lower .order-lower-indicator:before { 3078 content: "\f347"; 3079 } 3080 3081 .js .postbox .handle-order-higher[aria-disabled=true] .order-higher-indicator:before, 3082 .js .postbox .handle-order-lower[aria-disabled=true] .order-lower-indicator:before { 3083 cursor: default; 3084 pointer-events: none; 3085 opacity: .5; 3086 } 3087 3088 .js .postbox .handle-order-higher .order-higher-indicator:before, 3089 .js .postbox .handle-order-lower .order-lower-indicator:before, 3052 3090 .js .postbox .handlediv .toggle-indicator:before { 3053 3091 margin-top: 4px; 3054 3092 width: 20px; … … img { 3056 3094 text-indent: -1px; /* account for the dashicon alignment */ 3057 3095 } 3058 3096 3097 .rtl.js .postbox .handle-order-higher .order-higher-indicator:before, 3098 .rtl.js .postbox .handle-order-lower .order-lower-indicator:before, 3059 3099 .rtl.js .postbox .handlediv .toggle-indicator:before { 3060 3100 text-indent: 1px; /* account for the dashicon alignment */ 3061 3101 } … … img { 3066 3106 color: #72777c; 3067 3107 } 3068 3108 3109 .js .postbox .handle-order-higher:focus, 3110 .js .postbox .handle-order-lower:focus, 3069 3111 .js .postbox .handlediv:focus { 3070 3112 box-shadow: none; 3071 3113 outline: none; 3072 3114 } 3073 3115 3116 .js .postbox .handle-order-higher:focus .order-higher-indicator:before, 3117 .js .postbox .handle-order-lower:focus .order-lower-indicator:before, 3074 3118 .js .postbox .handlediv:focus .toggle-indicator:before { 3075 3119 box-shadow: 3076 3120 0 0 0 1px #5b9dd9, … … img { 3376 3420 .postbox .handlediv.button-link, 3377 3421 .item-edit, 3378 3422 .toggle-indicator, 3423 .order-higher-indicator, 3424 .order-lower-indicator, 3379 3425 .accordion-section-title:after { 3380 3426 color: #72777c; 3381 3427 } -
src/wp-admin/includes/ajax-actions.php
diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index ea33d9d792..036ce33fc4 100644
a b function wp_ajax_meta_box_order() { 1923 1923 update_user_option( $user->ID, "screen_layout_$page", $page_columns, true ); 1924 1924 } 1925 1925 1926 wp_ die( 1);1926 wp_send_json_success(); 1927 1927 } 1928 1928 1929 1929 /** -
src/wp-admin/includes/template.php
diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index a6f74722cf..f5c8144156 100644
a b function do_meta_boxes( $screen, $context, $object ) { 1308 1308 unset( $box['args']['__widget_basename'] ); 1309 1309 } 1310 1310 1311 echo '<div class="handle-actions">'; 1312 1313 echo '<div class="order-buttons-group">'; 1314 1315 echo '<button type="button" class="handle-order-higher" aria-disabled="false">'; 1316 echo '<span class="screen-reader-text">' . sprintf( 1317 /* translators: Meta box title. */ 1318 __( 'Order %s panel higher' ), 1319 $widget_title 1320 ) . '</span>'; 1321 echo '<span class="order-higher-indicator" aria-hidden="true"></span>'; 1322 echo '</button>'; 1323 1324 echo '<button type="button" class="handle-order-lower" aria-disabled="false">'; 1325 echo '<span class="screen-reader-text">' . sprintf( 1326 /* translators: Meta box title. */ 1327 __( 'Order %s panel lower' ), 1328 $widget_title 1329 ) . '</span>'; 1330 echo '<span class="order-lower-indicator" aria-hidden="true"></span>'; 1331 echo '</button>'; 1332 1333 echo '</div>'; 1334 1311 1335 echo '<button type="button" class="handlediv" aria-expanded="true">'; 1312 1336 echo '<span class="screen-reader-text">' . sprintf( 1313 1337 /* translators: %s: Meta box title. */ … … function do_meta_boxes( $screen, $context, $object ) { 1316 1340 ) . '</span>'; 1317 1341 echo '<span class="toggle-indicator" aria-hidden="true"></span>'; 1318 1342 echo '</button>'; 1343 1344 echo '</div>'; 1319 1345 } 1320 1346 echo '<h2 class="hndle">'; 1321 1347 if ( 'dashboard_php_nag' === $box['id'] ) { -
src/wp-includes/script-loader.php
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index ef085b5c93..3789a5ab80 100644
a b function wp_default_scripts( &$scripts ) { 1337 1337 1338 1338 $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array( 'jquery' ), false, 1 ); 1339 1339 1340 $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable' ), false, 1 );1340 $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable', 'wp-a11y', 'wp-i18n' ), false, 1 ); 1341 1341 did_action( 'init' ) && $scripts->localize( 1342 1342 'postbox', 1343 1343 'postBoxL10n',