Changeset 21820
- Timestamp:
- 09/11/2012 09:13:07 PM (11 years ago)
- Location:
- trunk/wp-includes/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-models.js
r21692 r21820 17 17 media = wp.media = function( attributes ) { 18 18 if ( media.controller.Workflow ) 19 return new media.controller.Workflow( attributes ). render();19 return new media.controller.Workflow( attributes ).attach().render(); 20 20 }; 21 21 -
trunk/wp-includes/js/media-views.js
r21814 r21820 17 17 media.controller.Workflow = Backbone.Model.extend({ 18 18 defaults: { 19 multiple: false 19 multiple: false, 20 view: 'library' 20 21 }, 21 22 … … 23 24 this.createSelection(); 24 25 25 // Initialize views. 26 this.modal = new media.view.Modal({ controller: this }); 27 this.workspace = new media.view.Workspace({ controller: this }); 26 // Initialize view storage. 27 this._views = {}; 28 this._pending = {}; 29 30 // Initialize modal container view. 31 this.modal = new media.view.Modal({ controller: this }); 32 33 // Add default views. 34 this.add( 'library', { 35 view: media.view.Workspace 36 }); 37 }, 38 39 40 // Accepts an `id` and `options` for a view. Options is an object that 41 // contains two keys: the `view` key is a `Backbone.View` constructor, 42 // and the `options` key are the options to be passed when the view is 43 // initialized. 44 // 45 // Triggers the `add` and `add:VIEW_ID` events. 46 add: function( id, options ) { 47 this.remove( id ); 48 this._pending[ id ] = options; 49 this.trigger( 'add add:' + id, options ); 50 return this; 51 }, 52 53 // Returns a registered view instance. If an `id` is not provided, 54 // it will return the active view. 55 // 56 // Lazily instantiates a registered view. 57 // 58 // Triggers the `init` and `init:VIEW_ID` events. 59 view: function( id ) { 60 var pending; 61 62 id = id || this.get('view'); 63 pending = this._pending[ id ]; 64 65 if ( ! this._views[ id ] && pending ) { 66 this._views[ id ] = new pending.view( _.extend({ controller: this }, pending.options || {} ) ); 67 delete this._pending[ id ]; 68 this.trigger( 'init init:' + id, this._views[ id ] ); 69 } 70 71 return this._views[ id ]; 72 }, 73 74 // Unregisters a view from the workflow. 75 // 76 // Triggers the `remove` and `remove:VIEW_ID` events. 77 remove: function( id ) { 78 delete this._views[ id ]; 79 delete this._pending[ id ]; 80 this.trigger( 'remove remove:' + id ); 81 return this; 82 }, 83 84 // Renders a view and places it within the modal window. 85 // Automatically adds a view if `options` are provided. 86 render: function( id, options ) { 87 var view; 88 id = id || this.get('view'); 89 90 if ( options ) 91 this.add( id, options ); 92 93 view = this.view( id ); 94 95 if ( ! view ) 96 return; 97 98 view.render(); 99 this.modal.content( view ); 100 return this; 28 101 }, 29 102 … … 66 139 } 67 140 }); 68 }, 69 70 render: function() { 71 this.workspace.render(); 72 this.modal.content( this.workspace ).attach(); 73 return this; 74 } 141 } 142 }); 143 144 // Map modal methods to the workflow. 145 _.each(['attach','detach','open','close'], function( method ) { 146 media.controller.Workflow.prototype[ method ] = function() { 147 this.modal[ method ].apply( this.modal, arguments ); 148 return this; 149 }; 75 150 }); 76 151
Note: See TracChangeset
for help on using the changeset viewer.