2009-01-12 14:43:17 +01:00
|
|
|
var postboxes;
|
2009-01-02 16:08:58 +01:00
|
|
|
(function($) {
|
|
|
|
postboxes = {
|
|
|
|
add_postbox_toggles : function(page,args) {
|
2009-03-25 15:29:22 +01:00
|
|
|
this.init(page,args);
|
2009-01-02 16:08:58 +01:00
|
|
|
$('.postbox h3, .postbox .handlediv').click( function() {
|
2009-06-20 12:30:09 +02:00
|
|
|
var p = $(this).parent('.postbox'), id = p.attr('id');
|
2010-03-02 19:06:14 +01:00
|
|
|
|
2009-03-25 15:29:22 +01:00
|
|
|
p.toggleClass('closed');
|
2009-01-02 16:08:58 +01:00
|
|
|
postboxes.save_state(page);
|
2009-06-20 12:30:09 +02:00
|
|
|
if ( id ) {
|
|
|
|
if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) )
|
|
|
|
postboxes.pbshow(id);
|
|
|
|
else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
|
|
|
|
postboxes.pbhide(id);
|
|
|
|
}
|
2009-01-02 16:08:58 +01:00
|
|
|
} );
|
|
|
|
$('.postbox h3 a').click( function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
} );
|
|
|
|
$('.hide-postbox-tog').click( function() {
|
2009-03-25 15:29:22 +01:00
|
|
|
var box = $(this).val();
|
2010-03-02 19:06:14 +01:00
|
|
|
|
2009-03-25 15:29:22 +01:00
|
|
|
if ( $(this).attr('checked') ) {
|
|
|
|
$('#' + box).show();
|
2009-01-02 16:08:58 +01:00
|
|
|
if ( $.isFunction( postboxes.pbshow ) )
|
|
|
|
postboxes.pbshow( box );
|
|
|
|
} else {
|
2009-03-25 15:29:22 +01:00
|
|
|
$('#' + box).hide();
|
2009-01-02 16:08:58 +01:00
|
|
|
if ( $.isFunction( postboxes.pbhide ) )
|
|
|
|
postboxes.pbhide( box );
|
|
|
|
}
|
|
|
|
postboxes.save_state(page);
|
|
|
|
} );
|
2009-02-24 03:37:22 +01:00
|
|
|
$('.columns-prefs input[type="radio"]').click(function(){
|
2009-03-25 15:29:22 +01:00
|
|
|
var num = $(this).val(), i, el, p = $('#poststuff');
|
|
|
|
|
|
|
|
if ( p.length ) { // write pages
|
|
|
|
if ( num == 2 ) {
|
|
|
|
p.addClass('has-right-sidebar');
|
|
|
|
$('#side-sortables').addClass('temp-border');
|
|
|
|
} else if ( num == 1 ) {
|
|
|
|
p.removeClass('has-right-sidebar');
|
|
|
|
$('#normal-sortables').append($('#side-sortables').children('.postbox'));
|
|
|
|
}
|
|
|
|
} else { // dashboard
|
2009-02-24 03:37:22 +01:00
|
|
|
for ( i = 4; ( i > num && i > 1 ); i-- ) {
|
2009-03-25 15:29:22 +01:00
|
|
|
el = $('#' + colname(i) + '-sortables');
|
|
|
|
$('#' + colname(i-1) + '-sortables').append(el.children('.postbox'));
|
|
|
|
el.parent().hide();
|
2009-02-24 03:37:22 +01:00
|
|
|
}
|
|
|
|
for ( i = 1; i <= num; i++ ) {
|
2009-03-25 15:29:22 +01:00
|
|
|
el = $('#' + colname(i) + '-sortables');
|
2009-02-24 03:37:22 +01:00
|
|
|
if ( el.parent().is(':hidden') )
|
|
|
|
el.addClass('temp-border').parent().show();
|
|
|
|
}
|
2009-03-25 15:29:22 +01:00
|
|
|
$('.postbox-container:visible').css('width', 98/num + '%');
|
2009-02-24 03:37:22 +01:00
|
|
|
}
|
|
|
|
postboxes.save_order(page);
|
|
|
|
});
|
2009-03-25 15:29:22 +01:00
|
|
|
|
2009-02-24 03:37:22 +01:00
|
|
|
function colname(n) {
|
|
|
|
switch (n) {
|
|
|
|
case 1:
|
|
|
|
return 'normal';
|
|
|
|
break
|
|
|
|
case 2:
|
|
|
|
return 'side';
|
|
|
|
break
|
|
|
|
case 3:
|
|
|
|
return 'column3';
|
|
|
|
break
|
|
|
|
case 4:
|
|
|
|
return 'column4';
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2009-01-02 16:08:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
init : function(page, args) {
|
|
|
|
$.extend( this, args || {} );
|
|
|
|
$('#wpbody-content').css('overflow','hidden');
|
2009-03-25 15:29:22 +01:00
|
|
|
$('.meta-box-sortables').sortable({
|
2009-01-02 16:08:58 +01:00
|
|
|
placeholder: 'sortable-placeholder',
|
2009-03-25 15:29:22 +01:00
|
|
|
connectWith: '.meta-box-sortables',
|
|
|
|
items: '.postbox',
|
2009-01-02 16:08:58 +01:00
|
|
|
handle: '.hndle',
|
2009-03-25 15:29:22 +01:00
|
|
|
cursor: 'move',
|
2009-01-02 16:08:58 +01:00
|
|
|
distance: 2,
|
|
|
|
tolerance: 'pointer',
|
2009-03-25 15:29:22 +01:00
|
|
|
forcePlaceholderSize: true,
|
|
|
|
helper: 'clone',
|
|
|
|
opacity: 0.65,
|
|
|
|
start: function(e,ui) {
|
2009-03-28 09:21:43 +01:00
|
|
|
$('body').css({
|
|
|
|
WebkitUserSelect: 'none',
|
|
|
|
KhtmlUserSelect: 'none'
|
|
|
|
});
|
|
|
|
/*
|
2009-03-25 15:29:22 +01:00
|
|
|
if ( $.browser.msie )
|
2009-02-24 03:37:22 +01:00
|
|
|
return;
|
2009-03-25 15:29:22 +01:00
|
|
|
ui.item.addClass('noclick');
|
2009-03-28 09:21:43 +01:00
|
|
|
*/
|
2009-01-02 16:08:58 +01:00
|
|
|
},
|
2009-02-24 03:37:22 +01:00
|
|
|
stop: function(e,ui) {
|
|
|
|
postboxes.save_order(page);
|
|
|
|
ui.item.parent().removeClass('temp-border');
|
2009-03-28 09:21:43 +01:00
|
|
|
$('body').css({
|
|
|
|
WebkitUserSelect: '',
|
|
|
|
KhtmlUserSelect: ''
|
|
|
|
});
|
2009-01-02 16:08:58 +01:00
|
|
|
}
|
2009-03-28 09:21:43 +01:00
|
|
|
});
|
2009-01-02 16:08:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
save_state : function(page) {
|
|
|
|
var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','),
|
2010-03-02 19:06:14 +01:00
|
|
|
hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
|
|
|
|
|
2009-10-13 12:02:42 +02:00
|
|
|
$.post(ajaxurl, {
|
2009-01-02 16:08:58 +01:00
|
|
|
action: 'closed-postboxes',
|
|
|
|
closed: closed,
|
|
|
|
hidden: hidden,
|
|
|
|
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
|
|
|
|
page: page
|
|
|
|
});
|
|
|
|
},
|
2009-03-25 15:29:22 +01:00
|
|
|
|
2009-02-24 03:37:22 +01:00
|
|
|
save_order : function(page) {
|
|
|
|
var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
|
2010-03-02 19:06:14 +01:00
|
|
|
|
2009-02-24 03:37:22 +01:00
|
|
|
postVars = {
|
|
|
|
action: 'meta-box-order',
|
|
|
|
_ajax_nonce: $('#meta-box-order-nonce').val(),
|
|
|
|
page_columns: page_columns,
|
|
|
|
page: page
|
|
|
|
}
|
|
|
|
$('.meta-box-sortables').each( function() {
|
|
|
|
postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(',');
|
|
|
|
} );
|
2009-10-13 12:02:42 +02:00
|
|
|
$.post( ajaxurl, postVars );
|
2009-02-24 03:37:22 +01:00
|
|
|
},
|
2009-01-02 16:08:58 +01:00
|
|
|
|
|
|
|
/* Callbacks */
|
|
|
|
pbshow : false,
|
|
|
|
|
|
|
|
pbhide : false
|
|
|
|
};
|
|
|
|
|
|
|
|
}(jQuery));
|