-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Improve Customizer JSDoc #10743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Improve Customizer JSDoc #10743
Changes from all commits
a603e94
a45b863
9817e3f
a2396e2
9a5e1a7
c633c29
5221d35
1835ade
162a1f1
cef3122
55be81e
6ddae5a
c7f407f
d512ff3
a5c5d5f
3d17619
d944c5c
5ca507b
ab9eb85
31e8243
1fa8f87
11ffe58
182301e
9b65262
a19d5df
32e8753
bc02b24
de984b7
8645a76
ffa1007
1485310
4f8350c
7106b2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,11 @@ | |
| */ | ||
|
|
||
| /* global _wpCustomizeHeader */ | ||
|
|
||
| /** | ||
| * @param {JQueryStatic} $ The jQuery object. | ||
| * @param {Object} wp The WordPress global object. | ||
| */ | ||
| (function( $, wp ) { | ||
| var api = wp.customize; | ||
| /** @namespace wp.customize.HeaderTool */ | ||
|
|
@@ -21,10 +26,15 @@ | |
| * @memberOf wp.customize.HeaderTool | ||
| * @alias wp.customize.HeaderTool.ImageModel | ||
| * | ||
| * @constructor | ||
| * @class | ||
| * @augments Backbone.Model | ||
| */ | ||
| api.HeaderTool.ImageModel = Backbone.Model.extend(/** @lends wp.customize.HeaderTool.ImageModel.prototype */{ | ||
| /** | ||
| * Default attributes. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: shouldn't all descriptions start with a verb in third person? See also all following cases: Initializes, Hides, Destroys, etc. Personally I wouldn't mind that much but as far as I can tell it's a convention... |
||
| * | ||
| * @return {Object} Default attributes. | ||
| */ | ||
| defaults: function() { | ||
| return { | ||
| header: { | ||
|
|
@@ -39,16 +49,25 @@ | |
| }; | ||
| }, | ||
|
|
||
| /** | ||
| * Initialize. | ||
| */ | ||
| initialize: function() { | ||
| this.on('hide', this.hide, this); | ||
| }, | ||
|
|
||
| /** | ||
| * Hide. | ||
| */ | ||
| hide: function() { | ||
| this.set('choice', ''); | ||
| api('header_image').set('remove-header'); | ||
| api('header_image_data').set('remove-header'); | ||
| }, | ||
|
|
||
| /** | ||
| * Destroy. | ||
| */ | ||
| destroy: function() { | ||
| var data = this.get('header'), | ||
| curr = api.HeaderTool.currentHeader.get('header').attachment_id; | ||
|
|
@@ -69,6 +88,9 @@ | |
| this.trigger('destroy', this, this.collection); | ||
| }, | ||
|
|
||
| /** | ||
| * Save. | ||
| */ | ||
| save: function() { | ||
| if (this.get('random')) { | ||
| api('header_image').set(this.get('header').random); | ||
|
|
@@ -86,6 +108,9 @@ | |
| api.HeaderTool.combinedList.trigger('control:setImage', this); | ||
| }, | ||
|
|
||
| /** | ||
| * Import image. | ||
| */ | ||
| importImage: function() { | ||
| var data = this.get('header'); | ||
| if (data.attachment_id === undefined) { | ||
|
|
@@ -100,6 +125,11 @@ | |
| } ); | ||
| }, | ||
|
|
||
| /** | ||
| * Should be cropped. | ||
| * | ||
| * @return {boolean} Whether the image should be cropped. | ||
| */ | ||
| shouldBeCropped: function() { | ||
| if (this.get('themeFlexWidth') === true && | ||
| this.get('themeFlexHeight') === true) { | ||
|
|
@@ -136,17 +166,25 @@ | |
| * @memberOf wp.customize.HeaderTool | ||
| * @alias wp.customize.HeaderTool.ChoiceList | ||
| * | ||
| * @constructor | ||
| * @class | ||
| * @augments Backbone.Collection | ||
| */ | ||
| api.HeaderTool.ChoiceList = Backbone.Collection.extend({ | ||
| model: api.HeaderTool.ImageModel, | ||
|
|
||
| // Ordered from most recently used to least. | ||
| /** | ||
| * Comparator which orders the collection from most recently used to least. | ||
| * | ||
| * @param {Backbone.Model} model The model to sort. | ||
| * @return {number} The sort order. | ||
| */ | ||
| comparator: function(model) { | ||
| return -model.get('header').timestamp; | ||
| }, | ||
|
|
||
| /** | ||
| * Initialize. | ||
| */ | ||
| initialize: function() { | ||
| var current = api.HeaderTool.currentHeader.get('choice').replace(/^https?:\/\//, ''), | ||
| isRandom = this.isRandomChoice(api.get().header_image); | ||
|
|
@@ -192,6 +230,11 @@ | |
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Maybe remove old crop. | ||
| * | ||
| * @param {Backbone.Model} model Model. | ||
| */ | ||
| maybeRemoveOldCrop: function( model ) { | ||
| var newID = model.get( 'header' ).attachment_id || false, | ||
| oldCrop; | ||
|
|
@@ -211,12 +254,20 @@ | |
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Maybe add random choice. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love the determinism of this!!! 🤪 |
||
| */ | ||
| maybeAddRandomChoice: function() { | ||
| if (this.size() === 1) { | ||
| this.addRandomChoice(); | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Add random choice. | ||
| * | ||
| * @param {string} initialChoice Initial choice. | ||
| */ | ||
| addRandomChoice: function(initialChoice) { | ||
| var isRandomSameType = RegExp(this.type).test(initialChoice), | ||
| randomChoice = 'random-' + this.type + '-image'; | ||
|
|
@@ -234,14 +285,30 @@ | |
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Is random choice? | ||
| * | ||
| * @param {string} choice Choice. | ||
| * @return {boolean} Whether the choice is random. | ||
| */ | ||
| isRandomChoice: function(choice) { | ||
| return (/^random-(uploaded|default)-image$/).test(choice); | ||
| }, | ||
|
|
||
| /** | ||
| * Should hide title? | ||
| * | ||
| * @return {boolean} Whether the title should be hidden. | ||
| */ | ||
| shouldHideTitle: function() { | ||
| return this.size() < 2; | ||
| }, | ||
|
|
||
| /** | ||
| * Set image. | ||
| * | ||
| * @param {Backbone.Model} model Model. | ||
| */ | ||
| setImage: function(model) { | ||
| this.each(function(m) { | ||
| m.set('selected', false); | ||
|
|
@@ -252,6 +319,9 @@ | |
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Remove image. | ||
| */ | ||
| removeImage: function() { | ||
| this.each(function(m) { | ||
| m.set('selected', false); | ||
|
|
@@ -266,11 +336,14 @@ | |
| * @memberOf wp.customize.HeaderTool | ||
| * @alias wp.customize.HeaderTool.DefaultsList | ||
| * | ||
| * @constructor | ||
| * @class | ||
| * @augments wp.customize.HeaderTool.ChoiceList | ||
| * @augments Backbone.Collection | ||
| */ | ||
| api.HeaderTool.DefaultsList = api.HeaderTool.ChoiceList.extend({ | ||
| /** | ||
| * Initialize. | ||
| */ | ||
| initialize: function() { | ||
| this.type = 'default'; | ||
| this.data = _wpCustomizeHeader.defaults; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.