Ticket #27389: 27389.6.diff
File 27389.6.diff, 11.3 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/mce-view.js
1 /* global tinymce */1 /* global tinymce, _wpmejsSettings, MediaElementPlayer */ 2 2 3 3 // Ensure the global `wp` object exists. 4 4 window.wp = window.wp || {}; … … 31 31 var html = this.getHtml(); 32 32 // Search all tinymce editor instances and update the placeholders 33 33 _.each( tinymce.editors, function( editor ) { 34 var doc ;34 var doc, self = this; 35 35 if ( editor.plugins.wpview ) { 36 36 doc = editor.getDoc(); 37 $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).html( html ); 37 $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) { 38 var node = $( elem ); 39 node.html( html ); 40 $( self ).trigger( 'ready', elem ); 41 }); 38 42 } 39 43 }, this ); 40 44 } … … 178 182 179 183 /** 180 184 * Refresh views after an update is made 181 * 185 * 182 186 * @param view {object} being refreshed 183 187 * @param text {string} textual representation of the view 184 188 */ … … 204 208 return instances[ encodedText ]; 205 209 }, 206 210 207 /** 211 /** 208 212 * render( scope ) 209 * 213 * 210 214 * Renders any view instances inside a DOM node `scope`. 211 215 * 212 216 * View instances are detected by the presence of wrapper elements. … … 302 306 303 307 }; 304 308 wp.mce.views.register( 'gallery', wp.mce.gallery ); 309 310 wp.mce.media = { 311 toView: function( content ) { 312 var match = wp.shortcode.next( this.shortcode, content ); 313 314 if ( ! match ) { 315 return; 316 } 317 318 return { 319 index: match.index, 320 content: match.content, 321 options: { 322 shortcode: match.shortcode 323 } 324 }; 325 }, 326 327 edit: function( node ) { 328 var p, 329 media = wp.media[ this.shortcode ], 330 self = this, 331 frame, data; 332 333 wp.media.mixin.pauseAllPlayers(); 334 335 data = window.decodeURIComponent( $( node ).data('wpview-text') ); 336 frame = media.edit( data ); 337 frame.on( 'close', function () { 338 frame.detach(); 339 } ); 340 frame.state( self.shortcode + '-details' ).on( 'update', function( selection ) { 341 var shortcode = wp.media[ self.shortcode ].update( selection ).string(); 342 $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) ); 343 wp.mce.views.refreshView( self, shortcode ); 344 frame.detach(); 345 } ); 346 frame.open(); 347 } 348 }; 349 350 wp.mce.media.View = wp.mce.View.extend({ 351 initialize: function( options ) { 352 this.shortcode = options.shortcode; 353 _.bindAll( this, 'setPlayer' ); 354 $(this).on( 'ready', this.setPlayer ); 355 }, 356 357 setPlayer: function (e, node) { 358 // if the ready event fires on an empty node 359 if ( ! node ) { 360 return; 361 } 362 363 var self = this, 364 media, 365 settings = {}, 366 className = '.wp-' + this.shortcode.tag + '-shortcode'; 367 368 if ( this.player ) { 369 this.unsetPlayer(); 370 } 371 372 media = $( node ).find( className ); 373 374 if ( ! _.isUndefined( window._wpmejsSettings ) ) { 375 settings.pluginPath = _wpmejsSettings.pluginPath; 376 } 377 378 if ( ! this.isCompatible( media ) ) { 379 media.closest( '.wpview-wrap' ).addClass( 'wont-play' ); 380 if ( ! media.parent().hasClass( 'wpview-wrap' ) ) { 381 media.parent().replaceWith( media ); 382 } 383 media.replaceWith( '<p>' + media.find( 'source' ).eq(0).prop( 'src' ) + '</p>' ); 384 return; 385 } else { 386 media.closest( '.wpview-wrap' ).removeClass( 'wont-play' ); 387 media.prop( 'preload', 'none' ); 388 } 389 390 media = wp.media.view.MediaDetails.prepareSrc( media.get(0) ); 391 392 // Thanks, Firefox! 393 setTimeout(function () { 394 self.player = new MediaElementPlayer( media, settings ); 395 }, 10); 396 }, 397 398 getHtml: function() { 399 var attrs = this.shortcode.attrs.named; 400 return this.template({ model: attrs }); 401 } 402 }); 403 _.extend( wp.mce.media.View.prototype, wp.media.mixin ); 404 405 wp.mce.video = _.extend( {}, wp.mce.media, { 406 shortcode: 'video', 407 View: wp.mce.media.View.extend({ 408 className: 'editor-video', 409 template: media.template('editor-video') 410 }) 411 } ); 412 413 wp.mce.views.register( 'video', wp.mce.video ); 414 415 wp.mce.audio = _.extend( {}, wp.mce.media, { 416 shortcode: 'audio', 417 View: wp.mce.media.View.extend({ 418 className: 'editor-audio', 419 template: media.template('editor-audio') 420 }) 421 } ); 422 423 wp.mce.views.register( 'audio', wp.mce.audio ); 305 424 }(jQuery)); -
src/wp-includes/js/media-editor.js
328 328 if ( isOpera ) { 329 329 opera = false; 330 330 media.find( 'source' ).each(function (i, elem) { 331 if ( elem.type.match(/video\/(og v|webm)/gi) !== null ||331 if ( elem.type.match(/video\/(ogg|webm)/gi) !== null || 332 332 ( elem.type.match(/audio\/(ogg|wav)/gi) !== null ) ) { 333 333 opera = true; 334 334 } … … 705 705 return frame; 706 706 }, 707 707 708 shortcode : function (shortcode) {709 var self = this ;708 update : function (model) { 709 var self = this, content; 710 710 711 _.each( wp.media.audio.defaults, function( value, key ) {712 shortcode[ key ] = self.coerce( shortcode, key );711 _.each( this.defaults, function( value, key ) { 712 model[ key ] = self.coerce( model, key ); 713 713 714 if ( value === shortcode[ key ] ) {715 delete shortcode[ key ];714 if ( value === model[ key ] ) { 715 delete model[ key ]; 716 716 } 717 717 }); 718 718 719 return wp.shortcode.string({ 720 tag: 'audio', 721 attrs: shortcode 719 content = model.content; 720 delete model.content; 721 722 return new wp.shortcode({ 723 tag: 'audio', 724 attrs: model, 725 content: content 722 726 }); 723 727 } 724 728 }; … … 757 761 return frame; 758 762 }, 759 763 760 shortcode : function (shortcode) {761 var self = this, content = shortcode.content;762 delete shortcode.content;764 update : function (model) { 765 var self = this, content = model.content; 766 delete model.content; 763 767 764 768 _.each( this.defaults, function( value, key ) { 765 shortcode[ key ] = self.coerce( shortcode, key );769 model[ key ] = self.coerce( model, key ); 766 770 767 if ( value === shortcode[ key ] ) {768 delete shortcode[ key ];771 if ( value === model[ key ] ) { 772 delete model[ key ]; 769 773 } 770 774 }); 771 775 772 return wp.shortcode.string({ 773 tag: 'video', 774 attrs: shortcode, 776 content = model.content; 777 delete model.content; 778 779 return new wp.shortcode({ 780 tag: 'video', 781 attrs: model, 775 782 content: content 776 783 }); 777 784 } -
src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js
25 25 } 26 26 27 27 function replaceAVShortcodes( content ) { 28 var testRegex = /\[(video-playlist| audio|video|playlist)[^\]]*\]/,29 replaceRegex = /\[(video-playlist| audio|video|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/;28 var testRegex = /\[(video-playlist|playlist)[^\]]*\]/, 29 replaceRegex = /\[(video-playlist|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/; 30 30 31 31 while ( testRegex.test( content ) ) { 32 32 content = content.replace( replaceRegex, replaceCallback ); … … 92 92 editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) ); 93 93 frame.detach(); 94 94 }); 95 } else if ( editor.dom.hasClass( node, 'wp-video' ) ) {96 frame = wp.media.video.edit( data );97 frame.on( 'close', function () {98 frame.detach();99 } );100 frame.state( 'video-details' ).on(101 'update replace add-source select-poster-image add-track',102 function ( selection ) {103 var shortcode = wp.media.video.shortcode( selection );104 editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) );105 frame.detach();106 }107 );108 frame.open();109 } else if ( editor.dom.hasClass( node, 'wp-audio' ) ) {110 frame = wp.media.audio.edit( data );111 frame.on( 'close', function () {112 frame.detach();113 } );114 frame.state( 'audio-details' ).on( 'update replace add-source', function ( selection ) {115 var shortcode = wp.media.audio.shortcode( selection );116 editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) );117 frame.detach();118 } );119 frame.open();120 95 } else { 121 96 // temp 122 97 window.console && window.console.log( 'Edit AV shortcode ' + data ); … … 177 152 if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) { 178 153 if ( dom.hasClass( node, 'wp-gallery' ) ) { 179 154 event.name = 'gallery'; 180 } else if ( dom.hasClass( node, 'wp-video' ) ) {181 event.name = 'video';182 } else if ( dom.hasClass( node, 'wp-audio' ) ) {183 event.name = 'audio';184 155 } else if ( dom.hasClass( node, 'wp-playlist' ) ) { 185 156 event.name = 'playlist'; 186 157 } else if ( dom.hasClass( node, 'wp-video-playlist' ) ) { -
src/wp-includes/js/tinymce/skins/wordpress/wp-content.css
242 242 } 243 243 244 244 /** 245 * Gallery preview245 * Media previews 246 246 */ 247 .wpview-type-gallery { 247 .wpview-type-gallery, 248 .wpview-type-audio, 249 .wpview-type-video { 248 250 position: relative; 249 251 padding: 0 0 12px; 250 252 margin-bottom: 16px; … … 251 253 cursor: pointer; 252 254 } 253 255 254 .wpview-type-gallery:after { 256 .wpview-type-audio { 257 padding: 32px 0 0; 258 } 259 260 .wpview-type-video { 261 padding: 16px 0 0; 262 } 263 264 .wont-play { 265 padding: 8px 0; 266 } 267 268 .wont-play p { 269 display: block; 270 width: 80%; 271 margin: 0 5% 0 15%; 272 } 273 274 .wpview-type-gallery:after { 255 275 content: ''; 256 276 display: block; 257 277 height: 0; … … 259 279 visibility: hidden; 260 280 } 261 281 262 .wpview-type-gallery.selected { 282 .wpview-type-gallery.selected, 283 .wpview-type-audio, 284 .wpview-type-video { 263 285 background-color: #efefef; 264 286 } 265 287 266 .wpview-type-gallery .toolbar { 288 .wpview-type-gallery .toolbar, 289 .wpview-type-audio .toolbar, 290 .wpview-type-video .toolbar { 267 291 position: absolute; 268 292 top: 0; 269 293 left: 0; … … 271 295 color: white; 272 296 padding: 4px; 273 297 display: none; 298 z-index: 100; 274 299 } 275 300 301 .wpview-type-audio .toolbar, 302 .wpview-type-video .toolbar, 276 303 .wpview-type-gallery.selected .toolbar { 277 304 display: block; 278 305 } 279 306 307 .wpview-type-audio .toolbar span, 308 .wpview-type-video .toolbar span, 280 309 .wpview-type-gallery .toolbar span { 281 310 cursor: pointer; 282 311 } -
src/wp-includes/media-template.php
927 927 <# } ); #> 928 928 </div> 929 929 </script> 930 931 <script type="text/html" id="tmpl-editor-audio"> 932 <div class="toolbar"> 933 <div class="dashicons dashicons-format-audio edit"></div> 934 <div class="dashicons dashicons-no-alt remove"></div> 935 </div> 936 <?php wp_underscore_audio_template() ?> 937 </script> 938 939 <script type="text/html" id="tmpl-editor-video"> 940 <div class="toolbar"> 941 <div class="dashicons dashicons-format-video edit"></div> 942 <div class="dashicons dashicons-no-alt remove"></div> 943 </div> 944 <?php wp_underscore_video_template() ?> 945 </script> 946 930 947 <?php 931 948 932 949 /**