wp/wp-includes/js/customize-base.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/js/customize-base.js	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/js/customize-base.js	Tue Dec 15 13:49:49 2020 +0100
@@ -17,25 +17,29 @@
 	 * Similar to `goog.inherits`, but uses a hash of prototype properties and
 	 * class properties to be extended.
 	 *
-	 * @param  object parent      Parent class constructor to inherit from.
-	 * @param  object protoProps  Properties to apply to the prototype for use as class instance properties.
-	 * @param  object staticProps Properties to apply directly to the class constructor.
-	 * @return child              The subclassed constructor.
+	 * @param object parent      Parent class constructor to inherit from.
+	 * @param object protoProps  Properties to apply to the prototype for use as class instance properties.
+	 * @param object staticProps Properties to apply directly to the class constructor.
+	 * @return child The subclassed constructor.
 	 */
 	inherits = function( parent, protoProps, staticProps ) {
 		var child;
 
-		// The constructor function for the new subclass is either defined by you
-		// (the "constructor" property in your `extend` definition), or defaulted
-		// by us to simply call `super()`.
+		/*
+		 * The constructor function for the new subclass is either defined by you
+		 * (the "constructor" property in your `extend` definition), or defaulted
+		 * by us to simply call `super()`.
+		 */
 		if ( protoProps && protoProps.hasOwnProperty( 'constructor' ) ) {
 			child = protoProps.constructor;
 		} else {
 			child = function() {
-				// Storing the result `super()` before returning the value
-				// prevents a bug in Opera where, if the constructor returns
-				// a function, Opera will reject the return value in favor of
-				// the original object. This causes all sorts of trouble.
+				/*
+				 * Storing the result `super()` before returning the value
+				 * prevents a bug in Opera where, if the constructor returns
+				 * a function, Opera will reject the return value in favor of
+				 * the original object. This causes all sorts of trouble.
+				 */
 				var result = parent.apply( this, arguments );
 				return result;
 			};
@@ -44,19 +48,21 @@
 		// Inherit class (static) properties from parent.
 		$.extend( child, parent );
 
-		// Set the prototype chain to inherit from `parent`, without calling
-		// `parent`'s constructor function.
+		// Set the prototype chain to inherit from `parent`,
+		// without calling `parent`'s constructor function.
 		ctor.prototype  = parent.prototype;
 		child.prototype = new ctor();
 
 		// Add prototype properties (instance properties) to the subclass,
 		// if supplied.
-		if ( protoProps )
+		if ( protoProps ) {
 			$.extend( child.prototype, protoProps );
+		}
 
 		// Add static properties to the constructor function, if supplied.
-		if ( staticProps )
+		if ( staticProps ) {
 			$.extend( child, staticProps );
+		}
 
 		// Correctly set child's `prototype.constructor`.
 		child.prototype.constructor = child;
@@ -102,9 +108,9 @@
 	/**
 	 * Creates a subclass of the class.
 	 *
-	 * @param  object protoProps  Properties to apply to the prototype.
-	 * @param  object staticProps Properties to apply directly to the class.
-	 * @return child              The subclass.
+	 * @param object protoProps  Properties to apply to the prototype.
+	 * @param object staticProps Properties to apply directly to the class.
+	 * @return child The subclass.
 	 */
 	api.Class.extend = function( protoProps, classProps ) {
 		var child = inherits( this, protoProps, classProps );
@@ -132,10 +138,12 @@
 		var proto = this;
 
 		while ( typeof proto.constructor !== 'undefined' ) {
-			if ( proto.constructor === constructor )
+			if ( proto.constructor === constructor ) {
 				return true;
-			if ( typeof proto.constructor.__super__ === 'undefined' )
+			}
+			if ( typeof proto.constructor.__super__ === 'undefined' ) {
 				return false;
+			}
 			proto = proto.constructor.__super__;
 		}
 		return false;
@@ -148,8 +156,9 @@
 	 */
 	api.Events = {
 		trigger: function( id ) {
-			if ( this.topics && this.topics[ id ] )
+			if ( this.topics && this.topics[ id ] ) {
 				this.topics[ id ].fireWith( this, slice.call( arguments, 1 ) );
+			}
 			return this;
 		},
 
@@ -161,8 +170,9 @@
 		},
 
 		unbind: function( id ) {
-			if ( this.topics && this.topics[ id ] )
+			if ( this.topics && this.topics[ id ] ) {
 				this.topics[ id ].remove.apply( this.topics[ id ], slice.call( arguments, 1 ) );
+			}
 			return this;
 		}
 	};
@@ -178,10 +188,10 @@
 	api.Value = api.Class.extend(/** @lends wp.customize.Value.prototype */{
 		/**
 		 * @param {mixed}  initial The initial value.
-		 * @param {object} options
+		 * @param {Object} options
 		 */
 		initialize: function( initial, options ) {
-			this._value = initial; // @todo: potentially change this to a this.set() call.
+			this._value = initial; // @todo Potentially change this to a this.set() call.
 			this.callbacks = $.Callbacks();
 			this._dirty = false;
 
@@ -210,7 +220,7 @@
 		/**
 		 * Set the value and trigger all bound callbacks.
 		 *
-		 * @param {object} to New value.
+		 * @param {Object} to New value.
 		 */
 		set: function( to ) {
 			var from = this._value;
@@ -344,15 +354,16 @@
 		 *
 		 * @see {api.Values.when}
 		 *
-		 * @param  {string}   id ID of the item.
-		 * @param  {...}         Zero or more IDs of items to wait for and a callback
-		 *                       function to invoke when they're available. Optional.
-		 * @return {mixed}    The item instance if only one ID was supplied.
-		 *                    A Deferred Promise object if a callback function is supplied.
+		 * @param {string} id ID of the item.
+		 * @param {...}       Zero or more IDs of items to wait for and a callback
+		 *                    function to invoke when they're available. Optional.
+		 * @return {mixed} The item instance if only one ID was supplied.
+		 *                 A Deferred Promise object if a callback function is supplied.
 		 */
 		instance: function( id ) {
-			if ( arguments.length === 1 )
+			if ( arguments.length === 1 ) {
 				return this.value( id );
+			}
 
 			return this.when.apply( this, arguments );
 		},
@@ -360,8 +371,8 @@
 		/**
 		 * Get the instance of an item.
 		 *
-		 * @param  {string} id The ID of the item.
-		 * @return {[type]}    [description]
+		 * @param {string} id The ID of the item.
+		 * @return {[type]} [description]
 		 */
 		value: function( id ) {
 			return this._value[ id ];
@@ -370,8 +381,8 @@
 		/**
 		 * Whether the collection has an item with the given ID.
 		 *
-		 * @param  {string}  id The ID of the item to look for.
-		 * @return {Boolean}
+		 * @param {string} id The ID of the item to look for.
+		 * @return {boolean}
 		 */
 		has: function( id ) {
 			return typeof this._value[ id ] !== 'undefined';
@@ -424,9 +435,9 @@
 		 * Create a new item of the collection using the collection's default constructor
 		 * and store it in the collection.
 		 *
-		 * @param  {string} id    The ID of the item.
-		 * @param  {mixed}  value Any extra arguments are passed into the item's initialize method.
-		 * @return {mixed}  The new item's instance.
+		 * @param {string} id    The ID of the item.
+		 * @param {mixed}  value Any extra arguments are passed into the item's initialize method.
+		 * @return {mixed} The new item's instance.
 		 */
 		create: function( id ) {
 			return this.add( id, new this.defaultConstructor( api.Class.applicator, slice.call( arguments, 1 ) ) );
@@ -435,8 +446,8 @@
 		/**
 		 * Iterate over all items in the collection invoking the provided callback.
 		 *
-		 * @param  {Function} callback Function to invoke.
-		 * @param  {object}   context  Object context to invoke the function with. Optional.
+		 * @param {Function} callback Function to invoke.
+		 * @param {Object}   context  Object context to invoke the function with. Optional.
 		 */
 		each: function( callback, context ) {
 			context = typeof context === 'undefined' ? this : context;
@@ -449,7 +460,7 @@
 		/**
 		 * Remove an item from the collection.
 		 *
-		 * @param  {string} id The ID of the item to remove.
+		 * @param {string} id The ID of the item to remove.
 		 */
 		remove: function( id ) {
 			var value = this.value( id );
@@ -482,24 +493,26 @@
 		 * For example:
 		 *     when( id1, id2, id3, function( value1, value2, value3 ) {} );
 		 *
-		 * @returns $.Deferred.promise();
+		 * @return $.Deferred.promise();
 		 */
 		when: function() {
 			var self = this,
 				ids  = slice.call( arguments ),
 				dfd  = $.Deferred();
 
-			// If the last argument is a callback, bind it to .done()
-			if ( $.isFunction( ids[ ids.length - 1 ] ) )
+			// If the last argument is a callback, bind it to .done().
+			if ( $.isFunction( ids[ ids.length - 1 ] ) ) {
 				dfd.done( ids.pop() );
+			}
 
 			/*
 			 * Create a stack of deferred objects for each item that is not
 			 * yet available, and invoke the supplied callback when they are.
 			 */
 			$.when.apply( $, $.map( ids, function( id ) {
-				if ( self.has( id ) )
+				if ( self.has( id ) ) {
 					return;
+				}
 
 				/*
 				 * The requested item is not available yet, create a deferred
@@ -546,7 +559,7 @@
 	 * @param {string|jQuery collection} element
 	 */
 	api.ensure = function( element ) {
-		return typeof element == 'string' ? $( element ) : element;
+		return typeof element === 'string' ? $( element ) : element;
 	};
 
 	/**
@@ -657,10 +670,10 @@
 		/**
 		 * Create a new Value.
 		 *
-		 * @param  {string} key     Unique identifier.
-		 * @param  {mixed}  initial Initial value.
-		 * @param  {mixed}  options Options hash. Optional.
-		 * @return {Value}          Class instance of the Value.
+		 * @param {string} key     Unique identifier.
+		 * @param {mixed}  initial Initial value.
+		 * @param {mixed}  options Options hash. Optional.
+		 * @return {Value} Class instance of the Value.
 		 */
 		add: function( key, initial, options ) {
 			return this[ key ] = new api.Value( initial, options );
@@ -669,11 +682,11 @@
 		/**
 		 * Initialize Messenger.
 		 *
-		 * @param  {object} params - Parameters to configure the messenger.
-		 *         {string} params.url - The URL to communicate with.
-		 *         {window} params.targetWindow - The window instance to communicate with. Default window.parent.
-		 *         {string} params.channel - If provided, will send the channel with each message and only accept messages a matching channel.
-		 * @param  {object} options - Extend any instance parameter or method with this object.
+		 * @param {Object} params  - Parameters to configure the messenger.
+		 *        {string} params.url          - The URL to communicate with.
+		 *        {window} params.targetWindow - The window instance to communicate with. Default window.parent.
+		 *        {string} params.channel      - If provided, will send the channel with each message and only accept messages a matching channel.
+		 * @param {Object} options - Extend any instance parameter or method with this object.
 		 */
 		initialize: function( params, options ) {
 			// Target the parent frame by default, but only if a parent frame exists.
@@ -690,7 +703,7 @@
 				return urlParser.protocol + '//' + urlParser.host.replace( /:(80|443)$/, '' );
 			});
 
-			// first add with no value
+			// First add with no value.
 			this.add( 'targetWindow', null );
 			// This avoids SecurityErrors when setting a window object in x-origin iframe'd scenarios.
 			this.targetWindow.set = function( to ) {
@@ -710,15 +723,17 @@
 
 				return this;
 			};
-			// now set it
+			// Now set it.
 			this.targetWindow( params.targetWindow || defaultTarget );
 
 
-			// Since we want jQuery to treat the receive function as unique
-			// to this instance, we give the function a new guid.
-			//
-			// This will prevent every Messenger's receive function from being
-			// unbound when calling $.off( 'message', this.receive );
+			/*
+			 * Since we want jQuery to treat the receive function as unique
+			 * to this instance, we give the function a new guid.
+			 *
+			 * This will prevent every Messenger's receive function from being
+			 * unbound when calling $.off( 'message', this.receive );
+			 */
 			this.receive = $.proxy( this.receive, this );
 			this.receive.guid = $.guid++;
 
@@ -732,7 +747,7 @@
 		/**
 		 * Receive data from the other window.
 		 *
-		 * @param  {jQuery.Event} event Event with embedded data.
+		 * @param {jQuery.Event} event Event with embedded data.
 		 */
 		receive: function( event ) {
 			var message;
@@ -744,10 +759,11 @@
 			}
 
 			// Check to make sure the origin is valid.
-			if ( this.origin() && event.origin !== this.origin() )
+			if ( this.origin() && event.origin !== this.origin() ) {
 				return;
+			}
 
-			// Ensure we have a string that's JSON.parse-able
+			// Ensure we have a string that's JSON.parse-able.
 			if ( typeof event.data !== 'string' || event.data[0] !== '{' ) {
 				return;
 			}
@@ -755,12 +771,14 @@
 			message = JSON.parse( event.data );
 
 			// Check required message properties.
-			if ( ! message || ! message.id || typeof message.data === 'undefined' )
+			if ( ! message || ! message.id || typeof message.data === 'undefined' ) {
 				return;
+			}
 
 			// Check if channel names match.
-			if ( ( message.channel || this.channel() ) && this.channel() !== message.channel )
+			if ( ( message.channel || this.channel() ) && this.channel() !== message.channel ) {
 				return;
+			}
 
 			this.trigger( message.id, message.data );
 		},
@@ -768,20 +786,22 @@
 		/**
 		 * Send data to the other window.
 		 *
-		 * @param  {string} id   The event name.
-		 * @param  {object} data Data.
+		 * @param {string} id   The event name.
+		 * @param {Object} data Data.
 		 */
 		send: function( id, data ) {
 			var message;
 
 			data = typeof data === 'undefined' ? null : data;
 
-			if ( ! this.url() || ! this.targetWindow() )
+			if ( ! this.url() || ! this.targetWindow() ) {
 				return;
+			}
 
 			message = { id: id, data: data };
-			if ( this.channel() )
+			if ( this.channel() ) {
 				message.channel = this.channel();
+			}
 
 			this.targetWindow().postMessage( JSON.stringify( message ), this.origin() );
 		}
@@ -842,7 +862,7 @@
 		 * @since 4.9.0
 		 *
 		 * @param {string}   code - Notification code.
-		 * @param {object}   params - Notification parameters.
+		 * @param {Object}   params - Notification parameters.
 		 * @param {string}   params.message - Message.
 		 * @param {string}   [params.type=error] - Type.
 		 * @param {string}   [params.setting] - Related setting ID.
@@ -876,7 +896,7 @@
 		 *
 		 * @since 4.9.0
 		 *
-		 * @returns {jQuery} Notification container element.
+		 * @return {jQuery} Notification container element.
 		 */
 		render: function() {
 			var notification = this, container, data;
@@ -914,7 +934,7 @@
 	 *
 	 * @alias wp.customize.get
 	 *
-	 * @return {object}
+	 * @return {Object}
 	 */
 	api.get = function() {
 		var result = {};
@@ -942,7 +962,7 @@
 	 * @alias wp.customize.utils.parseQueryString
 	 *
 	 * @param {string} queryString Query string.
-	 * @returns {object} Parsed query string.
+	 * @return {Object} Parsed query string.
 	 */
 	api.utils.parseQueryString = function parseQueryString( queryString ) {
 		var queryParams = {};