Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: customize-base.js
/**
[0] Fix | Delete
* @output wp-includes/js/customize-base.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/** @namespace wp */
[4] Fix | Delete
window.wp = window.wp || {};
[5] Fix | Delete
[6] Fix | Delete
(function( exports, $ ){
[7] Fix | Delete
var api = {}, ctor, inherits,
[8] Fix | Delete
slice = Array.prototype.slice;
[9] Fix | Delete
[10] Fix | Delete
// Shared empty constructor function to aid in prototype-chain creation.
[11] Fix | Delete
ctor = function() {};
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Helper function to correctly set up the prototype chain, for subclasses.
[15] Fix | Delete
* Similar to `goog.inherits`, but uses a hash of prototype properties and
[16] Fix | Delete
* class properties to be extended.
[17] Fix | Delete
*
[18] Fix | Delete
* @param object parent Parent class constructor to inherit from.
[19] Fix | Delete
* @param object protoProps Properties to apply to the prototype for use as class instance properties.
[20] Fix | Delete
* @param object staticProps Properties to apply directly to the class constructor.
[21] Fix | Delete
* @return child The subclassed constructor.
[22] Fix | Delete
*/
[23] Fix | Delete
inherits = function( parent, protoProps, staticProps ) {
[24] Fix | Delete
var child;
[25] Fix | Delete
[26] Fix | Delete
/*
[27] Fix | Delete
* The constructor function for the new subclass is either defined by you
[28] Fix | Delete
* (the "constructor" property in your `extend` definition), or defaulted
[29] Fix | Delete
* by us to simply call `super()`.
[30] Fix | Delete
*/
[31] Fix | Delete
if ( protoProps && protoProps.hasOwnProperty( 'constructor' ) ) {
[32] Fix | Delete
child = protoProps.constructor;
[33] Fix | Delete
} else {
[34] Fix | Delete
child = function() {
[35] Fix | Delete
/*
[36] Fix | Delete
* Storing the result `super()` before returning the value
[37] Fix | Delete
* prevents a bug in Opera where, if the constructor returns
[38] Fix | Delete
* a function, Opera will reject the return value in favor of
[39] Fix | Delete
* the original object. This causes all sorts of trouble.
[40] Fix | Delete
*/
[41] Fix | Delete
var result = parent.apply( this, arguments );
[42] Fix | Delete
return result;
[43] Fix | Delete
};
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
// Inherit class (static) properties from parent.
[47] Fix | Delete
$.extend( child, parent );
[48] Fix | Delete
[49] Fix | Delete
// Set the prototype chain to inherit from `parent`,
[50] Fix | Delete
// without calling `parent`'s constructor function.
[51] Fix | Delete
ctor.prototype = parent.prototype;
[52] Fix | Delete
child.prototype = new ctor();
[53] Fix | Delete
[54] Fix | Delete
// Add prototype properties (instance properties) to the subclass,
[55] Fix | Delete
// if supplied.
[56] Fix | Delete
if ( protoProps ) {
[57] Fix | Delete
$.extend( child.prototype, protoProps );
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
// Add static properties to the constructor function, if supplied.
[61] Fix | Delete
if ( staticProps ) {
[62] Fix | Delete
$.extend( child, staticProps );
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
// Correctly set child's `prototype.constructor`.
[66] Fix | Delete
child.prototype.constructor = child;
[67] Fix | Delete
[68] Fix | Delete
// Set a convenience property in case the parent's prototype is needed later.
[69] Fix | Delete
child.__super__ = parent.prototype;
[70] Fix | Delete
[71] Fix | Delete
return child;
[72] Fix | Delete
};
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* Base class for object inheritance.
[76] Fix | Delete
*/
[77] Fix | Delete
api.Class = function( applicator, argsArray, options ) {
[78] Fix | Delete
var magic, args = arguments;
[79] Fix | Delete
[80] Fix | Delete
if ( applicator && argsArray && api.Class.applicator === applicator ) {
[81] Fix | Delete
args = argsArray;
[82] Fix | Delete
$.extend( this, options || {} );
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
magic = this;
[86] Fix | Delete
[87] Fix | Delete
/*
[88] Fix | Delete
* If the class has a method called "instance",
[89] Fix | Delete
* the return value from the class' constructor will be a function that
[90] Fix | Delete
* calls the "instance" method.
[91] Fix | Delete
*
[92] Fix | Delete
* It is also an object that has properties and methods inside it.
[93] Fix | Delete
*/
[94] Fix | Delete
if ( this.instance ) {
[95] Fix | Delete
magic = function() {
[96] Fix | Delete
return magic.instance.apply( magic, arguments );
[97] Fix | Delete
};
[98] Fix | Delete
[99] Fix | Delete
$.extend( magic, this );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
magic.initialize.apply( magic, args );
[103] Fix | Delete
return magic;
[104] Fix | Delete
};
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Creates a subclass of the class.
[108] Fix | Delete
*
[109] Fix | Delete
* @param object protoProps Properties to apply to the prototype.
[110] Fix | Delete
* @param object staticProps Properties to apply directly to the class.
[111] Fix | Delete
* @return child The subclass.
[112] Fix | Delete
*/
[113] Fix | Delete
api.Class.extend = function( protoProps, staticProps ) {
[114] Fix | Delete
var child = inherits( this, protoProps, staticProps );
[115] Fix | Delete
child.extend = this.extend;
[116] Fix | Delete
return child;
[117] Fix | Delete
};
[118] Fix | Delete
[119] Fix | Delete
api.Class.applicator = {};
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Initialize a class instance.
[123] Fix | Delete
*
[124] Fix | Delete
* Override this function in a subclass as needed.
[125] Fix | Delete
*/
[126] Fix | Delete
api.Class.prototype.initialize = function() {};
[127] Fix | Delete
[128] Fix | Delete
/*
[129] Fix | Delete
* Checks whether a given instance extended a constructor.
[130] Fix | Delete
*
[131] Fix | Delete
* The magic surrounding the instance parameter causes the instanceof
[132] Fix | Delete
* keyword to return inaccurate results; it defaults to the function's
[133] Fix | Delete
* prototype instead of the constructor chain. Hence this function.
[134] Fix | Delete
*/
[135] Fix | Delete
api.Class.prototype.extended = function( constructor ) {
[136] Fix | Delete
var proto = this;
[137] Fix | Delete
[138] Fix | Delete
while ( typeof proto.constructor !== 'undefined' ) {
[139] Fix | Delete
if ( proto.constructor === constructor ) {
[140] Fix | Delete
return true;
[141] Fix | Delete
}
[142] Fix | Delete
if ( typeof proto.constructor.__super__ === 'undefined' ) {
[143] Fix | Delete
return false;
[144] Fix | Delete
}
[145] Fix | Delete
proto = proto.constructor.__super__;
[146] Fix | Delete
}
[147] Fix | Delete
return false;
[148] Fix | Delete
};
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* An events manager object, offering the ability to bind to and trigger events.
[152] Fix | Delete
*
[153] Fix | Delete
* Used as a mixin.
[154] Fix | Delete
*/
[155] Fix | Delete
api.Events = {
[156] Fix | Delete
trigger: function( id ) {
[157] Fix | Delete
if ( this.topics && this.topics[ id ] ) {
[158] Fix | Delete
this.topics[ id ].fireWith( this, slice.call( arguments, 1 ) );
[159] Fix | Delete
}
[160] Fix | Delete
return this;
[161] Fix | Delete
},
[162] Fix | Delete
[163] Fix | Delete
bind: function( id ) {
[164] Fix | Delete
this.topics = this.topics || {};
[165] Fix | Delete
this.topics[ id ] = this.topics[ id ] || $.Callbacks();
[166] Fix | Delete
this.topics[ id ].add.apply( this.topics[ id ], slice.call( arguments, 1 ) );
[167] Fix | Delete
return this;
[168] Fix | Delete
},
[169] Fix | Delete
[170] Fix | Delete
unbind: function( id ) {
[171] Fix | Delete
if ( this.topics && this.topics[ id ] ) {
[172] Fix | Delete
this.topics[ id ].remove.apply( this.topics[ id ], slice.call( arguments, 1 ) );
[173] Fix | Delete
}
[174] Fix | Delete
return this;
[175] Fix | Delete
}
[176] Fix | Delete
};
[177] Fix | Delete
[178] Fix | Delete
/**
[179] Fix | Delete
* Observable values that support two-way binding.
[180] Fix | Delete
*
[181] Fix | Delete
* @memberOf wp.customize
[182] Fix | Delete
* @alias wp.customize.Value
[183] Fix | Delete
*
[184] Fix | Delete
* @constructor
[185] Fix | Delete
*/
[186] Fix | Delete
api.Value = api.Class.extend(/** @lends wp.customize.Value.prototype */{
[187] Fix | Delete
/**
[188] Fix | Delete
* @param {mixed} initial The initial value.
[189] Fix | Delete
* @param {Object} options
[190] Fix | Delete
*/
[191] Fix | Delete
initialize: function( initial, options ) {
[192] Fix | Delete
this._value = initial; // @todo Potentially change this to a this.set() call.
[193] Fix | Delete
this.callbacks = $.Callbacks();
[194] Fix | Delete
this._dirty = false;
[195] Fix | Delete
[196] Fix | Delete
$.extend( this, options || {} );
[197] Fix | Delete
[198] Fix | Delete
this.set = $.proxy( this.set, this );
[199] Fix | Delete
},
[200] Fix | Delete
[201] Fix | Delete
/*
[202] Fix | Delete
* Magic. Returns a function that will become the instance.
[203] Fix | Delete
* Set to null to prevent the instance from extending a function.
[204] Fix | Delete
*/
[205] Fix | Delete
instance: function() {
[206] Fix | Delete
return arguments.length ? this.set.apply( this, arguments ) : this.get();
[207] Fix | Delete
},
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Get the value.
[211] Fix | Delete
*
[212] Fix | Delete
* @return {mixed}
[213] Fix | Delete
*/
[214] Fix | Delete
get: function() {
[215] Fix | Delete
return this._value;
[216] Fix | Delete
},
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Set the value and trigger all bound callbacks.
[220] Fix | Delete
*
[221] Fix | Delete
* @param {Object} to New value.
[222] Fix | Delete
*/
[223] Fix | Delete
set: function( to ) {
[224] Fix | Delete
var from = this._value;
[225] Fix | Delete
[226] Fix | Delete
to = this._setter.apply( this, arguments );
[227] Fix | Delete
to = this.validate( to );
[228] Fix | Delete
[229] Fix | Delete
// Bail if the sanitized value is null or unchanged.
[230] Fix | Delete
if ( null === to || _.isEqual( from, to ) ) {
[231] Fix | Delete
return this;
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
this._value = to;
[235] Fix | Delete
this._dirty = true;
[236] Fix | Delete
[237] Fix | Delete
this.callbacks.fireWith( this, [ to, from ] );
[238] Fix | Delete
[239] Fix | Delete
return this;
[240] Fix | Delete
},
[241] Fix | Delete
[242] Fix | Delete
_setter: function( to ) {
[243] Fix | Delete
return to;
[244] Fix | Delete
},
[245] Fix | Delete
[246] Fix | Delete
setter: function( callback ) {
[247] Fix | Delete
var from = this.get();
[248] Fix | Delete
this._setter = callback;
[249] Fix | Delete
// Temporarily clear value so setter can decide if it's valid.
[250] Fix | Delete
this._value = null;
[251] Fix | Delete
this.set( from );
[252] Fix | Delete
return this;
[253] Fix | Delete
},
[254] Fix | Delete
[255] Fix | Delete
resetSetter: function() {
[256] Fix | Delete
this._setter = this.constructor.prototype._setter;
[257] Fix | Delete
this.set( this.get() );
[258] Fix | Delete
return this;
[259] Fix | Delete
},
[260] Fix | Delete
[261] Fix | Delete
validate: function( value ) {
[262] Fix | Delete
return value;
[263] Fix | Delete
},
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Bind a function to be invoked whenever the value changes.
[267] Fix | Delete
*
[268] Fix | Delete
* @param {...Function} A function, or multiple functions, to add to the callback stack.
[269] Fix | Delete
*/
[270] Fix | Delete
bind: function() {
[271] Fix | Delete
this.callbacks.add.apply( this.callbacks, arguments );
[272] Fix | Delete
return this;
[273] Fix | Delete
},
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Unbind a previously bound function.
[277] Fix | Delete
*
[278] Fix | Delete
* @param {...Function} A function, or multiple functions, to remove from the callback stack.
[279] Fix | Delete
*/
[280] Fix | Delete
unbind: function() {
[281] Fix | Delete
this.callbacks.remove.apply( this.callbacks, arguments );
[282] Fix | Delete
return this;
[283] Fix | Delete
},
[284] Fix | Delete
[285] Fix | Delete
link: function() { // values*
[286] Fix | Delete
var set = this.set;
[287] Fix | Delete
$.each( arguments, function() {
[288] Fix | Delete
this.bind( set );
[289] Fix | Delete
});
[290] Fix | Delete
return this;
[291] Fix | Delete
},
[292] Fix | Delete
[293] Fix | Delete
unlink: function() { // values*
[294] Fix | Delete
var set = this.set;
[295] Fix | Delete
$.each( arguments, function() {
[296] Fix | Delete
this.unbind( set );
[297] Fix | Delete
});
[298] Fix | Delete
return this;
[299] Fix | Delete
},
[300] Fix | Delete
[301] Fix | Delete
sync: function() { // values*
[302] Fix | Delete
var that = this;
[303] Fix | Delete
$.each( arguments, function() {
[304] Fix | Delete
that.link( this );
[305] Fix | Delete
this.link( that );
[306] Fix | Delete
});
[307] Fix | Delete
return this;
[308] Fix | Delete
},
[309] Fix | Delete
[310] Fix | Delete
unsync: function() { // values*
[311] Fix | Delete
var that = this;
[312] Fix | Delete
$.each( arguments, function() {
[313] Fix | Delete
that.unlink( this );
[314] Fix | Delete
this.unlink( that );
[315] Fix | Delete
});
[316] Fix | Delete
return this;
[317] Fix | Delete
}
[318] Fix | Delete
});
[319] Fix | Delete
[320] Fix | Delete
/**
[321] Fix | Delete
* A collection of observable values.
[322] Fix | Delete
*
[323] Fix | Delete
* @memberOf wp.customize
[324] Fix | Delete
* @alias wp.customize.Values
[325] Fix | Delete
*
[326] Fix | Delete
* @constructor
[327] Fix | Delete
* @augments wp.customize.Class
[328] Fix | Delete
* @mixes wp.customize.Events
[329] Fix | Delete
*/
[330] Fix | Delete
api.Values = api.Class.extend(/** @lends wp.customize.Values.prototype */{
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* The default constructor for items of the collection.
[334] Fix | Delete
*
[335] Fix | Delete
* @type {object}
[336] Fix | Delete
*/
[337] Fix | Delete
defaultConstructor: api.Value,
[338] Fix | Delete
[339] Fix | Delete
initialize: function( options ) {
[340] Fix | Delete
$.extend( this, options || {} );
[341] Fix | Delete
[342] Fix | Delete
this._value = {};
[343] Fix | Delete
this._deferreds = {};
[344] Fix | Delete
},
[345] Fix | Delete
[346] Fix | Delete
/**
[347] Fix | Delete
* Get the instance of an item from the collection if only ID is specified.
[348] Fix | Delete
*
[349] Fix | Delete
* If more than one argument is supplied, all are expected to be IDs and
[350] Fix | Delete
* the last to be a function callback that will be invoked when the requested
[351] Fix | Delete
* items are available.
[352] Fix | Delete
*
[353] Fix | Delete
* @see {api.Values.when}
[354] Fix | Delete
*
[355] Fix | Delete
* @param {string} id ID of the item.
[356] Fix | Delete
* @param {...} Zero or more IDs of items to wait for and a callback
[357] Fix | Delete
* function to invoke when they're available. Optional.
[358] Fix | Delete
* @return {mixed} The item instance if only one ID was supplied.
[359] Fix | Delete
* A Deferred Promise object if a callback function is supplied.
[360] Fix | Delete
*/
[361] Fix | Delete
instance: function( id ) {
[362] Fix | Delete
if ( arguments.length === 1 ) {
[363] Fix | Delete
return this.value( id );
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
return this.when.apply( this, arguments );
[367] Fix | Delete
},
[368] Fix | Delete
[369] Fix | Delete
/**
[370] Fix | Delete
* Get the instance of an item.
[371] Fix | Delete
*
[372] Fix | Delete
* @param {string} id The ID of the item.
[373] Fix | Delete
* @return {[type]} [description]
[374] Fix | Delete
*/
[375] Fix | Delete
value: function( id ) {
[376] Fix | Delete
return this._value[ id ];
[377] Fix | Delete
},
[378] Fix | Delete
[379] Fix | Delete
/**
[380] Fix | Delete
* Whether the collection has an item with the given ID.
[381] Fix | Delete
*
[382] Fix | Delete
* @param {string} id The ID of the item to look for.
[383] Fix | Delete
* @return {boolean}
[384] Fix | Delete
*/
[385] Fix | Delete
has: function( id ) {
[386] Fix | Delete
return typeof this._value[ id ] !== 'undefined';
[387] Fix | Delete
},
[388] Fix | Delete
[389] Fix | Delete
/**
[390] Fix | Delete
* Add an item to the collection.
[391] Fix | Delete
*
[392] Fix | Delete
* @param {string|wp.customize.Class} item - The item instance to add, or the ID for the instance to add. When an ID string is supplied, then itemObject must be provided.
[393] Fix | Delete
* @param {wp.customize.Class} [itemObject] - The item instance when the first argument is a ID string.
[394] Fix | Delete
* @return {wp.customize.Class} The new item's instance, or an existing instance if already added.
[395] Fix | Delete
*/
[396] Fix | Delete
add: function( item, itemObject ) {
[397] Fix | Delete
var collection = this, id, instance;
[398] Fix | Delete
if ( 'string' === typeof item ) {
[399] Fix | Delete
id = item;
[400] Fix | Delete
instance = itemObject;
[401] Fix | Delete
} else {
[402] Fix | Delete
if ( 'string' !== typeof item.id ) {
[403] Fix | Delete
throw new Error( 'Unknown key' );
[404] Fix | Delete
}
[405] Fix | Delete
id = item.id;
[406] Fix | Delete
instance = item;
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
if ( collection.has( id ) ) {
[410] Fix | Delete
return collection.value( id );
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
collection._value[ id ] = instance;
[414] Fix | Delete
instance.parent = collection;
[415] Fix | Delete
[416] Fix | Delete
// Propagate a 'change' event on an item up to the collection.
[417] Fix | Delete
if ( instance.extended( api.Value ) ) {
[418] Fix | Delete
instance.bind( collection._change );
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
collection.trigger( 'add', instance );
[422] Fix | Delete
[423] Fix | Delete
// If a deferred object exists for this item,
[424] Fix | Delete
// resolve it.
[425] Fix | Delete
if ( collection._deferreds[ id ] ) {
[426] Fix | Delete
collection._deferreds[ id ].resolve();
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
return collection._value[ id ];
[430] Fix | Delete
},
[431] Fix | Delete
[432] Fix | Delete
/**
[433] Fix | Delete
* Create a new item of the collection using the collection's default constructor
[434] Fix | Delete
* and store it in the collection.
[435] Fix | Delete
*
[436] Fix | Delete
* @param {string} id The ID of the item.
[437] Fix | Delete
* @param {mixed} value Any extra arguments are passed into the item's initialize method.
[438] Fix | Delete
* @return {mixed} The new item's instance.
[439] Fix | Delete
*/
[440] Fix | Delete
create: function( id ) {
[441] Fix | Delete
return this.add( id, new this.defaultConstructor( api.Class.applicator, slice.call( arguments, 1 ) ) );
[442] Fix | Delete
},
[443] Fix | Delete
[444] Fix | Delete
/**
[445] Fix | Delete
* Iterate over all items in the collection invoking the provided callback.
[446] Fix | Delete
*
[447] Fix | Delete
* @param {Function} callback Function to invoke.
[448] Fix | Delete
* @param {Object} context Object context to invoke the function with. Optional.
[449] Fix | Delete
*/
[450] Fix | Delete
each: function( callback, context ) {
[451] Fix | Delete
context = typeof context === 'undefined' ? this : context;
[452] Fix | Delete
[453] Fix | Delete
$.each( this._value, function( key, obj ) {
[454] Fix | Delete
callback.call( context, obj, key );
[455] Fix | Delete
});
[456] Fix | Delete
},
[457] Fix | Delete
[458] Fix | Delete
/**
[459] Fix | Delete
* Remove an item from the collection.
[460] Fix | Delete
*
[461] Fix | Delete
* @param {string} id The ID of the item to remove.
[462] Fix | Delete
*/
[463] Fix | Delete
remove: function( id ) {
[464] Fix | Delete
var value = this.value( id );
[465] Fix | Delete
[466] Fix | Delete
if ( value ) {
[467] Fix | Delete
[468] Fix | Delete
// Trigger event right before the element is removed from the collection.
[469] Fix | Delete
this.trigger( 'remove', value );
[470] Fix | Delete
[471] Fix | Delete
if ( value.extended( api.Value ) ) {
[472] Fix | Delete
value.unbind( this._change );
[473] Fix | Delete
}
[474] Fix | Delete
delete value.parent;
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
delete this._value[ id ];
[478] Fix | Delete
delete this._deferreds[ id ];
[479] Fix | Delete
[480] Fix | Delete
// Trigger removed event after the item has been eliminated from the collection.
[481] Fix | Delete
if ( value ) {
[482] Fix | Delete
this.trigger( 'removed', value );
[483] Fix | Delete
}
[484] Fix | Delete
},
[485] Fix | Delete
[486] Fix | Delete
/**
[487] Fix | Delete
* Runs a callback once all requested values exist.
[488] Fix | Delete
*
[489] Fix | Delete
* when( ids*, [callback] );
[490] Fix | Delete
*
[491] Fix | Delete
* For example:
[492] Fix | Delete
* when( id1, id2, id3, function( value1, value2, value3 ) {} );
[493] Fix | Delete
*
[494] Fix | Delete
* @return $.Deferred.promise();
[495] Fix | Delete
*/
[496] Fix | Delete
when: function() {
[497] Fix | Delete
var self = this,
[498] Fix | Delete
ids = slice.call( arguments ),
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function