Ticket #47069: admin-bar-no-jquery-wip.diff
File admin-bar-no-jquery-wip.diff, 13.6 KB (added by , 5 years ago) |
---|
-
src/js/_enqueues/lib/admin-bar.js
12 12 /* jshint ignore:end */ 13 13 } 14 14 jQuery(document).ready(function($){ 15 var adminbar = $('#wpadminbar'), refresh,touchOpen, touchClose, disableHoverIntent = false;15 var adminbar = $('#wpadminbar'), touchOpen, touchClose, disableHoverIntent = false; 16 16 17 17 /** 18 * Forces the browser to refresh the tabbing index.19 *20 * @since 3.3.021 *22 * @param {number} i The index of the HTML element to remove the tab index23 * from. This parameter is necessary because we use this24 * function in .each calls.25 * @param {HTMLElement} el The HTML element to remove the tab index from.26 *27 * @return {void}28 */29 refresh = function(i, el){30 var node = $(el), tab = node.attr('tabindex');31 if ( tab )32 node.attr('tabindex', '0').attr('tabindex', tab);33 };34 35 /**36 18 * Adds or removes the hover class on touch. 37 19 * 38 20 * @since 3.5.0 … … 118 100 interval: 100 119 101 }); 120 102 121 // Prevents the toolbar from covering up content when a hash is present in the122 // URL.123 if ( window.location.hash )124 window.scrollBy( 0, -32 );125 126 103 /** 127 104 * Handles the selected state of the Shortlink link. 128 105 * … … 143 120 /** 144 121 * Removes the hoverclass if the enter key is pressed. 145 122 * 146 * Makes sure the tab index is refreshed by refreshing each ab-item147 * and its children.148 *149 123 * @param {Object} e The keydown event. 150 124 * 151 125 * @return {void} … … 170 144 if ( ! parentHasHover ) { 171 145 target.parent().toggleClass('hover'); 172 146 } 147 }); 173 148 174 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);175 }).each(refresh);176 177 149 /** 178 150 * Removes the hover class when the escape key is pressed. 179 151 * 180 * Makes sure the tab index is refreshed by refreshing each ab-item181 * and its children.182 *183 152 * @param {Object} e The keydown event. 184 153 * 185 154 * @return {void} 186 155 */ 187 $('#wpadminbar .ab-item ').bind('keydown.adminbar', function(e){156 $('#wpadminbar .ab-item, .shortlink-input').bind('keydown.adminbar', function(e){ 188 157 // Key code 27 is the escape key. 189 158 if ( e.which != 27 ) 190 159 return; … … 195 164 e.preventDefault(); 196 165 197 166 target.closest('.hover').removeClass('hover').children('.ab-item').focus(); 198 target.siblings('.ab-sub-wrapper').find('.ab-item').each(refresh);199 167 }); 200 168 201 169 /** … … 214 182 $( 'html, body' ).animate( { scrollTop: 0 }, 'fast' ); 215 183 e.preventDefault(); 216 184 }); 217 218 /**219 * Sets the focus on an element with a href attribute.220 *221 * The timeout is used to fix a focus bug in WebKit.222 *223 * @param {Object} e The keydown event.224 *225 * @return {void}226 */227 $('.screen-reader-shortcut').keydown( function(e) {228 var id, ua;229 230 if ( 13 != e.which )231 return;232 233 id = $( this ).attr( 'href' );234 235 ua = navigator.userAgent.toLowerCase();236 237 if ( ua.indexOf('applewebkit') != -1 && id && id.charAt(0) == '#' ) {238 setTimeout(function () {239 $(id).focus();240 }, 100);241 }242 });243 244 $( '#adminbar-search' ).on({245 /**246 * Adds the adminbar-focused class on focus.247 *248 * @return {void}249 */250 focus: function() {251 $( '#adminbarsearch' ).addClass( 'adminbar-focused' );252 /**253 * Removes the adminbar-focused class on blur.254 *255 * @return {void}256 */257 }, blur: function() {258 $( '#adminbarsearch' ).removeClass( 'adminbar-focused' );259 }260 } );261 262 if ( 'sessionStorage' in window ) {263 /**264 * Empties sessionStorage on logging out.265 *266 * @return {void}267 */268 $('#wp-admin-bar-logout a').click( function() {269 try {270 for ( var key in sessionStorage ) {271 if ( key.indexOf('wp-autosave-') != -1 )272 sessionStorage.removeItem(key);273 }274 } catch(e) {}275 });276 }277 278 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&279 /Android (1.0|1.1|1.5|1.6|2.0|2.1)|Nokia|Opera Mini|w(eb)?OSBrowser|webOS|UCWEB|Windows Phone OS 7|XBLWP7|ZuneWP7|MSIE 7/.test( navigator.userAgent ) ) {280 281 document.body.className += ' no-font-face';282 }283 185 }); 284 186 } else { 285 187 /** … … 312 214 } 313 215 }, 314 216 315 aB, hc = new RegExp('\\bhover\\b', 'g'), q = [], 316 rselected = new RegExp('\\bselected\\b', 'g'), 217 aB, q = [], 317 218 318 219 /** 319 220 * Gets the timeout ID of the given element. … … 352 253 if ( 'LI' == t.nodeName.toUpperCase() ) { 353 254 ancestors[ ancestors.length ] = t; 354 255 id = getTOID(t); 355 if ( id ) 256 if ( id ) { 356 257 clearTimeout( id ); 357 t.className = t.className ? ( t.className.replace(hc, '') + ' hover' ) : 'hover'; 258 } 259 t.classList.add( 'hover' ); 358 260 hovering = t; 359 261 } 360 262 t = t.parentNode; … … 367 269 i = ul.childNodes.length; 368 270 while ( i-- ) { 369 271 li = ul.childNodes[i]; 370 if ( li != hovering ) 371 li.className = li.className ? li.className.replace( rselected, '' ) : ''; 272 if ( li != hovering ) { 273 li.classList.remove( 'selected' ); 274 } 275 372 276 } 373 277 } 374 278 } … … 383 287 inA = true; 384 288 } 385 289 386 if ( ! inA ) 387 q[i][1].className = q[i][1].className ? q[i][1].className.replace(hc, '') : ''; 290 if ( ! inA ) { 291 q[i][1].classList.remove( 'hover' ); 292 } 388 293 } 389 294 }, 390 295 … … 402 307 if ( 'LI' == t.nodeName.toUpperCase() ) { 403 308 (function(t) { 404 309 var to = setTimeout(function() { 405 t.class Name = t.className ? t.className.replace(hc, '') : '';310 t.classList.remove( 'hover' ); 406 311 }, 500); 407 312 q[q.length] = [to, t]; 408 313 })(t); … … 441 346 e.preventDefault(); 442 347 e.returnValue = false; 443 348 444 if ( -1 == t.className.indexOf('selected') ) 445 t.className += ' selected'; 349 if ( -1 == t.className.indexOf( 'selected' ) ) { 350 t.classList.add( 'selected' ); 351 } 446 352 447 353 for ( i = 0, l = t.childNodes.length; i < l; i++ ) { 448 354 node = t.childNodes[i]; … … 450 356 node.focus(); 451 357 node.select(); 452 358 node.onblur = function() { 453 t.class Name = t.className ? t.className.replace( rselected, '' ) : '';359 t.classList.remove( 'selected' ); 454 360 }; 455 361 break; 456 362 } … … 480 386 return; 481 387 482 388 speed_step = distance > 800 ? 130 : 100; 483 speed = Math.min( 12, Math.round( distance / speed_step ) );484 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 );485 steps = [];486 timer = 0;389 speed = Math.min( 12, Math.round( distance / speed_step ) ); 390 step = distance > 800 ? Math.round( distance / 30 ) : Math.round( distance / 20 ); 391 steps = []; 392 timer = 0; 487 393 488 394 // Animate scrolling to the top of the page by generating steps to 489 395 // the top of the page and shifting to each step at a set interval. … … 504 410 addEvent(w, 'load', function() { 505 411 aB = d.getElementById('wpadminbar'); 506 412 507 if ( d.body && aB ) { 508 d.body.appendChild( aB ); 509 413 if ( aB ) { 510 414 if ( aB.className ) 511 415 aB.className = aB.className.replace(/nojs/, ''); 512 416 … … 523 427 addEvent(aB, 'click', function(e) { 524 428 scrollToTop( e.target || e.srcElement ); 525 429 }); 430 } 431 }); 432 })( document, window ); 433 } 526 434 527 addEvent( document.getElementById('wp-admin-bar-logout'), 'click', function() { 528 if ( 'sessionStorage' in window ) { 529 try { 530 for ( var key in sessionStorage ) { 531 if ( key.indexOf('wp-autosave-') != -1 ) 532 sessionStorage.removeItem(key); 533 } 534 } catch(e) {} 435 // Common functions. 436 (function() { 437 /** 438 * Specify a function to execute when the DOM is fully loaded. 439 * 440 * Can be replaced by `@wordpress/dom-ready`. 441 * 442 * @param {Function} callback A function to execute after the DOM is ready. 443 * 444 * @returns {void} 445 */ 446 var domReady = function( callback ) { 447 if ( document.readyState === 'complete' ) { 448 return callback(); 449 } 450 451 document.addEventListener( 'DOMContentLoaded', callback ); 452 }; 453 454 /* 455 * Clear any autosave in the session storage. 456 * Note: `sessionStorage` is cleared out also in `wp-login.php`. 457 */ 458 var clearAutoSave = function() { 459 if ( 'sessionStorage' in window ) { 460 document.querySelector( '#wp-admin-bar-logout .ab-item' ).addEventListener( 'click', function() { 461 try { 462 for ( var key in sessionStorage ) { 463 if ( key.indexOf( 'wp-autosave-' ) !== -1 ) 464 sessionStorage.removeItem( key ); 535 465 } 536 }); 537 } 466 } catch( e ) {} 467 } ); 468 } 469 }; 538 470 539 if ( w.location.hash ) 540 w.scrollBy(0,-32); 471 domReady( clearAutoSave ); 541 472 542 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 && 543 /Android (1.0|1.1|1.5|1.6|2.0|2.1)|Nokia|Opera Mini|w(eb)?OSBrowser|webOS|UCWEB|Windows Phone OS 7|XBLWP7|ZuneWP7|MSIE 7/.test( navigator.userAgent ) ) { 473 // Adds a `no-font-face` CSS class to the body for browsers that don't support font-face. 474 if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 && 475 /Android (1.0|1.1|1.5|1.6|2.0|2.1)|Nokia|Opera Mini|w(eb)?OSBrowser|webOS|UCWEB|Windows Phone OS 7|XBLWP7|ZuneWP7|MSIE 7/.test( navigator.userAgent ) ) { 544 476 545 document.body.className += ' no-font-face'; 546 } 547 }); 548 })(document, window); 477 document.body.className += ' no-font-face'; 478 } 549 479 550 } 480 /* 481 * Prevents the toolbar from covering up content when a hash is present in the URL. 482 * Note: this works only when following a link with a hash from another page. 483 */ 484 if ( window.location.hash ) { 485 // Looks like WebKit browsers need a setTimeout. 486 setTimeout( function() { 487 window.scrollBy( 0, -32 ); 488 }, 0 ); 489 } 490 })(); -
src/wp-admin/css/colors/_admin.scss
316 316 #wpadminbar li .ab-item:focus:before, 317 317 #wpadminbar li .ab-item:focus .ab-icon:before, 318 318 #wpadminbar li.hover .ab-icon:before, 319 #wpadminbar li.hover .ab-item:before, 320 #wpadminbar li:hover #adminbarsearch:before, 321 #wpadminbar li #adminbarsearch.adminbar-focused:before { 319 #wpadminbar li.hover .ab-item:before { 322 320 color: $menu-submenu-focus-text; 323 321 } 324 322 -
src/wp-includes/admin-bar.php
1029 1029 } 1030 1030 1031 1031 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; 1032 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>'; 1032 1033 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; 1033 $form .= '< label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>';1034 $form .= '<span class="adminbar-search-icon" aria-hidden="true"></span>'; 1034 1035 $form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '"/>'; 1035 1036 $form .= '</form>'; 1036 1037 -
src/wp-includes/css/admin-bar.css
151 151 float: none; 152 152 } 153 153 154 #wpadminbar.ie7 .menupop .ab-sub-wrapper,155 #wpadminbar.ie7 .shortlink-input {156 top: 32px;157 left: 0;158 }159 160 154 #wpadminbar .ab-top-menu > .menupop > .ab-sub-wrapper { 161 155 min-width: 100%; 162 156 } … … 294 288 #wpadminbar li .ab-item:focus .ab-icon:before, 295 289 #wpadminbar li.hover .ab-icon:before, 296 290 #wpadminbar li.hover .ab-item:before, 297 #wpadminbar li:hover #adminbarsearch:before, 298 #wpadminbar li #adminbarsearch.adminbar-focused:before { 291 #adminbar-search:focus + .adminbar-search-icon::before { 299 292 color: #00b9eb; 300 293 } 301 294 … … 424 417 min-width: 270px; 425 418 } 426 419 427 #wpadminbar.ie8 #wp-admin-bar-my-account.with-avatar .ab-item {428 white-space: nowrap;429 }430 431 420 #wpadminbar #wp-admin-bar-user-actions > li { 432 421 margin-left: 16px; 433 422 margin-right: 16px; … … 491 480 display: inline; 492 481 } 493 482 494 #wpadminbar.ie8 #wp-admin-bar-my-account.with-avatar > .ab-empty-item img,495 #wpadminbar.ie8 #wp-admin-bar-my-account.with-avatar > a img {496 width: auto;497 }498 499 483 /** 500 484 * WP Logo 501 485 */ … … 607 591 /** 608 592 * Search 609 593 */ 610 #wpadminbar.ie8 #wp-admin-bar-search {611 display: block;612 min-width: 32px;613 }614 594 #wpadminbar #wp-admin-bar-search .ab-item { 615 595 padding: 0; 616 596 background: transparent; … … 623 603 z-index: 1; 624 604 } 625 605 626 #wpadminbar #adminbar search:before {606 #wpadminbar #adminbar-search + .adminbar-search-icon::before { 627 607 position: absolute; 628 608 top: 6px; 629 609 left: 5px; … … 671 651 border: 0; 672 652 } 673 653 674 #wpadminbar.ie7 > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input {675 margin-top: 3px;676 width: 120px;677 }678 679 #wpadminbar.ie8 > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input {680 /* IE8 z-index bug with transparent / empty elements - fill in with an encoded transparent GIF */681 background: transparent 0 0 repeat scroll url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");682 }683 684 /* IE8 doesn't redraw the pseudo elements unless you make a change to the content */685 #wpadminbar.ie8 #adminbarsearch.adminbar-focused:before {686 content: "\f179 "; /* extra space */687 }688 689 #wpadminbar.ie8 > #wp-toolbar > #wp-admin-bar-top-secondary > #wp-admin-bar-search #adminbarsearch input.adminbar-input:focus {690 background: #fff;691 z-index: -1;692 }693 694 654 #wpadminbar #adminbarsearch .adminbar-button { 695 655 display: none; 696 656 }