Ticket #47569: 47569.diff
| File 47569.diff, 12.3 KB (added by , 7 years ago) |
|---|
-
postbox.js
9 9 10 10 /* global ajaxurl, postBoxL10n, postboxes */ 11 11 12 (function ($) {13 var $document = $( document);12 (function ($) { 13 var $document = $(document); 14 14 15 15 /** 16 16 * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see … … 37 37 * 38 38 * @returns {void} 39 39 */ 40 handle_click : function () {41 var $el = $( this),42 p = $el.parent( '.postbox'),43 id = p.attr( 'id'),40 handle_click: function () { 41 var $el = $(this), 42 p = $el.parent('.postbox'), 43 id = p.attr('id'), 44 44 ariaExpandedValue; 45 45 46 if ( 'dashboard_browser_nag' === id) {46 if ('dashboard_browser_nag' === id) { 47 47 return; 48 48 } 49 49 50 p.toggleClass( 'closed');50 p.toggleClass('closed'); 51 51 52 ariaExpandedValue = ! p.hasClass( 'closed');52 ariaExpandedValue = !p.hasClass('closed'); 53 53 54 if ( $el.hasClass( 'handlediv' )) {54 if ($el.hasClass('handlediv')) { 55 55 // The handle button was clicked. 56 $el.attr( 'aria-expanded', ariaExpandedValue);56 $el.attr('aria-expanded', ariaExpandedValue); 57 57 } else { 58 58 // The handle heading was clicked. 59 $el.closest( '.postbox' ).find( 'button.handlediv')60 .attr( 'aria-expanded', ariaExpandedValue);59 $el.closest('.postbox').find('button.handlediv') 60 .attr('aria-expanded', ariaExpandedValue); 61 61 } 62 62 63 if ( postboxes.page !== 'press-this') {64 postboxes.save_state( postboxes.page);63 if (postboxes.page !== 'press-this') { 64 postboxes.save_state(postboxes.page); 65 65 } 66 66 67 if ( id) {68 if ( !p.hasClass('closed') && $.isFunction( postboxes.pbshow )) {69 postboxes.pbshow( id);70 } else if ( p.hasClass('closed') && $.isFunction( postboxes.pbhide )) {71 postboxes.pbhide( id);67 if (id) { 68 if (!p.hasClass('closed') && $.isFunction(postboxes.pbshow)) { 69 postboxes.pbshow(id); 70 } else if (p.hasClass('closed') && $.isFunction(postboxes.pbhide)) { 71 postboxes.pbhide(id); 72 72 } 73 73 } 74 74 … … 83 83 * @event postboxes#postbox-toggled 84 84 * @type {Object} 85 85 */ 86 $document.trigger( 'postbox-toggled', p);86 $document.trigger('postbox-toggled', p); 87 87 }, 88 88 89 89 /** … … 98 98 * @param {Function} args.pbhide A callback that is called when a postbox closes. 99 99 * @returns {void} 100 100 */ 101 add_postbox_toggles : function (page, args) {102 var $handles = $( '.postbox .hndle, .postbox .handlediv');101 add_postbox_toggles: function (page, args) { 102 var $handles = $('.postbox .hndle, .postbox .handlediv'); 103 103 104 104 this.page = page; 105 this.init( page, args);105 this.init(page, args); 106 106 107 $handles.on( 'click.postboxes', this.handle_click);107 $handles.on('click.postboxes', this.handle_click); 108 108 109 109 /** 110 110 * @since 2.7.0 111 111 */ 112 $('.postbox .hndle a').click( function(e) {112 $('.postbox .hndle a').click(function (e) { 113 113 e.stopPropagation(); 114 114 }); 115 115 … … 123 123 * 124 124 * @returns {void} 125 125 */ 126 $( '.postbox a.dismiss' ).on( 'click.postboxes', function( e) {126 $('.postbox a.dismiss').on('click.postboxes', function (e) { 127 127 var hide_id = $(this).parents('.postbox').attr('id') + '-hide'; 128 128 e.preventDefault(); 129 $( '#' + hide_id).prop('checked', false).triggerHandler('click');129 $('#' + hide_id).prop('checked', false).triggerHandler('click'); 130 130 }); 131 131 132 132 /** … … 142 142 * 143 143 * @returns {void} 144 144 */ 145 $('.hide-postbox-tog').bind('click.postboxes', function () {145 $('.hide-postbox-tog').bind('click.postboxes', function () { 146 146 var $el = $(this), 147 147 boxId = $el.val(), 148 $postbox = $( '#' + boxId);148 $postbox = $('#' + boxId); 149 149 150 if ( $el.prop( 'checked' )) {150 if ($el.prop('checked')) { 151 151 $postbox.show(); 152 if ( $.isFunction( postboxes.pbshow )) {153 postboxes.pbshow( boxId);152 if ($.isFunction(postboxes.pbshow)) { 153 postboxes.pbshow(boxId); 154 154 } 155 155 } else { 156 156 $postbox.hide(); 157 if ( $.isFunction( postboxes.pbhide )) {158 postboxes.pbhide( boxId);157 if ($.isFunction(postboxes.pbhide)) { 158 postboxes.pbhide(boxId); 159 159 } 160 160 } 161 161 162 postboxes.save_state( page);162 postboxes.save_state(page); 163 163 postboxes._mark_area(); 164 164 165 165 /** … … 166 166 * @since 4.0.0 167 167 * @see postboxes.handle_click 168 168 */ 169 $document.trigger( 'postbox-toggled', $postbox);169 $document.trigger('postbox-toggled', $postbox); 170 170 }); 171 171 172 172 /** … … 176 176 * 177 177 * @returns {void} 178 178 */ 179 $('.columns-prefs input[type="radio"]').bind('click.postboxes', function (){179 $('.columns-prefs input[type="radio"]').bind('click.postboxes', function () { 180 180 var n = parseInt($(this).val(), 10); 181 181 182 if ( n) {182 if (n) { 183 183 postboxes._pb_edit(n); 184 postboxes.save_order( page);184 postboxes.save_order(page); 185 185 } 186 186 }); 187 187 }, … … 200 200 * 201 201 * @returns {void} 202 202 */ 203 init : function(page, args) {204 var isMobile = $( document.body ).hasClass( 'mobile'),205 $handleButtons = $( '.postbox .handlediv');203 init: function (page, args) { 204 var isMobile = $(document.body).hasClass('mobile'), 205 $handleButtons = $('.postbox .handlediv'); 206 206 207 $.extend( this, args || {});208 $('#wpbody-content').css('overflow','hidden');207 $.extend(this, args || {}); 208 // $('#wpbody-content').css('overflow','hidden'); 209 209 $('.meta-box-sortables').sortable({ 210 210 placeholder: 'sortable-placeholder', 211 211 connectWith: '.meta-box-sortables', … … 212 212 items: '.postbox', 213 213 handle: '.hndle', 214 214 cursor: 'move', 215 delay: ( isMobile ? 200 : 0),215 delay: (isMobile ? 200 : 0), 216 216 distance: 2, 217 217 tolerance: 'pointer', 218 218 forcePlaceholderSize: true, 219 helper: function ( event, element) {219 helper: function (event, element) { 220 220 /* `helper: 'clone'` is equivalent to `return element.clone();` 221 221 * Cloning a checked radio and then inserting that clone next to the original 222 222 * radio unchecks the original radio (since only one of the two can be checked). … … 225 225 * duplicated, and no original radio gets unchecked. 226 226 */ 227 227 return element.clone() 228 .find( ':input')229 .attr( 'name', function( i, currentName) {230 return 'sort_' + parseInt( Math.random() * 100000, 10).toString() + '_' + currentName;231 })228 .find(':input') 229 .attr('name', function (i, currentName) { 230 return 'sort_' + parseInt(Math.random() * 100000, 10).toString() + '_' + currentName; 231 }) 232 232 .end(); 233 233 }, 234 234 opacity: 0.65, 235 stop: function () {236 var $el = $( this);235 stop: function () { 236 var $el = $(this); 237 237 238 if ( $el.find( '#dashboard_browser_nag' ).is( ':visible' ) && 'dashboard_browser_nag' != this.firstChild.id) {238 if ($el.find('#dashboard_browser_nag').is(':visible') && 'dashboard_browser_nag' != this.firstChild.id) { 239 239 $el.sortable('cancel'); 240 240 return; 241 241 } … … 242 242 243 243 postboxes.save_order(page); 244 244 }, 245 receive: function (e,ui) {246 if ( 'dashboard_browser_nag' == ui.item[0].id)245 receive: function (e, ui) { 246 if ('dashboard_browser_nag' == ui.item[0].id) 247 247 $(ui.sender).sortable('cancel'); 248 248 249 249 postboxes._mark_area(); 250 $document.trigger( 'postbox-moved', ui.item);250 $document.trigger('postbox-moved', ui.item); 251 251 } 252 252 }); 253 253 254 if ( isMobile) {255 $(document.body).bind('orientationchange.postboxes', function (){ postboxes._pb_change(); });254 if (isMobile) { 255 $(document.body).bind('orientationchange.postboxes', function () { postboxes._pb_change(); }); 256 256 this._pb_change(); 257 257 } 258 258 … … 259 259 this._mark_area(); 260 260 261 261 // Set the handle buttons `aria-expanded` attribute initial value on page load. 262 $handleButtons.each( function () {263 var $el = $( this);264 $el.attr( 'aria-expanded', ! $el.parent( '.postbox' ).hasClass( 'closed' ));262 $handleButtons.each(function () { 263 var $el = $(this); 264 $el.attr('aria-expanded', !$el.parent('.postbox').hasClass('closed')); 265 265 }); 266 266 }, 267 267 … … 277 277 * @param {string} page The page we are currently on. 278 278 * @returns {void} 279 279 */ 280 save_state : function(page) {280 save_state: function (page) { 281 281 var closed, hidden; 282 282 283 283 // Return on the nav-menus.php screen, see #35112. 284 if ( 'nav-menus' === page) {284 if ('nav-menus' === page) { 285 285 return; 286 286 } 287 287 288 closed = $( '.postbox' ).filter( '.closed' ).map( function() { return this.id; } ).get().join( ',');289 hidden = $( '.postbox' ).filter( ':hidden' ).map( function() { return this.id; } ).get().join( ',');288 closed = $('.postbox').filter('.closed').map(function () { return this.id; }).get().join(','); 289 hidden = $('.postbox').filter(':hidden').map(function () { return this.id; }).get().join(','); 290 290 291 291 $.post(ajaxurl, { 292 292 action: 'closed-postboxes', … … 308 308 * @param {string} page The page we are currently on. 309 309 * @returns {void} 310 310 */ 311 save_order : function(page) {311 save_order: function (page) { 312 312 var postVars, page_columns = $('.columns-prefs input:checked').val() || 0; 313 313 314 314 postVars = { … … 318 318 page: page 319 319 }; 320 320 321 $('.meta-box-sortables').each( function() {322 postVars[ 'order[' + this.id.split( '-' )[0] + ']' ] = $( this ).sortable( 'toArray' ).join( ',');323 } );321 $('.meta-box-sortables').each(function () { 322 postVars['order[' + this.id.split('-')[0] + ']'] = $(this).sortable('toArray').join(','); 323 }); 324 324 325 $.post( ajaxurl, postVars);325 $.post(ajaxurl, postVars); 326 326 }, 327 327 328 328 /** … … 338 338 * 339 339 * @returns {void} 340 340 */ 341 _mark_area : function() {341 _mark_area: function () { 342 342 var visible = $('div.postbox:visible').length, side = $('#post-body #side-sortables'); 343 343 344 $( '#dashboard-widgets .meta-box-sortables:visible' ).each( function() {344 $('#dashboard-widgets .meta-box-sortables:visible').each(function () { 345 345 var t = $(this); 346 346 347 if ( visible == 1 || t.children('.postbox:visible').length) {347 if (visible == 1 || t.children('.postbox:visible').length) { 348 348 t.removeClass('empty-container'); 349 349 } 350 350 else { … … 353 353 } 354 354 }); 355 355 356 if ( side.length) {357 if ( side.children('.postbox:visible').length)356 if (side.length) { 357 if (side.children('.postbox:visible').length) 358 358 side.removeClass('empty-container'); 359 else if ( $('#postbox-container-1').css('width') == '280px')359 else if ($('#postbox-container-1').css('width') == '280px') 360 360 side.addClass('empty-container'); 361 361 } 362 362 }, … … 372 372 * @param {number} n The amount of columns to divide the post edit page in. 373 373 * @returns {void} 374 374 */ 375 _pb_edit : function(n) {375 _pb_edit: function (n) { 376 376 var el = $('.metabox-holder').get(0); 377 377 378 if ( el) {378 if (el) { 379 379 el.className = el.className.replace(/columns-\d+/, 'columns-' + n); 380 380 } 381 381 … … 387 387 * 388 388 * @event postboxes#postboxes-columnchange 389 389 */ 390 $( document ).trigger( 'postboxes-columnchange');390 $(document).trigger('postboxes-columnchange'); 391 391 }, 392 392 393 393 /** … … 400 400 * 401 401 * @returns {void} 402 402 */ 403 _pb_change : function() {404 var check = $( 'label.columns-prefs-1 input[type="radio"]');403 _pb_change: function () { 404 var check = $('label.columns-prefs-1 input[type="radio"]'); 405 405 406 switch ( window.orientation) {406 switch (window.orientation) { 407 407 case 90: 408 408 case -90: 409 if ( !check.length || !check.is(':checked'))409 if (!check.length || !check.is(':checked')) 410 410 this._pb_edit(2); 411 411 break; 412 412 case 0: 413 413 case 180: 414 if ( $('#poststuff').length) {414 if ($('#poststuff').length) { 415 415 this._pb_edit(1); 416 416 } else { 417 if ( !check.length || !check.is(':checked'))417 if (!check.length || !check.is(':checked')) 418 418 this._pb_edit(2); 419 419 } 420 420 break; … … 430 430 * @property {Function|boolean} pbshow A callback that is called when a postbox 431 431 * is opened. 432 432 */ 433 pbshow : false,433 pbshow: false, 434 434 435 435 /** 436 436 * @since 2.7.0 … … 439 439 * @property {Function|boolean} pbhide A callback that is called when a postbox 440 440 * is closed. 441 441 */ 442 pbhide : false442 pbhide: false 443 443 }; 444 444 445 445 }(jQuery));