Changeset 27215
- Timestamp:
- 02/20/2014 06:33:39 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media-views.js
r27214 r27215 924 924 }; 925 925 926 /** 927 * wp.media.controller.GalleryEdit 928 * 929 * @constructor 930 * @augments wp.media.controller.Library 931 * @augments wp.media.controller.State 932 * @augments Backbone.Model 933 */ 934 media.controller.GalleryEdit = media.controller.Library.extend({ 926 // wp.media.controller.GalleryEdit 927 // ------------------------------- 928 media.controller.GalleryEdit = media.controller.CollectionEdit( 'gallery', { 929 type: 'image', 930 settings: 'Gallery', 935 931 defaults: { 936 id: 'gallery-edit', 937 multiple: false, 938 describe: true, 939 edge: 199, 940 editing: false, 941 sortable: true, 942 searchable: false, 943 toolbar: 'gallery-edit', 944 content: 'browse', 945 title: l10n.editGalleryTitle, 946 priority: 60, 947 dragInfo: true, 948 949 // Don't sync the selection, as the Edit Gallery library 950 // *is* the selection. 951 syncSelection: false 952 }, 953 954 initialize: function() { 955 // If we haven't been provided a `library`, create a `Selection`. 956 if ( ! this.get('library') ) { 957 this.set( 'library', new media.model.Selection() ); 958 } 959 960 // The single `Attachment` view to be used in the `Attachments` view. 961 if ( ! this.get('AttachmentView') ) { 962 this.set( 'AttachmentView', media.view.Attachment.EditLibrary ); 963 } 964 965 media.controller.Library.prototype.initialize.apply( this, arguments ); 966 }, 967 968 activate: function() { 969 var library = this.get('library'); 970 971 // Limit the library to images only. 972 library.props.set( 'type', 'image' ); 973 974 // Watch for uploaded attachments. 975 this.get('library').observe( wp.Uploader.queue ); 976 977 this.frame.on( 'content:render:browse', this.gallerySettings, this ); 978 979 media.controller.Library.prototype.activate.apply( this, arguments ); 980 }, 981 982 deactivate: function() { 983 // Stop watching for uploaded attachments. 984 this.get('library').unobserve( wp.Uploader.queue ); 985 986 this.frame.off( 'content:render:browse', this.gallerySettings, this ); 987 988 media.controller.Library.prototype.deactivate.apply( this, arguments ); 989 }, 990 991 /** 992 * @param {Object} browser 993 */ 994 gallerySettings: function( browser ) { 995 var library = this.get('library'); 996 997 if ( ! library || ! browser ) { 998 return; 999 } 1000 1001 library.gallery = library.gallery || new Backbone.Model(); 1002 1003 browser.sidebar.set({ 1004 gallery: new media.view.Settings.Gallery({ 1005 controller: this, 1006 model: library.gallery, 1007 priority: 40 1008 }) 1009 }); 1010 1011 browser.toolbar.set( 'reverse', { 1012 text: l10n.reverseOrder, 1013 priority: 80, 1014 1015 click: function() { 1016 library.reset( library.toArray().reverse() ); 1017 } 1018 }); 1019 } 1020 }); 1021 1022 /** 1023 * wp.media.controller.GalleryAdd 1024 * 1025 * @constructor 1026 * @augments wp.media.controller.Library 1027 * @augments wp.media.controller.State 1028 * @augments Backbone.Model 1029 */ 1030 media.controller.GalleryAdd = media.controller.Library.extend({ 1031 defaults: _.defaults({ 1032 id: 'gallery-library', 1033 filterable: 'uploaded', 1034 multiple: 'add', 1035 menu: 'gallery', 1036 toolbar: 'gallery-add', 1037 title: l10n.addToGalleryTitle, 1038 priority: 100, 1039 1040 // Don't sync the selection, as the Edit Gallery library 1041 // *is* the selection. 1042 syncSelection: false 1043 }, media.controller.Library.prototype.defaults ), 1044 1045 /** 1046 * If we haven't been provided a `library`, create a `Selection`. 1047 */ 1048 initialize: function() { 1049 if ( ! this.get('library') ) { 1050 this.set( 'library', media.query({ type: 'image' }) ); 1051 } 1052 media.controller.Library.prototype.initialize.apply( this, arguments ); 1053 }, 1054 1055 activate: function() { 1056 var library = this.get('library'), 1057 edit = this.frame.state('gallery-edit').get('library'); 1058 1059 if ( this.editLibrary && this.editLibrary !== edit ) { 1060 library.unobserve( this.editLibrary ); 1061 } 1062 1063 // Accepts attachments that exist in the original library and 1064 // that do not exist in gallery's library. 1065 library.validator = function( attachment ) { 1066 return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && 1067 media.model.Selection.prototype.validator.apply( this, arguments ); 1068 }; 1069 1070 // Reset the library to ensure that all attachments are re-added 1071 // to the collection. Do so silently, as calling `observe` will 1072 // trigger the `reset` event. 1073 library.reset( library.mirroring.models, { silent: true }); 1074 library.observe( edit ); 1075 this.editLibrary = edit; 1076 1077 media.controller.Library.prototype.activate.apply( this, arguments ); 1078 } 1079 }); 1080 932 title: l10n.editGalleryTitle 933 } 934 }); 935 936 // wp.media.controller.GalleryAdd 937 // --------------------------------- 938 media.controller.GalleryAdd = media.controller.CollectionAdd( 'gallery', { 939 type: 'image', 940 defaults: { 941 title: l10n.addToGalleryTitle 942 } 943 }); 1081 944 /** 1082 945 * wp.media.controller.FeaturedImage
Note: See TracChangeset
for help on using the changeset viewer.