diff --git wp-admin/js/common.js wp-admin/js/common.js
index 3406ee0..58be5a5 100644
|
|
$(document).ready( function() { |
447 | 447 | })(); |
448 | 448 | }); |
449 | 449 | |
450 | | stickyMenu = { |
451 | | active: false, |
452 | | |
453 | | init: function () { |
454 | | this.$window = $( window ); |
455 | | this.$body = $( document.body ); |
456 | | this.$adminMenuWrap = $( '#adminmenuwrap' ); |
457 | | this.$collapseMenu = $( '#collapse-menu' ); |
458 | | this.bodyMinWidth = parseInt( this.$body.css( 'min-width' ), 10 ); |
459 | | this.enable(); |
460 | | }, |
| 450 | stickyMenu = ( function( window, undefined ) { |
| 451 | |
| 452 | var t = this, |
| 453 | active = false, |
| 454 | $window, |
| 455 | $body, |
| 456 | $adminMenuWrap, |
| 457 | $collapseMenu, |
| 458 | bodyMinWidth; |
| 459 | |
| 460 | function init() { |
| 461 | $window = $( window ); |
| 462 | $body = $( document.body ); |
| 463 | $adminMenuWrap = $( '#adminmenuwrap' ); |
| 464 | $collapseMenu = $( '#collapse-menu' ); |
| 465 | bodyMinWidth = parseInt( $body.css( 'min-width' ), 10 ); |
| 466 | enable(); |
| 467 | } |
461 | 468 | |
462 | | enable: function () { |
463 | | if ( ! this.active ) { |
464 | | this.$window.on( 'resize.stickyMenu scroll.stickyMenu', this.debounce( |
465 | | $.proxy( this.update, this ), 200 |
| 469 | function enable() { |
| 470 | if ( ! active ) { |
| 471 | $window.on( 'resize.stickyMenu scroll.stickyMenu', debounce( |
| 472 | $.proxy( update, this ), 200 |
466 | 473 | ) ); |
467 | | this.$collapseMenu.on( 'click.stickyMenu', $.proxy( this.update, this ) ); |
468 | | this.update(); |
469 | | this.active = true; |
| 474 | $collapseMenu.on( 'click.stickyMenu', $.proxy( update, this ) ); |
| 475 | update(); |
| 476 | active = true; |
470 | 477 | } |
471 | | }, |
| 478 | } |
472 | 479 | |
473 | | disable: function () { |
474 | | if ( this.active ) { |
475 | | this.$window.off( 'resize.stickyMenu scroll.stickyMenu' ); |
476 | | this.$collapseMenu.off( 'click.stickyMenu' ); |
477 | | this.$body.removeClass( 'sticky-menu' ); |
478 | | this.active = false; |
| 480 | function disable() { |
| 481 | if ( active ) { |
| 482 | $window.off( 'resize.stickyMenu scroll.stickyMenu' ); |
| 483 | $collapseMenu.off( 'click.stickyMenu' ); |
| 484 | $body.removeClass( 'sticky-menu' ); |
| 485 | active = false; |
479 | 486 | } |
480 | | }, |
| 487 | } |
481 | 488 | |
482 | | update: function () { |
| 489 | function update() { |
483 | 490 | // Make the admin menu sticky if both of the following: |
484 | 491 | // 1. The viewport is taller than the admin menu |
485 | 492 | // 2. The viewport is wider than the min-width of the <body> |
486 | | if ( this.$window.height() > this.$adminMenuWrap.height() + 32 && this.$window.width() > this.bodyMinWidth) { |
487 | | if ( ! this.$body.hasClass( 'sticky-menu' ) ) { |
488 | | this.$body.addClass( 'sticky-menu' ); |
| 493 | if ( $window.height() > $adminMenuWrap.height() + 32 && $window.width() > bodyMinWidth) { |
| 494 | if ( ! $body.hasClass( 'sticky-menu' ) ) { |
| 495 | $body.addClass( 'sticky-menu' ); |
489 | 496 | } |
490 | 497 | } else { |
491 | | if ( this.$body.hasClass( 'sticky-menu' ) ) { |
492 | | this.$body.removeClass( 'sticky-menu' ); |
| 498 | if ( $body.hasClass( 'sticky-menu' ) ) { |
| 499 | $body.removeClass( 'sticky-menu' ); |
493 | 500 | } |
494 | 501 | } |
495 | | }, |
| 502 | } |
496 | 503 | |
497 | 504 | // Borrowed from Underscore.js |
498 | | debounce: function( func, wait, immediate ) { |
| 505 | function debounce( func, wait, immediate ) { |
499 | 506 | var timeout, args, context, timestamp, result; |
500 | 507 | return function() { |
501 | 508 | var later, callNow; |
… |
… |
stickyMenu = { |
526 | 533 | return result; |
527 | 534 | }; |
528 | 535 | } |
529 | | }; |
| 536 | |
| 537 | return { |
| 538 | init: init, |
| 539 | disable: disable, |
| 540 | enable: enable |
| 541 | }; |
| 542 | } )( window ); |
530 | 543 | |
531 | 544 | stickyMenu.init(); |
532 | 545 | |