Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

187 Zeilen
4.3 KiB

  1. (function( $, wp, _ ) {
  2. if ( ! wp || ! wp.customize ) { return; }
  3. var api = wp.customize;
  4. /**
  5. * wp.customize.HeaderTool.CurrentView
  6. *
  7. * Displays the currently selected header image, or a placeholder in lack
  8. * thereof.
  9. *
  10. * Instantiate with model wp.customize.HeaderTool.currentHeader.
  11. *
  12. * @constructor
  13. * @augments wp.Backbone.View
  14. */
  15. api.HeaderTool.CurrentView = wp.Backbone.View.extend({
  16. template: wp.template('header-current'),
  17. initialize: function() {
  18. this.listenTo(this.model, 'change', this.render);
  19. this.render();
  20. },
  21. render: function() {
  22. this.$el.html(this.template(this.model.toJSON()));
  23. this.setButtons();
  24. return this;
  25. },
  26. setButtons: function() {
  27. var elements = $('#customize-control-header_image .actions .remove');
  28. if (this.model.get('choice')) {
  29. elements.show();
  30. } else {
  31. elements.hide();
  32. }
  33. }
  34. });
  35. /**
  36. * wp.customize.HeaderTool.ChoiceView
  37. *
  38. * Represents a choosable header image, be it user-uploaded,
  39. * theme-suggested or a special Randomize choice.
  40. *
  41. * Takes a wp.customize.HeaderTool.ImageModel.
  42. *
  43. * Manually changes model wp.customize.HeaderTool.currentHeader via the
  44. * `select` method.
  45. *
  46. * @constructor
  47. * @augments wp.Backbone.View
  48. */
  49. api.HeaderTool.ChoiceView = wp.Backbone.View.extend({
  50. template: wp.template('header-choice'),
  51. className: 'header-view',
  52. events: {
  53. 'click .choice,.random': 'select',
  54. 'click .close': 'removeImage'
  55. },
  56. initialize: function() {
  57. var properties = [
  58. this.model.get('header').url,
  59. this.model.get('choice')
  60. ];
  61. this.listenTo(this.model, 'change:selected', this.toggleSelected);
  62. if (_.contains(properties, api.get().header_image)) {
  63. api.HeaderTool.currentHeader.set(this.extendedModel());
  64. }
  65. },
  66. render: function() {
  67. this.$el.html(this.template(this.extendedModel()));
  68. this.toggleSelected();
  69. return this;
  70. },
  71. toggleSelected: function() {
  72. this.$el.toggleClass('selected', this.model.get('selected'));
  73. },
  74. extendedModel: function() {
  75. var c = this.model.get('collection');
  76. return _.extend(this.model.toJSON(), {
  77. type: c.type
  78. });
  79. },
  80. select: function() {
  81. this.preventJump();
  82. this.model.save();
  83. api.HeaderTool.currentHeader.set(this.extendedModel());
  84. },
  85. preventJump: function() {
  86. var container = $('.wp-full-overlay-sidebar-content'),
  87. scroll = container.scrollTop();
  88. _.defer(function() {
  89. container.scrollTop(scroll);
  90. });
  91. },
  92. removeImage: function(e) {
  93. e.stopPropagation();
  94. this.model.destroy();
  95. this.remove();
  96. }
  97. });
  98. /**
  99. * wp.customize.HeaderTool.ChoiceListView
  100. *
  101. * A container for ChoiceViews. These choices should be of one same type:
  102. * user-uploaded headers or theme-defined ones.
  103. *
  104. * Takes a wp.customize.HeaderTool.ChoiceList.
  105. *
  106. * @constructor
  107. * @augments wp.Backbone.View
  108. */
  109. api.HeaderTool.ChoiceListView = wp.Backbone.View.extend({
  110. initialize: function() {
  111. this.listenTo(this.collection, 'add', this.addOne);
  112. this.listenTo(this.collection, 'remove', this.render);
  113. this.listenTo(this.collection, 'sort', this.render);
  114. this.listenTo(this.collection, 'change', this.toggleList);
  115. this.render();
  116. },
  117. render: function() {
  118. this.$el.empty();
  119. this.collection.each(this.addOne, this);
  120. this.toggleList();
  121. },
  122. addOne: function(choice) {
  123. var view;
  124. choice.set({ collection: this.collection });
  125. view = new api.HeaderTool.ChoiceView({ model: choice });
  126. this.$el.append(view.render().el);
  127. },
  128. toggleList: function() {
  129. var title = this.$el.parents().prev('.customize-control-title'),
  130. randomButton = this.$el.find('.random').parent();
  131. if (this.collection.shouldHideTitle()) {
  132. title.add(randomButton).hide();
  133. } else {
  134. title.add(randomButton).show();
  135. }
  136. }
  137. });
  138. /**
  139. * wp.customize.HeaderTool.CombinedList
  140. *
  141. * Aggregates wp.customize.HeaderTool.ChoiceList collections (or any
  142. * Backbone object, really) and acts as a bus to feed them events.
  143. *
  144. * @constructor
  145. * @augments wp.Backbone.View
  146. */
  147. api.HeaderTool.CombinedList = wp.Backbone.View.extend({
  148. initialize: function(collections) {
  149. this.collections = collections;
  150. this.on('all', this.propagate, this);
  151. },
  152. propagate: function(event, arg) {
  153. _.each(this.collections, function(collection) {
  154. collection.trigger(event, arg);
  155. });
  156. }
  157. });
  158. })( jQuery, window.wp, _ );