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