wp/wp-includes/js/customize-models.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    11 
    11 
    12 	/**
    12 	/**
    13 	 * wp.customize.HeaderTool.ImageModel
    13 	 * wp.customize.HeaderTool.ImageModel
    14 	 *
    14 	 *
    15 	 * A header image. This is where saves via the Customizer API are
    15 	 * A header image. This is where saves via the Customizer API are
    16 	 * abstracted away, plus our own AJAX calls to add images to and remove
    16 	 * abstracted away, plus our own Ajax calls to add images to and remove
    17 	 * images from the user's recently uploaded images setting on the server.
    17 	 * images from the user's recently uploaded images setting on the server.
    18 	 * These calls are made regardless of whether the user actually saves new
    18 	 * These calls are made regardless of whether the user actually saves new
    19 	 * Customizer settings.
    19 	 * Customizer settings.
    20 	 *
    20 	 *
    21 	 * @memberOf wp.customize.HeaderTool
    21 	 * @memberOf wp.customize.HeaderTool
    51 
    51 
    52 		destroy: function() {
    52 		destroy: function() {
    53 			var data = this.get('header'),
    53 			var data = this.get('header'),
    54 				curr = api.HeaderTool.currentHeader.get('header').attachment_id;
    54 				curr = api.HeaderTool.currentHeader.get('header').attachment_id;
    55 
    55 
    56 			// If the image we're removing is also the current header, unset
    56 			// If the image we're removing is also the current header,
    57 			// the latter
    57 			// unset the latter.
    58 			if (curr && data.attachment_id === curr) {
    58 			if (curr && data.attachment_id === curr) {
    59 				api.HeaderTool.currentHeader.trigger('hide');
    59 				api.HeaderTool.currentHeader.trigger('hide');
    60 			}
    60 			}
    61 
    61 
    62 			wp.ajax.post( 'custom-header-remove', {
    62 			wp.ajax.post( 'custom-header-remove', {
   140 	 * @augments Backbone.Collection
   140 	 * @augments Backbone.Collection
   141 	 */
   141 	 */
   142 	api.HeaderTool.ChoiceList = Backbone.Collection.extend({
   142 	api.HeaderTool.ChoiceList = Backbone.Collection.extend({
   143 		model: api.HeaderTool.ImageModel,
   143 		model: api.HeaderTool.ImageModel,
   144 
   144 
   145 		// Ordered from most recently used to least
   145 		// Ordered from most recently used to least.
   146 		comparator: function(model) {
   146 		comparator: function(model) {
   147 			return -model.get('header').timestamp;
   147 			return -model.get('header').timestamp;
   148 		},
   148 		},
   149 
   149 
   150 		initialize: function() {
   150 		initialize: function() {
   151 			var current = api.HeaderTool.currentHeader.get('choice').replace(/^https?:\/\//, ''),
   151 			var current = api.HeaderTool.currentHeader.get('choice').replace(/^https?:\/\//, ''),
   152 				isRandom = this.isRandomChoice(api.get().header_image);
   152 				isRandom = this.isRandomChoice(api.get().header_image);
   153 
   153 
   154 			// Overridable by an extending class
   154 			// Overridable by an extending class.
   155 			if (!this.type) {
   155 			if (!this.type) {
   156 				this.type = 'uploaded';
   156 				this.type = 'uploaded';
   157 			}
   157 			}
   158 
   158 
   159 			// Overridable by an extending class
   159 			// Overridable by an extending class.
   160 			if (typeof this.data === 'undefined') {
   160 			if (typeof this.data === 'undefined') {
   161 				this.data = _wpCustomizeHeader.uploads;
   161 				this.data = _wpCustomizeHeader.uploads;
   162 			}
   162 			}
   163 
   163 
   164 			if (isRandom) {
   164 			if (isRandom) {
   165 				// So that when adding data we don't hide regular images
   165 				// So that when adding data we don't hide regular images.
   166 				current = api.get().header_image;
   166 				current = api.get().header_image;
   167 			}
   167 			}
   168 
   168 
   169 			this.on('control:setImage', this.setImage, this);
   169 			this.on('control:setImage', this.setImage, this);
   170 			this.on('control:removeImage', this.removeImage, this);
   170 			this.on('control:removeImage', this.removeImage, this);