Ticket #35465: 35465.diff
File 35465.diff, 2.3 KB (added by , 9 years ago) |
---|
-
src/wp-includes/js/wp-backbone.js
4 4 // Create the WordPress Backbone namespace. 5 5 wp.Backbone = {}; 6 6 7 8 // wp.Backbone.Subviews 9 // -------------------- 10 // 11 // A subview manager. 7 /** 8 * A subview manager. 9 * 10 * @class 11 * 12 * @param {wp.Backbone.View} view The main view. 13 * @param {array|object} views The subviews for the main view. 14 */ 12 15 wp.Backbone.Subviews = function( view, views ) { 13 16 this.view = view; 14 17 this._views = _.isArray( views ) ? { '': views } : views || {}; … … 17 20 wp.Backbone.Subviews.extend = Backbone.Model.extend; 18 21 19 22 _.extend( wp.Backbone.Subviews.prototype, { 20 // ### Fetch all of the subviews 21 // 22 // Returns an array of all subviews. 23 /** 24 * Fetch all of the subviews. 25 * 26 * @return {array} All the subviews. 27 */ 23 28 all: function() { 24 29 return _.flatten( this._views ); 25 30 }, 26 31 27 // ### Get a selector's subviews 28 // 29 // Fetches all subviews that match a given `selector`. 30 // 31 // If no `selector` is provided, it will grab all subviews attached 32 // to the view's root. 32 /** 33 * Fetches all subviews that match a given `selector`. 34 * 35 * If no `selector` is provided, it will grab all subviews attached 36 * to the view's root. 37 * 38 * @param {string} selector A jQuery selector. 39 * @return {array} 40 */ 33 41 get: function( selector ) { 34 42 selector = selector || ''; 35 43 return this._views[ selector ]; 36 44 }, 37 45 38 // ### Get a selector's first subview 39 // 40 // Fetches the first subview that matches a given `selector`. 41 // 42 // If no `selector` is provided, it will grab the first subview 43 // attached to the view's root. 44 // 45 // Useful when a selector only has one subview at a time. 46 /** 47 * Fetches the first subview that matches a given `selector`. 48 * 49 * If no `selector` is provided, it will grab the first subview 50 * attached to the view's root. 51 * 52 * Useful when a selector only has one subview at a time. 53 * 54 * @param {string} selector A jQuery selector. 55 * @return {Backbone.View} The view. 56 */ 46 57 first: function( selector ) { 47 58 var views = this.get( selector ); 48 59 return views && views.length ? views[0] : null;