|
1193 | 1193 | media.controller.MediaLibrary = media.controller.Library.extend({ |
1194 | 1194 | defaults: _.defaults({ |
1195 | 1195 | filterable: 'uploaded', |
1196 | | - multiple: false, |
1197 | 1196 | priority: 80, |
1198 | 1197 | syncSelection: false, |
1199 | | - displaySettings: true |
| 1198 | + displaySettings: false |
1200 | 1199 | }, media.controller.Library.prototype.defaults ), |
1201 | 1200 |
|
1202 | 1201 | initialize: function( options ) { |
1203 | | - var library, comparator; |
1204 | | - |
1205 | 1202 | this.media = options.media; |
1206 | 1203 | this.set( 'library', media.query({ type: options.type }) ); |
1207 | 1204 |
|
1208 | 1205 | media.controller.Library.prototype.initialize.apply( this, arguments ); |
1209 | | - |
1210 | | - library = this.get('library'); |
1211 | | - comparator = library.comparator; |
1212 | | - |
1213 | | - // Overload the library's comparator to push items that are not in |
1214 | | - // the mirrored query to the front of the aggregate collection. |
1215 | | - library.comparator = function( a, b ) { |
1216 | | - var aInQuery = !! this.mirroring.get( a.cid ), |
1217 | | - bInQuery = !! this.mirroring.get( b.cid ); |
1218 | | - |
1219 | | - if ( ! aInQuery && bInQuery ) { |
1220 | | - return -1; |
1221 | | - } else if ( aInQuery && ! bInQuery ) { |
1222 | | - return 1; |
1223 | | - } else { |
1224 | | - return comparator.apply( this, arguments ); |
1225 | | - } |
1226 | | - }; |
1227 | | - |
1228 | | - // Add all items in the selection to the library, so any featured |
1229 | | - // images that are not initially loaded still appear. |
1230 | | - library.observe( this.get('selection') ); |
1231 | 1206 | } |
1232 | 1207 | }); |
1233 | 1208 |
|
|
2952 | 2927 | this.on( 'toolbar:render:replace-video', this.renderReplaceToolbar, this ); |
2953 | 2928 | this.on( 'toolbar:render:add-video-source', this.renderAddSourceToolbar, this ); |
2954 | 2929 | this.on( 'toolbar:render:select-poster-image', this.renderSelectPosterImageToolbar, this ); |
| 2930 | + this.on( 'toolbar:render:add-track', this.renderAddTrackToolbar, this ); |
2955 | 2931 | }, |
2956 | 2932 |
|
2957 | 2933 | createStates: function() { |
|
2987 | 2963 | toolbar: 'select-poster-image', |
2988 | 2964 | media: this.media, |
2989 | 2965 | menu: 'video-details' |
| 2966 | + } ), |
| 2967 | + |
| 2968 | + new media.controller.MediaLibrary( { |
| 2969 | + type: 'text', |
| 2970 | + id: 'add-track', |
| 2971 | + title: l10n.videoAddTrackTitle, |
| 2972 | + toolbar: 'add-track', |
| 2973 | + media: this.media, |
| 2974 | + menu: 'video-details' |
2990 | 2975 | } ) |
2991 | 2976 | ]); |
2992 | 2977 | }, |
|
3010 | 2995 |
|
3011 | 2996 | state.trigger( 'set-poster-image', controller.media.toJSON() ); |
3012 | 2997 |
|
| 2998 | + // Restore and reset the default state. |
| 2999 | + controller.setState( controller.options.state ); |
| 3000 | + controller.reset(); |
| 3001 | + } |
| 3002 | + } |
| 3003 | + } |
| 3004 | + }) ); |
| 3005 | + }, |
| 3006 | + |
| 3007 | + renderAddTrackToolbar: function() { |
| 3008 | + this.toolbar.set( new media.view.Toolbar({ |
| 3009 | + controller: this, |
| 3010 | + items: { |
| 3011 | + replace: { |
| 3012 | + style: 'primary', |
| 3013 | + text: l10n.videoAddTrackTitle, |
| 3014 | + priority: 80, |
| 3015 | + |
| 3016 | + click: function() { |
| 3017 | + var controller = this.controller, |
| 3018 | + state = controller.state(), |
| 3019 | + selection = state.get( 'selection' ), |
| 3020 | + attachment = selection.single(), |
| 3021 | + content = controller.media.get( 'content' ); |
| 3022 | + |
| 3023 | + if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) { |
| 3024 | + content += [ |
| 3025 | + '<track srclang="en" label="English"kind="subtitles" src="', |
| 3026 | + attachment.get( 'url' ), |
| 3027 | + '" />' |
| 3028 | + ].join(''); |
| 3029 | + |
| 3030 | + controller.media.set( 'content', content ); |
| 3031 | + } |
| 3032 | + |
| 3033 | + state.trigger( 'add-track', controller.media.toJSON() ); |
| 3034 | + |
3013 | 3035 | // Restore and reset the default state. |
3014 | 3036 | controller.setState( controller.options.state ); |
3015 | 3037 | controller.reset(); |
|
6366 | 6388 | this.on( 'media:setting:remove', this.render ); |
6367 | 6389 | this.on( 'media:setting:remove', this.setPlayer ); |
6368 | 6390 | this.events = _.extend( this.events, { |
6369 | | - 'click .remove-setting' : 'removeSetting' |
| 6391 | + 'click .remove-setting' : 'removeSetting', |
| 6392 | + 'change .content-track' : 'setTracks', |
| 6393 | + 'click .remove-track' : 'setTracks' |
6370 | 6394 | } ); |
6371 | 6395 |
|
6372 | 6396 | media.view.Settings.AttachmentDisplay.prototype.initialize.apply( this, arguments ); |
6373 | 6397 | }, |
6374 | 6398 |
|
6375 | 6399 | prepare: function() { |
6376 | | - var attachment = false; |
6377 | | - |
6378 | | - if ( this.model.attachment ) { |
6379 | | - attachment = this.model.attachment.toJSON(); |
6380 | | - } |
6381 | 6400 | return _.defaults({ |
6382 | | - model: this.model.toJSON(), |
6383 | | - attachment: attachment |
| 6401 | + model: this.model.toJSON() |
6384 | 6402 | }, this.options ); |
6385 | 6403 | }, |
6386 | 6404 |
|
|
6404 | 6422 | }, |
6405 | 6423 |
|
6406 | 6424 | removeSetting : function (e) { |
6407 | | - var setting = $( e.currentTarget ).parent(); |
| 6425 | + var wrap = $( e.currentTarget ).parent(), setting; |
| 6426 | + |
| 6427 | + setting = wrap.find( 'input' ).data( 'setting' ); |
| 6428 | + |
| 6429 | + if ( setting ) { |
| 6430 | + this.model.unset( setting ); |
| 6431 | + this.trigger( 'media:setting:remove', this ); |
| 6432 | + } |
| 6433 | + |
| 6434 | + wrap.remove(); |
| 6435 | + }, |
6408 | 6436 |
|
6409 | | - this.model.unset( setting.find( 'input' ).data( 'setting' ) ); |
| 6437 | + setTracks : function () { |
| 6438 | + var tracks = ''; |
6410 | 6439 |
|
6411 | | - setting.remove(); |
| 6440 | + _.each( this.$('.content-track'), function (track) { |
| 6441 | + tracks += $( track ).val(); |
| 6442 | + } ); |
6412 | 6443 |
|
| 6444 | + this.model.set( 'content', tracks ); |
6413 | 6445 | this.trigger( 'media:setting:remove', this ); |
6414 | 6446 | }, |
6415 | 6447 |
|
|
0 commit comments