Changeset 63458
- Timestamp:
- 09/04/2026 12:01:14 AM (2 months ago)
- Location:
- trunk/src/js/_enqueues/wp/customize
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/wp/customize/models.js
r48168 r63458 4 4 5 5 /* global _wpCustomizeHeader */ 6 7 /** 8 * @param {JQueryStatic} $ The jQuery object. 9 * @param {Object} wp The WordPress global object. 10 */ 6 11 (function( $, wp ) { 7 12 var api = wp.customize; … … 22 27 * @alias wp.customize.HeaderTool.ImageModel 23 28 * 24 * @c onstructor29 * @class 25 30 * @augments Backbone.Model 26 31 */ 27 32 api.HeaderTool.ImageModel = Backbone.Model.extend(/** @lends wp.customize.HeaderTool.ImageModel.prototype */{ 33 /** 34 * Returns the default attributes for a header image. 35 * 36 * @return {Object} Default attributes. 37 */ 28 38 defaults: function() { 29 39 return { … … 40 50 }, 41 51 52 /** 53 * Initializes the model, hiding the header when asked to. 54 */ 42 55 initialize: function() { 43 56 this.on('hide', this.hide, this); 44 57 }, 45 58 59 /** 60 * Hides the header image, removing it from the site. 61 */ 46 62 hide: function() { 47 63 this.set('choice', ''); … … 50 66 }, 51 67 68 /** 69 * Removes the image, hiding the header first if it is the current one. 70 */ 52 71 destroy: function() { 53 72 var data = this.get('header'), … … 70 89 }, 71 90 91 /** 92 * Makes this image the current header image. 93 */ 72 94 save: function() { 73 95 if (this.get('random')) { … … 87 109 }, 88 110 111 /** 112 * Adds the image to the theme's uploaded headers. 113 */ 89 114 importImage: function() { 90 115 var data = this.get('header'); … … 101 126 }, 102 127 128 /** 129 * Returns whether the image needs cropping for this theme. 130 * 131 * @return {boolean} Whether the image should be cropped. 132 */ 103 133 shouldBeCropped: function() { 104 134 if (this.get('themeFlexWidth') === true && … … 137 167 * @alias wp.customize.HeaderTool.ChoiceList 138 168 * 139 * @c onstructor169 * @class 140 170 * @augments Backbone.Collection 141 171 */ … … 143 173 model: api.HeaderTool.ImageModel, 144 174 145 // Ordered from most recently used to least. 175 /** 176 * Orders the collection from most recently used to least. 177 * 178 * @param {Backbone.Model} model The model to sort. 179 * @return {number} The sort order. 180 */ 146 181 comparator: function(model) { 147 182 return -model.get('header').timestamp; 148 183 }, 149 184 185 /** 186 * Initializes the collection from the uploaded header images. 187 */ 150 188 initialize: function() { 151 189 var current = api.HeaderTool.currentHeader.get('choice').replace(/^https?:\/\//, ''), … … 193 231 }, 194 232 233 /** 234 * Removes an image's previous crop once it has been replaced. 235 * 236 * @param {Backbone.Model} model Model. 237 */ 195 238 maybeRemoveOldCrop: function( model ) { 196 239 var newID = model.get( 'header' ).attachment_id || false, … … 212 255 }, 213 256 257 /** 258 * Adds the random choice once a single image is left. 259 */ 214 260 maybeAddRandomChoice: function() { 215 261 if (this.size() === 1) { … … 218 264 }, 219 265 266 /** 267 * Adds the random image choice to the collection. 268 * 269 * @param {string} initialChoice Initial choice. 270 */ 220 271 addRandomChoice: function(initialChoice) { 221 272 var isRandomSameType = RegExp(this.type).test(initialChoice), … … 235 286 }, 236 287 288 /** 289 * Returns whether a choice is one of the random image choices. 290 * 291 * @param {string} choice Choice. 292 * @return {boolean} Whether the choice is random. 293 */ 237 294 isRandomChoice: function(choice) { 238 295 return (/^random-(uploaded|default)-image$/).test(choice); 239 296 }, 240 297 298 /** 299 * Returns whether the list title should be hidden. 300 * 301 * @return {boolean} Whether the title should be hidden. 302 */ 241 303 shouldHideTitle: function() { 242 304 return this.size() < 2; 243 305 }, 244 306 307 /** 308 * Marks a single image as the selected one. 309 * 310 * @param {Backbone.Model} model Model. 311 */ 245 312 setImage: function(model) { 246 313 this.each(function(m) { … … 253 320 }, 254 321 322 /** 323 * Clears the selection. 324 */ 255 325 removeImage: function() { 256 326 this.each(function(m) { … … 267 337 * @alias wp.customize.HeaderTool.DefaultsList 268 338 * 269 * @c onstructor339 * @class 270 340 * @augments wp.customize.HeaderTool.ChoiceList 271 341 * @augments Backbone.Collection 272 342 */ 273 343 api.HeaderTool.DefaultsList = api.HeaderTool.ChoiceList.extend({ 344 /** 345 * Initializes the collection from the theme's default header images. 346 */ 274 347 initialize: function() { 275 348 this.type = 'default'; -
trunk/src/js/_enqueues/wp/customize/views.js
r60645 r63458 3 3 */ 4 4 5 /** 6 * @param {JQueryStatic} $ The jQuery object. 7 * @param {Object} wp The WordPress global object. 8 * @param {_.UnderscoreStatic} _ The Underscore.js object. 9 */ 5 10 (function( $, wp, _ ) { 6 11 … … 19 24 * @alias wp.customize.HeaderTool.CurrentView 20 25 * 21 * @c onstructor26 * @class 22 27 * @augments wp.Backbone.View 23 28 */ … … 25 30 template: wp.template('header-current'), 26 31 32 /** 33 * Initializes the view, rendering it whenever the model changes. 34 */ 27 35 initialize: function() { 28 36 this.listenTo(this.model, 'change', this.render); … … 30 38 }, 31 39 40 /** 41 * Renders the currently selected header image. 42 * 43 * @return {wp.customize.HeaderTool.CurrentView} Current view. 44 */ 32 45 render: function() { 33 46 this.$el.html(this.template(this.model.toJSON())); … … 36 49 }, 37 50 51 /** 52 * Shows or hides the header's action buttons. 53 */ 38 54 setButtons: function() { 39 55 var elements = $('#customize-control-header_image .actions .remove'); … … 65 81 * @alias wp.customize.HeaderTool.ChoiceView 66 82 * 67 * @c onstructor83 * @class 68 84 * @augments wp.Backbone.View 69 85 */ … … 78 94 }, 79 95 96 /** 97 * Initializes the view, marking it current when it matches the header image. 98 */ 80 99 initialize: function() { 81 100 var properties = [ … … 91 110 }, 92 111 112 /** 113 * Renders the choice. 114 * 115 * @return {wp.customize.HeaderTool.ChoiceView} Choice view. 116 */ 93 117 render: function() { 94 118 this.$el.html(this.template(this.extendedModel())); … … 98 122 }, 99 123 124 /** 125 * Toggles the selected class on the choice. 126 */ 100 127 toggleSelected: function() { 101 128 this.$el.toggleClass('selected', this.model.get('selected')); 102 129 }, 103 130 131 /** 132 * Returns the model's attributes together with its collection type. 133 * 134 * @return {Object} Extended model. 135 */ 104 136 extendedModel: function() { 105 137 var c = this.model.get('collection'); … … 109 141 }, 110 142 143 /** 144 * Selects the choice as the header image. 145 */ 111 146 select: function() { 112 147 this.preventJump(); … … 115 150 }, 116 151 152 /** 153 * Keeps the sidebar at its current scroll position. 154 */ 117 155 preventJump: function() { 118 156 var container = $('.wp-full-overlay-sidebar-content'), … … 124 162 }, 125 163 164 /** 165 * Removes the image from the collection. 166 * 167 * @param {JQuery.Event} e Event. 168 */ 126 169 removeImage: function(e) { 127 170 e.stopPropagation(); … … 143 186 * @alias wp.customize.HeaderTool.ChoiceListView 144 187 * 145 * @c onstructor188 * @class 146 189 * @augments wp.Backbone.View 147 190 */ 148 191 api.HeaderTool.ChoiceListView = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.ChoiceListView.prototype */{ 192 /** 193 * Initializes the view, rendering it as the collection changes. 194 */ 149 195 initialize: function() { 150 196 this.listenTo(this.collection, 'add', this.addOne); … … 155 201 }, 156 202 203 /** 204 * Renders each choice in the collection. 205 * 206 * @return {wp.customize.HeaderTool.ChoiceListView} Choice list view. 207 */ 157 208 render: function() { 158 209 this.$el.empty(); 159 210 this.collection.each(this.addOne, this); 160 211 this.toggleList(); 161 }, 162 212 return this; 213 }, 214 215 /** 216 * Renders a single choice into the list. 217 * 218 * @param {Backbone.Model} choice Choice. 219 */ 163 220 addOne: function(choice) { 164 221 var view; … … 168 225 }, 169 226 227 /** 228 * Shows or hides the list title and the random button. 229 */ 170 230 toggleList: function() { 171 231 var title = this.$el.parents().prev('.customize-control-title'), … … 189 249 * @alias wp.customize.HeaderTool.CombinedList 190 250 * 191 * @c onstructor251 * @class 192 252 * @augments wp.Backbone.View 193 253 */ 194 254 api.HeaderTool.CombinedList = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.CombinedList.prototype */{ 255 /** 256 * Initializes the view with the collections to combine. 257 * 258 * @param {Backbone.Collection[]} collections Collections. 259 */ 195 260 initialize: function(collections) { 196 261 this.collections = collections; 197 262 this.on('all', this.propagate, this); 198 263 }, 264 265 /** 266 * Passes an event on to each of the combined collections. 267 * 268 * @param {string} event Event. 269 * @param {*} arg Argument. 270 */ 199 271 propagate: function(event, arg) { 200 272 _.each(this.collections, function(collection) {
Note:
See TracChangeset
for help on using the changeset viewer.