Changeset 27655
- Timestamp:
- 03/22/2014 11:25:08 PM (10 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media-audiovideo.js
r27643 r27655 1 1 /* global _wpMediaViewsL10n, _wpmejsSettings, MediaElementPlayer, tinymce, WPPlaylistView */ 2 2 3 (function ($, _, Backbone) { 4 var media = wp.media, l10n = typeof _wpMediaViewsL10n === 'undefined' ? {} : _wpMediaViewsL10n; 3 (function($, _, Backbone) { 4 var media = wp.media, 5 baseSettings = {}, 6 l10n = typeof _wpMediaViewsL10n === 'undefined' ? {} : _wpMediaViewsL10n; 7 8 if ( ! _.isUndefined( window._wpmejsSettings ) ) { 9 baseSettings.pluginPath = _wpmejsSettings.pluginPath; 10 } 5 11 6 12 /** … … 12 18 * Pauses every instance of MediaElementPlayer 13 19 */ 14 pauseAllPlayers: function 20 pauseAllPlayers: function() { 15 21 var p; 16 22 if ( window.mejs && window.mejs.players ) { … … 25 31 */ 26 32 ua: { 27 is : function (browser) {33 is : function( browser ) { 28 34 var passes = false, ua = window.navigator.userAgent; 29 35 … … 45 51 break; 46 52 case 'chrome': 47 passes = ua.match(/safari/gi) && ua.match(/chrome/gi) !== null;53 passes = ua.match(/safari/gi) !== null && ua.match(/chrome/gi) !== null; 48 54 break; 49 55 } … … 86 92 * @returns {Boolean} 87 93 */ 88 isCompatible: function 94 isCompatible: function( media ) { 89 95 if ( ! media.find( 'source' ).length ) { 90 96 return false; … … 99 105 sources = media.find( 'source' ); 100 106 101 _.find( this.compat, function (supports, browser) {107 _.find( this.compat, function( supports, browser ) { 102 108 if ( ua.is( browser ) ) { 103 109 found = true; 104 _.each( sources, function (elem) {110 _.each( sources, function( elem ) { 105 111 var audio = new RegExp( 'audio\/(' + supports.audio.join('|') + ')', 'gi' ), 106 112 video = new RegExp( 'video\/(' + supports.video.join('|') + ')', 'gi' ); … … 215 221 }, 216 222 217 edit : function (data) {223 edit : function( data ) { 218 224 var frame, shortcode = wp.shortcode.next( 'audio', data ).shortcode; 219 225 frame = wp.media({ 220 226 frame: 'audio', 221 227 state: 'audio-details', 222 metadata: _.defaults( 223 shortcode.attrs.named, 224 wp.media.audio.defaults 225 ) 228 metadata: _.defaults( shortcode.attrs.named, this.defaults ) 226 229 }); 227 230 … … 229 232 }, 230 233 231 shortcode : function (model) {234 shortcode : function( model ) { 232 235 var self = this, content; 233 236 … … 269 272 preload : 'metadata', 270 273 content : '', 271 caption : '' 272 }, 273 274 edit : function (data) { 274 caption : '', 275 width : 640, 276 height : 360 277 }, 278 279 edit : function( data ) { 275 280 var frame, 276 defaults = this.defaults,277 281 shortcode = wp.shortcode.next( 'video', data ).shortcode, 278 282 attrs; … … 284 288 frame: 'video', 285 289 state: 'video-details', 286 metadata: _.defaults( attrs, defaults )290 metadata: _.defaults( attrs, this.defaults ) 287 291 }); 288 292 … … 290 294 }, 291 295 292 shortcode : function (model) {296 shortcode : function( model ) { 293 297 var self = this, content; 294 298 … … 313 317 314 318 /** 315 * wp.media.model.PostMedia 319 * Shared model class for audio and video. Updates the model after 320 * "Add Audio|Video Source" and "Replace Audio|Video" states return 316 321 * 317 322 * @constructor 318 323 * @augments Backbone.Model 319 * */324 */ 320 325 media.model.PostMedia = Backbone.Model.extend({ 321 326 initialize: function() { … … 323 328 }, 324 329 325 setSource: function 330 setSource: function( attachment ) { 326 331 this.attachment = attachment; 327 this.extension = attachment.get( 'filename' ).split('.').pop();332 this.extension = attachment.get( 'filename' ).split('.').pop(); 328 333 329 334 if ( this.get( 'src' ) && this.extension === this.get( 'src' ).split('.').pop() ) { … … 344 349 345 350 this.unset( 'src' ); 346 _.each( _.without( wp.media.view.settings.embedExts, this.extension ), function (ext) {351 _.each( _.without( wp.media.view.settings.embedExts, this.extension ), function( ext ) { 347 352 self.unset( ext ); 348 353 } ); … … 351 356 352 357 /** 353 * wp.media.controller.AudioDetails358 * The controller for the Audio Details state 354 359 * 355 360 * @constructor … … 358 363 */ 359 364 media.controller.AudioDetails = media.controller.State.extend({ 360 defaults: _.defaults({365 defaults: { 361 366 id: 'audio-details', 362 367 toolbar: 'audio-details', … … 365 370 menu: 'audio-details', 366 371 router: false, 367 attachment: false, 368 priority: 60, 369 editing: false 370 }, media.controller.Library.prototype.defaults ), 372 priority: 60 373 }, 371 374 372 375 initialize: function( options ) { … … 377 380 378 381 /** 379 * wp.media.controller.VideoDetails382 * The controller for the Video Details state 380 383 * 381 384 * @constructor … … 384 387 */ 385 388 media.controller.VideoDetails = media.controller.State.extend({ 386 defaults: _.defaults({389 defaults: { 387 390 id: 'video-details', 388 391 toolbar: 'video-details', … … 391 394 menu: 'video-details', 392 395 router: false, 393 attachment: false, 394 priority: 60, 395 editing: false 396 }, media.controller.Library.prototype.defaults ), 396 priority: 60 397 }, 397 398 398 399 initialize: function( options ) { … … 481 482 }, 482 483 483 renderDetailsToolbar: function() {484 setPrimaryButton: function(text, handler) { 484 485 this.toolbar.set( new media.view.Toolbar({ 485 486 controller: this, 486 487 items: { 487 select: {488 button: { 488 489 style: 'primary', 489 text: l10n.update,490 text: text, 490 491 priority: 80, 491 492 click: function() { 493 var controller = this.controller, 494 state = controller.state(); 495 496 controller.close(); 497 498 state.trigger( 'update', controller.media.toJSON() ); 499 492 click: function() { 493 var controller = this.controller; 494 handler.call( this, controller, controller.state() ); 500 495 // Restore and reset the default state. 501 496 controller.setState( controller.options.state ); … … 507 502 }, 508 503 504 renderDetailsToolbar: function() { 505 this.setPrimaryButton( l10n.update, function( controller, state ) { 506 controller.close(); 507 state.trigger( 'update', controller.media.toJSON() ); 508 } ); 509 }, 510 509 511 renderReplaceToolbar: function() { 510 this.toolbar.set( new media.view.Toolbar({ 511 controller: this, 512 items: { 513 replace: { 514 style: 'primary', 515 text: l10n.replace, 516 priority: 80, 517 518 click: function() { 519 var controller = this.controller, 520 state = controller.state(), 521 selection = state.get( 'selection' ), 522 attachment = selection.single(); 523 524 controller.media.changeAttachment( attachment ); 525 526 state.trigger( 'replace', controller.media.toJSON() ); 527 528 // Restore and reset the default state. 529 controller.setState( controller.options.state ); 530 controller.reset(); 531 } 532 } 533 } 534 }) ); 512 this.setPrimaryButton( l10n.replace, function( controller, state ) { 513 var attachment = state.get( 'selection' ).single(); 514 controller.media.changeAttachment( attachment ); 515 state.trigger( 'replace', controller.media.toJSON() ); 516 } ); 535 517 }, 536 518 537 519 renderAddSourceToolbar: function() { 538 this.toolbar.set( new media.view.Toolbar({ 539 controller: this, 540 items: { 541 replace: { 542 style: 'primary', 543 text: this.addText, 544 priority: 80, 545 546 click: function() { 547 var controller = this.controller, 548 state = controller.state(), 549 selection = state.get( 'selection' ), 550 attachment = selection.single(); 551 552 controller.media.setSource( attachment ); 553 554 state.trigger( 'add-source', controller.media.toJSON() ); 555 556 // Restore and reset the default state. 557 controller.setState( controller.options.state ); 558 controller.reset(); 559 } 560 } 561 } 562 }) ); 520 this.setPrimaryButton( this.addText, function( controller, state ) { 521 var attachment = state.get( 'selection' ).single(); 522 controller.media.setSource( attachment ); 523 state.trigger( 'add-source', controller.media.toJSON() ); 524 } ); 563 525 } 564 526 }); … … 607 569 this.states.add([ 608 570 new media.controller.AudioDetails( { 609 media: this.media, 610 editable: false, 611 menu: 'audio-details' 571 media: this.media 612 572 } ), 613 573 … … 678 638 this.states.add([ 679 639 new media.controller.VideoDetails({ 680 media: this.media, 681 editable: false, 682 menu: 'video-details' 640 media: this.media 683 641 }), 684 642 … … 722 680 723 681 renderSelectPosterImageToolbar: function() { 724 this.toolbar.set( new media.view.Toolbar({ 725 controller: this, 726 items: { 727 replace: { 728 style: 'primary', 729 text: l10n.videoSelectPosterImageTitle, 730 priority: 80, 731 732 click: function() { 733 var controller = this.controller, 734 state = controller.state(), 735 selection = state.get( 'selection' ), 736 attachment = selection.single(); 737 738 controller.media.set( 'poster', attachment.get( 'url' ) ); 739 740 state.trigger( 'set-poster-image', controller.media.toJSON() ); 741 742 // Restore and reset the default state. 743 controller.setState( controller.options.state ); 744 controller.reset(); 745 } 746 } 747 } 748 }) ); 682 this.setPrimaryButton( l10n.videoSelectPosterImageTitle, function( controller, state ) { 683 var attachment = state.get( 'selection' ).single(); 684 685 controller.media.set( 'poster', attachment.get( 'url' ) ); 686 state.trigger( 'set-poster-image', controller.media.toJSON() ); 687 } ); 749 688 }, 750 689 751 690 renderAddTrackToolbar: function() { 752 this.toolbar.set( new media.view.Toolbar({ 753 controller: this, 754 items: { 755 replace: { 756 style: 'primary', 757 text: l10n.videoAddTrackTitle, 758 priority: 80, 759 760 click: function() { 761 var controller = this.controller, 762 state = controller.state(), 763 selection = state.get( 'selection' ), 764 attachment = selection.single(), 765 content = controller.media.get( 'content' ); 766 767 if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) { 768 content += [ 769 '<track srclang="en" label="English"kind="subtitles" src="', 770 attachment.get( 'url' ), 771 '" />' 772 ].join(''); 773 774 controller.media.set( 'content', content ); 775 } 776 777 state.trigger( 'add-track', controller.media.toJSON() ); 778 779 // Restore and reset the default state. 780 controller.setState( controller.options.state ); 781 controller.reset(); 782 } 783 } 784 } 785 }) ); 691 this.setPrimaryButton( l10n.videoAddTrackTitle, function( controller, state ) { 692 var attachment = state.get( 'selection' ).single(), 693 content = controller.media.get( 'content' ); 694 695 if ( -1 === content.indexOf( attachment.get( 'url' ) ) ) { 696 content += [ 697 '<track srclang="en" label="English"kind="subtitles" src="', 698 attachment.get( 'url' ), 699 '" />' 700 ].join(''); 701 702 controller.media.set( 'content', content ); 703 } 704 state.trigger( 'add-track', controller.media.toJSON() ); 705 } ); 786 706 } 787 707 }); … … 828 748 * @param {Event} e 829 749 */ 830 removeSetting : function 750 removeSetting : function(e) { 831 751 var wrap = $( e.currentTarget ).parent(), setting; 832 833 752 setting = wrap.find( 'input' ).data( 'setting' ); 834 753 … … 845 764 * @fires wp.media.view.MediaDetails#media:setting:remove 846 765 */ 847 setTracks : function 766 setTracks : function() { 848 767 var tracks = ''; 849 768 850 _.each( this.$('.content-track'), function 769 _.each( this.$('.content-track'), function(track) { 851 770 tracks += $( track ).val(); 852 771 } ); … … 859 778 * @global MediaElementPlayer 860 779 */ 861 setPlayer : function 780 setPlayer : function() { 862 781 if ( ! this.player && this.media ) { 863 782 this.player = new MediaElementPlayer( this.media, this.settings ); … … 868 787 * @abstract 869 788 */ 870 setMedia : function 789 setMedia : function() { 871 790 return this; 872 791 }, 873 792 874 success : function 793 success : function(mejs) { 875 794 var autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay; 876 795 877 796 if ( 'flash' === mejs.pluginType && autoplay ) { 878 mejs.addEventListener( 'canplay', function 797 mejs.addEventListener( 'canplay', function() { 879 798 mejs.play(); 880 799 }, false ); … … 885 804 886 805 /** 887 * @global _wpmejsSettings888 *889 806 * @returns {media.view.MediaDetails} Returns itself to allow chaining 890 807 */ 891 808 render: function() { 892 var self = this, settings = { 893 success : this.success 894 }; 895 896 if ( ! _.isUndefined( window._wpmejsSettings ) ) { 897 settings.pluginPath = _wpmejsSettings.pluginPath; 898 } 809 var self = this; 899 810 900 811 media.view.Settings.AttachmentDisplay.prototype.render.apply( this, arguments ); 901 812 setTimeout( function() { self.resetFocus(); }, 10 ); 902 813 903 this.settings = settings; 814 this.settings = _.defaults( { 815 success : this.success 816 }, baseSettings ); 904 817 905 818 return this.setMedia(); … … 915 828 * When multiple players in the DOM contain the same src, things get weird. 916 829 * 917 * @param {HTMLElement} media830 * @param {HTMLElement} elem 918 831 * @returns {HTMLElement} 919 832 */ 920 prepareSrc : function (media) {921 var i = wp.media.view.MediaDetails.instances++;922 _.each( $( media).find('source'), function (source) {833 prepareSrc : function( elem ) { 834 var i = media.view.MediaDetails.instances++; 835 _.each( $( elem ).find( 'source' ), function( source ) { 923 836 source.src = [ 924 837 source.src, … … 927 840 i 928 841 ].join(''); 929 } );930 931 return media;842 } ); 843 844 return elem; 932 845 } 933 846 }); … … 1011 924 * @returns {Object} 1012 925 */ 1013 counts : (function 926 counts : (function(settings) { 1014 927 var counts = {}; 1015 928 1016 return function 929 return function() { 1017 930 if ( ! _.isEmpty( counts ) ) { 1018 931 return counts; … … 1020 933 1021 934 var a = 0, v = 0; 1022 _.each( settings.attachmentCounts, function 935 _.each( settings.attachmentCounts, function(total, mime) { 1023 936 var type; 1024 937 if ( -1 < mime.indexOf('/') ) { … … 1051 964 * @returns {Array} 1052 965 */ 1053 states : function 966 states : function(options) { 1054 967 return [ 1055 968 new media.controller.Library({ … … 1094 1007 * @returns {Array} 1095 1008 */ 1096 videoStates : function 1009 videoStates : function(options) { 1097 1010 return [ 1098 1011 new media.controller.Library({ … … 1184 1097 data = window.decodeURIComponent( $( node ).attr('data-wpview-text') ); 1185 1098 frame = media.edit( data ); 1186 frame.on( 'close', function 1099 frame.on( 'close', function() { 1187 1100 frame.detach(); 1188 1101 } ); … … 1220 1133 * @param {HTMLElement} node 1221 1134 */ 1222 setPlayer: function 1135 setPlayer: function(e, node) { 1223 1136 // if the ready event fires on an empty node 1224 1137 if ( ! node ) { … … 1228 1141 var self = this, 1229 1142 media, 1230 settings = {},1143 firefox = this.ua.is( 'ff' ), 1231 1144 className = '.wp-' + this.shortcode.tag + '-shortcode'; 1232 1145 … … 1236 1149 1237 1150 media = $( node ).find( className ); 1238 1239 if ( ! _.isUndefined( window._wpmejsSettings ) ) {1240 settings.pluginPath = _wpmejsSettings.pluginPath;1241 }1242 1151 1243 1152 if ( ! this.isCompatible( media ) ) { … … 1250 1159 } else { 1251 1160 media.closest( '.wpview-wrap' ).removeClass( 'wont-play' ); 1252 if ( this.ua.is( 'ff' )) {1161 if ( firefox ) { 1253 1162 media.prop( 'preload', 'metadata' ); 1254 1163 } else { … … 1260 1169 1261 1170 // Thanks, Firefox! 1262 setTimeout(function () { 1263 self.player = new MediaElementPlayer( media, settings ); 1264 }, 50); 1171 if ( firefox ) { 1172 setTimeout( function() { 1173 self.player = new MediaElementPlayer( media, baseSettings ); 1174 }, 50 ); 1175 } else { 1176 this.player = new MediaElementPlayer( media, baseSettings ); 1177 } 1265 1178 }, 1266 1179 … … 1271 1184 */ 1272 1185 getHtml: function() { 1273 var attrs = this.shortcode.attrs.named; 1186 var attrs = _.defaults( 1187 this.shortcode.attrs.named, 1188 wp.media[ this.shortcode.tag ].defaults 1189 ); 1274 1190 return this.template({ model: attrs }); 1275 1191 } … … 1333 1249 * @param {HTMLElement} node 1334 1250 */ 1335 setNode: function 1251 setNode: function(e, node) { 1336 1252 this.node = node; 1337 1253 this.fetch(); … … 1354 1270 * @global tinymce.editors 1355 1271 */ 1356 setPlayer: function 1272 setPlayer: function() { 1357 1273 var p, 1358 1274 html = this.getHtml(), … … 1366 1282 if ( editor.plugins.wpview ) { 1367 1283 doc = editor.getDoc(); 1368 $( doc ).find( '[data-wpview-text="' + t + '"]' ).each(function 1284 $( doc ).find( '[data-wpview-text="' + t + '"]' ).each(function(i, elem) { 1369 1285 var node = $( elem ); 1370 1286 node.html( html ); … … 1415 1331 }; 1416 1332 1417 _.each( attachments, function (attachment) {1418 var size = {}, track = {1333 _.each( attachments, function( attachment ) { 1334 var size = {}, resize = {}, track = { 1419 1335 src : attachment.url, 1420 1336 type : attachment.mime, … … 1426 1342 1427 1343 if ( 'video' === type ) { 1428 if ( ! options.width ) {1429 options.width = attachment.width;1430 options.height = attachment.height;1431 }1432 1344 size.width = attachment.width; 1433 1345 size.height = attachment.height; 1346 if ( media.view.settings.contentWidth ) { 1347 resize.width = media.view.settings.contentWidth - 22; 1348 resize.height = Math.ceil( ( size.height * resize.width ) / size.width ); 1349 if ( ! options.width ) { 1350 options.width = resize.width; 1351 options.height = resize.height; 1352 } 1353 } else { 1354 if ( ! options.width ) { 1355 options.width = attachment.width; 1356 options.height = attachment.height; 1357 } 1358 } 1434 1359 track.dimensions = { 1435 1360 original : size, 1436 resized : size1361 resized : _.isEmpty( resize ) ? size : resize 1437 1362 }; 1438 1363 } else { … … 1484 1409 $(document.body) 1485 1410 .on( 'click', '.wp-switch-editor', wp.media.mixin.pauseAllPlayers ) 1486 .on( 'click', '.add-media-source', function 1411 .on( 'click', '.add-media-source', function() { 1487 1412 media.frame.setState('add-' + media.frame.defaults.id + '-source'); 1488 1413 } ); -
trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css
r27640 r27655 163 163 display: inline-block; 164 164 max-width: 100%; 165 } 166 167 audio { 168 visibility: hidden; 165 169 } 166 170 -
trunk/src/wp-includes/media-template.php
r27645 r27655 49 49 $video_types = wp_get_video_extensions(); 50 50 ?> 51 <# 52 var isYouTube = ! _.isEmpty( data.model.src ) && data.model.src.match(/youtube|youtu\.be/); 53 w = ! data.model.width || data.model.width > 640 ? 640 : data.model.width, 54 h = ! data.model.height ? 360 : data.model.height; 55 56 if ( data.model.width && w !== data.model.width ) { 57 h = Math.ceil( ( h * w ) / data.model.width ); 58 } 51 <# var w, h, settings = wp.media.view.settings, 52 isYouTube = ! _.isEmpty( data.model.src ) && data.model.src.match(/youtube|youtu\.be/); 53 54 if ( settings.contentWidth && data.model.width >= settings.contentWidth ) { 55 w = settings.contentWidth; 56 } else { 57 w = data.model.width; 58 } 59 60 if ( w !== data.model.width ) { 61 h = Math.ceil( ( h * w ) / data.model.width ); 62 } else { 63 h = data.model.height; 64 } 59 65 #> 60 66 <div style="max-width: 100%; width: {{ w }}px"> … … 86 92 <source src="{{ data.model.src }}" type="video/youtube" /> 87 93 <# } else { #> 88 <source src="{{ data.model.src }}" type="{{ wp.media.view.settings.embedMimes[ data.model.src.split('.').pop() ] }}" />94 <source src="{{ data.model.src }}" type="{{ settings.embedMimes[ data.model.src.split('.').pop() ] }}" /> 89 95 <# } 90 96 } #> … … 92 98 <?php foreach ( $video_types as $type ): 93 99 ?><# if ( data.model.<?php echo $type ?> ) { #> 94 <source src="{{ data.model.<?php echo $type ?> }}" type="{{ wp.media.view.settings.embedMimes[ '<?php echo $type ?>' ] }}" />100 <source src="{{ data.model.<?php echo $type ?> }}" type="{{ settings.embedMimes[ '<?php echo $type ?>' ] }}" /> 95 101 <# } #> 96 102 <?php endforeach; ?> -
trunk/src/wp-includes/media.php
r27640 r27655 1198 1198 $default_height = 360; 1199 1199 1200 $theme_width = $content_width - $outer;1201 $theme_height = round( ( $default_height * $theme_width ) / $default_width );1200 $theme_width = empty( $content_width ) ? $default_width : ( $content_width - $outer ); 1201 $theme_height = empty( $content_width ) ? $default_height : round( ( $default_height * $theme_width ) / $default_width ); 1202 1202 1203 1203 $data = compact( 'type', 'style' ); … … 1586 1586 } else { 1587 1587 // if the video is bigger than the theme 1588 if ( $width > $content_width ) {1588 if ( ! empty( $content_width ) && $width > $content_width ) { 1589 1589 $height = round( ( $height * $content_width ) / $width ); 1590 1590 $width = $content_width; … … 2382 2382 return; 2383 2383 2384 global $content_width; 2385 2384 2386 $defaults = array( 2385 2387 'post' => null, … … 2432 2434 'attachmentCounts' => wp_count_attachments(), 2433 2435 'embedExts' => $exts, 2434 'embedMimes' => $ext_mimes 2436 'embedMimes' => $ext_mimes, 2437 'contentWidth' => $content_width, 2435 2438 ); 2436 2439
Note: See TracChangeset
for help on using the changeset viewer.