Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: customize-models.js
/**
[0] Fix | Delete
* @output wp-includes/js/customize-models.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global _wpCustomizeHeader */
[4] Fix | Delete
(function( $, wp ) {
[5] Fix | Delete
var api = wp.customize;
[6] Fix | Delete
/** @namespace wp.customize.HeaderTool */
[7] Fix | Delete
api.HeaderTool = {};
[8] Fix | Delete
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* wp.customize.HeaderTool.ImageModel
[12] Fix | Delete
*
[13] Fix | Delete
* A header image. This is where saves via the Customizer API are
[14] Fix | Delete
* abstracted away, plus our own Ajax calls to add images to and remove
[15] Fix | Delete
* images from the user's recently uploaded images setting on the server.
[16] Fix | Delete
* These calls are made regardless of whether the user actually saves new
[17] Fix | Delete
* Customizer settings.
[18] Fix | Delete
*
[19] Fix | Delete
* @memberOf wp.customize.HeaderTool
[20] Fix | Delete
* @alias wp.customize.HeaderTool.ImageModel
[21] Fix | Delete
*
[22] Fix | Delete
* @constructor
[23] Fix | Delete
* @augments Backbone.Model
[24] Fix | Delete
*/
[25] Fix | Delete
api.HeaderTool.ImageModel = Backbone.Model.extend(/** @lends wp.customize.HeaderTool.ImageModel.prototype */{
[26] Fix | Delete
defaults: function() {
[27] Fix | Delete
return {
[28] Fix | Delete
header: {
[29] Fix | Delete
attachment_id: 0,
[30] Fix | Delete
url: '',
[31] Fix | Delete
timestamp: _.now(),
[32] Fix | Delete
thumbnail_url: ''
[33] Fix | Delete
},
[34] Fix | Delete
choice: '',
[35] Fix | Delete
selected: false,
[36] Fix | Delete
random: false
[37] Fix | Delete
};
[38] Fix | Delete
},
[39] Fix | Delete
[40] Fix | Delete
initialize: function() {
[41] Fix | Delete
this.on('hide', this.hide, this);
[42] Fix | Delete
},
[43] Fix | Delete
[44] Fix | Delete
hide: function() {
[45] Fix | Delete
this.set('choice', '');
[46] Fix | Delete
api('header_image').set('remove-header');
[47] Fix | Delete
api('header_image_data').set('remove-header');
[48] Fix | Delete
},
[49] Fix | Delete
[50] Fix | Delete
destroy: function() {
[51] Fix | Delete
var data = this.get('header'),
[52] Fix | Delete
curr = api.HeaderTool.currentHeader.get('header').attachment_id;
[53] Fix | Delete
[54] Fix | Delete
// If the image we're removing is also the current header,
[55] Fix | Delete
// unset the latter.
[56] Fix | Delete
if (curr && data.attachment_id === curr) {
[57] Fix | Delete
api.HeaderTool.currentHeader.trigger('hide');
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
wp.ajax.post( 'custom-header-remove', {
[61] Fix | Delete
nonce: _wpCustomizeHeader.nonces.remove,
[62] Fix | Delete
wp_customize: 'on',
[63] Fix | Delete
theme: api.settings.theme.stylesheet,
[64] Fix | Delete
attachment_id: data.attachment_id
[65] Fix | Delete
});
[66] Fix | Delete
[67] Fix | Delete
this.trigger('destroy', this, this.collection);
[68] Fix | Delete
},
[69] Fix | Delete
[70] Fix | Delete
save: function() {
[71] Fix | Delete
if (this.get('random')) {
[72] Fix | Delete
api('header_image').set(this.get('header').random);
[73] Fix | Delete
api('header_image_data').set(this.get('header').random);
[74] Fix | Delete
} else {
[75] Fix | Delete
if (this.get('header').defaultName) {
[76] Fix | Delete
api('header_image').set(this.get('header').url);
[77] Fix | Delete
api('header_image_data').set(this.get('header').defaultName);
[78] Fix | Delete
} else {
[79] Fix | Delete
api('header_image').set(this.get('header').url);
[80] Fix | Delete
api('header_image_data').set(this.get('header'));
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
api.HeaderTool.combinedList.trigger('control:setImage', this);
[85] Fix | Delete
},
[86] Fix | Delete
[87] Fix | Delete
importImage: function() {
[88] Fix | Delete
var data = this.get('header');
[89] Fix | Delete
if (data.attachment_id === undefined) {
[90] Fix | Delete
return;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
wp.ajax.post( 'custom-header-add', {
[94] Fix | Delete
nonce: _wpCustomizeHeader.nonces.add,
[95] Fix | Delete
wp_customize: 'on',
[96] Fix | Delete
theme: api.settings.theme.stylesheet,
[97] Fix | Delete
attachment_id: data.attachment_id
[98] Fix | Delete
} );
[99] Fix | Delete
},
[100] Fix | Delete
[101] Fix | Delete
shouldBeCropped: function() {
[102] Fix | Delete
if (this.get('themeFlexWidth') === true &&
[103] Fix | Delete
this.get('themeFlexHeight') === true) {
[104] Fix | Delete
return false;
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
if (this.get('themeFlexWidth') === true &&
[108] Fix | Delete
this.get('themeHeight') === this.get('imageHeight')) {
[109] Fix | Delete
return false;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
if (this.get('themeFlexHeight') === true &&
[113] Fix | Delete
this.get('themeWidth') === this.get('imageWidth')) {
[114] Fix | Delete
return false;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
if (this.get('themeWidth') === this.get('imageWidth') &&
[118] Fix | Delete
this.get('themeHeight') === this.get('imageHeight')) {
[119] Fix | Delete
return false;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
if (this.get('imageWidth') <= this.get('themeWidth')) {
[123] Fix | Delete
return false;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
return true;
[127] Fix | Delete
}
[128] Fix | Delete
});
[129] Fix | Delete
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* wp.customize.HeaderTool.ChoiceList
[133] Fix | Delete
*
[134] Fix | Delete
* @memberOf wp.customize.HeaderTool
[135] Fix | Delete
* @alias wp.customize.HeaderTool.ChoiceList
[136] Fix | Delete
*
[137] Fix | Delete
* @constructor
[138] Fix | Delete
* @augments Backbone.Collection
[139] Fix | Delete
*/
[140] Fix | Delete
api.HeaderTool.ChoiceList = Backbone.Collection.extend({
[141] Fix | Delete
model: api.HeaderTool.ImageModel,
[142] Fix | Delete
[143] Fix | Delete
// Ordered from most recently used to least.
[144] Fix | Delete
comparator: function(model) {
[145] Fix | Delete
return -model.get('header').timestamp;
[146] Fix | Delete
},
[147] Fix | Delete
[148] Fix | Delete
initialize: function() {
[149] Fix | Delete
var current = api.HeaderTool.currentHeader.get('choice').replace(/^https?:\/\//, ''),
[150] Fix | Delete
isRandom = this.isRandomChoice(api.get().header_image);
[151] Fix | Delete
[152] Fix | Delete
// Overridable by an extending class.
[153] Fix | Delete
if (!this.type) {
[154] Fix | Delete
this.type = 'uploaded';
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
// Overridable by an extending class.
[158] Fix | Delete
if (typeof this.data === 'undefined') {
[159] Fix | Delete
this.data = _wpCustomizeHeader.uploads;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
if (isRandom) {
[163] Fix | Delete
// So that when adding data we don't hide regular images.
[164] Fix | Delete
current = api.get().header_image;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
this.on('control:setImage', this.setImage, this);
[168] Fix | Delete
this.on('control:removeImage', this.removeImage, this);
[169] Fix | Delete
this.on('add', this.maybeRemoveOldCrop, this);
[170] Fix | Delete
this.on('add', this.maybeAddRandomChoice, this);
[171] Fix | Delete
[172] Fix | Delete
_.each(this.data, function(elt, index) {
[173] Fix | Delete
if (!elt.attachment_id) {
[174] Fix | Delete
elt.defaultName = index;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
if (typeof elt.timestamp === 'undefined') {
[178] Fix | Delete
elt.timestamp = 0;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
this.add({
[182] Fix | Delete
header: elt,
[183] Fix | Delete
choice: elt.url.split('/').pop(),
[184] Fix | Delete
selected: current === elt.url.replace(/^https?:\/\//, '')
[185] Fix | Delete
}, { silent: true });
[186] Fix | Delete
}, this);
[187] Fix | Delete
[188] Fix | Delete
if (this.size() > 0) {
[189] Fix | Delete
this.addRandomChoice(current);
[190] Fix | Delete
}
[191] Fix | Delete
},
[192] Fix | Delete
[193] Fix | Delete
maybeRemoveOldCrop: function( model ) {
[194] Fix | Delete
var newID = model.get( 'header' ).attachment_id || false,
[195] Fix | Delete
oldCrop;
[196] Fix | Delete
[197] Fix | Delete
// Bail early if we don't have a new attachment ID.
[198] Fix | Delete
if ( ! newID ) {
[199] Fix | Delete
return;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
oldCrop = this.find( function( item ) {
[203] Fix | Delete
return ( item.cid !== model.cid && item.get( 'header' ).attachment_id === newID );
[204] Fix | Delete
} );
[205] Fix | Delete
[206] Fix | Delete
// If we found an old crop, remove it from the collection.
[207] Fix | Delete
if ( oldCrop ) {
[208] Fix | Delete
this.remove( oldCrop );
[209] Fix | Delete
}
[210] Fix | Delete
},
[211] Fix | Delete
[212] Fix | Delete
maybeAddRandomChoice: function() {
[213] Fix | Delete
if (this.size() === 1) {
[214] Fix | Delete
this.addRandomChoice();
[215] Fix | Delete
}
[216] Fix | Delete
},
[217] Fix | Delete
[218] Fix | Delete
addRandomChoice: function(initialChoice) {
[219] Fix | Delete
var isRandomSameType = RegExp(this.type).test(initialChoice),
[220] Fix | Delete
randomChoice = 'random-' + this.type + '-image';
[221] Fix | Delete
[222] Fix | Delete
this.add({
[223] Fix | Delete
header: {
[224] Fix | Delete
timestamp: 0,
[225] Fix | Delete
random: randomChoice,
[226] Fix | Delete
width: 245,
[227] Fix | Delete
height: 41
[228] Fix | Delete
},
[229] Fix | Delete
choice: randomChoice,
[230] Fix | Delete
random: true,
[231] Fix | Delete
selected: isRandomSameType
[232] Fix | Delete
});
[233] Fix | Delete
},
[234] Fix | Delete
[235] Fix | Delete
isRandomChoice: function(choice) {
[236] Fix | Delete
return (/^random-(uploaded|default)-image$/).test(choice);
[237] Fix | Delete
},
[238] Fix | Delete
[239] Fix | Delete
shouldHideTitle: function() {
[240] Fix | Delete
return this.size() < 2;
[241] Fix | Delete
},
[242] Fix | Delete
[243] Fix | Delete
setImage: function(model) {
[244] Fix | Delete
this.each(function(m) {
[245] Fix | Delete
m.set('selected', false);
[246] Fix | Delete
});
[247] Fix | Delete
[248] Fix | Delete
if (model) {
[249] Fix | Delete
model.set('selected', true);
[250] Fix | Delete
}
[251] Fix | Delete
},
[252] Fix | Delete
[253] Fix | Delete
removeImage: function() {
[254] Fix | Delete
this.each(function(m) {
[255] Fix | Delete
m.set('selected', false);
[256] Fix | Delete
});
[257] Fix | Delete
}
[258] Fix | Delete
});
[259] Fix | Delete
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* wp.customize.HeaderTool.DefaultsList
[263] Fix | Delete
*
[264] Fix | Delete
* @memberOf wp.customize.HeaderTool
[265] Fix | Delete
* @alias wp.customize.HeaderTool.DefaultsList
[266] Fix | Delete
*
[267] Fix | Delete
* @constructor
[268] Fix | Delete
* @augments wp.customize.HeaderTool.ChoiceList
[269] Fix | Delete
* @augments Backbone.Collection
[270] Fix | Delete
*/
[271] Fix | Delete
api.HeaderTool.DefaultsList = api.HeaderTool.ChoiceList.extend({
[272] Fix | Delete
initialize: function() {
[273] Fix | Delete
this.type = 'default';
[274] Fix | Delete
this.data = _wpCustomizeHeader.defaults;
[275] Fix | Delete
api.HeaderTool.ChoiceList.prototype.initialize.apply(this);
[276] Fix | Delete
}
[277] Fix | Delete
});
[278] Fix | Delete
[279] Fix | Delete
})( jQuery, window.wp );
[280] Fix | Delete
[281] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function