wp/wp-admin/js/postbox.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     1 /**
     1 /**
     2  * Contains the postboxes logic, opening and closing postboxes, reordering and saving
     2  * Contains the postboxes logic, opening and closing postboxes, reordering and saving
     3  * the state and ordering to the database.
     3  * the state and ordering to the database.
     4  *
     4  *
     5  * @summary Contains postboxes logic
       
     6  *
       
     7  * @since 2.5.0
     5  * @since 2.5.0
     8  * @requires jQuery
     6  * @requires jQuery
       
     7  * @output wp-admin/js/postbox.js
     9  */
     8  */
    10 
     9 
    11 /* global ajaxurl, postBoxL10n */
    10 /* global ajaxurl, postBoxL10n, postboxes */
    12 
       
    13 /**
       
    14  * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see
       
    15  * around the content on the edit page.
       
    16  *
       
    17  * @since 2.7.0
       
    18  *
       
    19  * @namespace postboxes
       
    20  *
       
    21  * @type {Object}
       
    22  */
       
    23 var postboxes;
       
    24 
    11 
    25 (function($) {
    12 (function($) {
    26 	var $document = $( document );
    13 	var $document = $( document );
    27 
    14 
    28 	postboxes = {
    15 	/**
    29 
    16 	 * This object contains all function to handle the behaviour of the post boxes. The post boxes are the boxes you see
    30 		/**
    17 	 * around the content on the edit page.
    31 		 * @summary Handles a click on either the postbox heading or the postbox open/close icon.
    18 	 *
       
    19 	 * @since 2.7.0
       
    20 	 *
       
    21 	 * @namespace postboxes
       
    22 	 *
       
    23 	 * @type {Object}
       
    24 	 */
       
    25 	window.postboxes = {
       
    26 
       
    27 		/**
       
    28 		 * Handles a click on either the postbox heading or the postbox open/close icon.
    32 		 *
    29 		 *
    33 		 * Opens or closes the postbox. Expects `this` to equal the clicked element.
    30 		 * Opens or closes the postbox. Expects `this` to equal the clicked element.
    34 		 * Calls postboxes.pbshow if the postbox has been opened, calls postboxes.pbhide
    31 		 * Calls postboxes.pbshow if the postbox has been opened, calls postboxes.pbhide
    35 		 * if the postbox has been closed.
    32 		 * if the postbox has been closed.
    36 		 *
    33 		 *
    74 					postboxes.pbhide( id );
    71 					postboxes.pbhide( id );
    75 				}
    72 				}
    76 			}
    73 			}
    77 
    74 
    78 			/**
    75 			/**
    79 			 * @summary Fires when a postbox has been opened or closed.
    76 			 * Fires when a postbox has been opened or closed.
    80 			 *
    77 			 *
    81 			 * Contains a jQuery object with the relevant postbox element.
    78 			 * Contains a jQuery object with the relevant postbox element.
    82 			 *
    79 			 *
    83 			 * @since 4.0.0
    80 			 * @since 4.0.0
       
    81 			 * @ignore
       
    82 			 *
    84 			 * @event postboxes#postbox-toggled
    83 			 * @event postboxes#postbox-toggled
    85 			 * @type {Object}
    84 			 * @type {Object}
    86 			 */
    85 			 */
    87 			$document.trigger( 'postbox-toggled', p );
    86 			$document.trigger( 'postbox-toggled', p );
    88 		},
    87 		},
   113 			$('.postbox .hndle a').click( function(e) {
   112 			$('.postbox .hndle a').click( function(e) {
   114 				e.stopPropagation();
   113 				e.stopPropagation();
   115 			});
   114 			});
   116 
   115 
   117 			/**
   116 			/**
   118 			 * @summary Hides a postbox.
   117 			 * Hides a postbox.
   119 			 *
   118 			 *
   120 			 * Event handler for the postbox dismiss button. After clicking the button
   119 			 * Event handler for the postbox dismiss button. After clicking the button
   121 			 * the postbox will be hidden.
   120 			 * the postbox will be hidden.
   122 			 *
   121 			 *
   123 			 * @since 3.2.0
   122 			 * @since 3.2.0
   129 				e.preventDefault();
   128 				e.preventDefault();
   130 				$( '#' + hide_id ).prop('checked', false).triggerHandler('click');
   129 				$( '#' + hide_id ).prop('checked', false).triggerHandler('click');
   131 			});
   130 			});
   132 
   131 
   133 			/**
   132 			/**
   134 			 * @summary Hides the postbox element
   133 			 * Hides the postbox element
   135 			 *
   134 			 *
   136 			 * Event handler for the screen options checkboxes. When a checkbox is
   135 			 * Event handler for the screen options checkboxes. When a checkbox is
   137 			 * clicked this function will hide or show the relevant postboxes.
   136 			 * clicked this function will hide or show the relevant postboxes.
   138 			 *
   137 			 *
   139 			 * @since 2.7.0
   138 			 * @since 2.7.0
       
   139 			 * @ignore
       
   140 			 *
   140 			 * @fires postboxes#postbox-toggled
   141 			 * @fires postboxes#postbox-toggled
   141 			 *
   142 			 *
   142 			 * @returns {void}
   143 			 * @returns {void}
   143 			 */
   144 			 */
   144 			$('.hide-postbox-tog').bind('click.postboxes', function() {
   145 			$('.hide-postbox-tog').bind('click.postboxes', function() {
   167 				 */
   168 				 */
   168 				$document.trigger( 'postbox-toggled', $postbox );
   169 				$document.trigger( 'postbox-toggled', $postbox );
   169 			});
   170 			});
   170 
   171 
   171 			/**
   172 			/**
   172 			 * @summary Changes the amount of columns based on the layout preferences.
   173 			 * Changes the amount of columns based on the layout preferences.
   173 			 *
   174 			 *
   174 			 * @since 2.8.0
   175 			 * @since 2.8.0
   175 			 *
   176 			 *
   176 			 * @returns {void}
   177 			 * @returns {void}
   177 			 */
   178 			 */
   184 				}
   185 				}
   185 			});
   186 			});
   186 		},
   187 		},
   187 
   188 
   188 		/**
   189 		/**
   189 		 * @summary Initializes all the postboxes, mainly their sortable behaviour.
   190 		 * Initializes all the postboxes, mainly their sortable behaviour.
   190 		 *
   191 		 *
   191 		 * @since 2.7.0
   192 		 * @since 2.7.0
   192 		 * @memberof postboxes
   193 		 * @memberof postboxes
   193 		 *
   194 		 *
   194 		 * @param {string} page The page we are currently on.
   195 		 * @param {string} page The page we are currently on.
   263 				$el.attr( 'aria-expanded', ! $el.parent( '.postbox' ).hasClass( 'closed' ) );
   264 				$el.attr( 'aria-expanded', ! $el.parent( '.postbox' ).hasClass( 'closed' ) );
   264 			});
   265 			});
   265 		},
   266 		},
   266 
   267 
   267 		/**
   268 		/**
   268 		 * @summary Saves the state of the postboxes to the server.
   269 		 * Saves the state of the postboxes to the server.
   269 		 *
   270 		 *
   270 		 * Saves the state of the postboxes to the server. It sends two lists, one with
   271 		 * It sends two lists, one with all the closed postboxes, one with all the
   271 		 * all the closed postboxes, one with all the hidden postboxes.
   272 		 * hidden postboxes.
   272 		 *
   273 		 *
   273 		 * @since 2.7.0
   274 		 * @since 2.7.0
   274 		 * @memberof postboxes
   275 		 * @memberof postboxes
   275 		 *
   276 		 *
   276 		 * @param {string} page The page we are currently on.
   277 		 * @param {string} page The page we are currently on.
   295 				page: page
   296 				page: page
   296 			});
   297 			});
   297 		},
   298 		},
   298 
   299 
   299 		/**
   300 		/**
   300 		 * @summary Saves the order of the postboxes to the server.
   301 		 * Saves the order of the postboxes to the server.
   301 		 *
   302 		 *
   302 		 * Saves the order of the postboxes to the server. Sends a list of all postboxes
   303 		 * Sends a list of all postboxes inside a sortable area to the server.
   303 		 * inside a sortable area to the server.
       
   304 		 *
   304 		 *
   305 		 * @since 2.8.0
   305 		 * @since 2.8.0
   306 		 * @memberof postboxes
   306 		 * @memberof postboxes
   307 		 *
   307 		 *
   308 		 * @param {string} page The page we are currently on.
   308 		 * @param {string} page The page we are currently on.
   324 
   324 
   325 			$.post( ajaxurl, postVars );
   325 			$.post( ajaxurl, postVars );
   326 		},
   326 		},
   327 
   327 
   328 		/**
   328 		/**
   329 		 * @summary Marks empty postbox areas.
   329 		 * Marks empty postbox areas.
   330 		 *
   330 		 *
   331 		 * Adds a message to empty sortable areas on the dashboard page. Also adds a
   331 		 * Adds a message to empty sortable areas on the dashboard page. Also adds a
   332 		 * border around the side area on the post edit screen if there are no postboxes
   332 		 * border around the side area on the post edit screen if there are no postboxes
   333 		 * present.
   333 		 * present.
   334 		 *
   334 		 *
   360 					side.addClass('empty-container');
   360 					side.addClass('empty-container');
   361 			}
   361 			}
   362 		},
   362 		},
   363 
   363 
   364 		/**
   364 		/**
   365 		 * @summary Changes the amount of columns on the post edit page.
   365 		 * Changes the amount of columns on the post edit page.
   366 		 *
   366 		 *
   367 		 * @since 3.3.0
   367 		 * @since 3.3.0
   368 		 * @memberof postboxes
   368 		 * @memberof postboxes
   369 		 * @fires postboxes#postboxes-columnchange
   369 		 * @fires postboxes#postboxes-columnchange
   370 		 * @access private
   370 		 * @access private
   381 
   381 
   382 			/**
   382 			/**
   383 			 * Fires when the amount of columns on the post edit page has been changed.
   383 			 * Fires when the amount of columns on the post edit page has been changed.
   384 			 *
   384 			 *
   385 			 * @since 4.0.0
   385 			 * @since 4.0.0
       
   386 			 * @ignore
       
   387 			 *
   386 			 * @event postboxes#postboxes-columnchange
   388 			 * @event postboxes#postboxes-columnchange
   387 			 */
   389 			 */
   388 			$( document ).trigger( 'postboxes-columnchange' );
   390 			$( document ).trigger( 'postboxes-columnchange' );
   389 		},
   391 		},
   390 
   392 
   391 		/**
   393 		/**
   392 		 * @summary Changes the amount of columns the postboxes are in based on the
   394 		 * Changes the amount of columns the postboxes are in based on the current
   393 		 *          current orientation of the browser.
   395 		 * orientation of the browser.
   394 		 *
   396 		 *
   395 		 * @since 3.3.0
   397 		 * @since 3.3.0
   396 		 * @memberof postboxes
   398 		 * @memberof postboxes
   397 		 * @access private
   399 		 * @access private
   398 		 *
   400 		 *