~canonical-sysadmins/wordpress/4.9.1

« back to all changes in this revision

Viewing changes to wp-includes/js/customize-models.js

  • Committer: Barry Price
  • Date: 2017-11-17 04:49:02 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: barry.price@canonical.com-20171117044902-5frux4ycbq6g9fyf
Merge WP4.9 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* global _wpCustomizeHeader */
2
2
(function( $, wp ) {
3
3
        var api = wp.customize;
 
4
        /** @namespace wp.customize.HeaderTool */
4
5
        api.HeaderTool = {};
5
6
 
6
7
 
13
14
         * These calls are made regardless of whether the user actually saves new
14
15
         * Customizer settings.
15
16
         *
 
17
         * @memberOf wp.customize.HeaderTool
 
18
         * @alias wp.customize.HeaderTool.ImageModel
 
19
         *
16
20
         * @constructor
17
21
         * @augments Backbone.Model
18
22
         */
19
 
        api.HeaderTool.ImageModel = Backbone.Model.extend({
 
23
        api.HeaderTool.ImageModel = Backbone.Model.extend(/** @lends wp.customize.HeaderTool.ImageModel.prototype */{
20
24
                defaults: function() {
21
25
                        return {
22
26
                                header: {
125
129
        /**
126
130
         * wp.customize.HeaderTool.ChoiceList
127
131
         *
 
132
         * @memberOf wp.customize.HeaderTool
 
133
         * @alias wp.customize.HeaderTool.ChoiceList
 
134
         *
128
135
         * @constructor
129
136
         * @augments Backbone.Collection
130
137
         */
157
164
 
158
165
                        this.on('control:setImage', this.setImage, this);
159
166
                        this.on('control:removeImage', this.removeImage, this);
 
167
                        this.on('add', this.maybeRemoveOldCrop, this);
160
168
                        this.on('add', this.maybeAddRandomChoice, this);
161
169
 
162
170
                        _.each(this.data, function(elt, index) {
180
188
                        }
181
189
                },
182
190
 
 
191
                maybeRemoveOldCrop: function( model ) {
 
192
                        var newID = model.get( 'header' ).attachment_id || false,
 
193
                                oldCrop;
 
194
 
 
195
                        // Bail early if we don't have a new attachment ID.
 
196
                        if ( ! newID ) {
 
197
                                return;
 
198
                        }
 
199
 
 
200
                        oldCrop = this.find( function( item ) {
 
201
                                return ( item.cid !== model.cid && item.get( 'header' ).attachment_id === newID );
 
202
                        } );
 
203
 
 
204
                        // If we found an old crop, remove it from the collection.
 
205
                        if ( oldCrop ) {
 
206
                                this.remove( oldCrop );
 
207
                        }
 
208
                },
 
209
 
183
210
                maybeAddRandomChoice: function() {
184
211
                        if (this.size() === 1) {
185
212
                                this.addRandomChoice();
232
259
        /**
233
260
         * wp.customize.HeaderTool.DefaultsList
234
261
         *
 
262
         * @memberOf wp.customize.HeaderTool
 
263
         * @alias wp.customize.HeaderTool.DefaultsList
 
264
         *
235
265
         * @constructor
236
266
         * @augments wp.customize.HeaderTool.ChoiceList
237
267
         * @augments Backbone.Collection