6 var $document = $( document );
9 add_postbox_toggles : function(page, args) {
12 self.init(page, args);
14 $('.postbox .hndle, .postbox .handlediv').bind('click.postboxes', function() {
15 var p = $(this).parent('.postbox'), id = p.attr('id');
17 if ( 'dashboard_browser_nag' == id )
20 p.toggleClass('closed');
22 if ( page != 'press-this' )
23 self.save_state(page);
26 if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) )
28 else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) )
32 $document.trigger( 'postbox-toggled', p );
35 $('.postbox .hndle a').click( function(e) {
39 $( '.postbox a.dismiss' ).bind( 'click.postboxes', function() {
40 var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
41 $( '#' + hide_id ).prop('checked', false).triggerHandler('click');
45 $('.hide-postbox-tog').bind('click.postboxes', function() {
46 var boxId = $(this).val(),
47 $postbox = $( '#' + boxId );
49 if ( $(this).prop('checked') ) {
51 if ( $.isFunction( postboxes.pbshow ) )
55 if ( $.isFunction( postboxes.pbhide ) )
58 self.save_state(page);
60 $document.trigger( 'postbox-toggled', $postbox );
63 $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){
64 var n = parseInt($(this).val(), 10);
68 self.save_order(page);
73 init : function(page, args) {
74 var isMobile = $(document.body).hasClass('mobile');
76 $.extend( this, args || {} );
77 $('#wpbody-content').css('overflow','hidden');
78 $('.meta-box-sortables').sortable({
79 placeholder: 'sortable-placeholder',
80 connectWith: '.meta-box-sortables',
84 delay: ( isMobile ? 200 : 0 ),
87 forcePlaceholderSize: true,
91 if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) {
92 $(this).sortable('cancel');
96 postboxes.save_order(page);
98 receive: function(e,ui) {
99 if ( 'dashboard_browser_nag' == ui.item[0].id )
100 $(ui.sender).sortable('cancel');
102 postboxes._mark_area();
107 $(document.body).bind('orientationchange.postboxes', function(){ postboxes._pb_change(); });
114 save_state : function(page) {
115 var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','),
116 hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(',');
119 action: 'closed-postboxes',
122 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
127 save_order : function(page) {
128 var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
131 action: 'meta-box-order',
132 _ajax_nonce: $('#meta-box-order-nonce').val(),
133 page_columns: page_columns,
136 $('.meta-box-sortables').each( function() {
137 postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' );
139 $.post( ajaxurl, postVars );
142 _mark_area : function() {
143 var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables');
145 $( '#dashboard-widgets .meta-box-sortables:visible' ).each( function() {
148 if ( visible == 1 || t.children('.postbox:visible').length )
149 t.removeClass('empty-container');
151 t.addClass('empty-container');
155 if ( side.children('.postbox:visible').length )
156 side.removeClass('empty-container');
157 else if ( $('#postbox-container-1').css('width') == '280px' )
158 side.addClass('empty-container');
162 _pb_edit : function(n) {
163 var el = $('.metabox-holder').get(0);
166 el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
169 $( document ).trigger( 'postboxes-columnchange' );
172 _pb_change : function() {
173 var check = $( 'label.columns-prefs-1 input[type="radio"]' );
175 switch ( window.orientation ) {
178 if ( !check.length || !check.is(':checked') )
183 if ( $('#poststuff').length ) {
186 if ( !check.length || !check.is(':checked') )