web/wp-admin/js/common.dev.js
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
     1 var showNotice, adminMenu, columns;
     1 var showNotice, adminMenu, columns, validateForm;
     2 (function($){
     2 (function($){
     3 // sidebar admin menu
     3 // sidebar admin menu
     4 adminMenu = {
     4 adminMenu = {
     5 
       
     6 	init : function() {
     5 	init : function() {
     7 		$('#adminmenu div.wp-menu-toggle').each( function() {
     6 		var menu = $('#adminmenu');
     8 			if ( $(this).siblings('.wp-submenu').length )
     7 
     9 				$(this).click(function(){ adminMenu.toggle( $(this).siblings('.wp-submenu') ); });
     8 		$('.wp-menu-toggle', menu).each( function() {
       
     9 			var t = $(this), sub = t.siblings('.wp-submenu');
       
    10 			if ( sub.length )
       
    11 				t.click(function(){ adminMenu.toggle( sub ); });
    10 			else
    12 			else
    11 				$(this).hide();
    13 				t.hide();
    12 		});
    14 		});
    13 
    15 
    14 		this.favorites();
    16 		this.favorites();
    15 
    17 
    16 		$('a.separator').click(function(){
    18 		$('.separator', menu).click(function(){
    17 			if ( $('body').hasClass('folded') ) {
    19 			if ( $('body').hasClass('folded') ) {
    18 				adminMenu.fold(1);
    20 				adminMenu.fold(1);
    19 				deleteUserSetting( 'mfold' );
    21 				deleteUserSetting( 'mfold' );
    20 			} else {
    22 			} else {
    21 				adminMenu.fold();
    23 				adminMenu.fold();
    22 				setUserSetting( 'mfold', 'f' );
    24 				setUserSetting( 'mfold', 'f' );
    23 			}
    25 			}
    24 			return false;
    26 			return false;
    25 		});
    27 		});
    26 
    28 
    27 		if ( $('body').hasClass('folded') ) {
    29 		if ( $('body').hasClass('folded') )
    28 			this.fold();
    30 			this.fold();
    29 		}
    31 
    30 		this.restoreMenuState();
    32 		this.restoreMenuState();
    31 	},
    33 	},
    32 
    34 
    33 	restoreMenuState : function() {
    35 	restoreMenuState : function() {
    34 		$('#adminmenu li.wp-has-submenu').each(function(i, e) {
    36 		$('li.wp-has-submenu', '#adminmenu').each(function(i, e) {
    35 			var v = getUserSetting( 'm'+i );
    37 			var v = getUserSetting( 'm'+i );
    36 			if ( $(e).hasClass('wp-has-current-submenu') ) return true; // leave the current parent open
    38 			if ( $(e).hasClass('wp-has-current-submenu') )
    37 
    39 				return true; // leave the current parent open
    38 			if ( 'o' == v ) $(e).addClass('wp-menu-open');
    40 
    39 			else if ( 'c' == v ) $(e).removeClass('wp-menu-open');
    41 			if ( 'o' == v )
       
    42 				$(e).addClass('wp-menu-open');
       
    43 			else if ( 'c' == v )
       
    44 				$(e).removeClass('wp-menu-open');
    40 		});
    45 		});
    41 	},
    46 	},
    42 
    47 
    43 	toggle : function(el) {
    48 	toggle : function(el) {
    44 
    49 		var id = el.slideToggle(150, function() {
    45 		el['slideToggle'](150, function(){el.css('display','');}).parent().toggleClass( 'wp-menu-open' );
    50 			el.css('display','');
    46 
    51 		}).parent().toggleClass( 'wp-menu-open' ).attr('id');
    47 		$('#adminmenu li.wp-has-submenu').each(function(i, e) {
    52 
    48 			var v = $(e).hasClass('wp-menu-open') ? 'o' : 'c';
    53 		if ( id ) {
    49 			setUserSetting( 'm'+i, v );
    54 			$('li.wp-has-submenu', '#adminmenu').each(function(i, e) {
    50 		});
    55 				if ( id == e.id ) {
       
    56 				    var v = $(e).hasClass('wp-menu-open') ? 'o' : 'c';
       
    57 				    setUserSetting( 'm'+i, v );
       
    58 				}
       
    59 			});
       
    60 		}
    51 
    61 
    52 		return false;
    62 		return false;
    53 	},
    63 	},
    54 
    64 
    55 	fold : function(off) {
    65 	fold : function(off) {
    60 			$('body').addClass('folded');
    70 			$('body').addClass('folded');
    61 			$('#adminmenu li.wp-has-submenu').hoverIntent({
    71 			$('#adminmenu li.wp-has-submenu').hoverIntent({
    62 				over: function(e){
    72 				over: function(e){
    63 					var m, b, h, o, f;
    73 					var m, b, h, o, f;
    64 					m = $(this).find('.wp-submenu');
    74 					m = $(this).find('.wp-submenu');
    65 					b = m.parent().offset().top + m.height() + 1; // Bottom offset of the menu
    75 					b = $(this).offset().top + m.height() + 1; // Bottom offset of the menu
    66 					h = $('#wpwrap').height(); // Height of the entire page
    76 					h = $('#wpwrap').height(); // Height of the entire page
    67 					o = 60 + b - h;
    77 					o = 60 + b - h;
    68 					f = $(window).height() + $('body').scrollTop() - 15; // The fold
    78 					f = $(window).height() + $(window).scrollTop() - 15; // The fold
    69 					if (f < (b - o)) {
    79 					if ( f < (b - o) ) {
    70 						o = b - f;
    80 						o = b - f;
    71 					}
    81 					}
    72 					if (o > 1) {
    82 					if ( o > 1 ) {
    73 						m.css({'marginTop':'-'+o+'px'});
    83 						m.css({'marginTop':'-'+o+'px'});
    74 					} else if ( m.css('marginTop') ) {
    84 					} else if ( m.css('marginTop') ) {
    75 						m.css({'marginTop':''});
    85 						m.css({'marginTop':''});
    76 					}
    86 					}
    77 					m.addClass('sub-open');
    87 					m.addClass('sub-open');
    84 
    94 
    85 		}
    95 		}
    86 	},
    96 	},
    87 
    97 
    88 	favorites : function() {
    98 	favorites : function() {
    89 		$('#favorite-inside').width($('#favorite-actions').width()-4);
    99 		$('#favorite-inside').width( $('#favorite-actions').width() - 4 );
    90 		$('#favorite-toggle, #favorite-inside').bind( 'mouseenter', function(){$('#favorite-inside').removeClass('slideUp').addClass('slideDown'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideDown') ) { $('#favorite-inside').slideDown(100); $('#favorite-first').addClass('slide-down'); }}, 200) } );
   100 		$('#favorite-toggle, #favorite-inside').bind('mouseenter', function() {
    91 
   101 			$('#favorite-inside').removeClass('slideUp').addClass('slideDown');
    92 		$('#favorite-toggle, #favorite-inside').bind( 'mouseleave', function(){$('#favorite-inside').removeClass('slideDown').addClass('slideUp'); setTimeout(function(){if ( $('#favorite-inside').hasClass('slideUp') ) { $('#favorite-inside').slideUp(100, function(){ $('#favorite-first').removeClass('slide-down'); } ); }}, 300) } );
   102 			setTimeout(function() {
       
   103 				if ( $('#favorite-inside').hasClass('slideDown') ) {
       
   104 					$('#favorite-inside').slideDown(100);
       
   105 					$('#favorite-first').addClass('slide-down');
       
   106 				}
       
   107 			}, 200);
       
   108 		}).bind('mouseleave', function() {
       
   109 			$('#favorite-inside').removeClass('slideDown').addClass('slideUp');
       
   110 			setTimeout(function() {
       
   111 				if ( $('#favorite-inside').hasClass('slideUp') ) {
       
   112 					$('#favorite-inside').slideUp(100, function() {
       
   113 						$('#favorite-first').removeClass('slide-down');
       
   114 					});
       
   115 				}
       
   116 			}, 300);
       
   117 		});
    93 	}
   118 	}
    94 };
   119 };
    95 
   120 
    96 $(document).ready(function(){adminMenu.init();});
   121 $(document).ready(function(){ adminMenu.init(); });
    97 
   122 
    98 // show/hide/save table columns
   123 // show/hide/save table columns
    99 columns = {
   124 columns = {
   100 	init : function() {
   125 	init : function() {
   101 		$('.hide-column-tog').click( function() {
   126 		$('.hide-column-tog', '#adv-settings').click( function() {
   102 			var column = $(this).val(), show = $(this).attr('checked');
   127 			var column = $(this).val();
   103 			if ( show ) {
   128 			if ( $(this).attr('checked') )
   104 				$('.column-' + column).show();
   129 				$('.column-' + column).show();
   105 			} else {
   130 			else
   106 				$('.column-' + column).hide();
   131 				$('.column-' + column).hide();
   107 			}
   132 
   108 			columns.save_manage_columns_state();
   133 			columns.save_manage_columns_state();
   109 		} );
   134 		});
   110 	},
   135 	},
   111 
   136 
   112 	save_manage_columns_state : function() {
   137 	save_manage_columns_state : function() {
   113 		var hidden = $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
   138 		var hidden = $('.manage-column').filter(':hidden').map(function() { return this.id; }).get().join(',');
   114 		$.post(ajaxurl, {
   139 		$.post(ajaxurl, {
   120 	}
   145 	}
   121 }
   146 }
   122 
   147 
   123 $(document).ready(function(){columns.init();});
   148 $(document).ready(function(){columns.init();});
   124 
   149 
       
   150 validateForm = function( form ) {
       
   151 	return !$( form ).find('.form-required').filter( function() { return $('input:visible', this).val() == ''; } ).addClass( 'form-invalid' ).find('input:visible').change( function() { $(this).closest('.form-invalid').removeClass( 'form-invalid' ); } ).size();
       
   152 }
       
   153 
   125 })(jQuery);
   154 })(jQuery);
   126 
   155 
   127 // stub for doing better warnings
   156 // stub for doing better warnings
   128 showNotice = {
   157 showNotice = {
   129 	warn : function() {
   158 	warn : function() {
   141 };
   170 };
   142 
   171 
   143 jQuery(document).ready( function($) {
   172 jQuery(document).ready( function($) {
   144 	var lastClicked = false, checks, first, last, checked;
   173 	var lastClicked = false, checks, first, last, checked;
   145 
   174 
   146 	// pulse
       
   147 	$('.fade').animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300).animate( { backgroundColor: '#ffffe0' }, 300).animate( { backgroundColor: '#fffbcc' }, 300);
       
   148 
       
   149 	// Move .updated and .error alert boxes
   175 	// Move .updated and .error alert boxes
   150 	$('div.wrap h2 ~ div.updated, div.wrap h2 ~ div.error').addClass('below-h2');
   176 	$('div.wrap h2:first').nextAll('div.updated, div.error').addClass('below-h2');
   151 	$('div.updated, div.error').not('.below-h2').insertAfter('div.wrap h2:first');
   177 	$('div.updated, div.error').not('.below-h2').insertAfter( $('div.wrap h2:first') );
   152 
       
   153 	// show warnings
       
   154 	$('#doaction, #doaction2').click(function(){
       
   155 		if ( $('select[name="action"]').val() == 'delete' || $('select[name="action2"]').val() == 'delete' ) {
       
   156 			return showNotice.warn();
       
   157 		}
       
   158 	});
       
   159 
   178 
   160 	// screen settings tab
   179 	// screen settings tab
   161 	$('#show-settings-link').click(function () {
   180 	$('#show-settings-link').click(function () {
   162 		if ( ! $('#screen-options-wrap').hasClass('screen-options-open') ) {
   181 		if ( ! $('#screen-options-wrap').hasClass('screen-options-open') )
   163 			$('#contextual-help-link-wrap').css('visibility', 'hidden');
   182 			$('#contextual-help-link-wrap').css('visibility', 'hidden');
   164 		}
   183 
   165 		$('#screen-options-wrap').slideToggle('fast', function(){
   184 		$('#screen-options-wrap').slideToggle('fast', function(){
   166 			if ( $(this).hasClass('screen-options-open') ) {
   185 			if ( $(this).hasClass('screen-options-open') ) {
   167 				$('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
   186 				$('#show-settings-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
   168 				$('#contextual-help-link-wrap').css('visibility', '');
   187 				$('#contextual-help-link-wrap').css('visibility', '');
   169 				$(this).removeClass('screen-options-open');
   188 				$(this).removeClass('screen-options-open');
   175 		return false;
   194 		return false;
   176 	});
   195 	});
   177 
   196 
   178 	// help tab
   197 	// help tab
   179 	$('#contextual-help-link').click(function () {
   198 	$('#contextual-help-link').click(function () {
   180 		if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') ) {
   199 		if ( ! $('#contextual-help-wrap').hasClass('contextual-help-open') )
   181 			$('#screen-options-link-wrap').css('visibility', 'hidden');
   200 			$('#screen-options-link-wrap').css('visibility', 'hidden');
   182 		}
   201 
   183 		$('#contextual-help-wrap').slideToggle('fast', function(){
   202 		$('#contextual-help-wrap').slideToggle('fast', function() {
   184 			if ( $(this).hasClass('contextual-help-open') ) {
   203 			if ( $(this).hasClass('contextual-help-open') ) {
   185 				$('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
   204 				$('#contextual-help-link').css({'backgroundImage':'url("images/screen-options-right.gif")'});
   186 				$('#screen-options-link-wrap').css('visibility', '');
   205 				$('#screen-options-link-wrap').css('visibility', '');
   187 				$(this).removeClass('contextual-help-open');
   206 				$(this).removeClass('contextual-help-open');
   188 			} else {
   207 			} else {
   190 				$(this).addClass('contextual-help-open');
   209 				$(this).addClass('contextual-help-open');
   191 			}
   210 			}
   192 		});
   211 		});
   193 		return false;
   212 		return false;
   194 	});
   213 	});
   195 	$('#contextual-help-link-wrap, #screen-options-link-wrap').show();
       
   196 
   214 
   197 	// check all checkboxes
   215 	// check all checkboxes
   198 	$( 'table:visible tbody .check-column :checkbox' ).click( function(e) {
   216 	$('tbody').children().children('.check-column').find(':checkbox').click( function(e) {
   199 		if ( 'undefined' == e.shiftKey ) { return true; }
   217 		if ( 'undefined' == e.shiftKey ) { return true; }
   200 		if ( e.shiftKey ) {
   218 		if ( e.shiftKey ) {
   201 			if ( !lastClicked ) { return true; }
   219 			if ( !lastClicked ) { return true; }
   202 			checks = $( lastClicked ).parents( 'form:first' ).find( ':checkbox' );
   220 			checks = $( lastClicked ).closest( 'form' ).find( ':checkbox' );
   203 			first = checks.index( lastClicked );
   221 			first = checks.index( lastClicked );
   204 			last = checks.index( this );
   222 			last = checks.index( this );
   205 			checked = $(this).attr('checked');
   223 			checked = $(this).attr('checked');
   206 			if ( 0 < first && 0 < last && first != last ) {
   224 			if ( 0 < first && 0 < last && first != last ) {
   207 				checks.slice( first, last ).attr( 'checked', function(){
   225 				checks.slice( first, last ).attr( 'checked', function(){
   208 					if ( $(this).parents('tr').is(':visible') )
   226 					if ( $(this).closest('tr').is(':visible') )
   209 						return checked ? 'checked' : '';
   227 						return checked ? 'checked' : '';
   210 
   228 
   211 					return '';
   229 					return '';
   212 				});
   230 				});
   213 			}
   231 			}
   214 		}
   232 		}
   215 		lastClicked = this;
   233 		lastClicked = this;
   216 		return true;
   234 		return true;
   217 	} );
   235 	});
   218 	$( 'thead :checkbox, tfoot :checkbox' ).click( function(e) {
   236 
   219 		var c = $(this).attr('checked'), kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard, toggle = e.shiftKey || kbtoggle;
   237 	$('thead, tfoot').find(':checkbox').click( function(e) {
   220 
   238 		var c = $(this).attr('checked'),
   221 
   239 			kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
   222 		$(this).parents( 'form:first' ).find( 'table tbody:visible' ).find( '.check-column :checkbox' ).attr( 'checked', function() {
   240 			toggle = e.shiftKey || kbtoggle;
   223 			if ( $(this).parents('tr').is(':hidden') )
   241 
       
   242 		$(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
       
   243 		.children().children('.check-column').find(':checkbox')
       
   244 		.attr('checked', function() {
       
   245 			if ( $(this).closest('tr').is(':hidden') )
   224 				return '';
   246 				return '';
   225 			if ( toggle )
   247 			if ( toggle )
   226 				return $(this).attr( 'checked' ) ? '' : 'checked';
   248 				return $(this).attr( 'checked' ) ? '' : 'checked';
   227 			else if (c)
   249 			else if (c)
   228 				return 'checked';
   250 				return 'checked';
   229 			return '';
   251 			return '';
   230 		});
   252 		});
   231 		$(this).parents( 'form:first' ).find( 'table thead:visible, table tfoot:visible').find( '.check-column :checkbox' ).attr( 'checked', function() {
   253 
       
   254 		$(this).closest('table').children('thead,  tfoot').filter(':visible')
       
   255 		.children().children('.check-column').find(':checkbox')
       
   256 		.attr('checked', function() {
   232 			if ( toggle )
   257 			if ( toggle )
   233 				return '';
   258 				return '';
   234 			else if (c)
   259 			else if (c)
   235 				return 'checked';
   260 				return 'checked';
   236 			return '';
   261 			return '';
   237 		});
   262 		});
   238 	});
   263 	});
       
   264 
   239 	$('#default-password-nag-no').click( function() {
   265 	$('#default-password-nag-no').click( function() {
   240 		setUserSetting('default_password_nag', 'hide');
   266 		setUserSetting('default_password_nag', 'hide');
   241 		$('div.default-password-nag').hide();
   267 		$('div.default-password-nag').hide();
   242 		return false;
   268 		return false;
   243 	});
   269 	});
   244 	
       
   245 	
       
   246 });
   270 });
   247 
   271 
   248 jQuery(document).ready( function($){
   272 jQuery(document).ready( function($){
   249 	var turboNag = $('.turbo-nag');
   273 	var turboNag = $('span.turbo-nag', '#user_info');
   250 
   274 
   251 	if ( !turboNag.length || ('undefined' != typeof(google) && google.gears) )
   275 	if ( !turboNag.length || ('undefined' != typeof(google) && google.gears) )
   252 		return;
   276 		return;
   253 
   277 
   254 	if ( 'undefined' != typeof GearsFactory ) {
   278 	if ( 'undefined' != typeof GearsFactory ) {
   261 			}
   285 			}
   262 		} catch(e){}
   286 		} catch(e){}
   263 	}
   287 	}
   264 
   288 
   265 	turboNag.show();
   289 	turboNag.show();
   266 
       
   267 });
   290 });