2009-01-12 08:43:17 -05:00
|
|
|
var postboxes;
|
2009-01-02 10:08:58 -05:00
|
|
|
(function($) {
|
|
|
|
postboxes = {
|
|
|
|
add_postbox_toggles : function(page,args) {
|
2009-03-25 10:29:22 -04:00
|
|
|
this.init(page,args);
|
2009-01-02 10:08:58 -05:00
|
|
|
$('.postbox h3, .postbox .handlediv').click( function() {
|
2009-06-20 06:32:09 -04:00
|
|
|
var p = $(this).parent('.postbox'), id = p.attr('id');
|
2009-03-25 10:29:22 -04:00
|
|
|
p.toggleClass('closed');
|
2009-01-02 10:08:58 -05:00
|
|
|
postboxes.save_state(page);
|
2009-06-20 06:32:09 -04: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 10:08:58 -05:00
|
|
|
} );
|
|
|
|
$('.postbox h3 a').click( function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
} );
|
|
|
|
$('.hide-postbox-tog').click( function() {
|
2009-03-25 10:29:22 -04:00
|
|
|
var box = $(this).val();
|
|
|
|
if ( $(this).attr('checked') ) {
|
|
|
|
$('#' + box).show();
|
2009-01-02 10:08:58 -05:00
|
|
|
if ( $.isFunction( postboxes.pbshow ) )
|
|
|
|
postboxes.pbshow( box );
|
|
|
|
} else {
|
2009-03-25 10:29:22 -04:00
|
|
|
$('#' + box).hide();
|
2009-01-02 10:08:58 -05:00
|
|
|
if ( $.isFunction( postboxes.pbhide ) )
|
|
|
|
postboxes.pbhide( box );
|
|
|
|
}
|
|
|
|
postboxes.save_state(page);
|
|
|
|
} );
|
2009-02-23 21:37:22 -05:00
|
|
|
$('.columns-prefs input[type="radio"]').click(function(){
|
2009-03-25 10:29:22 -04: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-23 21:37:22 -05:00
|
|
|
for ( i = 4; ( i > num && i > 1 ); i-- ) {
|
2009-03-25 10:29:22 -04:00
|
|
|
el = $('#' + colname(i) + '-sortables');
|
|
|
|
$('#' + colname(i-1) + '-sortables').append(el.children('.postbox'));
|
|
|
|
el.parent().hide();
|
2009-02-23 21:37:22 -05:00
|
|
|
}
|
|
|
|
for ( i = 1; i <= num; i++ ) {
|
2009-03-25 10:29:22 -04:00
|
|
|
el = $('#' + colname(i) + '-sortables');
|
2009-02-23 21:37:22 -05:00
|
|
|
if ( el.parent().is(':hidden') )
|
|
|
|
el.addClass('temp-border').parent().show();
|
|
|
|
}
|
2009-03-25 10:29:22 -04:00
|
|
|
$('.postbox-container:visible').css('width', 98/num + '%');
|
2009-02-23 21:37:22 -05:00
|
|
|
}
|
|
|
|
postboxes.save_order(page);
|
|
|
|
});
|
2009-03-25 10:29:22 -04:00
|
|
|
|
2009-02-23 21:37:22 -05: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 10:08:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
init : function(page, args) {
|
|
|
|
$.extend( this, args || {} );
|
|
|
|
$('#wpbody-content').css('overflow','hidden');
|
2009-03-25 10:29:22 -04:00
|
|
|
$('.meta-box-sortables').sortable({
|
2009-01-02 10:08:58 -05:00
|
|
|
placeholder: 'sortable-placeholder',
|
2009-03-25 10:29:22 -04:00
|
|
|
connectWith: '.meta-box-sortables',
|
|
|
|
items: '.postbox',
|
2009-01-02 10:08:58 -05:00
|
|
|
handle: '.hndle',
|
2009-03-25 10:29:22 -04:00
|
|
|
cursor: 'move',
|
2009-01-02 10:08:58 -05:00
|
|
|
distance: 2,
|
|
|
|
tolerance: 'pointer',
|
2009-03-25 10:29:22 -04:00
|
|
|
forcePlaceholderSize: true,
|
|
|
|
helper: 'clone',
|
|
|
|
opacity: 0.65,
|
|
|
|
start: function(e,ui) {
|
2009-03-28 04:21:43 -04:00
|
|
|
$('body').css({
|
|
|
|
WebkitUserSelect: 'none',
|
|
|
|
KhtmlUserSelect: 'none'
|
|
|
|
});
|
|
|
|
/*
|
2009-03-25 10:29:22 -04:00
|
|
|
if ( $.browser.msie )
|
2009-02-23 21:37:22 -05:00
|
|
|
return;
|
2009-03-25 10:29:22 -04:00
|
|
|
ui.item.addClass('noclick');
|
2009-03-28 04:21:43 -04:00
|
|
|
*/
|
2009-01-02 10:08:58 -05:00
|
|
|
},
|
2009-02-23 21:37:22 -05:00
|
|
|
stop: function(e,ui) {
|
|
|
|
postboxes.save_order(page);
|
|
|
|
ui.item.parent().removeClass('temp-border');
|
2009-03-28 04:21:43 -04:00
|
|
|
$('body').css({
|
|
|
|
WebkitUserSelect: '',
|
|
|
|
KhtmlUserSelect: ''
|
|
|
|
});
|
2009-01-02 10:08:58 -05:00
|
|
|
}
|
2009-03-28 04:21:43 -04:00
|
|
|
});
|
2009-01-02 10:08:58 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
save_state : function(page) {
|
|
|
|
var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','),
|
|
|
|
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
|
|
|
|
});
|
|
|
|
},
|
2009-03-25 10:29:22 -04:00
|
|
|
|
2009-02-23 21:37:22 -05:00
|
|
|
save_order : function(page) {
|
|
|
|
var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
|
|
|
|
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(',');
|
|
|
|
} );
|
|
|
|
$.post( postboxL10n.requestFile, postVars );
|
|
|
|
},
|
2009-01-02 10:08:58 -05:00
|
|
|
|
|
|
|
/* Callbacks */
|
|
|
|
pbshow : false,
|
|
|
|
|
|
|
|
pbhide : false
|
|
|
|
};
|
|
|
|
|
|
|
|
}(jQuery));
|