Ticket #38678: 38678.yt.diff
| File 38678.yt.diff, 3.3 KB (added by , 10 years ago) |
|---|
-
src/wp-content/themes/twentyseventeen/style.css
4141 4141 padding: 0; 4142 4142 } 4143 4143 } 4144 4145 /* For testing purposes. */ 4146 .wp-custom-header-video-button { 4147 background: red; 4148 position: relative; 4149 } -
src/wp-includes/js/wp-custom-header.js
61 61 } 62 62 63 63 function nativeHandler( settings ) { 64 var video = document.createElement( 'video' ); 64 var video = document.createElement( 'video' ), 65 button = document.createElement( 'button' ); 65 66 66 67 video.id = 'wp-custom-header-video'; 67 68 video.autoplay = 'autoplay'; … … 70 71 video.width = settings.width; 71 72 video.height = settings.height; 72 73 73 video.addEventListener( 'click', function() { 74 button.setAttribute( 'type', 'button' ); 75 button.setAttribute( 'id', 'wp-custom-header-video-button' ); 76 button.setAttribute( 'class', 'wp-custom-header-video-button' ); 77 button.setAttribute( 'aria-hidden', true ); 78 button.innerHTML = 'Pause'; 79 80 button.addEventListener( 'click', function() { 74 81 if ( video.paused ) { 82 button.innerHTML = 'Pause'; 75 83 video.play(); 76 84 } else { 85 button.innerHTML = 'Play'; 77 86 video.pause(); 78 87 } 79 88 }); … … 80 89 81 90 settings.container.innerHTML = ''; 82 91 settings.container.appendChild( video ); 92 settings.container.appendChild( button ); 83 93 video.src = settings.videoUrl; 84 94 } 85 95 … … 86 96 function youtubeHandler( settings ) { 87 97 // @link http://stackoverflow.com/a/27728417 88 98 var VIDEO_ID_REGEX = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/, 89 videoId = settings.videoUrl.match( VIDEO_ID_REGEX )[1]; 99 videoId = settings.videoUrl.match( VIDEO_ID_REGEX )[1], 100 button = document.createElement( 'button' ), 101 player; 90 102 91 103 function loadVideo() { 92 104 var YT = window.YT || {}; … … 97 109 settings.container.innerHTML = ''; 98 110 settings.container.appendChild( video ); 99 111 100 new YT.Player( video, {112 player = new YT.Player( video, { 101 113 height: settings.height, 102 114 width: settings.width, 103 115 videoId: videoId, … … 119 131 iv_load_policy: 3, 120 132 loop: 1, 121 133 modestbranding: 1, 122 //origin: '',123 134 playsinline: 1, 124 135 rel: 0, 125 136 showinfo: 0 126 137 } 127 138 }); 139 140 button.setAttribute( 'type', 'button' ); 141 button.setAttribute( 'id', 'wp-custom-header-video-button' ); 142 button.setAttribute( 'class', 'wp-custom-header-video-button' ); 143 button.setAttribute( 'aria-hidden', true ); 144 button.innerHTML = 'Pause'; 145 146 button.addEventListener( 'click', function() { 147 var playbackStatus = player.getPlayerState(); 148 // The YT API returns 1 for playing and 2 for paused. 149 if ( 2 === playbackStatus ) { 150 button.innerHTML = 'Pause'; 151 player.playVideo(); 152 } else { 153 button.innerHTML = 'Play'; 154 player.pauseVideo(); 155 } 128 156 }); 157 158 settings.container.appendChild( button ); 159 }); 129 160 } 130 161 131 162 if ( 'YT' in window ) {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)