2008-08-20 17:42:31 -04:00
|
|
|
(function($) {
|
|
|
|
postboxes = {
|
2008-10-08 19:32:34 -04:00
|
|
|
add_postbox_toggles : function(page,args) {
|
2008-11-09 09:54:39 -05:00
|
|
|
$('.postbox h3, .postbox .handlediv').click( function() {
|
2008-09-14 08:58:00 -04:00
|
|
|
$($(this).parent().get(0)).toggleClass('closed');
|
|
|
|
postboxes.save_state(page);
|
2008-10-22 02:52:06 -04:00
|
|
|
} );
|
2008-10-08 19:32:34 -04:00
|
|
|
$('.postbox h3 a').click( function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
} );
|
2008-08-20 17:42:31 -04:00
|
|
|
|
2008-10-29 23:03:00 -04:00
|
|
|
$('.hide-postbox-tog').click( function() {
|
|
|
|
var box = jQuery(this).val();
|
|
|
|
if ( jQuery(this).attr('checked') ) {
|
|
|
|
jQuery('#' + box).show();
|
|
|
|
if ( $.isFunction( postboxes.pbshow ) )
|
|
|
|
postboxes.pbshow( box );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
jQuery('#' + box).hide();
|
|
|
|
if ( $.isFunction( postboxes.pbhide ) )
|
|
|
|
postboxes.pbhide( box );
|
|
|
|
|
|
|
|
}
|
2008-10-22 02:52:06 -04:00
|
|
|
postboxes.save_state(page);
|
|
|
|
} );
|
|
|
|
|
2008-10-29 23:03:00 -04:00
|
|
|
this.expandSidebar();
|
2008-10-08 19:32:34 -04:00
|
|
|
this.init(page,args);
|
2008-08-20 17:42:31 -04:00
|
|
|
},
|
2008-09-14 08:58:00 -04:00
|
|
|
|
2008-10-29 23:03:00 -04:00
|
|
|
expandSidebar : function(doIt) {
|
|
|
|
if ( doIt || $('#side-sortables > .postbox:visible').length ) {
|
2008-10-30 19:43:08 -04:00
|
|
|
if ( ! $('#post-body').hasClass('has-sidebar') ) {
|
|
|
|
$('#post-body').addClass('has-sidebar');
|
2008-11-04 09:18:46 -05:00
|
|
|
var h = Math.min( $('#post-body').height(), 300 );
|
|
|
|
$('#side-sortables').css({'minHeight':h+'px'});
|
2008-10-30 19:43:08 -04:00
|
|
|
}
|
2008-08-20 17:42:31 -04:00
|
|
|
} else {
|
2008-10-29 23:03:00 -04:00
|
|
|
$('#post-body').removeClass('has-sidebar');
|
2008-10-30 19:43:08 -04:00
|
|
|
$('#side-sortables').css({'minHeight':'0'});
|
2008-08-20 17:42:31 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-10-29 23:03:00 -04:00
|
|
|
init : function(page, args) {
|
2008-10-08 19:32:34 -04:00
|
|
|
$.extend( this, args || {} );
|
2008-11-21 04:11:17 -05:00
|
|
|
$('#wpbody-content').css('overflow','hidden');
|
2008-10-29 23:03:00 -04:00
|
|
|
$('.meta-box-sortables').sortable( {
|
2008-10-21 18:06:41 -04:00
|
|
|
placeholder: 'sortable-placeholder',
|
2008-08-20 17:42:31 -04:00
|
|
|
connectWith: [ '.meta-box-sortables' ],
|
|
|
|
items: '> .postbox',
|
2008-09-11 17:40:28 -04:00
|
|
|
handle: '.hndle',
|
|
|
|
distance: 2,
|
2008-10-22 18:08:58 -04:00
|
|
|
tolerance: 'pointer',
|
2008-10-29 23:03:00 -04:00
|
|
|
sort: function(e,ui) {
|
|
|
|
if ( $(document).width() - e.clientX < 300 ) {
|
|
|
|
if ( ! $('#post-body').hasClass('has-sidebar') ) {
|
|
|
|
var pos = $('#side-sortables').offset();
|
|
|
|
|
|
|
|
$('#side-sortables').append(ui.item)
|
|
|
|
$(ui.placeholder).css({'top':pos.top,'left':pos.left}).width($(ui.item).width())
|
|
|
|
postboxes.expandSidebar(1);
|
|
|
|
}
|
|
|
|
}
|
2008-10-22 18:08:58 -04:00
|
|
|
},
|
2008-08-20 17:42:31 -04:00
|
|
|
stop: function() {
|
|
|
|
var postVars = {
|
|
|
|
action: 'meta-box-order',
|
2008-10-29 23:03:00 -04:00
|
|
|
_ajax_nonce: $('#meta-box-order-nonce').val(),
|
2008-08-20 17:42:31 -04:00
|
|
|
page: page
|
|
|
|
}
|
2008-10-29 23:03:00 -04:00
|
|
|
$('.meta-box-sortables').each( function() {
|
|
|
|
postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(',');
|
2008-08-20 17:42:31 -04:00
|
|
|
} );
|
2008-10-29 23:03:00 -04:00
|
|
|
$.post( postboxL10n.requestFile, postVars, function() {
|
2008-08-20 17:42:31 -04:00
|
|
|
postboxes.expandSidebar();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
2008-09-14 08:58:00 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
save_state : function(page) {
|
|
|
|
var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(',');
|
|
|
|
var hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
|
|
|
|
$.post(postboxL10n.requestFile, {
|
|
|
|
action: 'closed-postboxes',
|
|
|
|
closed: closed,
|
|
|
|
hidden: hidden,
|
|
|
|
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
|
|
|
|
page: page
|
|
|
|
});
|
2008-10-29 23:03:00 -04:00
|
|
|
postboxes.expandSidebar();
|
2008-10-08 19:32:34 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Callbacks */
|
2008-10-29 23:03:00 -04:00
|
|
|
pbshow : false,
|
2008-08-20 17:42:31 -04:00
|
|
|
|
2008-10-29 23:03:00 -04:00
|
|
|
pbhide : false
|
|
|
|
};
|
2008-01-28 16:34:42 -05:00
|
|
|
|
2008-09-14 08:58:00 -04:00
|
|
|
}(jQuery));
|