2008-08-20 23:42:31 +02:00
|
|
|
(function($) {
|
|
|
|
postboxes = {
|
2008-10-09 01:32:34 +02:00
|
|
|
add_postbox_toggles : function(page,args) {
|
2008-10-21 06:55:38 +02:00
|
|
|
$('.postbox h3').click( function() {
|
2008-09-14 14:58:00 +02:00
|
|
|
$($(this).parent().get(0)).toggleClass('closed');
|
|
|
|
postboxes.save_state(page);
|
2008-10-22 08:52:06 +02:00
|
|
|
} );
|
2008-10-09 01:32:34 +02:00
|
|
|
$('.postbox h3 a').click( function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
} );
|
2008-08-20 23:42:31 +02:00
|
|
|
|
2008-10-30 04:03:00 +01: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 08:52:06 +02:00
|
|
|
postboxes.save_state(page);
|
|
|
|
} );
|
|
|
|
|
2008-10-30 04:03:00 +01:00
|
|
|
this.expandSidebar();
|
2008-10-09 01:32:34 +02:00
|
|
|
this.init(page,args);
|
2008-08-20 23:42:31 +02:00
|
|
|
},
|
2008-09-14 14:58:00 +02:00
|
|
|
|
2008-10-30 04:03:00 +01:00
|
|
|
expandSidebar : function(doIt) {
|
|
|
|
if ( doIt || $('#side-sortables > .postbox:visible').length ) {
|
|
|
|
$('#post-body').addClass('has-sidebar');
|
|
|
|
$('#side-sortables').height( $('#post-body').height() );
|
2008-08-20 23:42:31 +02:00
|
|
|
} else {
|
2008-10-30 04:03:00 +01:00
|
|
|
$('#post-body').removeClass('has-sidebar');
|
|
|
|
$('#side-sortables').height('0')
|
2008-08-20 23:42:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-10-30 04:03:00 +01:00
|
|
|
init : function(page, args) {
|
2008-10-09 01:32:34 +02:00
|
|
|
$.extend( this, args || {} );
|
2008-10-30 04:03:00 +01:00
|
|
|
$('.meta-box-sortables').sortable( {
|
2008-10-22 00:06:41 +02:00
|
|
|
placeholder: 'sortable-placeholder',
|
2008-08-20 23:42:31 +02:00
|
|
|
connectWith: [ '.meta-box-sortables' ],
|
|
|
|
items: '> .postbox',
|
2008-09-11 23:40:28 +02:00
|
|
|
handle: '.hndle',
|
|
|
|
distance: 2,
|
2008-10-23 00:08:58 +02:00
|
|
|
tolerance: 'pointer',
|
2008-10-30 04:03:00 +01: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-23 00:08:58 +02:00
|
|
|
},
|
2008-08-20 23:42:31 +02:00
|
|
|
stop: function() {
|
|
|
|
var postVars = {
|
|
|
|
action: 'meta-box-order',
|
2008-10-30 04:03:00 +01:00
|
|
|
_ajax_nonce: $('#meta-box-order-nonce').val(),
|
2008-08-20 23:42:31 +02:00
|
|
|
page: page
|
|
|
|
}
|
2008-10-30 04:03:00 +01:00
|
|
|
$('.meta-box-sortables').each( function() {
|
|
|
|
postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(',');
|
2008-08-20 23:42:31 +02:00
|
|
|
} );
|
2008-10-30 04:03:00 +01:00
|
|
|
$.post( postboxL10n.requestFile, postVars, function() {
|
2008-08-20 23:42:31 +02:00
|
|
|
postboxes.expandSidebar();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
} );
|
2008-09-14 14:58:00 +02: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-30 04:03:00 +01:00
|
|
|
postboxes.expandSidebar();
|
2008-10-09 01:32:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/* Callbacks */
|
2008-10-30 04:03:00 +01:00
|
|
|
pbshow : false,
|
2008-08-20 23:42:31 +02:00
|
|
|
|
2008-10-30 04:03:00 +01:00
|
|
|
pbhide : false
|
|
|
|
};
|
2008-01-28 22:34:42 +01:00
|
|
|
|
2008-09-14 14:58:00 +02:00
|
|
|
}(jQuery));
|