Make WordPress Core

Ticket #39239: 39239.diff

File 39239.diff, 3.1 KB (added by bradyvercher, 8 years ago)
  • src/wp-includes/js/wp-custom-header.js

     
    11/* global YT */
    22(function( window, settings ) {
    33
    4         var NativeHandler, YouTubeHandler;
     4        var NativeHandler, YouTubeHandler,
     5                storage = {};
    56
    67        window.wp = window.wp || {};
    78
     
    4950                 * until one is found that can handle the video.
    5051                 */
    5152                initialize: function() {
     53                        settings.autoplay = 'no' !== storage['wp-custom-header-video-autoplay'];
     54
    5255                        if ( this.supportsVideo() ) {
    5356                                for ( var id in this.handlers ) {
    5457                                        var handler = this.handlers[ id ];
     
    130133                                if ( 'a11y' in window.wp ) {
    131134                                        window.wp.a11y.speak( settings.l10n.playSpeak);
    132135                                }
     136                                storage['wp-custom-header-video-autoplay'] = 'yes';
    133137                        });
    134138
    135139                        this.container.addEventListener( 'pause', function() {
     
    138142                                if ( 'a11y' in window.wp ) {
    139143                                        window.wp.a11y.speak( settings.l10n.pauseSpeak);
    140144                                }
     145                                storage['wp-custom-header-video-autoplay'] = 'no';
    141146                        });
    142147
    143148                        this.ready();
     
    274279                                video = document.createElement( 'video' );
    275280
    276281                        video.id = 'wp-custom-header-video';
    277                         video.autoplay = 'autoplay';
    278282                        video.loop = 'loop';
    279283                        video.muted = 'muted';
    280284                        video.width = this.settings.width;
    281285                        video.height = this.settings.height;
    282286
     287                        if ( this.settings.autoplay ) {
     288                                video.autoplay = 'autoplay';
     289                        }
     290
    283291                        video.addEventListener( 'play', function() {
    284292                                handler.trigger( 'play' );
    285293                        });
     
    327335         * @class YouTubeHandler
    328336         */
    329337        YouTubeHandler = BaseHandler.extend({
     338                playerVars: {
     339                        autoplay: 1,
     340                        controls: 0,
     341                        disablekb: 1,
     342                        fs: 0,
     343                        iv_load_policy: 3,
     344                        loop: 1,
     345                        modestbranding: 1,
     346                        playsinline: 1,
     347                        rel: 0,
     348                        showinfo: 0
     349                },
     350
    330351                /**
    331352                 * Whether the handler supports a video.
    332353                 *
     
    370391                        video.id = 'wp-custom-header-video';
    371392                        handler.setVideo( video );
    372393
     394                        handler.playerVars.autoplay = this.settings.autoplay;
     395
    373396                        handler.player = new YT.Player( video, {
    374397                                height: this.settings.height,
    375398                                width: this.settings.width,
     
    389412                                                }
    390413                                        }
    391414                                },
    392                                 playerVars: {
    393                                         autoplay: 1,
    394                                         controls: 0,
    395                                         disablekb: 1,
    396                                         fs: 0,
    397                                         iv_load_policy: 3,
    398                                         loop: 1,
    399                                         modestbranding: 1,
    400                                         playsinline: 1,
    401                                         rel: 0,
    402                                         showinfo: 0
    403                                 }
     415                                playerVars: handler.playerVars
    404416                        });
    405417                },
    406418
     
    428440                }
    429441        });
    430442
     443        /**
     444         * Whether local storage is avaialble.
     445         *
     446         * @return {boolean}
     447         */
     448        function checkStorage() {
     449                var key = 'wp-custom-header';
     450                try {
     451                        window.localStorage.setItem( key, key );
     452                        window.localStorage.removeItem( key );
     453                        return true;
     454                } catch( e ) {
     455                        return false;
     456                }
     457        }
     458
     459        if ( checkStorage() ) {
     460                storage = window.localStorage;
     461        }
     462
    431463        // Initialize the custom header when the DOM is ready.
    432464        window.wp.customHeader = new CustomHeader();
    433465        document.addEventListener( 'DOMContentLoaded', window.wp.customHeader.initialize.bind( window.wp.customHeader ), false );