wp/wp-admin/js/postbox.js
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
       
     1 /* global ajaxurl */
       
     2 
     1 var postboxes;
     3 var postboxes;
     2 
     4 
     3 (function($) {
     5 (function($) {
       
     6 	var $document = $( document );
       
     7 
     4 	postboxes = {
     8 	postboxes = {
     5 		add_postbox_toggles : function(page, args) {
     9 		add_postbox_toggles : function(page, args) {
     6 			var self = this;
    10 			var self = this;
     7 
    11 
     8 			self.init(page, args);
    12 			self.init(page, args);
     9 
    13 
    10 			$('.postbox h3, .postbox .handlediv').bind('click.postboxes', function() {
    14 			$('.postbox .hndle, .postbox .handlediv').bind('click.postboxes', function() {
    11 				var p = $(this).parent('.postbox'), id = p.attr('id');
    15 				var p = $(this).parent('.postbox'), id = p.attr('id');
    12 
    16 
    13 				if ( 'dashboard_browser_nag' == id )
    17 				if ( 'dashboard_browser_nag' == id )
    14 					return;
    18 					return;
    15 
    19 
    22 					if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) )
    26 					if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) )
    23 						self.pbshow(id);
    27 						self.pbshow(id);
    24 					else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
    28 					else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
    25 						self.pbhide(id);
    29 						self.pbhide(id);
    26 				}
    30 				}
       
    31 
       
    32 				$document.trigger( 'postbox-toggled', p );
    27 			});
    33 			});
    28 
    34 
    29 			$('.postbox h3 a').click( function(e) {
    35 			$('.postbox .hndle a').click( function(e) {
    30 				e.stopPropagation();
    36 				e.stopPropagation();
    31 			});
    37 			});
    32 
    38 
    33 			$('.postbox a.dismiss').bind('click.postboxes', function(e) {
    39 			$( '.postbox a.dismiss' ).bind( 'click.postboxes', function() {
    34 				var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
    40 				var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
    35 				$( '#' + hide_id ).prop('checked', false).triggerHandler('click');
    41 				$( '#' + hide_id ).prop('checked', false).triggerHandler('click');
    36 				return false;
    42 				return false;
    37 			});
    43 			});
    38 
    44 
    39 			$('.hide-postbox-tog').bind('click.postboxes', function() {
    45 			$('.hide-postbox-tog').bind('click.postboxes', function() {
    40 				var box = $(this).val();
    46 				var boxId = $(this).val(),
       
    47 					$postbox = $( '#' + boxId );
    41 
    48 
    42 				if ( $(this).prop('checked') ) {
    49 				if ( $(this).prop('checked') ) {
    43 					$('#' + box).show();
    50 					$postbox.show();
    44 					if ( $.isFunction( postboxes.pbshow ) )
    51 					if ( $.isFunction( postboxes.pbshow ) )
    45 						self.pbshow( box );
    52 						self.pbshow( boxId );
    46 				} else {
    53 				} else {
    47 					$('#' + box).hide();
    54 					$postbox.hide();
    48 					if ( $.isFunction( postboxes.pbhide ) )
    55 					if ( $.isFunction( postboxes.pbhide ) )
    49 						self.pbhide( box );
    56 						self.pbhide( boxId );
    50 				}
    57 				}
    51 				self.save_state(page);
    58 				self.save_state(page);
    52 				self._mark_area();
    59 				self._mark_area();
       
    60 				$document.trigger( 'postbox-toggled', $postbox );
    53 			});
    61 			});
    54 
    62 
    55 			$('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){
    63 			$('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){
    56 				var n = parseInt($(this).val(), 10);
    64 				var n = parseInt($(this).val(), 10);
    57 
    65 
    77 				distance: 2,
    85 				distance: 2,
    78 				tolerance: 'pointer',
    86 				tolerance: 'pointer',
    79 				forcePlaceholderSize: true,
    87 				forcePlaceholderSize: true,
    80 				helper: 'clone',
    88 				helper: 'clone',
    81 				opacity: 0.65,
    89 				opacity: 0.65,
    82 				stop: function(e,ui) {
    90 				stop: function() {
    83 					if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) {
    91 					if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) {
    84 						$(this).sortable('cancel');
    92 						$(this).sortable('cancel');
    85 						return;
    93 						return;
    86 					}
    94 					}
    87 
    95 
   122 			postVars = {
   130 			postVars = {
   123 				action: 'meta-box-order',
   131 				action: 'meta-box-order',
   124 				_ajax_nonce: $('#meta-box-order-nonce').val(),
   132 				_ajax_nonce: $('#meta-box-order-nonce').val(),
   125 				page_columns: page_columns,
   133 				page_columns: page_columns,
   126 				page: page
   134 				page: page
   127 			}
   135 			};
   128 			$('.meta-box-sortables').each( function() {
   136 			$('.meta-box-sortables').each( function() {
   129 				postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(',');
   137 				postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' );
   130 			} );
   138 			} );
   131 			$.post( ajaxurl, postVars );
   139 			$.post( ajaxurl, postVars );
   132 		},
   140 		},
   133 
   141 
   134 		_mark_area : function() {
   142 		_mark_area : function() {
   135 			var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables');
   143 			var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables');
   136 
   144 
   137 			$('#dashboard-widgets .meta-box-sortables:visible').each(function(n, el){
   145 			$( '#dashboard-widgets .meta-box-sortables:visible' ).each( function() {
   138 				var t = $(this);
   146 				var t = $(this);
   139 
   147 
   140 				if ( visible == 1 || t.children('.postbox:visible').length )
   148 				if ( visible == 1 || t.children('.postbox:visible').length )
   141 					t.removeClass('empty-container');
   149 					t.removeClass('empty-container');
   142 				else
   150 				else
   151 			}
   159 			}
   152 		},
   160 		},
   153 
   161 
   154 		_pb_edit : function(n) {
   162 		_pb_edit : function(n) {
   155 			var el = $('.metabox-holder').get(0);
   163 			var el = $('.metabox-holder').get(0);
   156 			el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
   164 
       
   165 			if ( el ) {
       
   166 				el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
       
   167 			}
       
   168 
       
   169 			$( document ).trigger( 'postboxes-columnchange' );
   157 		},
   170 		},
   158 
   171 
   159 		_pb_change : function() {
   172 		_pb_change : function() {
   160 			var check = $( 'label.columns-prefs-1 input[type="radio"]' );
   173 			var check = $( 'label.columns-prefs-1 input[type="radio"]' );
   161 
   174