From 3d55dbb82fcbe9447877ae7eba938fe0915abc0b Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Tue, 26 Nov 2013 04:37:27 +0000 Subject: [PATCH] Dashboard JS cleanup. props kadamwhite, helen. see #25824. git-svn-id: https://develop.svn.wordpress.org/trunk@26390 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/js/dashboard.js | 48 +++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/wp-admin/js/dashboard.js b/src/wp-admin/js/dashboard.js index abc7595437..9d905947c4 100644 --- a/src/wp-admin/js/dashboard.js +++ b/src/wp-admin/js/dashboard.js @@ -2,16 +2,20 @@ var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad; jQuery(document).ready( function($) { - /* Dashboard Welcome Panel */ - var welcomePanel = $('#welcome-panel'), + var $window = $( window ), + welcomePanel = $( '#welcome-panel' ), welcomePanelHide = $('#wp_welcome_panel-hide'), - updateWelcomePanel = function( visible ) { - $.post( ajaxurl, { - action: 'update-welcome-panel', - visible: visible, - welcomepanelnonce: $('#welcomepanelnonce').val() - }); - }; + updateWelcomePanel, + metaboxHolder = $( '.metabox-holder' ), + updateColumnCount; + + updateWelcomePanel = function( visible ) { + $.post( ajaxurl, { + action: 'update-welcome-panel', + visible: visible, + welcomepanelnonce: $( '#welcomepanelnonce' ).val() + }); + }; if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) { welcomePanel.removeClass('hidden'); @@ -128,19 +132,9 @@ jQuery(document).ready( function($) { e.preventDefault(); }); - // Dashboard columns - jQuery(document).ready(function () { - // Update main column count on load - updateColumnCount(); - }); - - jQuery(window).resize( _.debounce( function(){ - updateColumnCount(); - }, 30) ); - - function updateColumnCount() { + updateColumnCount = function( $window, $holder ) { var cols = 1, - windowWidth = parseInt(jQuery(window).width(), 10); + windowWidth = parseInt( $window.width(), 10 ); if (799 < windowWidth && 1299 > windowWidth) { cols = 2; @@ -153,7 +147,15 @@ jQuery(document).ready( function($) { if (1800 < windowWidth) { cols = 4; } - jQuery('.metabox-holder').attr('class', jQuery('.metabox-holder').attr('class').replace(/columns-\d+/, 'columns-' + cols)); - } + + $holder.attr( 'class', $holder.attr( 'class' ).replace( /columns-\d+/, 'columns-' + cols ) ); + }; + + // Update main column count on load + updateColumnCount( $window, metaboxHolder ); + + $window.on( 'resize', _.debounce(function() { + updateColumnCount( $window, metaboxHolder ); + }, 30 ) ); } );