Merge the sticky menu component from MP6. The admin menu is now fixed if the viewport is large enough. props tollmanz, tillkruess, dd32. see #25858.

Built from https://develop.svn.wordpress.org/trunk@26125


git-svn-id: http://core.svn.wordpress.org/trunk@26037 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2013-11-13 04:30:10 +00:00
parent 07544aec69
commit dcb1701e51
6 changed files with 113 additions and 4 deletions

View File

@ -1919,6 +1919,19 @@ div.wp-menu-image:before {
height: 34px;
}
/* Sticky admin menu */
.sticky-menu #wpwrap {
z-index: 1; /* prevent flyouts from going behind content in Webkit */
}
.sticky-menu #adminmenuwrap {
position: fixed;
top: 32px;
right: 0;
z-index: 2; /* needs to be above .sticky-menu #wpwrap */
}
/* A new arrow */
.wp-menu-arrow {

File diff suppressed because one or more lines are too long

View File

@ -1919,6 +1919,19 @@ div.wp-menu-image:before {
height: 34px;
}
/* Sticky admin menu */
.sticky-menu #wpwrap {
z-index: 1; /* prevent flyouts from going behind content in Webkit */
}
.sticky-menu #adminmenuwrap {
position: fixed;
top: 32px;
left: 0;
z-index: 2; /* needs to be above .sticky-menu #wpwrap */
}
/* A new arrow */
.wp-menu-arrow {

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
/* global setUserSetting, ajaxurl, commonL10n, alert, confirm, toggleWithKeyboard, pagenow */
var showNotice, adminMenu, columns, validateForm, screenMeta;
var showNotice, adminMenu, columns, validateForm, screenMeta, stickyMenu;
(function($){
// Removed in 3.3.
// (perhaps) needed for back-compat
@ -447,6 +447,89 @@ $(document).ready( function() {
})();
});
stickyMenu = {
active: false,
init: function () {
this.$window = $( window );
this.$body = $( document.body );
this.$adminMenuWrap = $( '#adminmenuwrap' );
this.$collapseMenu = $( '#collapse-menu' );
this.bodyMinWidth = parseInt( this.$body.css( 'min-width' ), 10 );
this.enable();
},
enable: function () {
if ( ! this.active ) {
this.$window.on( 'resize.stickyMenu scroll.stickyMenu', this.debounce(
$.proxy( this.update, this ), 200
) );
this.$collapseMenu.on( 'click.stickyMenu', $.proxy( this.update, this ) );
this.update();
this.active = true;
}
},
disable: function () {
if ( this.active ) {
this.$window.off( 'resize.stickyMenu scroll.stickyMenu' );
this.$collapseMenu.off( 'click.stickyMenu' );
this.$body.removeClass( 'sticky-menu' );
this.active = false;
}
},
update: function () {
// Make the admin menu sticky if both of the following:
// 1. The viewport is taller than the admin menu
// 2. The viewport is wider than the min-width of the <body>
if ( this.$window.height() > this.$adminMenuWrap.height() + 32 && this.$window.width() > this.bodyMinWidth) {
if ( ! this.$body.hasClass( 'sticky-menu' ) ) {
this.$body.addClass( 'sticky-menu' );
}
} else {
if ( this.$body.hasClass( 'sticky-menu' ) ) {
this.$body.removeClass( 'sticky-menu' );
}
}
},
// Borrowed from Underscore.js
debounce: function( func, wait, immediate ) {
var timeout, args, context, timestamp, result;
return function() {
var later, callNow;
context = this;
args = arguments;
timestamp = new Date().getTime();
later = function() {
var last = new Date().getTime() - timestamp;
if ( last < wait ) {
timeout = setTimeout( later, wait - last );
} else {
timeout = null;
if ( ! immediate ) {
result = func.apply( context, args );
context = args = null;
}
}
};
callNow = immediate && !timeout;
if ( ! timeout ) {
timeout = setTimeout( later, wait );
}
if ( callNow ) {
result = func.apply( context, args );
context = args = null;
}
return result;
};
}
};
stickyMenu.init();
// internal use
$(document).bind( 'wp_CloseOnEscape', function( e, data ) {
if ( typeof(data.cb) != 'function' )

File diff suppressed because one or more lines are too long