Changeset 29898
- Timestamp:
- 10/15/2014 06:04:15 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/common.js
r29835 r29898 174 174 var checks, first, last, checked, sliced, mobileEvent, transitionTimeout, focusedRowActions, 175 175 lastClicked = false, 176 menu = $('#adminmenu'),177 176 pageInput = $('input.current-page'), 178 177 currentPage = pageInput.val(), 179 178 isIOS = /iPhone|iPad|iPod/.test( navigator.userAgent ), 180 isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1; 179 isAndroid = navigator.userAgent.indexOf( 'Android' ) !== -1, 180 $document = $( document ), 181 $window = $( window ), 182 $body = $( document.body ), 183 $adminMenuWrap = $( '#adminmenuwrap' ), 184 $wpwrap = $( '#wpwrap' ), 185 $adminmenu = $( '#adminmenu' ), 186 $overlay = $( '#wp-responsive-overlay' ), 187 $toolbar = $( '#wp-toolbar' ), 188 $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ), 189 $sortables = $('.meta-box-sortables'), 190 wpResponsiveActive = false, 191 $adminbar = $( '#wpadminbar' ), 192 lastScrollPosition = 0, 193 pinnedMenuTop = false, 194 pinnedMenuBottom = false, 195 menuTop = 0, 196 height = { 197 window: $window.height(), 198 adminbar: $adminbar.height(), 199 menu: $adminMenuWrap.height() 200 }; 201 181 202 182 203 // when the menu is folded, make the fly-out submenu header clickable 183 menu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){204 $adminmenu.on('click.wp-submenu-head', '.wp-submenu-head', function(e){ 184 205 $(e.target).parent().siblings('a').get(0).click(); 185 206 }); … … 225 246 }); 226 247 248 function adjustSubmenu( $menuItem ) { 249 var bottomOffset, pageHeight, adjustment, theFold, menutop, wintop, maxtop, 250 $submenu = $menuItem.find( '.wp-submenu' ); 251 252 menutop = $menuItem.offset().top; 253 wintop = $window.scrollTop(); 254 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar 255 256 bottomOffset = menutop + $submenu.height() + 1; // Bottom offset of the menu 257 pageHeight = $wpwrap.height(); // Height of the entire page 258 adjustment = 60 + bottomOffset - pageHeight; 259 theFold = $window.height() + wintop - 50; // The fold 260 261 if ( theFold < ( bottomOffset - adjustment ) ) { 262 adjustment = bottomOffset - theFold; 263 } 264 265 if ( adjustment > maxtop ) { 266 adjustment = maxtop; 267 } 268 269 if ( adjustment > 1 ) { 270 $submenu.css( 'margin-top', '-' + adjustment + 'px' ); 271 } else { 272 $submenu.css( 'margin-top', '' ); 273 } 274 } 275 227 276 if ( 'ontouchstart' in window || /IEMobile\/[1-9]/.test(navigator.userAgent) ) { // touch screen device 228 277 // iOS Safari works with touchstart, the rest work with click … … 231 280 // close any open submenus when touch/click is not on the menu 232 281 $(document.body).on( mobileEvent+'.wp-mobile-hover', function(e) { 233 if ( menu.data('wp-responsive') ) {282 if ( $adminmenu.data('wp-responsive') ) { 234 283 return; 235 284 } 236 285 237 if ( ! $(e.target).closest('#adminmenu').length ) { 238 menu.find('li.wp-has-submenu.opensub').removeClass('opensub'); 239 } 240 }); 241 242 menu.find('a.wp-has-submenu').on( mobileEvent+'.wp-mobile-hover', function(e) { 243 var b, h, o, f, menutop, wintop, maxtop, 244 el = $(this), 245 parent = el.parent(), 246 m = parent.find('.wp-submenu'); 247 248 if ( menu.data('wp-responsive') ) { 286 if ( ! $( e.target ).closest( '#adminmenu' ).length ) { 287 $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); 288 } 289 }); 290 291 $adminmenu.find( 'a.wp-has-submenu' ).on( mobileEvent + '.wp-mobile-hover', function( event ) { 292 var $menuItem = $(this).parent(); 293 294 if ( $adminmenu.data( 'wp-responsive' ) ) { 249 295 return; 250 296 } … … 253 299 // - the submenu is not open 254 300 // - the submenu is not shown inline or the menu is not folded 255 if ( !parent.hasClass('opensub') && ( !parent.hasClass('wp-menu-open') || parent.width() < 40 ) ) { 256 e.preventDefault(); 257 258 menutop = parent.offset().top; 259 wintop = $(window).scrollTop(); 260 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar 261 262 b = menutop + m.height() + 1; // Bottom offset of the menu 263 h = $('#wpwrap').height(); // Height of the entire page 264 o = 60 + b - h; 265 f = $(window).height() + wintop - 50; // The fold 266 267 if ( f < (b - o) ) { 268 o = b - f; 269 } 270 271 if ( o > maxtop ) { 272 o = maxtop; 273 } 274 275 if ( o > 1 ) { 276 m.css('margin-top', '-'+o+'px'); 277 } else { 278 m.css('margin-top', ''); 279 } 280 281 menu.find('li.opensub').removeClass('opensub'); 282 parent.addClass('opensub'); 301 if ( ! $menuItem.hasClass( 'opensub' ) && ( ! $menuItem.hasClass( 'wp-menu-open' ) || $menuItem.width() < 40 ) ) { 302 event.preventDefault(); 303 adjustSubmenu( $menuItem ); 304 $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); 305 $menuItem.addClass('opensub'); 283 306 } 284 307 }); … … 286 309 287 310 if ( ! isIOS && ! isAndroid ) { 288 menu.find('li.wp-has-submenu').hoverIntent({311 $adminmenu.find( 'li.wp-has-submenu' ).hoverIntent({ 289 312 over: function() { 290 var b, h, o, f, m = $(this).find('.wp-submenu'), menutop, wintop, maxtop, top = parseInt( m.css('top'), 10 ); 291 292 if ( isNaN(top) || top > -5 ) { // meaning the submenu is visible 313 var $menuItem = $( this ), 314 $submenu = $menuItem.find( '.wp-submenu' ), 315 top = parseInt( $submenu.css( 'top' ), 10 ); 316 317 if ( isNaN( top ) || top > -5 ) { // the submenu is visible 293 318 return; 294 319 } 295 320 296 if ( menu.data('wp-responsive') ) {321 if ( $adminmenu.data( 'wp-responsive' ) ) { 297 322 // The menu is in responsive mode, bail 298 323 return; 299 324 } 300 325 301 menutop = $(this).offset().top; 302 wintop = $(window).scrollTop(); 303 maxtop = menutop - wintop - 30; // max = make the top of the sub almost touch admin bar 304 305 b = menutop + m.height() + 1; // Bottom offset of the menu 306 h = $('#wpwrap').height(); // Height of the entire page 307 o = 60 + b - h; 308 f = $(window).height() + wintop - 15; // The fold 309 310 if ( f < (b - o) ) { 311 o = b - f; 312 } 313 314 if ( o > maxtop ) { 315 o = maxtop; 316 } 317 318 if ( o > 1 ) { 319 m.css('margin-top', '-'+o+'px'); 320 } else { 321 m.css('margin-top', ''); 322 } 323 324 menu.find('li.menu-top').removeClass('opensub'); 325 $(this).addClass('opensub'); 326 adjustSubmenu( $menuItem ); 327 $adminmenu.find( 'li.opensub' ).removeClass( 'opensub' ); 328 $menuItem.addClass( 'opensub' ); 326 329 }, 327 330 out: function(){ 328 if ( menu.data('wp-responsive') ) {331 if ( $adminmenu.data( 'wp-responsive' ) ) { 329 332 // The menu is in responsive mode, bail 330 333 return; 331 334 } 332 335 333 $( this).removeClass('opensub').find('.wp-submenu').css('margin-top', '');336 $( this ).removeClass( 'opensub' ).find( '.wp-submenu' ).css( 'margin-top', '' ); 334 337 }, 335 338 timeout: 200, … … 338 341 }); 339 342 340 menu.on('focus.adminmenu', '.wp-submenu a', function(e){341 if ( menu.data('wp-responsive') ) {343 $adminmenu.on( 'focus.adminmenu', '.wp-submenu a', function( event ) { 344 if ( $adminmenu.data( 'wp-responsive' ) ) { 342 345 // The menu is in responsive mode, bail 343 346 return; 344 347 } 345 348 346 $(e.target).closest('li.menu-top').addClass('opensub'); 347 }).on('blur.adminmenu', '.wp-submenu a', function(e){ 348 if ( menu.data('wp-responsive') ) { 349 // The menu is in responsive mode, bail 349 $( event.target ).closest( 'li.menu-top' ).addClass( 'opensub' ); 350 }).on( 'blur.adminmenu', '.wp-submenu a', function( event ) { 351 if ( $adminmenu.data( 'wp-responsive' ) ) { 350 352 return; 351 353 } 352 354 353 $(e.target).closest('li.menu-top').removeClass('opensub'); 355 $( event.target ).closest( 'li.menu-top' ).removeClass( 'opensub' ); 356 }).find( 'li.wp-has-submenu' ).on( 'focusin.adminmenu', function() { 357 adjustSubmenu( $( this ) ); 354 358 }); 355 359 } … … 528 532 input.on('change', toggleUploadButton); 529 533 })(); 530 });531 532 // Fire a custom jQuery event at the end of window resize533 ( function() {534 var timeout;535 536 function triggerEvent() {537 $(document).trigger( 'wp-window-resized' );538 }539 540 function fireOnce() {541 window.clearTimeout( timeout );542 timeout = window.setTimeout( triggerEvent, 200 );543 }544 545 $(window).on( 'resize.wp-fire-once', fireOnce );546 }());547 548 $(document).ready( function() {549 var $document = $( document ),550 $window = $( window ),551 $body = $( document.body ),552 $adminMenuWrap = $( '#adminmenuwrap' ),553 $wpwrap = $( '#wpwrap' ),554 $adminmenu = $( '#adminmenu' ),555 $overlay = $( '#wp-responsive-overlay' ),556 $toolbar = $( '#wp-toolbar' ),557 $toolbarPopups = $toolbar.find( 'a[aria-haspopup="true"]' ),558 $sortables = $('.meta-box-sortables'),559 wpResponsiveActive = false,560 $adminbar = $( '#wpadminbar' ),561 lastScrollPosition = 0,562 fixedMenuTop = false,563 fixedMenuBottom = false,564 menuTop = 0,565 height = {566 window: $window.height(),567 adminbar: $adminbar.height(),568 menu: $adminMenuWrap.height()569 };570 534 571 535 function pinMenu() { 572 536 var windowPos = $window.scrollTop(); 573 537 574 if ( $adminmenu.data('wp-responsive') ) {538 if ( isIOS || $adminmenu.data('wp-responsive') ) { 575 539 return; 576 540 } … … 579 543 if ( windowPos > lastScrollPosition ) { 580 544 // Scrolling down 581 if ( fixedMenuTop ) {545 if ( pinnedMenuTop ) { 582 546 // let it scroll 583 fixedMenuTop = false;547 pinnedMenuTop = false; 584 548 menuTop = $adminMenuWrap.offset().top - height.adminbar; 585 549 … … 589 553 bottom: '' 590 554 }); 591 } else if ( ! fixedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) {555 } else if ( ! pinnedMenuBottom && $adminMenuWrap.offset().top + height.menu < windowPos + height.window ) { 592 556 // pin the bottom 593 fixedMenuBottom = true;557 pinnedMenuBottom = true; 594 558 595 559 $adminMenuWrap.css({ … … 601 565 } else if ( windowPos < lastScrollPosition ) { 602 566 // Scrolling up 603 if ( fixedMenuBottom ) {567 if ( pinnedMenuBottom ) { 604 568 // let it scroll 605 fixedMenuBottom = false;569 pinnedMenuBottom = false; 606 570 menuTop = $adminMenuWrap.offset().top - height.adminbar; 607 571 … … 611 575 bottom: '' 612 576 }); 613 } else if ( ! fixedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) {577 } else if ( ! pinnedMenuTop && $adminMenuWrap.offset().top >= windowPos + height.adminbar ) { 614 578 // pin the top 615 fixedMenuTop = true;579 pinnedMenuTop = true; 616 580 617 581 $adminMenuWrap.css({ … … 621 585 }); 622 586 } 587 } else { 588 // Resizing 589 pinnedMenuTop = pinnedMenuBottom = false; 590 menuTop = $adminMenuWrap.offset().top - height.adminbar; 591 592 $adminMenuWrap.css({ 593 position: 'absolute', 594 top: menuTop, 595 bottom: '' 596 }); 623 597 } 624 598 } 625 599 626 600 lastScrollPosition = windowPos; 601 } 602 603 function unpinMenu() { 604 if ( isIOS ) { 605 return; 606 } 607 608 pinnedMenuTop = pinnedMenuBottom = false; 609 $adminMenuWrap.css({ 610 position: '', 611 top: '', 612 bottom: '' 613 }); 627 614 } 628 615 … … 630 617 if ( $adminmenu.data('wp-responsive') ) { 631 618 $body.removeClass( 'sticky-menu' ); 632 $adminMenuWrap.css({ 633 position: '', 634 top: '', 635 bottom: '' 636 }); 619 unpinMenu(); 637 620 } else if ( height.menu + height.adminbar > height.window ) { 621 pinMenu(); 638 622 $body.removeClass( 'sticky-menu' ); 639 pinMenu();640 623 } else { 641 624 $body.addClass( 'sticky-menu' ); 625 unpinMenu(); 642 626 } 643 627 } 644 628 645 629 setPinMenu(); 646 $window.on( 'scroll.pin-menu', pinMenu ); 630 631 if ( ! isIOS ) { 632 $window.on( 'scroll.pin-menu', pinMenu ); 633 } 647 634 648 635 $document.on( 'wp-window-resized.pin-menu', function() { … … 791 778 }); 792 779 780 // Fire a custom jQuery event at the end of window resize 781 ( function() { 782 var timeout; 783 784 function triggerEvent() { 785 $(document).trigger( 'wp-window-resized' ); 786 } 787 788 function fireOnce() { 789 window.clearTimeout( timeout ); 790 timeout = window.setTimeout( triggerEvent, 200 ); 791 } 792 793 $(window).on( 'resize.wp-fire-once', fireOnce ); 794 }()); 795 793 796 // Make Windows 8 devices play along nicely. 794 797 (function(){
Note: See TracChangeset
for help on using the changeset viewer.