1 /* global ajaxurl, postBoxL10n */
6 var $document = $( document );
9 handle_click : function () {
11 p = $el.parent( '.postbox' ),
15 if ( 'dashboard_browser_nag' === id ) {
19 p.toggleClass( 'closed' );
21 ariaExpandedValue = ! p.hasClass( 'closed' );
23 if ( $el.hasClass( 'handlediv' ) ) {
24 // The handle button was clicked.
25 $el.attr( 'aria-expanded', ariaExpandedValue );
27 // The handle heading was clicked.
28 $el.closest( '.postbox' ).find( 'button.handlediv' )
29 .attr( 'aria-expanded', ariaExpandedValue );
32 if ( postboxes.page !== 'press-this' ) {
33 postboxes.save_state( postboxes.page );
37 if ( !p.hasClass('closed') && $.isFunction( postboxes.pbshow ) ) {
38 postboxes.pbshow( id );
39 } else if ( p.hasClass('closed') && $.isFunction( postboxes.pbhide ) ) {
40 postboxes.pbhide( id );
44 $document.trigger( 'postbox-toggled', p );
47 add_postbox_toggles : function (page, args) {
48 var $handles = $( '.postbox .hndle, .postbox .handlediv' );
51 this.init( page, args );
53 $handles.on( 'click.postboxes', this.handle_click );
55 $('.postbox .hndle a').click( function(e) {
59 $( '.postbox a.dismiss' ).on( 'click.postboxes', function( e ) {
60 var hide_id = $(this).parents('.postbox').attr('id') + '-hide';
62 $( '#' + hide_id ).prop('checked', false).triggerHandler('click');
65 $('.hide-postbox-tog').bind('click.postboxes', function() {
68 $postbox = $( '#' + boxId );
70 if ( $el.prop( 'checked' ) ) {
72 if ( $.isFunction( postboxes.pbshow ) ) {
73 postboxes.pbshow( boxId );
77 if ( $.isFunction( postboxes.pbhide ) ) {
78 postboxes.pbhide( boxId );
81 postboxes.save_state( page );
82 postboxes._mark_area();
83 $document.trigger( 'postbox-toggled', $postbox );
86 $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){
87 var n = parseInt($(this).val(), 10);
90 postboxes._pb_edit(n);
91 postboxes.save_order( page );
96 init : function(page, args) {
97 var isMobile = $( document.body ).hasClass( 'mobile' ),
98 $handleButtons = $( '.postbox .handlediv' );
100 $.extend( this, args || {} );
101 $('#wpbody-content').css('overflow','hidden');
102 $('.meta-box-sortables').sortable({
103 placeholder: 'sortable-placeholder',
104 connectWith: '.meta-box-sortables',
108 delay: ( isMobile ? 200 : 0 ),
110 tolerance: 'pointer',
111 forcePlaceholderSize: true,
112 helper: function( event, element ) {
113 // `helper: 'clone'` is equivalent to `return element.clone();`
114 // Cloning a checked radio and then inserting that clone next to the original
115 // radio unchecks the original radio (since only one of the two can be checked).
116 // We get around this by renaming the helper's inputs' name attributes so that,
117 // when the helper is inserted into the DOM for the sortable, no radios are
118 // duplicated, and no original radio gets unchecked.
119 return element.clone()
121 .attr( 'name', function( i, currentName ) {
122 return 'sort_' + parseInt( Math.random() * 100000, 10 ).toString() + '_' + currentName;
130 if ( $el.find( '#dashboard_browser_nag' ).is( ':visible' ) && 'dashboard_browser_nag' != this.firstChild.id ) {
131 $el.sortable('cancel');
135 postboxes.save_order(page);
137 receive: function(e,ui) {
138 if ( 'dashboard_browser_nag' == ui.item[0].id )
139 $(ui.sender).sortable('cancel');
141 postboxes._mark_area();
142 $document.trigger( 'postbox-moved', ui.item );
147 $(document.body).bind('orientationchange.postboxes', function(){ postboxes._pb_change(); });
153 // Set the handle buttons `aria-expanded` attribute initial value on page load.
154 $handleButtons.each( function () {
156 $el.attr( 'aria-expanded', ! $el.parent( '.postbox' ).hasClass( 'closed' ) );
160 save_state : function(page) {
163 // Return on the nav-menus.php screen, see #35112.
164 if ( 'nav-menus' === page ) {
168 closed = $( '.postbox' ).filter( '.closed' ).map( function() { return this.id; } ).get().join( ',' );
169 hidden = $( '.postbox' ).filter( ':hidden' ).map( function() { return this.id; } ).get().join( ',' );
172 action: 'closed-postboxes',
175 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
180 save_order : function(page) {
181 var postVars, page_columns = $('.columns-prefs input:checked').val() || 0;
184 action: 'meta-box-order',
185 _ajax_nonce: $('#meta-box-order-nonce').val(),
186 page_columns: page_columns,
189 $('.meta-box-sortables').each( function() {
190 postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',' );
192 $.post( ajaxurl, postVars );
195 _mark_area : function() {
196 var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables');
198 $( '#dashboard-widgets .meta-box-sortables:visible' ).each( function() {
201 if ( visible == 1 || t.children('.postbox:visible').length ) {
202 t.removeClass('empty-container');
205 t.addClass('empty-container');
206 t.attr('data-emptyString', postBoxL10n.postBoxEmptyString);
211 if ( side.children('.postbox:visible').length )
212 side.removeClass('empty-container');
213 else if ( $('#postbox-container-1').css('width') == '280px' )
214 side.addClass('empty-container');
218 _pb_edit : function(n) {
219 var el = $('.metabox-holder').get(0);
222 el.className = el.className.replace(/columns-\d+/, 'columns-' + n);
225 $( document ).trigger( 'postboxes-columnchange' );
228 _pb_change : function() {
229 var check = $( 'label.columns-prefs-1 input[type="radio"]' );
231 switch ( window.orientation ) {
234 if ( !check.length || !check.is(':checked') )
239 if ( $('#poststuff').length ) {
242 if ( !check.length || !check.is(':checked') )