2014-03-11 00:13:16 -04:00
|
|
|
(function( $, wp, _ ) {
|
|
|
|
|
|
|
|
if ( ! wp || ! wp.customize ) { return; }
|
|
|
|
var api = wp.customize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.customize.HeaderTool.CurrentView
|
|
|
|
*
|
|
|
|
* Displays the currently selected header image, or a placeholder in lack
|
|
|
|
* thereof.
|
|
|
|
*
|
|
|
|
* Instantiate with model wp.customize.HeaderTool.currentHeader.
|
|
|
|
*
|
2017-09-08 14:42:49 -04:00
|
|
|
* @memberOf wp.customize.HeaderTool
|
|
|
|
* @alias wp.customize.HeaderTool.CurrentView
|
|
|
|
*
|
2014-03-11 00:13:16 -04:00
|
|
|
* @constructor
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
*/
|
2017-09-08 14:42:49 -04:00
|
|
|
api.HeaderTool.CurrentView = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.CurrentView.prototype */{
|
2014-03-11 00:13:16 -04:00
|
|
|
template: wp.template('header-current'),
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
this.$el.html(this.template(this.model.toJSON()));
|
|
|
|
this.setButtons();
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setButtons: function() {
|
2014-05-06 00:14:14 -04:00
|
|
|
var elements = $('#customize-control-header_image .actions .remove');
|
2014-03-11 00:13:16 -04:00
|
|
|
if (this.model.get('choice')) {
|
|
|
|
elements.show();
|
|
|
|
} else {
|
|
|
|
elements.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.customize.HeaderTool.ChoiceView
|
|
|
|
*
|
|
|
|
* Represents a choosable header image, be it user-uploaded,
|
|
|
|
* theme-suggested or a special Randomize choice.
|
|
|
|
*
|
|
|
|
* Takes a wp.customize.HeaderTool.ImageModel.
|
|
|
|
*
|
|
|
|
* Manually changes model wp.customize.HeaderTool.currentHeader via the
|
|
|
|
* `select` method.
|
|
|
|
*
|
2017-09-08 14:42:49 -04:00
|
|
|
* @memberOf wp.customize.HeaderTool
|
|
|
|
* @alias wp.customize.HeaderTool.ChoiceView
|
|
|
|
*
|
2014-03-11 00:13:16 -04:00
|
|
|
* @constructor
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
*/
|
2017-09-08 14:42:49 -04:00
|
|
|
api.HeaderTool.ChoiceView = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.ChoiceView.prototype */{
|
2014-03-11 00:13:16 -04:00
|
|
|
template: wp.template('header-choice'),
|
|
|
|
|
|
|
|
className: 'header-view',
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click .choice,.random': 'select',
|
|
|
|
'click .close': 'removeImage'
|
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
var properties = [
|
|
|
|
this.model.get('header').url,
|
|
|
|
this.model.get('choice')
|
|
|
|
];
|
|
|
|
|
2014-04-04 11:49:15 -04:00
|
|
|
this.listenTo(this.model, 'change:selected', this.toggleSelected);
|
2014-03-11 00:13:16 -04:00
|
|
|
|
|
|
|
if (_.contains(properties, api.get().header_image)) {
|
|
|
|
api.HeaderTool.currentHeader.set(this.extendedModel());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
this.$el.html(this.template(this.extendedModel()));
|
|
|
|
|
2014-04-04 11:49:15 -04:00
|
|
|
this.toggleSelected();
|
2014-03-11 00:13:16 -04:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2014-04-04 11:49:15 -04:00
|
|
|
toggleSelected: function() {
|
|
|
|
this.$el.toggleClass('selected', this.model.get('selected'));
|
|
|
|
},
|
|
|
|
|
2014-03-11 00:13:16 -04:00
|
|
|
extendedModel: function() {
|
2014-03-19 04:18:14 -04:00
|
|
|
var c = this.model.get('collection');
|
2014-03-11 00:13:16 -04:00
|
|
|
return _.extend(this.model.toJSON(), {
|
2014-03-24 19:02:13 -04:00
|
|
|
type: c.type
|
2014-03-11 00:13:16 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
select: function() {
|
2014-04-04 11:49:15 -04:00
|
|
|
this.preventJump();
|
2014-03-11 00:13:16 -04:00
|
|
|
this.model.save();
|
|
|
|
api.HeaderTool.currentHeader.set(this.extendedModel());
|
|
|
|
},
|
|
|
|
|
2014-04-04 11:49:15 -04:00
|
|
|
preventJump: function() {
|
|
|
|
var container = $('.wp-full-overlay-sidebar-content'),
|
|
|
|
scroll = container.scrollTop();
|
|
|
|
|
|
|
|
_.defer(function() {
|
|
|
|
container.scrollTop(scroll);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-03-11 00:13:16 -04:00
|
|
|
removeImage: function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.model.destroy();
|
|
|
|
this.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.customize.HeaderTool.ChoiceListView
|
|
|
|
*
|
|
|
|
* A container for ChoiceViews. These choices should be of one same type:
|
|
|
|
* user-uploaded headers or theme-defined ones.
|
|
|
|
*
|
|
|
|
* Takes a wp.customize.HeaderTool.ChoiceList.
|
|
|
|
*
|
2017-09-08 14:42:49 -04:00
|
|
|
* @memberOf wp.customize.HeaderTool
|
|
|
|
* @alias wp.customize.HeaderTool.ChoiceListView
|
|
|
|
*
|
2014-03-11 00:13:16 -04:00
|
|
|
* @constructor
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
*/
|
2017-09-08 14:42:49 -04:00
|
|
|
api.HeaderTool.ChoiceListView = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.ChoiceListView.prototype */{
|
2014-03-11 00:13:16 -04:00
|
|
|
initialize: function() {
|
|
|
|
this.listenTo(this.collection, 'add', this.addOne);
|
|
|
|
this.listenTo(this.collection, 'remove', this.render);
|
|
|
|
this.listenTo(this.collection, 'sort', this.render);
|
2014-04-04 11:49:15 -04:00
|
|
|
this.listenTo(this.collection, 'change', this.toggleList);
|
2014-03-11 00:13:16 -04:00
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
this.$el.empty();
|
|
|
|
this.collection.each(this.addOne, this);
|
2014-04-04 11:49:15 -04:00
|
|
|
this.toggleList();
|
2014-03-11 00:13:16 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
addOne: function(choice) {
|
|
|
|
var view;
|
|
|
|
choice.set({ collection: this.collection });
|
|
|
|
view = new api.HeaderTool.ChoiceView({ model: choice });
|
|
|
|
this.$el.append(view.render().el);
|
|
|
|
},
|
|
|
|
|
2014-04-04 11:49:15 -04:00
|
|
|
toggleList: function() {
|
|
|
|
var title = this.$el.parents().prev('.customize-control-title'),
|
|
|
|
randomButton = this.$el.find('.random').parent();
|
2014-03-11 00:13:16 -04:00
|
|
|
if (this.collection.shouldHideTitle()) {
|
2014-04-04 11:49:15 -04:00
|
|
|
title.add(randomButton).hide();
|
2014-03-11 00:13:16 -04:00
|
|
|
} else {
|
2014-04-04 11:49:15 -04:00
|
|
|
title.add(randomButton).show();
|
2014-03-11 00:13:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.customize.HeaderTool.CombinedList
|
|
|
|
*
|
|
|
|
* Aggregates wp.customize.HeaderTool.ChoiceList collections (or any
|
|
|
|
* Backbone object, really) and acts as a bus to feed them events.
|
|
|
|
*
|
2017-09-08 14:42:49 -04:00
|
|
|
* @memberOf wp.customize.HeaderTool
|
|
|
|
* @alias wp.customize.HeaderTool.CombinedList
|
|
|
|
*
|
2014-03-11 00:13:16 -04:00
|
|
|
* @constructor
|
|
|
|
* @augments wp.Backbone.View
|
|
|
|
*/
|
2017-09-08 14:42:49 -04:00
|
|
|
api.HeaderTool.CombinedList = wp.Backbone.View.extend(/** @lends wp.customize.HeaderTool.CombinedList.prototype */{
|
2014-03-11 00:13:16 -04:00
|
|
|
initialize: function(collections) {
|
|
|
|
this.collections = collections;
|
|
|
|
this.on('all', this.propagate, this);
|
|
|
|
},
|
|
|
|
propagate: function(event, arg) {
|
|
|
|
_.each(this.collections, function(collection) {
|
|
|
|
collection.trigger(event, arg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})( jQuery, window.wp, _ );
|