Changeset 26986
- Timestamp:
- 01/20/2014 11:41:42 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media-views.js
r26161 r26986 1 1 /* global _wpMediaViewsL10n, confirm, getUserSetting, setUserSetting */ 2 2 (function($){ 3 var media = wp.media, 4 Attachment = media.model.Attachment, 5 Attachments = media.model.Attachments, 6 l10n; 3 var media = wp.media, l10n; 7 4 8 5 // Link any localized strings. … … 35 32 }()); 36 33 37 // Makes it easier to bind events using transitions. 34 /** 35 * Makes it easier to bind events using transitions. 36 * 37 * @param {string} selector 38 * @param {Number} sensitivity 39 * @returns {Promise} 40 */ 38 41 media.transition = function( selector, sensitivity ) { 39 42 var deferred = $.Deferred(); … … 67 70 /** 68 71 * wp.media.controller.Region 72 * 73 * @constructor 74 * @augments Backbone.Model 75 * 76 * @param {Object} [options={}] 69 77 */ 70 78 media.controller.Region = function( options ) { … … 76 84 77 85 _.extend( media.controller.Region.prototype, { 86 /** 87 * Switch modes 88 * 89 * @param {string} mode 90 * 91 * @fires wp.media.controller.Region#{id}:activate:{mode} 92 * @fires wp.media.controller.Region#{id}:deactivate:{mode} 93 * 94 * @returns {wp.media.controller.Region} Returns itself to allow chaining 95 */ 78 96 mode: function( mode ) { 79 if ( ! mode ) 97 if ( ! mode ) { 80 98 return this._mode; 81 99 } 82 100 // Bail if we're trying to change to the current mode. 83 if ( mode === this._mode ) 101 if ( mode === this._mode ) { 84 102 return this; 103 } 85 104 86 105 this.trigger('deactivate'); … … 90 109 return this; 91 110 }, 92 111 /** 112 * Render a new mode, the view is set in the `create` callback method 113 * of the extending class 114 * 115 * If no mode is provided, just re-render the current mode. 116 * If the provided mode isn't active, perform a full switch. 117 * 118 * @param {string} mode 119 * 120 * @fires wp.media.controller.Region#{id}:create:{mode} 121 * @fires wp.media.controller.Region#{id}:render:{mode} 122 * 123 * @returns {wp.media.controller.Region} Returns itself to allow chaining 124 */ 93 125 render: function( mode ) { 94 // If no mode is provided, just re-render the current mode. 95 // If the provided mode isn't active, perform a full switch. 96 if ( mode && mode !== this._mode ) 126 if ( mode && mode !== this._mode ) { 97 127 return this.mode( mode ); 128 } 98 129 99 130 var set = { view: null }, … … 103 134 view = set.view; 104 135 this.trigger( 'render', view ); 105 if ( view ) 136 if ( view ) { 106 137 this.set( view ); 138 } 107 139 return this; 108 140 }, 109 141 142 /** 143 * @returns {wp.media.View} Returns the selector's first subview 144 */ 110 145 get: function() { 111 146 return this.view.views.first( this.selector ); 112 147 }, 113 148 149 /** 150 * @param {Array|Object} views 151 * @param {Object} [options={}] 152 * @returns {wp.Backbone.Subviews} Subviews is returned to allow chaining 153 */ 114 154 set: function( views, options ) { 115 if ( options ) 155 if ( options ) { 116 156 options.add = false; 157 } 117 158 return this.view.views.set( this.selector, views, options ); 118 159 }, 119 160 161 /** 162 * Helper function to trigger view events based on {id}:{event}:{mode} 163 * 164 * @param {string} event 165 * @returns {undefined|wp.media.controller.Region} Returns itself to allow chaining 166 */ 120 167 trigger: function( event ) { 121 168 var base, args; 122 169 123 if ( ! this._mode ) 170 if ( ! this._mode ) { 124 171 return; 172 } 125 173 126 174 args = _.toArray( arguments ); … … 140 188 /** 141 189 * wp.media.controller.StateMachine 190 * 191 * @constructor 192 * @augments Backbone.Model 193 * @mixin 194 * @mixes Backbone.Events 195 * 196 * @param {Array} states 142 197 */ 143 198 media.controller.StateMachine = function( states ) { … … 150 205 // Add events to the `StateMachine`. 151 206 _.extend( media.controller.StateMachine.prototype, Backbone.Events, { 152 153 // Fetch a state. 154 // 155 // If no `id` is provided, returns the active state. 156 // 157 // Implicitly creates states. 207 /** 208 * Fetch a state. 209 * 210 * If no `id` is provided, returns the active state. 211 * 212 * Implicitly creates states. 213 * 214 * Ensure that the `states` collection exists so the `StateMachine` 215 * can be used as a mixin. 216 * 217 * @param {string} id 218 * @returns {wp.media.controller.State} Returns a State model 219 * from the StateMachine collection 220 */ 158 221 state: function( id ) { 159 // Ensure that the `states` collection exists so the `StateMachine`160 // can be used as a mixin.161 222 this.states = this.states || new Backbone.Collection(); 162 223 … … 164 225 id = id || this._state; 165 226 166 if ( id && ! this.states.get( id ) ) 227 if ( id && ! this.states.get( id ) ) { 167 228 this.states.add({ id: id }); 229 } 168 230 return this.states.get( id ); 169 231 }, 170 232 171 // Sets the active state. 233 /** 234 * Sets the active state. 235 * 236 * Bail if we're trying to select the current state, if we haven't 237 * created the `states` collection, or are trying to select a state 238 * that does not exist. 239 * 240 * @param {string} id 241 * 242 * @fires wp.media.controller.State#deactivate 243 * @fires wp.media.controller.State#activate 244 * 245 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining 246 */ 172 247 setState: function( id ) { 173 248 var previous = this.state(); 174 249 175 // Bail if we're trying to select the current state, if we haven't 176 // created the `states` collection, or are trying to select a state 177 // that does not exist. 178 if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) 250 if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) { 179 251 return this; 252 } 180 253 181 254 if ( previous ) { … … 190 263 }, 191 264 192 // Returns the previous active state. 193 // 194 // Call the `state()` method with no parameters to retrieve the current 195 // active state. 265 /** 266 * Returns the previous active state. 267 * 268 * Call the `state()` method with no parameters to retrieve the current 269 * active state. 270 * 271 * @returns {wp.media.controller.State} Returns a State model 272 * from the StateMachine collection 273 */ 196 274 lastState: function() { 197 if ( this._lastState ) 275 if ( this._lastState ) { 198 276 return this.state( this._lastState ); 277 } 199 278 } 200 279 }); … … 202 281 // Map methods from the `states` collection to the `StateMachine` itself. 203 282 _.each([ 'on', 'off', 'trigger' ], function( method ) { 283 /** 284 * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining 285 */ 204 286 media.controller.StateMachine.prototype[ method ] = function() { 205 287 // Ensure that the `states` collection exists so the `StateMachine` … … 212 294 }); 213 295 214 215 // wp.media.controller.State 216 // --------------------------- 296 /** 297 * wp.media.controller.State 298 * 299 * @constructor 300 * @augments Backbone.Model 301 */ 217 302 media.controller.State = Backbone.Model.extend({ 218 303 constructor: function() { … … 225 310 this.on( 'ready', this._ready, this ); 226 311 this.on( 'ready', this.ready, this ); 312 /** 313 * Call parent constructor with passed arguments 314 */ 227 315 Backbone.Model.apply( this, arguments ); 228 316 this.on( 'change:menu', this._updateMenu, this ); 229 317 }, 230 318 319 /** 320 * @abstract 321 */ 231 322 ready: function() {}, 323 /** 324 * @abstract 325 */ 232 326 activate: function() {}, 327 /** 328 * @abstract 329 */ 233 330 deactivate: function() {}, 331 /** 332 * @abstract 333 */ 234 334 reset: function() {}, 235 335 /** 336 * @access private 337 */ 236 338 _ready: function() { 237 339 this._updateMenu(); 238 340 }, 239 341 /** 342 * @access private 343 */ 240 344 _preActivate: function() { 241 345 this.active = true; 242 346 }, 243 347 /** 348 * @access private 349 */ 244 350 _postActivate: function() { 245 351 this.on( 'change:menu', this._menu, this ); … … 256 362 this._router(); 257 363 }, 258 259 364 /** 365 * @access private 366 */ 260 367 _deactivate: function() { 261 368 this.active = false; … … 268 375 this.off( 'change:toolbar', this._toolbar, this ); 269 376 }, 270 377 /** 378 * @access private 379 */ 271 380 _title: function() { 272 381 this.frame.title.render( this.get('titleMode') || 'default' ); 273 382 }, 274 383 /** 384 * @access private 385 */ 275 386 _renderTitle: function( view ) { 276 387 view.$el.text( this.get('title') || '' ); 277 388 }, 278 389 /** 390 * @access private 391 */ 279 392 _router: function() { 280 393 var router = this.frame.router, … … 283 396 284 397 this.frame.$el.toggleClass( 'hide-router', ! mode ); 285 if ( ! mode ) 398 if ( ! mode ) { 286 399 return; 400 } 287 401 288 402 this.frame.router.render( mode ); 289 403 290 404 view = router.get(); 291 if ( view && view.select ) 405 if ( view && view.select ) { 292 406 view.select( this.frame.content.mode() ); 293 }, 294 407 } 408 }, 409 /** 410 * @access private 411 */ 295 412 _menu: function() { 296 413 var menu = this.frame.menu, … … 298 415 view; 299 416 300 if ( ! mode ) 417 if ( ! mode ) { 301 418 return; 419 } 302 420 303 421 menu.mode( mode ); 304 422 305 423 view = menu.get(); 306 if ( view && view.select ) 424 if ( view && view.select ) { 307 425 view.select( this.id ); 308 }, 309 426 } 427 }, 428 /** 429 * @access private 430 */ 310 431 _updateMenu: function() { 311 432 var previous = this.previous('menu'), 312 433 menu = this.get('menu'); 313 434 314 if ( previous ) 435 if ( previous ) { 315 436 this.frame.off( 'menu:render:' + previous, this._renderMenu, this ); 316 317 if ( menu ) 437 } 438 439 if ( menu ) { 318 440 this.frame.on( 'menu:render:' + menu, this._renderMenu, this ); 319 }, 320 441 } 442 }, 443 /** 444 * @access private 445 */ 321 446 _renderMenu: function( view ) { 322 447 var menuItem = this.get('menuItem'), … … 327 452 menuItem = { text: title }; 328 453 329 if ( priority ) 454 if ( priority ) { 330 455 menuItem.priority = priority; 331 } 332 333 if ( ! menuItem ) 456 } 457 } 458 459 if ( ! menuItem ) { 334 460 return; 461 } 335 462 336 463 view.set( this.id, menuItem ); … … 339 466 340 467 _.each(['toolbar','content'], function( region ) { 468 /** 469 * @access private 470 */ 341 471 media.controller.State.prototype[ '_' + region ] = function() { 342 472 var mode = this.get( region ); 343 if ( mode ) 473 if ( mode ) { 344 474 this.frame[ region ].render( mode ); 475 } 345 476 }; 346 477 }); 347 478 348 // wp.media.controller.Library 349 // --------------------------- 479 /** 480 * wp.media.controller.Library 481 * 482 * @constructor 483 * @augments wp.media.controller.State 484 * @augments Backbone.Model 485 */ 350 486 media.controller.Library = media.controller.State.extend({ 351 487 defaults: { … … 370 506 }, 371 507 508 /** 509 * If a library isn't provided, query all media items. 510 * If a selection instance isn't provided, create one. 511 */ 372 512 initialize: function() { 373 513 var selection = this.get('selection'), 374 514 props; 375 515 376 // If a library isn't provided, query all media items. 377 if ( ! this.get('library') ) 516 if ( ! this.get('library') ) { 378 517 this.set( 'library', media.query() ); 379 380 // If a selection instance isn't provided, create one. 518 } 519 381 520 if ( ! (selection instanceof media.model.Selection) ) { 382 521 props = selection; … … 447 586 }, 448 587 588 /** 589 * @param {wp.media.model.Attachment} attachment 590 * @returns {Backbone.Model} 591 */ 449 592 display: function( attachment ) { 450 593 var displays = this._displays; 451 594 452 if ( ! displays[ attachment.cid ] ) 595 if ( ! displays[ attachment.cid ] ) { 453 596 displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) ); 454 597 } 455 598 return displays[ attachment.cid ]; 456 599 }, 457 600 601 /** 602 * @param {wp.media.model.Attachment} attachment 603 * @returns {Object} 604 */ 458 605 defaultDisplaySettings: function( attachment ) { 459 606 var settings = this._defaultDisplaySettings; 460 if ( settings.canEmbed = this.canEmbed( attachment ) ) 607 if ( settings.canEmbed = this.canEmbed( attachment ) ) { 461 608 settings.link = 'embed'; 609 } 462 610 return settings; 463 611 }, 464 612 613 /** 614 * @param {wp.media.model.Attachment} attachment 615 * @returns {Boolean} 616 */ 465 617 canEmbed: function( attachment ) { 466 618 // If uploading, we know the filename but not the mime type. 467 619 if ( ! attachment.get('uploading') ) { 468 620 var type = attachment.get('type'); 469 if ( type !== 'audio' && type !== 'video' ) 621 if ( type !== 'audio' && type !== 'video' ) { 470 622 return false; 623 } 471 624 } 472 625 … … 478 631 manager = this.frame._selection; 479 632 480 if ( ! this.get('syncSelection') || ! manager || ! selection ) 633 if ( ! this.get('syncSelection') || ! manager || ! selection ) { 481 634 return; 635 } 482 636 483 637 // If the selection supports multiple items, validate the stored … … 495 649 }, 496 650 651 /** 652 * Record the currently active attachments, which is a combination 653 * of the selection's attachments and the set of selected 654 * attachments that this specific selection considered invalid. 655 * Reset the difference and record the single attachment. 656 */ 497 657 recordSelection: function() { 498 658 var selection = this.get('selection'), 499 659 manager = this.frame._selection; 500 660 501 if ( ! this.get('syncSelection') || ! manager || ! selection ) 661 if ( ! this.get('syncSelection') || ! manager || ! selection ) { 502 662 return; 503 504 // Record the currently active attachments, which is a combination 505 // of the selection's attachments and the set of selected 506 // attachments that this specific selection considered invalid. 507 // Reset the difference and record the single attachment. 663 } 664 508 665 if ( selection.multiple ) { 509 666 manager.attachments.reset( selection.toArray().concat( manager.difference ) ); … … 516 673 }, 517 674 675 /** 676 * If the state is active, no items are selected, and the current 677 * content mode is not an option in the state's router (provided 678 * the state has a router), reset the content mode to the default. 679 */ 518 680 refreshContent: function() { 519 681 var selection = this.get('selection'), … … 522 684 mode = frame.content.mode(); 523 685 524 // If the state is active, no items are selected, and the current 525 // content mode is not an option in the state's router (provided 526 // the state has a router), reset the content mode to the default. 527 if ( this.active && ! selection.length && router && ! router.get( mode ) ) 686 if ( this.active && ! selection.length && router && ! router.get( mode ) ) { 528 687 this.frame.content.render( this.get('content') ); 529 }, 530 688 } 689 }, 690 691 /** 692 * If the uploader was selected, navigate to the browser. 693 * 694 * Automatically select any uploading attachments. 695 * 696 * Selections that don't support multiple attachments automatically 697 * limit themselves to one attachment (in this case, the last 698 * attachment in the upload queue). 699 * 700 * @param {wp.media.model.Attachment} attachment 701 */ 531 702 uploading: function( attachment ) { 532 703 var content = this.frame.content; 533 704 534 // If the uploader was selected, navigate to the browser. 535 if ( 'upload' === content.mode() ) 705 if ( 'upload' === content.mode() ) { 536 706 this.frame.content.mode('browse'); 537 538 // Automatically select any uploading attachments. 539 // 540 // Selections that don't support multiple attachments automatically 541 // limit themselves to one attachment (in this case, the last 542 // attachment in the upload queue). 707 } 543 708 this.get('selection').add( attachment ); 544 709 }, 545 710 711 /** 712 * Only track the browse router on library states. 713 */ 546 714 saveContentMode: function() { 547 // Only track the browse router on library states. 548 if ( 'browse' !== this.get('router') ) 715 if ( 'browse' !== this.get('router') ) { 549 716 return; 717 } 550 718 551 719 var mode = this.frame.content.mode(), 552 720 view = this.frame.router.get(); 553 721 554 if ( view && view.get( mode ) ) 722 if ( view && view.get( mode ) ) { 555 723 setUserSetting( 'libraryContent', mode ); 724 } 556 725 } 557 726 }); 558 727 559 // wp.media.controller.GalleryEdit 560 // ------------------------------- 728 /** 729 * wp.media.controller.GalleryEdit 730 * 731 * @constructor 732 * @augments wp.media.controller.Library 733 * @augments wp.media.controller.State 734 * @augments Backbone.Model 735 */ 561 736 media.controller.GalleryEdit = media.controller.Library.extend({ 562 737 defaults: { … … 581 756 initialize: function() { 582 757 // If we haven't been provided a `library`, create a `Selection`. 583 if ( ! this.get('library') ) 758 if ( ! this.get('library') ) { 584 759 this.set( 'library', new media.model.Selection() ); 760 } 585 761 586 762 // The single `Attachment` view to be used in the `Attachments` view. 587 if ( ! this.get('AttachmentView') ) 763 if ( ! this.get('AttachmentView') ) { 588 764 this.set( 'AttachmentView', media.view.Attachment.EditLibrary ); 765 } 766 /** 767 * call 'initialize' directly on the parent class 768 */ 589 769 media.controller.Library.prototype.initialize.apply( this, arguments ); 590 770 }, … … 600 780 601 781 this.frame.on( 'content:render:browse', this.gallerySettings, this ); 602 782 /** 783 * call 'activate' directly on the parent class 784 */ 603 785 media.controller.Library.prototype.activate.apply( this, arguments ); 604 786 }, … … 609 791 610 792 this.frame.off( 'content:render:browse', this.gallerySettings, this ); 611 793 /** 794 * call 'deactivate' directly on the parent class 795 */ 612 796 media.controller.Library.prototype.deactivate.apply( this, arguments ); 613 797 }, 614 798 799 /** 800 * @param {Object} browser 801 */ 615 802 gallerySettings: function( browser ) { 616 803 var library = this.get('library'); 617 804 618 if ( ! library || ! browser ) 805 if ( ! library || ! browser ) { 619 806 return; 807 } 620 808 621 809 library.gallery = library.gallery || new Backbone.Model(); … … 640 828 }); 641 829 642 // wp.media.controller.GalleryAdd 643 // --------------------------------- 830 /** 831 * wp.media.controller.GalleryAdd 832 * 833 * @constructor 834 * @augments wp.media.controller.Library 835 * @augments wp.media.controller.State 836 * @augments Backbone.Model 837 */ 644 838 media.controller.GalleryAdd = media.controller.Library.extend({ 645 839 defaults: _.defaults({ … … 657 851 }, media.controller.Library.prototype.defaults ), 658 852 853 /** 854 * If we haven't been provided a `library`, create a `Selection`. 855 */ 659 856 initialize: function() { 660 // If we haven't been provided a `library`, create a `Selection`. 661 if ( ! this.get('library') ) 857 if ( ! this.get('library') ) { 662 858 this.set( 'library', media.query({ type: 'image' }) ); 663 859 } 860 /** 861 * call 'initialize' directly on the parent class 862 */ 664 863 media.controller.Library.prototype.initialize.apply( this, arguments ); 665 864 }, … … 675 874 // that do not exist in gallery's library. 676 875 library.validator = function( attachment ) { 677 return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && media.model.Selection.prototype.validator.apply( this, arguments ); 876 return !! this.mirroring.get( attachment.cid ) 877 && ! edit.get( attachment.cid ) 878 /** 879 * call 'validator' directly on wp.media.model.Selection 880 */ 881 && media.model.Selection.prototype.validator.apply( this, arguments ); 678 882 }; 679 883 … … 684 888 library.observe( edit ); 685 889 this.editLibrary = edit; 686 890 /** 891 * call 'activate' directly on the parent class 892 */ 687 893 media.controller.Library.prototype.activate.apply( this, arguments ); 688 894 } 689 895 }); 690 896 691 // wp.media.controller.FeaturedImage 692 // --------------------------------- 897 /** 898 * wp.media.controller.FeaturedImage 899 * 900 * @constructor 901 * @augments wp.media.controller.Library 902 * @augments wp.media.controller.State 903 * @augments Backbone.Model 904 */ 693 905 media.controller.FeaturedImage = media.controller.Library.extend({ 694 906 defaults: _.defaults({ … … 707 919 708 920 // If we haven't been provided a `library`, create a `Selection`. 709 if ( ! this.get('library') ) 921 if ( ! this.get('library') ) { 710 922 this.set( 'library', media.query({ type: 'image' }) ); 711 923 } 924 /** 925 * call 'initialize' directly on the parent class 926 */ 712 927 media.controller.Library.prototype.initialize.apply( this, arguments ); 713 928 … … 721 936 bInQuery = !! this.mirroring.get( b.cid ); 722 937 723 if ( ! aInQuery && bInQuery ) 938 if ( ! aInQuery && bInQuery ) { 724 939 return -1; 725 else if ( aInQuery && ! bInQuery )940 } else if ( aInQuery && ! bInQuery ) { 726 941 return 1; 727 else942 } else { 728 943 return comparator.apply( this, arguments ); 944 } 729 945 }; 730 946 … … 737 953 this.updateSelection(); 738 954 this.frame.on( 'open', this.updateSelection, this ); 955 /** 956 * call 'activate' directly on the parent class 957 */ 739 958 media.controller.Library.prototype.activate.apply( this, arguments ); 740 959 }, … … 742 961 deactivate: function() { 743 962 this.frame.off( 'open', this.updateSelection, this ); 963 /** 964 * call 'deactivate' directly on the parent class 965 */ 744 966 media.controller.Library.prototype.deactivate.apply( this, arguments ); 745 967 }, … … 751 973 752 974 if ( '' !== id && -1 !== id ) { 753 attachment = Attachment.get( id );975 attachment = media.model.Attachment.get( id ); 754 976 attachment.fetch(); 755 977 } … … 759 981 }); 760 982 761 762 // wp.media.controller.Embed 763 // ------------------------- 983 /** 984 * wp.media.controller.Embed 985 * 986 * @constructor 987 * @augments wp.media.controller.State 988 * @augments Backbone.Model 989 */ 764 990 media.controller.Embed = media.controller.State.extend({ 765 991 defaults: { … … 786 1012 }, 787 1013 1014 /** 1015 * @fires wp.media.controller.Embed#scan 1016 */ 788 1017 scan: function() { 789 1018 var scanners, … … 797 1026 // state, useful for the 'type' attribute and 'scanners' attribute, 798 1027 // an array of promise objects for asynchronous scan operations. 799 if ( this.props.get('url') ) 1028 if ( this.props.get('url') ) { 800 1029 this.trigger( 'scan', attributes ); 1030 } 801 1031 802 1032 if ( attributes.scanners.length ) { … … 813 1043 this.set( attributes ); 814 1044 }, 815 1045 /** 1046 * @param {Object} attributes 1047 */ 816 1048 scanImage: function( attributes ) { 817 1049 var frame = this.frame, … … 827 1059 deferred.resolve(); 828 1060 829 if ( state !== frame.state() || url !== state.props.get('url') ) 1061 if ( state !== frame.state() || url !== state.props.get('url') ) { 830 1062 return; 1063 } 831 1064 832 1065 state.set({ … … 851 1084 this.props.clear().set({ url: '' }); 852 1085 853 if ( this.active ) 1086 if ( this.active ) { 854 1087 this.refresh(); 1088 } 855 1089 } 856 1090 }); … … 862 1096 */ 863 1097 864 // wp.media.View 865 // ------------- 866 // 867 // The base view class. 868 // 869 // Undelegating events, removing events from the model, and 870 // removing events from the controller mirror the code for 871 // `Backbone.View.dispose` in Backbone 0.9.8 development. 872 // 873 // This behavior has since been removed, and should not be used 874 // outside of the media manager. 1098 /** 1099 * wp.media.View 1100 * ------------- 1101 * 1102 * The base view class. 1103 * 1104 * Undelegating events, removing events from the model, and 1105 * removing events from the controller mirror the code for 1106 * `Backbone.View.dispose` in Backbone 0.9.8 development. 1107 * 1108 * This behavior has since been removed, and should not be used 1109 * outside of the media manager. 1110 * 1111 * @constructor 1112 * @augments wp.Backbone.View 1113 * @augments Backbone.View 1114 */ 875 1115 media.View = wp.Backbone.View.extend({ 876 1116 constructor: function( options ) { 877 if ( options && options.controller ) 1117 if ( options && options.controller ) { 878 1118 this.controller = options.controller; 879 1119 } 880 1120 wp.Backbone.View.apply( this, arguments ); 881 1121 }, 882 1122 /** 1123 * @returns {wp.media.View} Returns itself to allow chaining 1124 */ 883 1125 dispose: function() { 884 1126 // Undelegating events, removing events from the model, and … … 887 1129 this.undelegateEvents(); 888 1130 889 if ( this.model && this.model.off ) 1131 if ( this.model && this.model.off ) { 890 1132 this.model.off( null, null, this ); 891 892 if ( this.collection && this.collection.off ) 1133 } 1134 1135 if ( this.collection && this.collection.off ) { 893 1136 this.collection.off( null, null, this ); 1137 } 894 1138 895 1139 // Unbind controller events. 896 if ( this.controller && this.controller.off ) 1140 if ( this.controller && this.controller.off ) { 897 1141 this.controller.off( null, null, this ); 1142 } 898 1143 899 1144 return this; 900 1145 }, 901 1146 /** 1147 * @returns {wp.media.View} Returns itself to allow chaining 1148 */ 902 1149 remove: function() { 903 1150 this.dispose(); 1151 /** 1152 * call 'remove' directly on the parent class 1153 */ 904 1154 return wp.Backbone.View.prototype.remove.apply( this, arguments ); 905 1155 } … … 908 1158 /** 909 1159 * wp.media.view.Frame 1160 * 1161 * @constructor 1162 * @augments wp.media.View 1163 * @augments wp.Backbone.View 1164 * @augments Backbone.View 1165 * @mixes wp.media.controller.StateMachine 910 1166 */ 911 1167 media.view.Frame = media.View.extend({ … … 928 1184 }, this ); 929 1185 }, 930 1186 /** 1187 * @fires wp.media.controller.State#ready 1188 */ 931 1189 _createStates: function() { 932 1190 // Create the default `states` collection. … … 941 1199 }, this ); 942 1200 943 if ( this.options.states ) 1201 if ( this.options.states ) { 944 1202 this.states.add( this.options.states ); 945 }, 946 1203 } 1204 }, 1205 /** 1206 * @returns {wp.media.view.Frame} Returns itself to allow chaining 1207 */ 947 1208 reset: function() { 948 1209 this.states.invoke( 'trigger', 'reset' ); … … 956 1217 /** 957 1218 * wp.media.view.MediaFrame 1219 * 1220 * @constructor 1221 * @augments wp.media.view.Frame 1222 * @augments wp.media.View 1223 * @augments wp.Backbone.View 1224 * @augments Backbone.View 1225 * @mixes wp.media.controller.StateMachine 958 1226 */ 959 1227 media.view.MediaFrame = media.view.Frame.extend({ … … 962 1230 regions: ['menu','title','content','toolbar','router'], 963 1231 1232 /** 1233 * @global wp.Uploader 1234 */ 964 1235 initialize: function() { 1236 /** 1237 * call 'initialize' directly on the parent class 1238 */ 965 1239 media.view.Frame.prototype.initialize.apply( this, arguments ); 966 1240 … … 986 1260 // Force the uploader off if the upload limit has been exceeded or 987 1261 // if the browser isn't supported. 988 if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) 1262 if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) { 989 1263 this.options.uploader = false; 1264 } 990 1265 991 1266 // Initialize window-wide uploader. … … 1010 1285 this.on( 'menu:create:default', this.createMenu, this ); 1011 1286 }, 1012 1287 /** 1288 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining 1289 */ 1013 1290 render: function() { 1014 1291 // Activate the default state if no active state exists. 1015 if ( ! this.state() && this.options.state ) 1292 if ( ! this.state() && this.options.state ) { 1016 1293 this.setState( this.options.state ); 1017 1294 } 1295 /** 1296 * call 'render' directly on the parent class 1297 */ 1018 1298 return media.view.Frame.prototype.render.apply( this, arguments ); 1019 1299 }, 1020 1300 /** 1301 * @param {Object} title 1302 * @this wp.media.controller.Region 1303 */ 1021 1304 createTitle: function( title ) { 1022 1305 title.view = new media.View({ … … 1025 1308 }); 1026 1309 }, 1027 1310 /** 1311 * @param {Object} menu 1312 * @this wp.media.controller.Region 1313 */ 1028 1314 createMenu: function( menu ) { 1029 1315 menu.view = new media.view.Menu({ … … 1031 1317 }); 1032 1318 }, 1033 1319 /** 1320 * @param {Object} toolbar 1321 * @this wp.media.controller.Region 1322 */ 1034 1323 createToolbar: function( toolbar ) { 1035 1324 toolbar.view = new media.view.Toolbar({ … … 1037 1326 }); 1038 1327 }, 1039 1328 /** 1329 * @param {Object} router 1330 * @this wp.media.controller.Region 1331 */ 1040 1332 createRouter: function( router ) { 1041 1333 router.view = new media.view.Router({ … … 1043 1335 }); 1044 1336 }, 1045 1337 /** 1338 * @param {Object} options 1339 */ 1046 1340 createIframeStates: function( options ) { 1047 1341 var settings = media.view.settings, … … 1050 1344 $postId; 1051 1345 1052 if ( ! tabs || ! tabUrl ) 1346 if ( ! tabs || ! tabUrl ) { 1053 1347 return; 1348 } 1054 1349 1055 1350 // Add the post ID to the tab URL if it exists. 1056 1351 $postId = $('#post_ID'); 1057 if ( $postId.length ) 1352 if ( $postId.length ) { 1058 1353 tabUrl += '&post_id=' + $postId.val(); 1354 } 1059 1355 1060 1356 // Generate the tab states. … … 1075 1371 }, 1076 1372 1373 /** 1374 * @param {Object} content 1375 * @this wp.media.controller.Region 1376 */ 1077 1377 iframeContent: function( content ) { 1078 1378 this.$el.addClass('hide-toolbar'); … … 1085 1385 var views = {}; 1086 1386 1087 if ( ! view ) 1387 if ( ! view ) { 1088 1388 return; 1389 } 1089 1390 1090 1391 _.each( media.view.settings.tabs, function( title, id ) { … … 1101 1402 var frame = this; 1102 1403 1103 if ( ! window.tb_remove || this._tb_remove ) 1404 if ( ! window.tb_remove || this._tb_remove ) { 1104 1405 return; 1406 } 1105 1407 1106 1408 this._tb_remove = window.tb_remove; … … 1114 1416 1115 1417 restoreThickbox: function() { 1116 if ( ! this._tb_remove ) 1418 if ( ! this._tb_remove ) { 1117 1419 return; 1420 } 1118 1421 1119 1422 window.tb_remove = this._tb_remove; … … 1124 1427 // Map some of the modal's methods to the frame. 1125 1428 _.each(['open','close','attach','detach','escape'], function( method ) { 1429 /** 1430 * @returns {wp.media.view.MediaFrame} Returns itself to allow chaining 1431 */ 1126 1432 media.view.MediaFrame.prototype[ method ] = function() { 1127 if ( this.modal ) 1433 if ( this.modal ) { 1128 1434 this.modal[ method ].apply( this.modal, arguments ); 1435 } 1129 1436 return this; 1130 1437 }; … … 1133 1440 /** 1134 1441 * wp.media.view.MediaFrame.Select 1442 * 1443 * @constructor 1444 * @augments wp.media.view.MediaFrame 1445 * @augments wp.media.view.Frame 1446 * @augments wp.media.View 1447 * @augments wp.Backbone.View 1448 * @augments Backbone.View 1449 * @mixes wp.media.controller.StateMachine 1135 1450 */ 1136 1451 media.view.MediaFrame.Select = media.view.MediaFrame.extend({ 1137 1452 initialize: function() { 1453 /** 1454 * call 'initialize' directly on the parent class 1455 */ 1138 1456 media.view.MediaFrame.prototype.initialize.apply( this, arguments ); 1139 1457 … … 1160 1478 1161 1479 this._selection = { 1162 attachments: new Attachments(),1480 attachments: new media.model.Attachments(), 1163 1481 difference: [] 1164 1482 }; … … 1168 1486 var options = this.options; 1169 1487 1170 if ( this.options.states ) 1488 if ( this.options.states ) { 1171 1489 return; 1490 } 1172 1491 1173 1492 // Add the default states. … … 1205 1524 }, 1206 1525 1207 // Content 1526 /** 1527 * Content 1528 * 1529 * @param {Object} content 1530 * @this wp.media.controller.Region 1531 */ 1208 1532 browseContent: function( content ) { 1209 1533 var state = this.state(); … … 1227 1551 }, 1228 1552 1553 /** 1554 * 1555 * @this wp.media.controller.Region 1556 */ 1229 1557 uploadContent: function() { 1230 1558 this.$el.removeClass('hide-toolbar'); … … 1234 1562 }, 1235 1563 1236 // Toolbars 1564 /** 1565 * Toolbars 1566 * 1567 * @param {Object} toolbar 1568 * @param {Object} [options={}] 1569 * @this wp.media.controller.Region 1570 */ 1237 1571 createSelectToolbar: function( toolbar, options ) { 1238 1572 options = options || this.options.button || {}; … … 1245 1579 /** 1246 1580 * wp.media.view.MediaFrame.Post 1581 * 1582 * @constructor 1583 * @augments wp.media.view.MediaFrame.Select 1584 * @augments wp.media.view.MediaFrame 1585 * @augments wp.media.view.Frame 1586 * @augments wp.media.View 1587 * @augments wp.Backbone.View 1588 * @augments Backbone.View 1589 * @mixes wp.media.controller.StateMachine 1247 1590 */ 1248 1591 media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({ … … 1253 1596 state: 'insert' 1254 1597 }); 1255 1598 /** 1599 * call 'initialize' directly on the parent class 1600 */ 1256 1601 media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments ); 1257 1602 this.createIframeStates(); … … 1319 1664 1320 1665 bindHandlers: function() { 1666 /** 1667 * call 'bindHandlers' directly on the parent class 1668 */ 1321 1669 media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments ); 1322 1670 this.on( 'menu:create:gallery', this.createMenu, this ); … … 1327 1675 1328 1676 var handlers = { 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1677 menu: { 1678 'default': 'mainMenu', 1679 'gallery': 'galleryMenu' 1680 }, 1681 1682 content: { 1683 'embed': 'embedContent', 1684 'edit-selection': 'editSelectionContent' 1685 }, 1686 1687 toolbar: { 1688 'main-insert': 'mainInsertToolbar', 1689 'main-gallery': 'mainGalleryToolbar', 1690 'gallery-edit': 'galleryEditToolbar', 1691 'gallery-add': 'galleryAddToolbar' 1692 } 1693 }; 1346 1694 1347 1695 _.each( handlers, function( regionHandlers, region ) { … … 1353 1701 1354 1702 // Menus 1703 /** 1704 * @param {wp.Backbone.View} view 1705 */ 1355 1706 mainMenu: function( view ) { 1356 1707 view.set({ … … 1361 1712 }); 1362 1713 }, 1363 1714 /** 1715 * @param {wp.Backbone.View} view 1716 */ 1364 1717 galleryMenu: function( view ) { 1365 1718 var lastState = this.lastState(), … … 1427 1780 1428 1781 // Toolbars 1782 1783 /** 1784 * @param {wp.Backbone.View} view 1785 */ 1429 1786 selectionStatusToolbar: function( view ) { 1430 1787 var editable = this.state().get('editable'); … … 1443 1800 }, 1444 1801 1802 /** 1803 * @param {wp.Backbone.View} view 1804 */ 1445 1805 mainInsertToolbar: function( view ) { 1446 1806 var controller = this; … … 1454 1814 requires: { selection: true }, 1455 1815 1816 /** 1817 * @fires wp.media.controller.State#insert 1818 */ 1456 1819 click: function() { 1457 1820 var state = controller.state(), … … 1464 1827 }, 1465 1828 1829 /** 1830 * @param {wp.Backbone.View} view 1831 */ 1466 1832 mainGalleryToolbar: function( view ) { 1467 1833 var controller = this; … … 1514 1880 requires: { library: true }, 1515 1881 1882 /** 1883 * @fires wp.media.controller.State#update 1884 */ 1516 1885 click: function() { 1517 1886 var controller = this.controller, … … 1540 1909 requires: { selection: true }, 1541 1910 1911 /** 1912 * @fires wp.media.controller.State#reset 1913 */ 1542 1914 click: function() { 1543 1915 var controller = this.controller, … … 1557 1929 /** 1558 1930 * wp.media.view.Modal 1931 * 1932 * @constructor 1933 * @augments wp.media.View 1934 * @augments wp.Backbone.View 1935 * @augments Backbone.View 1559 1936 */ 1560 1937 media.view.Modal = media.View.extend({ … … 1579 1956 }); 1580 1957 }, 1581 1958 /** 1959 * @returns {Object} 1960 */ 1582 1961 prepare: function() { 1583 1962 return { … … 1586 1965 }, 1587 1966 1967 /** 1968 * @returns {wp.media.view.Modal} Returns itself to allow chaining 1969 */ 1588 1970 attach: function() { 1589 if ( this.views.attached ) 1971 if ( this.views.attached ) { 1590 1972 return this; 1591 1592 if ( ! this.views.rendered ) 1973 } 1974 1975 if ( ! this.views.rendered ) { 1593 1976 this.render(); 1977 } 1594 1978 1595 1979 this.$el.appendTo( this.options.container ); … … 1602 1986 }, 1603 1987 1988 /** 1989 * @returns {wp.media.view.Modal} Returns itself to allow chaining 1990 */ 1604 1991 detach: function() { 1605 if ( this.$el.is(':visible') ) 1992 if ( this.$el.is(':visible') ) { 1606 1993 this.close(); 1994 } 1607 1995 1608 1996 this.$el.detach(); … … 1611 1999 }, 1612 2000 2001 /** 2002 * @returns {wp.media.view.Modal} Returns itself to allow chaining 2003 */ 1613 2004 open: function() { 1614 2005 var $el = this.$el, 1615 2006 options = this.options; 1616 2007 1617 if ( $el.is(':visible') ) 2008 if ( $el.is(':visible') ) { 1618 2009 return this; 1619 1620 if ( ! this.views.attached ) 2010 } 2011 2012 if ( ! this.views.attached ) { 1621 2013 this.attach(); 2014 } 1622 2015 1623 2016 // If the `freeze` option is set, record the window's scroll position. … … 1632 2025 }, 1633 2026 2027 /** 2028 * @param {Object} options 2029 * @returns {wp.media.view.Modal} Returns itself to allow chaining 2030 */ 1634 2031 close: function( options ) { 1635 2032 var freeze = this._freeze; 1636 2033 1637 if ( ! this.views.attached || ! this.$el.is(':visible') ) 2034 if ( ! this.views.attached || ! this.$el.is(':visible') ) { 1638 2035 return this; 2036 } 1639 2037 1640 2038 this.$el.hide(); … … 1646 2044 } 1647 2045 1648 if ( options && options.escape ) 2046 if ( options && options.escape ) { 1649 2047 this.propagate('escape'); 2048 } 1650 2049 1651 2050 return this; 1652 2051 }, 1653 2052 /** 2053 * @returns {wp.media.view.Modal} Returns itself to allow chaining 2054 */ 1654 2055 escape: function() { 1655 2056 return this.close({ escape: true }); 1656 2057 }, 1657 2058 /** 2059 * @param {Object} event 2060 */ 1658 2061 escapeHandler: function( event ) { 1659 2062 event.preventDefault(); … … 1661 2064 }, 1662 2065 2066 /** 2067 * @param {Array|Object} content Views to register to '.media-modal-content' 2068 * @returns {wp.media.view.Modal} Returns itself to allow chaining 2069 */ 1663 2070 content: function( content ) { 1664 2071 this.views.set( '.media-modal-content', content ); … … 1666 2073 }, 1667 2074 1668 // Triggers a modal event and if the `propagate` option is set, 1669 // forwards events to the modal's controller. 2075 /** 2076 * Triggers a modal event and if the `propagate` option is set, 2077 * forwards events to the modal's controller. 2078 * 2079 * @param {string} id 2080 * @returns {wp.media.view.Modal} Returns itself to allow chaining 2081 */ 1670 2082 propagate: function( id ) { 1671 2083 this.trigger( id ); 1672 2084 1673 if ( this.options.propagate ) 2085 if ( this.options.propagate ) { 1674 2086 this.controller.trigger( id ); 2087 } 1675 2088 1676 2089 return this; 1677 2090 }, 1678 2091 /** 2092 * @param {Object} event 2093 */ 1679 2094 keydown: function( event ) { 1680 2095 // Close the modal when escape is pressed. … … 1687 2102 }); 1688 2103 1689 // wp.media.view.FocusManager 1690 // ---------------------------- 2104 /** 2105 * wp.media.view.FocusManager 2106 * 2107 * @constructor 2108 * @augments wp.media.View 2109 * @augments wp.Backbone.View 2110 * @augments Backbone.View 2111 */ 1691 2112 media.view.FocusManager = media.View.extend({ 1692 2113 events: { … … 1696 2117 1697 2118 focus: function() { 1698 if ( _.isUndefined( this.index ) ) 2119 if ( _.isUndefined( this.index ) ) { 1699 2120 return; 2121 } 1700 2122 1701 2123 // Update our collection of `$tabbables`. … … 1705 2127 this.$tabbables.eq( this.index ).focus(); 1706 2128 }, 1707 2129 /** 2130 * @param {Object} event 2131 */ 1708 2132 recordTab: function( event ) { 1709 2133 // Look for the tab key. 1710 if ( 9 !== event.keyCode ) 2134 if ( 9 !== event.keyCode ) { 1711 2135 return; 2136 } 1712 2137 1713 2138 // First try to update the index. 1714 if ( _.isUndefined( this.index ) ) 2139 if ( _.isUndefined( this.index ) ) { 1715 2140 this.updateIndex( event ); 2141 } 1716 2142 1717 2143 // If we still don't have an index, bail. 1718 if ( _.isUndefined( this.index ) ) 2144 if ( _.isUndefined( this.index ) ) { 1719 2145 return; 2146 } 1720 2147 1721 2148 var index = this.index + ( event.shiftKey ? -1 : 1 ); 1722 2149 1723 if ( index >= 0 && index < this.$tabbables.length ) 2150 if ( index >= 0 && index < this.$tabbables.length ) { 1724 2151 this.index = index; 1725 else2152 } else { 1726 2153 delete this.index; 1727 }, 1728 2154 } 2155 }, 2156 /** 2157 * @param {Object} event 2158 */ 1729 2159 updateIndex: function( event ) { 1730 2160 this.$tabbables = this.$(':tabbable'); … … 1732 2162 var index = this.$tabbables.index( event.target ); 1733 2163 1734 if ( -1 === index ) 2164 if ( -1 === index ) { 1735 2165 delete this.index; 1736 else2166 } else { 1737 2167 this.index = index; 2168 } 1738 2169 } 1739 2170 }); 1740 2171 1741 // wp.media.view.UploaderWindow 1742 // ---------------------------- 2172 /** 2173 * wp.media.view.UploaderWindow 2174 * 2175 * @constructor 2176 * @augments wp.media.View 2177 * @augments wp.Backbone.View 2178 * @augments Backbone.View 2179 */ 1743 2180 media.view.UploaderWindow = media.View.extend({ 1744 2181 tagName: 'div', … … 1758 2195 1759 2196 // Ensure the dropzone is a jQuery collection. 1760 if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) 2197 if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) { 1761 2198 uploader.dropzone = $( uploader.dropzone ); 2199 } 1762 2200 1763 2201 this.controller.on( 'activate', this.refresh, this ); … … 1765 2203 1766 2204 refresh: function() { 1767 if ( this.uploader ) 2205 if ( this.uploader ) { 1768 2206 this.uploader.refresh(); 2207 } 1769 2208 }, 1770 2209 … … 1774 2213 1775 2214 // If the uploader already exists, bail. 1776 if ( this.uploader ) 2215 if ( this.uploader ) { 1777 2216 return; 1778 1779 if ( postId ) 2217 } 2218 2219 if ( postId ) { 1780 2220 this.options.uploader.params.post_id = postId; 1781 2221 } 1782 2222 this.uploader = new wp.Uploader( this.options.uploader ); 1783 2223 … … 1809 2249 }); 1810 2250 2251 /** 2252 * wp.media.view.UploaderInline 2253 * 2254 * @constructor 2255 * @augments wp.media.View 2256 * @augments wp.Backbone.View 2257 * @augments Backbone.View 2258 */ 1811 2259 media.view.UploaderInline = media.View.extend({ 1812 2260 tagName: 'div', … … 1820 2268 }); 1821 2269 1822 if ( ! this.options.$browser && this.controller.uploader ) 2270 if ( ! this.options.$browser && this.controller.uploader ) { 1823 2271 this.options.$browser = this.controller.uploader.$browser; 1824 1825 if ( _.isUndefined( this.options.postId ) ) 2272 } 2273 2274 if ( _.isUndefined( this.options.postId ) ) { 1826 2275 this.options.postId = media.view.settings.post.id; 2276 } 1827 2277 1828 2278 if ( this.options.status ) { … … 1832 2282 } 1833 2283 }, 1834 2284 /** 2285 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining 2286 */ 1835 2287 dispose: function() { 1836 if ( this.disposing ) 2288 if ( this.disposing ) { 2289 /** 2290 * call 'dispose' directly on the parent class 2291 */ 1837 2292 return media.View.prototype.dispose.apply( this, arguments ); 2293 } 1838 2294 1839 2295 // Run remove on `dispose`, so we can be sure to refresh the … … 1843 2299 return this.remove(); 1844 2300 }, 1845 2301 /** 2302 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining 2303 */ 1846 2304 remove: function() { 2305 /** 2306 * call 'remove' directly on the parent class 2307 */ 1847 2308 var result = media.View.prototype.remove.apply( this, arguments ); 1848 2309 … … 1854 2315 var uploader = this.controller.uploader; 1855 2316 1856 if ( uploader ) 2317 if ( uploader ) { 1857 2318 uploader.refresh(); 1858 }, 1859 2319 } 2320 }, 2321 /** 2322 * @returns {wp.media.view.UploaderInline} 2323 */ 1860 2324 ready: function() { 1861 2325 var $browser = this.options.$browser, … … 1866 2330 1867 2331 // Check if we've already replaced the placeholder. 1868 if ( $placeholder[0] === $browser[0] ) 2332 if ( $placeholder[0] === $browser[0] ) { 1869 2333 return; 2334 } 1870 2335 1871 2336 $browser.detach().text( $placeholder.text() ); … … 1881 2346 /** 1882 2347 * wp.media.view.UploaderStatus 2348 * 2349 * @constructor 2350 * @augments wp.media.View 2351 * @augments wp.Backbone.View 2352 * @augments Backbone.View 1883 2353 */ 1884 2354 media.view.UploaderStatus = media.View.extend({ … … 1901 2371 this.errors.on( 'add', this.error, this ); 1902 2372 }, 1903 2373 /** 2374 * @global wp.Uploader 2375 * @returns {wp.media.view.UploaderStatus} 2376 */ 1904 2377 dispose: function() { 1905 2378 wp.Uploader.queue.off( null, null, this ); 2379 /** 2380 * call 'dispose' directly on the parent class 2381 */ 1906 2382 media.View.prototype.dispose.apply( this, arguments ); 1907 2383 return this; … … 1933 2409 $bar = this.$bar; 1934 2410 1935 if ( ! $bar || ! queue.length ) 2411 if ( ! $bar || ! queue.length ) { 1936 2412 return; 2413 } 1937 2414 1938 2415 $bar.width( ( queue.reduce( function( memo, attachment ) { 1939 if ( ! attachment.get('uploading') ) 2416 if ( ! attachment.get('uploading') ) { 1940 2417 return memo + 100; 2418 } 1941 2419 1942 2420 var percent = attachment.get('percent'); … … 1949 2427 index = 0, active; 1950 2428 1951 if ( ! queue.length ) 2429 if ( ! queue.length ) { 1952 2430 return; 2431 } 1953 2432 1954 2433 active = this.queue.find( function( attachment, i ) { … … 1961 2440 this.$filename.html( active ? this.filename( active.get('filename') ) : '' ); 1962 2441 }, 1963 2442 /** 2443 * @param {string} filename 2444 * @returns {string} 2445 */ 1964 2446 filename: function( filename ) { 1965 2447 return media.truncate( _.escape( filename ), 24 ); 1966 2448 }, 1967 2449 /** 2450 * @param {Backbone.Model} error 2451 */ 1968 2452 error: function( error ) { 1969 2453 this.views.add( '.upload-errors', new media.view.UploaderStatusError({ … … 1973 2457 }, 1974 2458 2459 /** 2460 * @global wp.Uploader 2461 * 2462 * @param {Object} event 2463 */ 1975 2464 dismiss: function( event ) { 1976 2465 var errors = this.views.get('.upload-errors'); … … 1978 2467 event.preventDefault(); 1979 2468 1980 if ( errors ) 2469 if ( errors ) { 1981 2470 _.invoke( errors, 'remove' ); 2471 } 1982 2472 wp.Uploader.errors.reset(); 1983 2473 } 1984 2474 }); 1985 2475 2476 /** 2477 * wp.media.view.UploaderStatusError 2478 * 2479 * @constructor 2480 * @augments wp.media.View 2481 * @augments wp.Backbone.View 2482 * @augments Backbone.View 2483 */ 1986 2484 media.view.UploaderStatusError = media.View.extend({ 1987 2485 className: 'upload-error', … … 1991 2489 /** 1992 2490 * wp.media.view.Toolbar 2491 * 2492 * @constructor 2493 * @augments wp.media.View 2494 * @augments wp.Backbone.View 2495 * @augments Backbone.View 1993 2496 */ 1994 2497 media.view.Toolbar = media.View.extend({ … … 2011 2514 this.views.set([ this.secondary, this.primary ]); 2012 2515 2013 if ( this.options.items ) 2516 if ( this.options.items ) { 2014 2517 this.set( this.options.items, { silent: true }); 2015 2016 if ( ! this.options.silent ) 2518 } 2519 2520 if ( ! this.options.silent ) { 2017 2521 this.render(); 2018 2019 if ( selection ) 2522 } 2523 2524 if ( selection ) { 2020 2525 selection.on( 'add remove reset', this.refresh, this ); 2021 if ( library ) 2526 } 2527 2528 if ( library ) { 2022 2529 library.on( 'add remove reset', this.refresh, this ); 2023 }, 2024 2530 } 2531 }, 2532 /** 2533 * @returns {wp.media.view.Toolbar} Returns itsef to allow chaining 2534 */ 2025 2535 dispose: function() { 2026 if ( this.selection ) 2536 if ( this.selection ) { 2027 2537 this.selection.off( null, null, this ); 2028 if ( this.library ) 2538 } 2539 2540 if ( this.library ) { 2029 2541 this.library.off( null, null, this ); 2542 } 2543 /** 2544 * call 'dispose' directly on the parent class 2545 */ 2030 2546 return media.View.prototype.dispose.apply( this, arguments ); 2031 2547 }, … … 2035 2551 }, 2036 2552 2553 /** 2554 * @param {string} id 2555 * @param {Backbone.View|Object} view 2556 * @param {Object} [options={}] 2557 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining 2558 */ 2037 2559 set: function( id, view, options ) { 2038 2560 var list; … … 2059 2581 } 2060 2582 2061 if ( ! options.silent ) 2583 if ( ! options.silent ) { 2062 2584 this.refresh(); 2585 } 2063 2586 2064 2587 return this; 2065 2588 }, 2066 2589 /** 2590 * @param {string} id 2591 * @returns {wp.media.view.Button} 2592 */ 2067 2593 get: function( id ) { 2068 2594 return this._views[ id ]; 2069 2595 }, 2070 2596 /** 2597 * @param {string} id 2598 * @param {Object} options 2599 * @returns {wp.media.view.Toolbar} Returns itself to allow chaining 2600 */ 2071 2601 unset: function( id, options ) { 2072 2602 delete this._views[ id ]; … … 2074 2604 this.secondary.unset( id, options ); 2075 2605 2076 if ( ! options || ! options.silent ) 2606 if ( ! options || ! options.silent ) { 2077 2607 this.refresh(); 2608 } 2078 2609 return this; 2079 2610 }, … … 2085 2616 2086 2617 _.each( this._views, function( button ) { 2087 if ( ! button.model || ! button.options || ! button.options.requires ) 2618 if ( ! button.model || ! button.options || ! button.options.requires ) { 2088 2619 return; 2620 } 2089 2621 2090 2622 var requires = button.options.requires, … … 2096 2628 }); 2097 2629 2098 if ( requires.selection && selection && ! selection.length ) 2630 if ( requires.selection && selection && ! selection.length ) { 2099 2631 disabled = true; 2100 else if ( requires.library && library && ! library.length )2632 } else if ( requires.library && library && ! library.length ) { 2101 2633 disabled = true; 2102 2634 } 2103 2635 button.model.set( 'disabled', disabled ); 2104 2636 }); … … 2106 2638 }); 2107 2639 2108 // wp.media.view.Toolbar.Select 2109 // ---------------------------- 2640 /** 2641 * wp.media.view.Toolbar.Select 2642 * 2643 * @constructor 2644 * @augments wp.media.view.Toolbar 2645 * @augments wp.media.View 2646 * @augments wp.Backbone.View 2647 * @augments Backbone.View 2648 */ 2110 2649 media.view.Toolbar.Select = media.view.Toolbar.extend({ 2111 2650 initialize: function() { … … 2136 2675 } 2137 2676 }); 2138 2677 /** 2678 * call 'initialize' directly on the parent class 2679 */ 2139 2680 media.view.Toolbar.prototype.initialize.apply( this, arguments ); 2140 2681 }, … … 2144 2685 controller = this.controller; 2145 2686 2146 if ( options.close ) 2687 if ( options.close ) { 2147 2688 controller.close(); 2148 2149 if ( options.event ) 2689 } 2690 2691 if ( options.event ) { 2150 2692 controller.state().trigger( options.event ); 2151 2152 if ( options.state ) 2693 } 2694 2695 if ( options.state ) { 2153 2696 controller.setState( options.state ); 2154 2155 if ( options.reset ) 2697 } 2698 2699 if ( options.reset ) { 2156 2700 controller.reset(); 2701 } 2157 2702 } 2158 2703 }); 2159 2704 2160 // wp.media.view.Toolbar.Embed 2161 // --------------------------- 2705 /** 2706 * wp.media.view.Toolbar.Embed 2707 * 2708 * @constructor 2709 * @augments wp.media.view.Toolbar.Select 2710 * @augments wp.media.view.Toolbar 2711 * @augments wp.media.View 2712 * @augments wp.Backbone.View 2713 * @augments Backbone.View 2714 */ 2162 2715 media.view.Toolbar.Embed = media.view.Toolbar.Select.extend({ 2163 2716 initialize: function() { … … 2166 2719 requires: false 2167 2720 }); 2168 2721 /** 2722 * call 'initialize' directly on the parent class 2723 */ 2169 2724 media.view.Toolbar.Select.prototype.initialize.apply( this, arguments ); 2170 2725 }, … … 2173 2728 var url = this.controller.state().props.get('url'); 2174 2729 this.get('select').model.set( 'disabled', ! url || url === 'http://' ); 2175 2730 /** 2731 * call 'refresh' directly on the parent class 2732 */ 2176 2733 media.view.Toolbar.Select.prototype.refresh.apply( this, arguments ); 2177 2734 } … … 2180 2737 /** 2181 2738 * wp.media.view.Button 2739 * 2740 * @constructor 2741 * @augments wp.media.View 2742 * @augments wp.Backbone.View 2743 * @augments Backbone.View 2182 2744 */ 2183 2745 media.view.Button = media.View.extend({ … … 2198 2760 2199 2761 initialize: function() { 2200 // Create a model with the provided `defaults`. 2762 /** 2763 * Create a model with the provided `defaults`. 2764 * 2765 * @member {Backbone.Model} 2766 */ 2201 2767 this.model = new Backbone.Model( this.defaults ); 2202 2768 … … 2214 2780 this.model.on( 'change', this.render, this ); 2215 2781 }, 2216 2782 /** 2783 * @returns {wp.media.view.Button} Returns itself to allow chaining 2784 */ 2217 2785 render: function() { 2218 2786 var classes = [ 'button', this.className ], 2219 2787 model = this.model.toJSON(); 2220 2788 2221 if ( model.style ) 2789 if ( model.style ) { 2222 2790 classes.push( 'button-' + model.style ); 2223 2224 if ( model.size ) 2791 } 2792 2793 if ( model.size ) { 2225 2794 classes.push( 'button-' + model.size ); 2795 } 2226 2796 2227 2797 classes = _.uniq( classes.concat( this.options.classes ) ); … … 2233 2803 return this; 2234 2804 }, 2235 2805 /** 2806 * @param {Object} event 2807 */ 2236 2808 click: function( event ) { 2237 if ( '#' === this.attributes.href ) 2809 if ( '#' === this.attributes.href ) { 2238 2810 event.preventDefault(); 2239 2240 if ( this.options.click && ! this.model.get('disabled') ) 2811 } 2812 2813 if ( this.options.click && ! this.model.get('disabled') ) { 2241 2814 this.options.click.apply( this, arguments ); 2815 } 2242 2816 } 2243 2817 }); … … 2245 2819 /** 2246 2820 * wp.media.view.ButtonGroup 2821 * 2822 * @constructor 2823 * @augments wp.media.View 2824 * @augments wp.Backbone.View 2825 * @augments Backbone.View 2247 2826 */ 2248 2827 media.view.ButtonGroup = media.View.extend({ … … 2251 2830 2252 2831 initialize: function() { 2832 /** 2833 * @member {wp.media.view.Button[]} 2834 */ 2253 2835 this.buttons = _.map( this.options.buttons || [], function( button ) { 2254 if ( button instanceof Backbone.View ) 2836 if ( button instanceof Backbone.View ) { 2255 2837 return button; 2256 else2838 } else { 2257 2839 return new media.view.Button( button ).render(); 2840 } 2258 2841 }); 2259 2842 2260 2843 delete this.options.buttons; 2261 2844 2262 if ( this.options.classes ) 2845 if ( this.options.classes ) { 2263 2846 this.$el.addClass( this.options.classes ); 2264 }, 2265 2847 } 2848 }, 2849 2850 /** 2851 * @returns {wp.media.view.ButtonGroup} 2852 */ 2266 2853 render: function() { 2267 2854 this.$el.html( $( _.pluck( this.buttons, 'el' ) ).detach() ); … … 2272 2859 /** 2273 2860 * wp.media.view.PriorityList 2274 */ 2275 2861 * 2862 * @constructor 2863 * @augments wp.media.View 2864 * @augments wp.Backbone.View 2865 * @augments Backbone.View 2866 */ 2276 2867 media.view.PriorityList = media.View.extend({ 2277 2868 tagName: 'div', … … 2283 2874 delete this.options.views; 2284 2875 2285 if ( ! this.options.silent ) 2876 if ( ! this.options.silent ) { 2286 2877 this.render(); 2287 }, 2288 2878 } 2879 }, 2880 /** 2881 * @param {string} id 2882 * @param {wp.media.View|Object} view 2883 * @param {Object} options 2884 * @returns {wp.media.view.PriorityList} Returns itself to allow chaining 2885 */ 2289 2886 set: function( id, view, options ) { 2290 2887 var priority, views, index; … … 2300 2897 } 2301 2898 2302 if ( ! (view instanceof Backbone.View) ) 2899 if ( ! (view instanceof Backbone.View) ) { 2303 2900 view = this.toView( view, id, options ); 2304 2901 } 2305 2902 view.controller = view.controller || this.controller; 2306 2903 … … 2324 2921 return this; 2325 2922 }, 2326 2923 /** 2924 * @param {string} id 2925 * @returns {wp.media.View} 2926 */ 2327 2927 get: function( id ) { 2328 2928 return this._views[ id ]; 2329 2929 }, 2330 2930 /** 2931 * @param {string} id 2932 * @returns {wp.media.view.PriorityList} 2933 */ 2331 2934 unset: function( id ) { 2332 2935 var view = this.get( id ); 2333 2936 2334 if ( view ) 2937 if ( view ) { 2335 2938 view.remove(); 2939 } 2336 2940 2337 2941 delete this._views[ id ]; 2338 2942 return this; 2339 2943 }, 2340 2944 /** 2945 * @param {Object} options 2946 * @returns {wp.media.View} 2947 */ 2341 2948 toView: function( options ) { 2342 2949 return new media.View( options ); … … 2346 2953 /** 2347 2954 * wp.media.view.MenuItem 2955 * 2956 * @constructor 2957 * @augments wp.media.View 2958 * @augments wp.Backbone.View 2959 * @augments Backbone.View 2348 2960 */ 2349 2961 media.view.MenuItem = media.View.extend({ … … 2358 2970 'click': '_click' 2359 2971 }, 2360 2972 /** 2973 * @param {Object} event 2974 */ 2361 2975 _click: function( event ) { 2362 2976 var clickOverride = this.options.click; 2363 2977 2364 if ( event ) 2978 if ( event ) { 2365 2979 event.preventDefault(); 2366 2367 if ( clickOverride ) 2980 } 2981 2982 if ( clickOverride ) { 2368 2983 clickOverride.call( this ); 2369 else2984 } else { 2370 2985 this.click(); 2986 } 2371 2987 }, 2372 2988 2373 2989 click: function() { 2374 2990 var state = this.options.state; 2375 if ( state ) 2991 if ( state ) { 2376 2992 this.controller.setState( state ); 2377 }, 2378 2993 } 2994 }, 2995 /** 2996 * @returns {wp.media.view.MenuItem} returns itself to allow chaining 2997 */ 2379 2998 render: function() { 2380 2999 var options = this.options; 2381 3000 2382 if ( options.text ) 3001 if ( options.text ) { 2383 3002 this.$el.text( options.text ); 2384 else if ( options.html )3003 } else if ( options.html ) { 2385 3004 this.$el.html( options.html ); 3005 } 2386 3006 2387 3007 return this; … … 2391 3011 /** 2392 3012 * wp.media.view.Menu 3013 * 3014 * @constructor 3015 * @augments wp.media.view.PriorityList 3016 * @augments wp.media.View 3017 * @augments wp.Backbone.View 3018 * @augments Backbone.View 2393 3019 */ 2394 3020 media.view.Menu = media.view.PriorityList.extend({ … … 2398 3024 ItemView: media.view.MenuItem, 2399 3025 region: 'menu', 2400 3026 /** 3027 * @param {Object} options 3028 * @param {string} id 3029 * @returns {wp.media.View} 3030 */ 2401 3031 toView: function( options, id ) { 2402 3032 options = options || {}; … … 2406 3036 2407 3037 ready: function() { 3038 /** 3039 * call 'ready' directly on the parent class 3040 */ 2408 3041 media.view.PriorityList.prototype.ready.apply( this, arguments ); 2409 3042 this.visibility(); … … 2411 3044 2412 3045 set: function() { 3046 /** 3047 * call 'set' directly on the parent class 3048 */ 2413 3049 media.view.PriorityList.prototype.set.apply( this, arguments ); 2414 3050 this.visibility(); … … 2416 3052 2417 3053 unset: function() { 3054 /** 3055 * call 'unset' directly on the parent class 3056 */ 2418 3057 media.view.PriorityList.prototype.unset.apply( this, arguments ); 2419 3058 this.visibility(); … … 2426 3065 hide = ! views || views.length < 2; 2427 3066 2428 if ( this === view ) 3067 if ( this === view ) { 2429 3068 this.controller.$el.toggleClass( 'hide-' + region, hide ); 2430 }, 2431 3069 } 3070 }, 3071 /** 3072 * @param {string} id 3073 */ 2432 3074 select: function( id ) { 2433 3075 var view = this.get( id ); 2434 3076 2435 if ( ! view ) 3077 if ( ! view ) { 2436 3078 return; 3079 } 2437 3080 2438 3081 this.deselect(); … … 2447 3090 /** 2448 3091 * wp.media.view.RouterItem 3092 * 3093 * @constructor 3094 * @augments wp.media.view.MenuItem 3095 * @augments wp.media.View 3096 * @augments wp.Backbone.View 3097 * @augments Backbone.View 2449 3098 */ 2450 3099 media.view.RouterItem = media.view.MenuItem.extend({ 2451 3100 click: function() { 2452 3101 var contentMode = this.options.contentMode; 2453 if ( contentMode ) 3102 if ( contentMode ) { 2454 3103 this.controller.content.mode( contentMode ); 3104 } 2455 3105 } 2456 3106 }); … … 2458 3108 /** 2459 3109 * wp.media.view.Router 3110 * 3111 * @constructor 3112 * @augments wp.media.view.Menu 3113 * @augments wp.media.view.PriorityList 3114 * @augments wp.media.View 3115 * @augments wp.Backbone.View 3116 * @augments Backbone.View 2460 3117 */ 2461 3118 media.view.Router = media.view.Menu.extend({ … … 2468 3125 initialize: function() { 2469 3126 this.controller.on( 'content:render', this.update, this ); 3127 /** 3128 * call 'initialize' directly on the parent class 3129 */ 2470 3130 media.view.Menu.prototype.initialize.apply( this, arguments ); 2471 3131 }, … … 2473 3133 update: function() { 2474 3134 var mode = this.controller.content.mode(); 2475 if ( mode ) 3135 if ( mode ) { 2476 3136 this.select( mode ); 3137 } 2477 3138 } 2478 3139 }); 2479 3140 2480 2481 3141 /** 2482 3142 * wp.media.view.Sidebar 3143 * 3144 * @constructor 3145 * @augments wp.media.view.PriorityList 3146 * @augments wp.media.View 3147 * @augments wp.Backbone.View 3148 * @augments Backbone.View 2483 3149 */ 2484 3150 media.view.Sidebar = media.view.PriorityList.extend({ … … 2488 3154 /** 2489 3155 * wp.media.view.Attachment 3156 * 3157 * @constructor 3158 * @augments wp.media.View 3159 * @augments wp.Backbone.View 3160 * @augments Backbone.View 2490 3161 */ 2491 3162 media.view.Attachment = media.View.extend({ … … 2518 3189 this.model.on( 'add', this.select, this ); 2519 3190 this.model.on( 'remove', this.deselect, this ); 2520 if ( selection ) 3191 if ( selection ) { 2521 3192 selection.on( 'reset', this.updateSelect, this ); 3193 } 2522 3194 2523 3195 // Update the model's details view. … … 2525 3197 this.details( this.model, this.controller.state().get('selection') ); 2526 3198 }, 2527 3199 /** 3200 * @returns {wp.media.view.Attachment} Returns itself to allow chaining 3201 */ 2528 3202 dispose: function() { 2529 3203 var selection = this.options.selection; … … 2532 3206 this.updateAll(); 2533 3207 2534 if ( selection ) 3208 if ( selection ) { 2535 3209 selection.off( null, null, this ); 2536 3210 } 3211 /** 3212 * call 'dispose' directly on the parent class 3213 */ 2537 3214 media.View.prototype.dispose.apply( this, arguments ); 2538 3215 return this; 2539 3216 }, 2540 3217 /** 3218 * @returns {wp.media.view.Attachment} Returns itself to allow chaining 3219 */ 2541 3220 render: function() { 2542 3221 var options = _.defaults( this.model.toJSON(), { … … 2593 3272 2594 3273 progress: function() { 2595 if ( this.$bar && this.$bar.length ) 3274 if ( this.$bar && this.$bar.length ) { 2596 3275 this.$bar.width( this.model.get('percent') + '%' ); 2597 }, 2598 3276 } 3277 }, 3278 /** 3279 * @param {Object} event 3280 */ 2599 3281 toggleSelectionHandler: function( event ) { 2600 3282 var method; 2601 3283 2602 if ( event.shiftKey ) 3284 if ( event.shiftKey ) { 2603 3285 method = 'between'; 2604 else if ( event.ctrlKey || event.metaKey )3286 } else if ( event.ctrlKey || event.metaKey ) { 2605 3287 method = 'toggle'; 3288 } 2606 3289 2607 3290 this.toggleSelection({ … … 2609 3292 }); 2610 3293 }, 2611 3294 /** 3295 * @param {Object} options 3296 */ 2612 3297 toggleSelection: function( options ) { 2613 3298 var collection = this.collection, … … 2617 3302 single, models, singleIndex, modelIndex; 2618 3303 2619 if ( ! selection ) 3304 if ( ! selection ) { 2620 3305 return; 3306 } 2621 3307 2622 3308 single = selection.single(); … … 2627 3313 if ( 'between' === method && single && selection.multiple ) { 2628 3314 // If the models are the same, short-circuit. 2629 if ( single === model ) 3315 if ( single === model ) { 2630 3316 return; 3317 } 2631 3318 2632 3319 singleIndex = collection.indexOf( single ); 2633 3320 modelIndex = collection.indexOf( this.model ); 2634 3321 2635 if ( singleIndex < modelIndex ) 3322 if ( singleIndex < modelIndex ) { 2636 3323 models = collection.models.slice( singleIndex, modelIndex + 1 ); 2637 else3324 } else { 2638 3325 models = collection.models.slice( modelIndex, singleIndex + 1 ); 3326 } 2639 3327 2640 3328 selection.add( models ).single( model ); … … 2648 3336 } 2649 3337 2650 if ( method !== 'add' ) 3338 if ( method !== 'add' ) { 2651 3339 method = 'reset'; 3340 } 2652 3341 2653 3342 if ( this.selected() ) { … … 2667 3356 this[ this.selected() ? 'select' : 'deselect' ](); 2668 3357 }, 2669 3358 /** 3359 * @returns {unresolved|Boolean} 3360 */ 2670 3361 selected: function() { 2671 3362 var selection = this.options.selection; 2672 if ( selection ) 3363 if ( selection ) { 2673 3364 return !! selection.get( this.model.cid ); 2674 }, 2675 3365 } 3366 }, 3367 /** 3368 * @param {Backbone.Model} model 3369 * @param {Backbone.Collection} collection 3370 */ 2676 3371 select: function( model, collection ) { 2677 3372 var selection = this.options.selection; … … 2680 3375 // If they're not the same collection, bail; we're in another 2681 3376 // selection's event loop. 2682 if ( ! selection || ( collection && collection !== selection ) ) 3377 if ( ! selection || ( collection && collection !== selection ) ) { 2683 3378 return; 3379 } 2684 3380 2685 3381 this.$el.addClass('selected'); 2686 3382 }, 2687 3383 /** 3384 * @param {Backbone.Model} model 3385 * @param {Backbone.Collection} collection 3386 */ 2688 3387 deselect: function( model, collection ) { 2689 3388 var selection = this.options.selection; … … 2692 3391 // If they're not the same collection, bail; we're in another 2693 3392 // selection's event loop. 2694 if ( ! selection || ( collection && collection !== selection ) ) 3393 if ( ! selection || ( collection && collection !== selection ) ) { 2695 3394 return; 2696 3395 } 2697 3396 this.$el.removeClass('selected'); 2698 3397 }, 2699 3398 /** 3399 * @param {Backbone.Model} model 3400 * @param {Backbone.Collection} collection 3401 */ 2700 3402 details: function( model, collection ) { 2701 3403 var selection = this.options.selection, 2702 3404 details; 2703 3405 2704 if ( selection !== collection ) 3406 if ( selection !== collection ) { 2705 3407 return; 3408 } 2706 3409 2707 3410 details = selection.single(); 2708 3411 this.$el.toggleClass( 'details', details === this.model ); 2709 3412 }, 2710 3413 /** 3414 * @param {Object} event 3415 */ 2711 3416 preventDefault: function( event ) { 2712 3417 event.preventDefault(); 2713 3418 }, 2714 3419 /** 3420 * @param {string} size 3421 * @returns {Object} 3422 */ 2715 3423 imageSize: function( size ) { 2716 3424 var sizes = this.model.get('sizes'); … … 2730 3438 } 2731 3439 }, 2732 3440 /** 3441 * @param {Object} event 3442 */ 2733 3443 updateSetting: function( event ) { 2734 3444 var $setting = $( event.target ).closest('[data-setting]'), 2735 3445 setting, value; 2736 3446 2737 if ( ! $setting.length ) 3447 if ( ! $setting.length ) { 2738 3448 return; 3449 } 2739 3450 2740 3451 setting = $setting.data('setting'); 2741 3452 value = event.target.value; 2742 3453 2743 if ( this.model.get( setting ) !== value ) 3454 if ( this.model.get( setting ) !== value ) { 2744 3455 this.save( setting, value ); 2745 }, 2746 2747 // Pass all the arguments to the model's save method. 2748 // 2749 // Records the aggregate status of all save requests and updates the 2750 // view's classes accordingly. 3456 } 3457 }, 3458 3459 /** 3460 * Pass all the arguments to the model's save method. 3461 * 3462 * Records the aggregate status of all save requests and updates the 3463 * view's classes accordingly. 3464 */ 2751 3465 save: function() { 2752 3466 var view = this, … … 2756 3470 2757 3471 // If we're waiting to remove 'Saved.', stop. 2758 if ( save.savedTimer ) 3472 if ( save.savedTimer ) { 2759 3473 clearTimeout( save.savedTimer ); 3474 } 2760 3475 2761 3476 this.updateSave('waiting'); … … 2763 3478 requests.always( function() { 2764 3479 // If we've performed another request since this one, bail. 2765 if ( save.requests !== requests ) 3480 if ( save.requests !== requests ) { 2766 3481 return; 3482 } 2767 3483 2768 3484 view.updateSave( requests.state() === 'resolved' ? 'complete' : 'error' ); … … 2772 3488 }, 2000 ); 2773 3489 }); 2774 2775 }, 2776 3490 }, 3491 /** 3492 * @param {string} status 3493 * @returns {wp.media.view.Attachment} Returns itself to allow chaining 3494 */ 2777 3495 updateSave: function( status ) { 2778 3496 var save = this._save = this._save || { status: 'ready' }; … … 2796 3514 setting, value; 2797 3515 2798 if ( ! $input.length ) 3516 if ( ! $input.length ) { 2799 3517 return; 3518 } 2800 3519 2801 3520 setting = $(el).data('setting'); … … 2803 3522 2804 3523 // Record the value if it changed. 2805 if ( model.get( setting ) !== value ) 3524 if ( model.get( setting ) !== value ) { 2806 3525 return [ setting, value ]; 3526 } 2807 3527 }).compact().object().value(); 2808 3528 2809 if ( ! _.isEmpty( changed ) ) 3529 if ( ! _.isEmpty( changed ) ) { 2810 3530 model.save( changed ); 2811 }, 2812 3531 } 3532 }, 3533 /** 3534 * @param {Object} event 3535 */ 2813 3536 removeFromLibrary: function( event ) { 2814 3537 // Stop propagation so the model isn't selected. … … 2817 3540 this.collection.remove( this.model ); 2818 3541 }, 2819 3542 /** 3543 * @param {Object} event 3544 */ 2820 3545 removeFromSelection: function( event ) { 2821 3546 var selection = this.options.selection; 2822 if ( ! selection ) 3547 if ( ! selection ) { 2823 3548 return; 3549 } 2824 3550 2825 3551 // Stop propagation so the model isn't selected. … … 2835 3561 title: '_syncTitle' 2836 3562 }, function( method, setting ) { 3563 /** 3564 * @param {Backbone.Model} model 3565 * @param {string} value 3566 * @returns {wp.media.view.Attachment} Returns itself to allow chaining 3567 */ 2837 3568 media.view.Attachment.prototype[ method ] = function( model, value ) { 2838 3569 var $setting = this.$('[data-setting="' + setting + '"]'); 2839 3570 2840 if ( ! $setting.length ) 3571 if ( ! $setting.length ) { 2841 3572 return this; 3573 } 2842 3574 2843 3575 // If the updated value is in sync with the value in the DOM, there … … 2845 3577 // it will automatically be in sync, suppressing the re-render for 2846 3578 // the view we're editing, while updating any others. 2847 if ( value === $setting.find('input, textarea, select, [value]').val() ) 3579 if ( value === $setting.find('input, textarea, select, [value]').val() ) { 2848 3580 return this; 3581 } 2849 3582 2850 3583 return this.render(); … … 2854 3587 /** 2855 3588 * wp.media.view.Attachment.Library 3589 * 3590 * @constructor 3591 * @augments wp.media.view.Attachment 3592 * @augments wp.media.View 3593 * @augments wp.Backbone.View 3594 * @augments Backbone.View 2856 3595 */ 2857 3596 media.view.Attachment.Library = media.view.Attachment.extend({ … … 2863 3602 /** 2864 3603 * wp.media.view.Attachment.EditLibrary 3604 * 3605 * @constructor 3606 * @augments wp.media.view.Attachment 3607 * @augments wp.media.View 3608 * @augments wp.Backbone.View 3609 * @augments Backbone.View 2865 3610 */ 2866 3611 media.view.Attachment.EditLibrary = media.view.Attachment.extend({ … … 2872 3617 /** 2873 3618 * wp.media.view.Attachments 3619 * 3620 * @constructor 3621 * @augments wp.media.View 3622 * @augments wp.Backbone.View 3623 * @augments Backbone.View 2874 3624 */ 2875 3625 media.view.Attachments = media.View.extend({ … … 2906 3656 delete this._viewsByCid[ attachment.cid ]; 2907 3657 2908 if ( view ) 3658 if ( view ) { 2909 3659 view.remove(); 3660 } 2910 3661 }, this ); 2911 3662 … … 2920 3671 this.model.on( 'change:edge change:gutter', this.css, this ); 2921 3672 this._resizeCss = _.debounce( _.bind( this.css, this ), this.refreshSensitivity ); 2922 if ( this.options.resize ) 3673 if ( this.options.resize ) { 2923 3674 $(window).on( 'resize.attachments', this._resizeCss ); 3675 } 2924 3676 this.css(); 2925 3677 }, … … 2928 3680 this.collection.props.off( null, null, this ); 2929 3681 $(window).off( 'resize.attachments', this._resizeCss ); 3682 /** 3683 * call 'dispose' directly on the parent class 3684 */ 2930 3685 media.View.prototype.dispose.apply( this, arguments ); 2931 3686 }, … … 2934 3689 var $css = $( '#' + this.el.id + '-css' ); 2935 3690 2936 if ( $css.length ) 3691 if ( $css.length ) { 2937 3692 $css.remove(); 3693 } 2938 3694 2939 3695 media.view.Attachments.$head().append( this.cssTemplate({ … … 2943 3699 }) ); 2944 3700 }, 2945 3701 /** 3702 * @returns {Number} 3703 */ 2946 3704 edge: function() { 2947 3705 var edge = this.model.get('edge'), 2948 3706 gutter, width, columns; 2949 3707 2950 if ( ! this.$el.is(':visible') ) 3708 if ( ! this.$el.is(':visible') ) { 2951 3709 return edge; 3710 } 2952 3711 2953 3712 gutter = this.model.get('gutter') * 2; … … 2961 3720 var collection = this.collection; 2962 3721 2963 if ( ! this.options.sortable || ! $.fn.sortable ) 3722 if ( ! this.options.sortable || ! $.fn.sortable ) { 2964 3723 return; 3724 } 2965 3725 2966 3726 this.$el.sortable( _.extend({ … … 3033 3793 }, 3034 3794 3795 /** 3796 * @param {wp.media.model.Attachment} attachment 3797 * @returns {wp.media.View} 3798 */ 3035 3799 createAttachmentView: function( attachment ) { 3036 3800 var view = new this.options.AttachmentView({ … … 3065 3829 scroll: function() { 3066 3830 // @todo: is this still necessary? 3067 if ( ! this.$el.is(':visible') ) 3831 if ( ! this.$el.is(':visible') ) { 3068 3832 return; 3833 } 3069 3834 3070 3835 if ( this.collection.hasMore() && this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) { … … 3083 3848 /** 3084 3849 * wp.media.view.Search 3850 * 3851 * @constructor 3852 * @augments wp.media.View 3853 * @augments wp.Backbone.View 3854 * @augments Backbone.View 3085 3855 */ 3086 3856 media.view.Search = media.View.extend({ … … 3100 3870 }, 3101 3871 3872 /** 3873 * @returns {wp.media.view.Search} Returns itself to allow chaining 3874 */ 3102 3875 render: function() { 3103 3876 this.el.value = this.model.escape('search'); … … 3106 3879 3107 3880 search: function( event ) { 3108 if ( event.target.value ) 3881 if ( event.target.value ) { 3109 3882 this.model.set( 'search', event.target.value ); 3110 else3883 } else { 3111 3884 this.model.unset('search'); 3885 } 3112 3886 } 3113 3887 }); … … 3115 3889 /** 3116 3890 * wp.media.view.AttachmentFilters 3891 * 3892 * @constructor 3893 * @augments wp.media.View 3894 * @augments wp.Backbone.View 3895 * @augments Backbone.View 3117 3896 */ 3118 3897 media.view.AttachmentFilters = media.View.extend({ … … 3149 3928 var filter = this.filters[ this.el.value ]; 3150 3929 3151 if ( filter ) 3930 if ( filter ) { 3152 3931 this.model.set( filter.props ); 3932 } 3153 3933 }, 3154 3934 … … 3163 3943 }); 3164 3944 3165 if ( equal ) 3945 if ( equal ) { 3166 3946 return value = id; 3947 } 3167 3948 }); 3168 3949 … … 3171 3952 }); 3172 3953 3954 /** 3955 * wp.media.view.AttachmentFilters.Uploaded 3956 * 3957 * @constructor 3958 * @augments wp.media.view.AttachmentFilters 3959 * @augments wp.media.View 3960 * @augments wp.Backbone.View 3961 * @augments Backbone.View 3962 */ 3173 3963 media.view.AttachmentFilters.Uploaded = media.view.AttachmentFilters.extend({ 3174 3964 createFilters: function() { … … 3177 3967 text; 3178 3968 3179 if ( types && type ) 3969 if ( types && type ) { 3180 3970 text = types[ type ]; 3971 } 3181 3972 3182 3973 this.filters = { … … 3204 3995 }); 3205 3996 3997 /** 3998 * wp.media.view.AttachmentFilters.All 3999 * 4000 * @constructor 4001 * @augments wp.media.view.AttachmentFilters 4002 * @augments wp.media.View 4003 * @augments wp.Backbone.View 4004 * @augments Backbone.View 4005 */ 3206 4006 media.view.AttachmentFilters.All = media.view.AttachmentFilters.extend({ 3207 4007 createFilters: function() { … … 3247 4047 3248 4048 3249 3250 4049 /** 3251 4050 * wp.media.view.AttachmentsBrowser 4051 * 4052 * @constructor 4053 * @augments wp.media.View 4054 * @augments wp.Backbone.View 4055 * @augments Backbone.View 3252 4056 */ 3253 4057 media.view.AttachmentsBrowser = media.View.extend({ … … 3270 4074 this.collection.on( 'add remove reset', this.updateContent, this ); 3271 4075 }, 3272 4076 /** 4077 * @returns {wp.media.view.AttachmentsBrowser} Returns itself to allow chaining 4078 */ 3273 4079 dispose: function() { 3274 4080 this.options.selection.off( null, null, this ); … … 3280 4086 var filters, FiltersConstructor; 3281 4087 4088 /** 4089 * @member {wp.media.view.Toolbar} 4090 */ 3282 4091 this.toolbar = new media.view.Toolbar({ 3283 4092 controller: this.controller … … 3287 4096 3288 4097 filters = this.options.filters; 3289 if ( 'uploaded' === filters ) 4098 if ( 'uploaded' === filters ) { 3290 4099 FiltersConstructor = media.view.AttachmentFilters.Uploaded; 3291 else if ( 'all' === filters )4100 } else if ( 'all' === filters ) { 3292 4101 FiltersConstructor = media.view.AttachmentFilters.All; 4102 } 3293 4103 3294 4104 if ( FiltersConstructor ) { … … 3319 4129 var view = this; 3320 4130 3321 if( ! this.attachments ) 4131 if( ! this.attachments ) { 3322 4132 this.createAttachments(); 4133 } 3323 4134 3324 4135 if ( ! this.collection.length ) { … … 3387 4198 selection.on( 'selection:unsingle', this.disposeSingle, this ); 3388 4199 3389 if ( selection.single() ) 4200 if ( selection.single() ) { 3390 4201 this.createSingle(); 4202 } 3391 4203 }, 3392 4204 … … 3428 4240 /** 3429 4241 * wp.media.view.Selection 4242 * 4243 * @constructor 4244 * @augments wp.media.View 4245 * @augments wp.Backbone.View 4246 * @augments Backbone.View 3430 4247 */ 3431 4248 media.view.Selection = media.View.extend({ … … 3445 4262 }); 3446 4263 4264 /** 4265 * @member {wp.media.view.Attachments.Selection} 4266 */ 3447 4267 this.attachments = new media.view.Attachments.Selection({ 3448 4268 controller: this.controller, … … 3466 4286 refresh: function() { 3467 4287 // If the selection hasn't been rendered, bail. 3468 if ( ! this.$el.children().length ) 4288 if ( ! this.$el.children().length ) { 3469 4289 return; 4290 } 3470 4291 3471 4292 var collection = this.collection, … … 3482 4303 edit: function( event ) { 3483 4304 event.preventDefault(); 3484 if ( this.options.editable ) 4305 if ( this.options.editable ) { 3485 4306 this.options.editable.call( this, this.collection ); 4307 } 3486 4308 }, 3487 4309 … … 3495 4317 /** 3496 4318 * wp.media.view.Attachment.Selection 4319 * 4320 * @constructor 4321 * @augments wp.media.view.Attachment 4322 * @augments wp.media.View 4323 * @augments wp.Backbone.View 4324 * @augments Backbone.View 3497 4325 */ 3498 4326 media.view.Attachment.Selection = media.view.Attachment.extend({ … … 3508 4336 /** 3509 4337 * wp.media.view.Attachments.Selection 4338 * 4339 * @constructor 4340 * @augments wp.media.view.Attachments 4341 * @augments wp.media.View 4342 * @augments wp.Backbone.View 4343 * @augments Backbone.View 3510 4344 */ 3511 4345 media.view.Attachments.Selection = media.view.Attachments.extend({ … … 3519 4353 AttachmentView: media.view.Attachment.Selection 3520 4354 }); 4355 /** 4356 * call 'initialize' directly on the parent class 4357 */ 3521 4358 return media.view.Attachments.prototype.initialize.apply( this, arguments ); 3522 4359 } … … 3525 4362 /** 3526 4363 * wp.media.view.Attachments.EditSelection 4364 * 4365 * @constructor 4366 * @augments wp.media.view.Attachment.Selection 4367 * @augments wp.media.view.Attachment 4368 * @augments wp.media.View 4369 * @augments wp.Backbone.View 4370 * @augments Backbone.View 3527 4371 */ 3528 4372 media.view.Attachment.EditSelection = media.view.Attachment.Selection.extend({ … … 3535 4379 /** 3536 4380 * wp.media.view.Settings 4381 * 4382 * @constructor 4383 * @augments wp.media.View 4384 * @augments wp.Backbone.View 4385 * @augments Backbone.View 3537 4386 */ 3538 4387 media.view.Settings = media.View.extend({ … … 3554 4403 }, this.options ); 3555 4404 }, 3556 4405 /** 4406 * @returns {wp.media.view.Setings} Returns itself to allow chaining 4407 */ 3557 4408 render: function() { 3558 4409 media.View.prototype.render.apply( this, arguments ); … … 3561 4412 return this; 3562 4413 }, 3563 4414 /** 4415 * @param {string} key 4416 */ 3564 4417 update: function( key ) { 3565 4418 var value = this.model.get( key ), … … 3568 4421 3569 4422 // Bail if we didn't find a matching setting. 3570 if ( ! $setting.length ) 4423 if ( ! $setting.length ) { 3571 4424 return; 4425 } 3572 4426 3573 4427 // Attempt to determine how the setting is rendered and update … … 3586 4440 } 3587 4441 3588 3589 4442 // Handle button groups. 3590 4443 } else if ( $setting.hasClass('button-group') ) { … … 3594 4447 // Handle text inputs and textareas. 3595 4448 } else if ( $setting.is('input[type="text"], textarea') ) { 3596 if ( ! $setting.is(':focus') ) 4449 if ( ! $setting.is(':focus') ) { 3597 4450 $setting.val( value ); 3598 4451 } 3599 4452 // Handle checkboxes. 3600 4453 } else if ( $setting.is('input[type="checkbox"]') ) { … … 3602 4455 } 3603 4456 }, 3604 4457 /** 4458 * @param {Object} event 4459 */ 3605 4460 updateHandler: function( event ) { 3606 4461 var $setting = $( event.target ).closest('[data-setting]'), … … 3610 4465 event.preventDefault(); 3611 4466 3612 if ( ! $setting.length ) 4467 if ( ! $setting.length ) { 3613 4468 return; 4469 } 3614 4470 3615 4471 // Use the correct value for checkboxes. 3616 if ( $setting.is('input[type="checkbox"]') ) 4472 if ( $setting.is('input[type="checkbox"]') ) { 3617 4473 value = $setting[0].checked; 4474 } 3618 4475 3619 4476 // Update the corresponding setting. … … 3622 4479 // If the setting has a corresponding user setting, 3623 4480 // update that as well. 3624 if ( userSetting = $setting.data('userSetting') ) 4481 if ( userSetting = $setting.data('userSetting') ) { 3625 4482 setUserSetting( userSetting, value ); 4483 } 3626 4484 }, 3627 4485 3628 4486 updateChanges: function( model ) { 3629 if ( model.hasChanged() ) 4487 if ( model.hasChanged() ) { 3630 4488 _( model.changed ).chain().keys().each( this.update, this ); 4489 } 3631 4490 } 3632 4491 }); … … 3634 4493 /** 3635 4494 * wp.media.view.Settings.AttachmentDisplay 4495 * 4496 * @constructor 4497 * @augments wp.media.view.Settings 4498 * @augments wp.media.View 4499 * @augments wp.Backbone.View 4500 * @augments Backbone.View 3636 4501 */ 3637 4502 media.view.Settings.AttachmentDisplay = media.view.Settings.extend({ … … 3645 4510 userSettings: false 3646 4511 }); 3647 4512 /** 4513 * call 'initialize' directly on the parent class 4514 */ 3648 4515 media.view.Settings.prototype.initialize.apply( this, arguments ); 3649 4516 this.model.on( 'change:link', this.updateLinkTo, this ); 3650 4517 3651 if ( attachment ) 4518 if ( attachment ) { 3652 4519 attachment.on( 'change:uploading', this.render, this ); 4520 } 3653 4521 }, 3654 4522 3655 4523 dispose: function() { 3656 4524 var attachment = this.options.attachment; 3657 if ( attachment ) 4525 if ( attachment ) { 3658 4526 attachment.off( null, null, this ); 3659 4527 } 4528 /** 4529 * call 'dispose' directly on the parent class 4530 */ 3660 4531 media.view.Settings.prototype.dispose.apply( this, arguments ); 3661 4532 }, 3662 4533 /** 4534 * @returns {wp.media.view.AttachmentDisplay} Returns itself to allow chaining 4535 */ 3663 4536 render: function() { 3664 4537 var attachment = this.options.attachment; … … 3669 4542 }); 3670 4543 } 3671 4544 /** 4545 * call 'render' directly on the parent class 4546 */ 3672 4547 media.view.Settings.prototype.render.call( this ); 3673 4548 this.updateLinkTo(); … … 3700 4575 3701 4576 // If the input is visible, focus and select its contents. 3702 if ( $input.is(':visible') ) 4577 if ( $input.is(':visible') ) { 3703 4578 $input.focus()[0].select(); 4579 } 3704 4580 } 3705 4581 }); … … 3707 4583 /** 3708 4584 * wp.media.view.Settings.Gallery 4585 * 4586 * @constructor 4587 * @augments wp.media.view.Settings 4588 * @augments wp.media.View 4589 * @augments wp.Backbone.View 4590 * @augments Backbone.View 3709 4591 */ 3710 4592 media.view.Settings.Gallery = media.view.Settings.extend({ … … 3715 4597 /** 3716 4598 * wp.media.view.Attachment.Details 4599 * 4600 * @constructor 4601 * @augments wp.media.view.Attachment 4602 * @augments wp.media.View 4603 * @augments wp.Backbone.View 4604 * @augments Backbone.View 3717 4605 */ 3718 4606 media.view.Attachment.Details = media.view.Attachment.extend({ … … 3732 4620 3733 4621 initialize: function() { 4622 /** 4623 * @member {wp.media.view.FocusManager} 4624 */ 3734 4625 this.focusManager = new media.view.FocusManager({ 3735 4626 el: this.el 3736 4627 }); 3737 4628 /** 4629 * call 'initialize' directly on the parent class 4630 */ 3738 4631 media.view.Attachment.prototype.initialize.apply( this, arguments ); 3739 4632 }, 3740 4633 /** 4634 * @returns {wp.media.view..Attachment.Details} Returns itself to allow chaining 4635 */ 3741 4636 render: function() { 4637 /** 4638 * call 'render' directly on the parent class 4639 */ 3742 4640 media.view.Attachment.prototype.render.apply( this, arguments ); 3743 4641 this.focusManager.focus(); 3744 4642 return this; 3745 4643 }, 3746 4644 /** 4645 * @param {Object} event 4646 */ 3747 4647 deleteAttachment: function( event ) { 3748 4648 event.preventDefault(); 3749 4649 3750 if ( confirm( l10n.warnDelete ) ) 4650 if ( confirm( l10n.warnDelete ) ) { 3751 4651 this.model.destroy(); 4652 } 3752 4653 }, 3753 4654 … … 3755 4656 this.$el.addClass('needs-refresh'); 3756 4657 }, 3757 4658 /** 4659 * @param {Object} event 4660 */ 3758 4661 refreshAttachment: function( event ) { 3759 4662 this.$el.removeClass('needs-refresh'); … … 3765 4668 /** 3766 4669 * wp.media.view.AttachmentCompat 4670 * 4671 * @constructor 4672 * @augments wp.media.View 4673 * @augments wp.Backbone.View 4674 * @augments Backbone.View 3767 4675 */ 3768 4676 media.view.AttachmentCompat = media.View.extend({ … … 3778 4686 3779 4687 initialize: function() { 4688 /** 4689 * @member {wp.media.view.FocusManager} 4690 */ 3780 4691 this.focusManager = new media.view.FocusManager({ 3781 4692 el: this.el … … 3784 4695 this.model.on( 'change:compat', this.render, this ); 3785 4696 }, 3786 4697 /** 4698 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining 4699 */ 3787 4700 dispose: function() { 3788 if ( this.$(':focus').length ) 4701 if ( this.$(':focus').length ) { 3789 4702 this.save(); 3790 4703 } 4704 /** 4705 * call 'dispose' directly on the parent class 4706 */ 3791 4707 return media.View.prototype.dispose.apply( this, arguments ); 3792 4708 }, 3793 4709 /** 4710 * @returns {wp.media.view.AttachmentCompat} Returns itself to allow chaining 4711 */ 3794 4712 render: function() { 3795 4713 var compat = this.model.get('compat'); 3796 if ( ! compat || ! compat.item ) 4714 if ( ! compat || ! compat.item ) { 3797 4715 return; 4716 } 3798 4717 3799 4718 this.views.detach(); … … 3804 4723 return this; 3805 4724 }, 3806 4725 /** 4726 * @param {Object} event 4727 */ 3807 4728 preventDefault: function( event ) { 3808 4729 event.preventDefault(); 3809 4730 }, 3810 4731 /** 4732 * @param {Object} event 4733 */ 3811 4734 save: function( event ) { 3812 4735 var data = {}; 3813 4736 3814 if ( event ) 4737 if ( event ) { 3815 4738 event.preventDefault(); 4739 } 3816 4740 3817 4741 _.each( this.$el.serializeArray(), function( pair ) { … … 3825 4749 /** 3826 4750 * wp.media.view.Iframe 4751 * 4752 * @constructor 4753 * @augments wp.media.View 4754 * @augments wp.Backbone.View 4755 * @augments Backbone.View 3827 4756 */ 3828 4757 media.view.Iframe = media.View.extend({ 3829 4758 className: 'media-iframe', 3830 4759 /** 4760 * @returns {wp.media.view.Iframe} Returns itself to allow chaining 4761 */ 3831 4762 render: function() { 3832 4763 this.views.detach(); … … 3839 4770 /** 3840 4771 * wp.media.view.Embed 4772 * 4773 * @constructor 4774 * @augments wp.media.View 4775 * @augments wp.Backbone.View 4776 * @augments Backbone.View 3841 4777 */ 3842 4778 media.view.Embed = media.View.extend({ … … 3844 4780 3845 4781 initialize: function() { 4782 /** 4783 * @member {wp.media.view.EmbedUrl} 4784 */ 3846 4785 this.url = new media.view.EmbedUrl({ 3847 4786 controller: this.controller, … … 3855 4794 }, 3856 4795 4796 /** 4797 * @param {Object} view 4798 */ 3857 4799 settings: function( view ) { 3858 if ( this._settings ) 4800 if ( this._settings ) { 3859 4801 this._settings.remove(); 4802 } 3860 4803 this._settings = view; 3861 4804 this.views.add( view ); … … 3866 4809 constructor; 3867 4810 3868 if ( 'image' === type ) 4811 if ( 'image' === type ) { 3869 4812 constructor = media.view.EmbedImage; 3870 else if ( 'link' === type )4813 } else if ( 'link' === type ) { 3871 4814 constructor = media.view.EmbedLink; 3872 else4815 } else { 3873 4816 return; 4817 } 3874 4818 3875 4819 this.settings( new constructor({ … … 3887 4831 /** 3888 4832 * wp.media.view.EmbedUrl 4833 * 4834 * @constructor 4835 * @augments wp.media.View 4836 * @augments wp.Backbone.View 4837 * @augments Backbone.View 3889 4838 */ 3890 4839 media.view.EmbedUrl = media.View.extend({ … … 3907 4856 this.model.on( 'change:url', this.render, this ); 3908 4857 }, 3909 4858 /** 4859 * @returns {wp.media.view.EmbedUrl} Returns itself to allow chaining 4860 */ 3910 4861 render: function() { 3911 4862 var $input = this.$input; 3912 4863 3913 if ( $input.is(':focus') ) 4864 if ( $input.is(':focus') ) { 3914 4865 return; 4866 } 3915 4867 3916 4868 this.input.value = this.model.get('url') || 'http://'; 4869 /** 4870 * Call `render` directly on parent class with passed arguments 4871 */ 3917 4872 media.View.prototype.render.apply( this, arguments ); 3918 4873 return this; … … 3927 4882 }, 3928 4883 4884 /** 4885 * If the input is visible, focus and select its contents. 4886 */ 3929 4887 focus: function() { 3930 4888 var $input = this.$input; 3931 // If the input is visible, focus and select its contents. 3932 if ( $input.is(':visible') ) 4889 if ( $input.is(':visible') ) { 3933 4890 $input.focus()[0].select(); 4891 } 3934 4892 } 3935 4893 }); … … 3937 4895 /** 3938 4896 * wp.media.view.EmbedLink 4897 * 4898 * @constructor 4899 * @augments wp.media.view.Settings 4900 * @augments wp.media.View 4901 * @augments wp.Backbone.View 4902 * @augments Backbone.View 3939 4903 */ 3940 4904 media.view.EmbedLink = media.view.Settings.extend({ … … 3945 4909 /** 3946 4910 * wp.media.view.EmbedImage 4911 * 4912 * @contructor 4913 * @augments wp.media.view.Settings.AttachmentDisplay 4914 * @augments wp.media.view.Settings 4915 * @augments wp.media.View 4916 * @augments wp.Backbone.View 4917 * @augments Backbone.View 3947 4918 */ 3948 4919 media.view.EmbedImage = media.view.Settings.AttachmentDisplay.extend({ … … 3951 4922 3952 4923 initialize: function() { 4924 /** 4925 * Call `initialize` directly on parent class with passed arguments 4926 */ 3953 4927 media.view.Settings.AttachmentDisplay.prototype.initialize.apply( this, arguments ); 3954 4928 this.model.on( 'change:url', this.updateImage, this );
Note: See TracChangeset
for help on using the changeset viewer.