| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 var postboxes; 2 3 (function($) { 4 postboxes = { 5 add_postbox_toggles : function(page, args) { 6 var self = this; 7 8 self.init(page, args); 9 10 $('.postbox h3, .postbox .handlediv').bind('click.postboxes', function() { 11 var p = $(this).parent('.postbox'), id = p.attr('id'); 12 13 if ( 'dashboard_browser_nag' == id ) 14 return; 15 16 p.toggleClass('closed'); 17 18 if ( page != 'press-this' ) 19 self.save_state(page); 20 21 if ( id ) { 22 if ( !p.hasClass('closed') && $.isFunction(postboxes.pbshow) ) 23 self.pbshow(id); 24 else if ( p.hasClass('closed') && $.isFunction(postboxes.pbhide) ) 25 self.pbhide(id); 26 } 27 }); 28 29 $('.postbox h3 a').click( function(e) { 30 e.stopPropagation(); 31 }); 32 33 $('.postbox a.dismiss').bind('click.postboxes', function(e) { 34 var hide_id = $(this).parents('.postbox').attr('id') + '-hide'; 35 $( '#' + hide_id ).prop('checked', false).triggerHandler('click'); 36 return false; 37 }); 38 39 $('.hide-postbox-tog').bind('click.postboxes', function() { 40 var box = $(this).val(); 41 42 if ( $(this).prop('checked') ) { 43 $('#' + box).show(); 44 if ( $.isFunction( postboxes.pbshow ) ) 45 self.pbshow( box ); 46 } else { 47 $('#' + box).hide(); 48 if ( $.isFunction( postboxes.pbhide ) ) 49 self.pbhide( box ); 50 } 51 self.save_state(page); 52 self._mark_area(); 53 }); 54 55 $('.columns-prefs input[type="radio"]').bind('click.postboxes', function(){ 56 var n = parseInt($(this).val(), 10); 57 58 if ( n ) { 59 self._pb_edit(n); 60 self.save_order(page); 61 } 62 }); 63 }, 64 65 init : function(page, args) { 66 var isMobile = $(document.body).hasClass('mobile'); 67 68 $.extend( this, args || {} ); 69 $('#wpbody-content').css('overflow','hidden'); 70 $('.meta-box-sortables').sortable({ 71 placeholder: 'sortable-placeholder', 72 connectWith: '.meta-box-sortables', 73 items: '.postbox', 74 handle: '.hndle', 75 cursor: 'move', 76 delay: ( isMobile ? 200 : 0 ), 77 distance: 2, 78 tolerance: 'pointer', 79 forcePlaceholderSize: true, 80 helper: 'clone', 81 opacity: 0.65, 82 stop: function(e,ui) { 83 if ( $(this).find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id ) { 84 $(this).sortable('cancel'); 85 return; 86 } 87 88 postboxes.save_order(page); 89 }, 90 receive: function(e,ui) { 91 if ( 'dashboard_browser_nag' == ui.item[0].id ) 92 $(ui.sender).sortable('cancel'); 93 94 postboxes._mark_area(); 95 } 96 }); 97 98 if ( isMobile ) { 99 $(document.body).bind('orientationchange.postboxes', function(){ postboxes._pb_change(); }); 100 this._pb_change(); 101 } 102 103 this._mark_area(); 104 }, 105 106 save_state : function(page) { 107 var closed = $('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','), 108 hidden = $('.postbox').filter(':hidden').map(function() { return this.id; }).get().join(','); 109 110 $.post(ajaxurl, { 111 action: 'closed-postboxes', 112 closed: closed, 113 hidden: hidden, 114 closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), 115 page: page 116 }); 117 }, 118 119 save_order : function(page) { 120 var postVars, page_columns = $('.columns-prefs input:checked').val() || 0; 121 122 postVars = { 123 action: 'meta-box-order', 124 _ajax_nonce: $('#meta-box-order-nonce').val(), 125 page_columns: page_columns, 126 page: page 127 } 128 $('.meta-box-sortables').each( function() { 129 postVars["order[" + this.id.split('-')[0] + "]"] = $(this).sortable( 'toArray' ).join(','); 130 } ); 131 $.post( ajaxurl, postVars ); 132 }, 133 134 _mark_area : function() { 135 var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables'); 136 137 $('#dashboard-widgets .meta-box-sortables:visible').each(function(n, el){ 138 var t = $(this); 139 140 if ( visible == 1 || t.children('.postbox:visible').length ) 141 t.removeClass('empty-container'); 142 else 143 t.addClass('empty-container'); 144 }); 145 146 if ( side.length ) { 147 if ( side.children('.postbox:visible').length ) 148 side.removeClass('empty-container'); 149 else if ( $('#postbox-container-1').css('width') == '280px' ) 150 side.addClass('empty-container'); 151 } 152 }, 153 154 _pb_edit : function(n) { 155 var el = $('.metabox-holder').get(0); 156 el.className = el.className.replace(/columns-\d+/, 'columns-' + n); 157 }, 158 159 _pb_change : function() { 160 switch ( window.orientation ) { 161 case 90: 162 case -90: 163 this._pb_edit(2); 164 break; 165 case 0: 166 case 180: 167 if ( $('#poststuff').length ) 168 this._pb_edit(1); 169 else 170 this._pb_edit(2); 171 break; 172 } 173 }, 174 175 /* Callbacks */ 176 pbshow : false, 177 178 pbhide : false 179 }; 180 181 }(jQuery));
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri May 25 03:56:23 2012 | Hosted by follow the white rabbit. |