Changeset 22323
- Timestamp:
- 10/29/2012 03:13:02 PM (13 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/css/media-views.css
r22322 r22323 308 308 } 309 309 310 .attachment .thumbnail,311 .attachment .thumbnail img {310 .attachment-preview .thumbnail, 311 .attachment-preview .thumbnail img { 312 312 -webkit-transition-property: width, height, top, left, right, bottom; 313 313 -moz-transition-property: width, height, top, left, right, bottom; … … 327 327 } 328 328 329 .attachment .thumbnail {329 .attachment-preview .thumbnail { 330 330 width: 199px; 331 331 height: 199px; 332 332 } 333 333 334 .attachment .thumbnail:after {334 .attachment-preview .thumbnail:after { 335 335 content: ''; 336 336 display: block; … … 389 389 } 390 390 391 . attachment.describe {391 .media-frame .describe { 392 392 position: relative; 393 393 display: block; … … 594 594 595 595 /** 596 * Attachment Details 597 */ 598 599 .attachment-details { 600 padding-top: 20px; 601 } 602 603 .attachment-details-preview { 604 cursor: default; 605 } 606 607 .attachment-details-preview, 608 .attachment-details-preview .thumbnail { 609 width: auto; 610 height: auto; 611 float: left; 612 position: relative; 613 } 614 615 .attachment-details-preview .thumbnail img { 616 max-width: 120px; 617 max-height: 120px; 618 display: block; 619 margin: 0 auto; 620 } 621 622 .attachment-details .describe { 623 float: left; 624 margin: 10px 0 0; 625 } 626 627 /** 596 628 * Attachment Display Settings 597 629 */ -
trunk/wp-includes/js/media-models.js
r22320 r22323 614 614 }); 615 615 616 /** 617 * wp.media.model.Selection 618 * 619 * Used to manage a selection of attachments in the views. 620 */ 621 media.model.Selection = Attachments.extend({ 622 initialize: function( models, options ) { 623 Attachments.prototype.initialize.apply( this, arguments ); 624 this.multiple = options && options.multiple; 625 }, 626 627 // Override the selection's add method. 628 // If the workflow does not support multiple 629 // selected attachments, reset the selection. 630 add: function( models, options ) { 631 if ( ! this.multiple ) { 632 models = _.isArray( models ) ? _.first( models ) : models; 633 this.clear( options ); 634 } 635 636 return Attachments.prototype.add.call( this, models, options ); 637 }, 638 639 // Removes all models from the selection. 640 clear: function( options ) { 641 return this.remove( this.models, options ); 642 }, 643 644 // Override the selection's reset method. 645 // Always direct items through add and remove, 646 // as we need them to fire. 647 reset: function( models, options ) { 648 return this.clear( options ).add( models, options ); 649 }, 650 651 // Create selection.has, which determines if a model 652 // exists in the collection based on cid and id, 653 // instead of direct comparison. 654 has: function( attachment ) { 655 return !! ( this.getByCid( attachment.cid ) || this.get( attachment.id ) ); 656 } 657 }); 658 616 659 }(jQuery)); -
trunk/wp-includes/js/media-views.js
r22322 r22323 119 119 120 120 initialize: function() { 121 if ( ! this.get('selection') ) 122 this.set( 'selection', new Attachments() ); 121 if ( ! this.get('selection') ) { 122 this.set( 'selection', new media.model.Selection( null, { 123 multiple: this.get('multiple') 124 }) ); 125 } 123 126 124 127 if ( ! this.get('library') ) … … 126 129 127 130 this.on( 'activate', this.activate, this ); 131 this.on( 'deactivate', this.deactivate, this ); 132 this.on( 'change:details', this.details, this ); 128 133 }, 129 134 130 135 activate: function() { 136 this.toolbar(); 137 this.sidebar(); 138 this.content(); 139 140 // If we're in a workflow that supports multiple attachments, 141 // automatically select any uploading attachments. 142 if ( this.get('multiple') ) 143 wp.Uploader.queue.on( 'add', this.selectUpload, this ); 144 145 this.get('selection').on( 'add remove', this.toggleDetails, this ); 146 }, 147 148 deactivate: function() { 149 var toolbar = this._postLibraryToolbar; 150 if ( toolbar ) 151 this.get('selection').off( 'add remove', toolbar.visibility, toolbar ); 152 153 wp.Uploader.queue.off( 'add', this.selectUpload, this ); 154 this.get('selection').off( 'add remove', this.toggleDetails, this ); 155 }, 156 157 toolbar: function() { 131 158 var frame = this.frame, 132 159 toolbar; … … 140 167 frame.toolbar( toolbar ); 141 168 this.get('selection').on( 'add remove', toolbar.visibility, toolbar ); 169 }, 170 171 sidebar: function() { 172 var frame = this.frame; 142 173 143 174 // Sidebar. 144 175 frame.sidebar( new media.view.Sidebar({ 145 controller: frame, 146 views: { 147 search: new media.view.Search({ 148 controller: frame, 149 model: this.get('library').props, 150 priority: 20 151 }), 152 153 selection: new media.view.SelectionPreview({ 154 controller: frame, 155 collection: this.get('selection'), 156 priority: 40 157 }) 158 } 176 controller: frame 159 177 }) ); 178 179 this.details({ silent: true }); 180 frame.sidebar().add({ 181 search: new media.view.Search({ 182 controller: frame, 183 model: this.get('library').props, 184 priority: 20 185 }), 186 187 selection: new media.view.SelectionPreview({ 188 controller: frame, 189 collection: this.get('selection'), 190 priority: 40 191 }) 192 }); 193 }, 194 195 content: function() { 196 var frame = this.frame; 160 197 161 198 // Content. … … 166 203 AttachmentView: media.view.Attachment.Library 167 204 }).render() ); 168 169 // If we're in a workflow that supports multiple attachments,170 // automatically select any uploading attachments.171 if ( this.get('multiple') )172 wp.Uploader.queue.on( 'add', this.selectUpload, this );173 },174 175 deactivate: function() {176 var toolbar = this._postLibraryToolbar;177 178 wp.Uploader.queue.off( 'add', this.selectUpload, this );179 this.get('selection').off( 'add remove', toolbar.visibility, toolbar );180 205 }, 181 206 182 207 selectUpload: function( attachment ) { 183 208 this.get('selection').add( attachment ); 209 }, 210 211 details: function( options ) { 212 var model = this.get('details'), 213 view; 214 215 if ( model ) { 216 view = new media.view.Attachment.Details({ 217 controller: this.frame, 218 model: model, 219 priority: 80 220 }); 221 } else { 222 view = new Backbone.View(); 223 } 224 225 if ( ! options || ! options.silent ) 226 view.render(); 227 228 this.frame.sidebar().add( 'details', view, options ); 229 }, 230 231 toggleDetails: function( model ) { 232 var details = this.get('details'), 233 selection = this.get('selection'); 234 235 if ( selection.has( model ) ) 236 this.set( 'details', model ); 237 else if ( selection.length ) 238 this.set( 'details', selection.last() ); 239 else 240 this.unset('details'); 184 241 } 185 242 }); … … 187 244 // wp.media.controller.Gallery 188 245 // --------------------------- 189 media.controller.Gallery = Backbone.Model.extend({246 media.controller.Gallery = media.controller.Library.extend({ 190 247 defaults: { 191 248 id: 'gallery', 192 multiple: true,249 multiple: false, 193 250 describe: true, 194 251 title: l10n.createGallery 195 252 }, 196 253 197 initialize: function() { 198 if ( ! this.get('selection') ) 199 this.set( 'selection', new Attachments() ); 200 201 this.on( 'activate', this.activate, this ); 202 }, 203 204 activate: function() { 205 var frame = this.frame; 206 207 // Toolbar. 208 frame.toolbar( new media.view.Toolbar.Gallery({ 209 controller: frame, 254 toolbar: function() { 255 this.frame.toolbar( new media.view.Toolbar.Gallery({ 256 controller: this.frame, 210 257 state: this 211 258 }) ); 259 }, 260 261 sidebar: function() { 262 var frame = this.frame; 212 263 213 264 // Sidebar. 214 265 frame.sidebar( new media.view.Sidebar({ 215 266 controller: frame 216 }).render() ); 217 218 // Content. 219 frame.content( new media.view.Attachments({ 220 controller: frame, 221 collection: this.get('selection'), 267 }) ); 268 269 this.details(); 270 }, 271 272 content: function() { 273 this.frame.content( new media.view.Attachments({ 274 controller: this.frame, 275 collection: this.get('library'), 222 276 sortable: true, 223 277 // The single `Attachment` view to be used in the `Attachments` view. 224 278 AttachmentView: media.view.Attachment.Gallery 225 279 }).render() ); 226 227 // Automatically select any uploading attachments.228 wp.Uploader.queue.on( 'add', this.selectUpload, this );229 },230 231 deactivate: function() {232 wp.Uploader.queue.off( 'add', this.selectUpload, this );233 },234 235 selectUpload: function( attachment ) {236 this.get('selection').add( attachment );237 280 } 238 281 }); … … 289 332 selection = this.options.selection; 290 333 291 if ( ! (selection instanceof Attachments) ) 292 selection = this.options.selection = new Attachments( selection ); 293 294 _.extend( selection, { 295 // Override the selection's add method. 296 // If the workflow does not support multiple 297 // selected attachments, reset the selection. 298 add: function( models, options ) { 299 if ( ! controller.state().get('multiple') ) { 300 models = _.isArray( models ) ? _.first( models ) : models; 301 this.clear( options ); 302 } 303 304 return Attachments.prototype.add.call( this, models, options ); 305 }, 306 307 // Removes all models from the selection. 308 clear: function( options ) { 309 return this.remove( this.models, options ); 310 }, 311 312 // Override the selection's reset method. 313 // Always direct items through add and remove, 314 // as we need them to fire. 315 reset: function( models, options ) { 316 return this.clear( options ).add( models, options ); 317 }, 318 319 // Create selection.has, which determines if a model 320 // exists in the collection based on cid and id, 321 // instead of direct comparison. 322 has: function( attachment ) { 323 return !! ( this.getByCid( attachment.cid ) || this.get( attachment.id ) ); 324 } 325 }); 334 if ( ! (selection instanceof media.model.Selection) ) { 335 selection = this.options.selection = new media.model.Selection( selection, { 336 multiple: this.options.multiple 337 }); 338 } 326 339 }, 327 340 … … 340 353 this.states.add([ 341 354 new media.controller.Library({ 342 selection: 343 collection:media.query( options.library ),344 multiple: 355 selection: options.selection, 356 library: media.query( options.library ), 357 multiple: this.options.multiple 345 358 }), 346 359 new media.controller.Gallery({ 347 selection:options.selection360 library: options.selection 348 361 }) 349 362 ]); … … 631 644 632 645 if ( this.options.items ) 633 this.add( this.options.items, { silent: true }).render(); 646 this.add( this.options.items, { silent: true }); 647 648 if ( ! this.options.silent ) 649 this.render(); 634 650 }, 635 651 … … 651 667 652 668 add: function( id, view, options ) { 669 options = options || {}; 670 653 671 // Accept an object with an `id` : `view` mapping. 654 672 if ( _.isObject( id ) ) { 655 673 _.each( id, function( view, id ) { 656 this.add( id, view, options);674 this.add( id, view, { silent: true }); 657 675 }, this ); 676 677 if ( ! options.silent ) 678 this.render(); 658 679 return this; 659 680 } … … 667 688 668 689 this._views[ id ] = view; 669 if ( ! options || ! options.silent )690 if ( ! options.silent ) 670 691 this.render(); 671 692 return this; … … 778 799 var state = this.options.state, 779 800 editing = state.get('editing'), 780 selection = state.get('selection'),801 library = state.get('library'), 781 802 controller = this.options.controller; 782 803 … … 788 809 click: function() { 789 810 controller.close(); 790 state.trigger( 'update', selection);791 selection.clear();811 state.trigger( 'update', library ); 812 library.clear(); 792 813 controller.state('library'); 793 814 } … … 922 943 923 944 if ( this.options.views ) 924 this.add( this.options.views, { silent: true }).render(); 945 this.add( this.options.views, { silent: true }); 946 947 if ( ! this.options.silent ) 948 this.render(); 925 949 }, 926 950 … … 950 974 951 975 add: function( id, view, options ) { 976 options = options || {}; 977 952 978 // Accept an object with an `id` : `view` mapping. 953 979 if ( _.isObject( id ) ) { 954 980 _.each( id, function( view, id ) { 955 this.add( id, view, options);981 this.add( id, view, { silent: true }); 956 982 }, this ); 983 984 if ( ! options.silent ) 985 this.render(); 957 986 return this; 958 987 } … … 961 990 962 991 this._views[ id ] = view; 963 if ( ! options || ! options.silent )992 if ( ! options.silent ) 964 993 this.render(); 965 994 return this; … … 990 1019 'mouseenter .attachment-preview': 'shrink', 991 1020 'mouseleave .attachment-preview': 'expand', 992 'change .describe': 'describe', 993 'click .close': 'toggleSelection' 1021 'change .describe': 'describe' 994 1022 }, 995 1023 … … 1183 1211 events: (function() { 1184 1212 var events = _.clone( media.view.Attachment.prototype.events ); 1185 delete events['click .attachment-preview'];1213 events['click .close'] = 'removeFromGallery'; 1186 1214 return events; 1187 }()) 1215 }()), 1216 1217 removeFromGallery: function() { 1218 this.controller.state().get('library').remove( this.model ); 1219 } 1188 1220 }); 1189 1221 … … 1377 1409 render: function() { 1378 1410 var options = _.clone( this.options ), 1379 first, sizes, amount;1411 last, sizes, amount; 1380 1412 1381 1413 // If nothing is selected, display nothing. … … 1386 1418 1387 1419 options.count = this.collection.length; 1388 first = this.collection.first();1389 sizes = first.get('sizes');1390 1391 if ( 'image' === first.get('type') )1392 options.thumbnail = ( sizes && sizes.thumbnail ) ? sizes.thumbnail.url : first.get('url');1420 last = this.collection.last(); 1421 sizes = last.get('sizes'); 1422 1423 if ( 'image' === last.get('type') ) 1424 options.thumbnail = ( sizes && sizes.thumbnail ) ? sizes.thumbnail.url : last.get('url'); 1393 1425 else 1394 options.thumbnail = first.get('icon');1426 options.thumbnail = last.get('icon'); 1395 1427 1396 1428 this.$el.html( this.template( options ) ); … … 1491 1523 } 1492 1524 }); 1525 1526 /** 1527 * wp.media.view.Attachment.Details 1528 */ 1529 media.view.Attachment.Details = media.view.Attachment.extend({ 1530 tagName: 'div', 1531 className: 'attachment-details', 1532 template: media.template('attachment-details'), 1533 1534 events: { 1535 'change .describe': 'describe' 1536 } 1537 }); 1493 1538 }(jQuery)); -
trunk/wp-includes/media.php
r22322 r22323 1306 1306 <script type="text/html" id="tmpl-uploader-window"> 1307 1307 <div class="uploader-window-content"> 1308 <h3><?php _e( 'Drop files hereto upload' ); ?></h3>1308 <h3><?php _e( 'Drop files to upload' ); ?></h3> 1309 1309 </div> 1310 1310 </script> … … 1359 1359 </script> 1360 1360 1361 <script type="text/html" id="tmpl-attachment-details"> 1362 <div class="attachment-preview attachment-details-preview type-<%- type %> subtype-<%- subtype %> <%- orientation %>"> 1363 <% if ( uploading ) { %> 1364 <div class="media-progress-bar"><div></div></div> 1365 <% } else if ( 'image' === type ) { %> 1366 <div class="thumbnail"> 1367 <img src="<%- url %>" draggable="false" /> 1368 </div> 1369 <% } else { %> 1370 <div class="icon-thumbnail"> 1371 <img src="<%- icon %>" class="icon" draggable="false" /> 1372 <div class="filename"><%- filename %></div> 1373 </div> 1374 <% } %> 1375 </div> 1376 1377 <% if ( 'image' === type ) { %> 1378 <textarea class="describe" 1379 placeholder="<?php esc_attr_e('Describe this image…'); ?>" 1380 ><%- caption %></textarea> 1381 <% } else { %> 1382 <textarea class="describe" 1383 <% if ( 'video' === type ) { %> 1384 placeholder="<?php esc_attr_e('Describe this video…'); ?>" 1385 <% } else if ( 'audio' === type ) { %> 1386 placeholder="<?php esc_attr_e('Describe this audio file…'); ?>" 1387 <% } else { %> 1388 placeholder="<?php esc_attr_e('Describe this media file…'); ?>" 1389 <% } %> 1390 ><%- title %></textarea> 1391 <% } %> 1392 </script> 1393 1361 1394 <script type="text/html" id="tmpl-media-selection-preview"> 1362 1395 <div class="selected-img selected-count-<%- count %>">
Note: See TracChangeset
for help on using the changeset viewer.