function blazyMedia(media) {
    var t = media;
    var iframe = t.querySelector('iframe');
    var btn = t.querySelector('.media__icon--play');

    // Media player toggler is disabled, just display iframe.
    if (btn === null) {
      return;
    }

    var url = btn.getAttribute('data-url');
    var newIframe;

    /**
     * Play the media.
     *
     * @param {Event} event
     *   The event triggered by a `click` event.
     *
     * @return {bool}|{mixed}
     *   Return false if url is not available.
     */
    function play(event) {
      event.preventDefault();

      // oEmbed/ Soundcloud needs internet, fails on disconnected local.
      if (url === '') {
        return false;
      }

      var target = this;
      var player = target.parentNode;
      var playing = document.querySelector('.is-playing');
      var iframe = player.querySelector('iframe');

      url = target.getAttribute('data-url');

      // First, reset any video to avoid multiple videos from playing.
      if (playing !== null) {
        var played = document.querySelector('.is-playing iframe');
        // Remove the previous iframe.
        if (played !== null) {
          playing.removeChild(played);
        }
        playing.className = playing.className.replace(/(\S+)playing/, '');
      }

      // Appends the iframe.
      player.className += ' is-playing';

      // Remove the existing iframe on the current clicked iframe.
      if (iframe !== null) {
        player.removeChild(iframe);
      }

      // Cache iframe for the potential repeating clicks.
      if (!newIframe) {
        newIframe = document.createElement('iframe');
        newIframe.className = 'media__iframe media__element';
        newIframe.setAttribute('src', url);
        newIframe.setAttribute('allowfullscreen', true);
      }

      player.appendChild(newIframe);
    }

    /**
     * Close the media.
     *
     * @param {Event} event
     *   The event triggered by a `click` event.
     */
    function stop(event) {
      event.preventDefault();

      var target = this;
      var player = target.parentNode;
      var iframe = player.querySelector('iframe');

      if (player.className.match('is-playing')) {
        player.className = player.className.replace(/(\S+)playing/, '');
      }

      if (iframe !== null) {
        player.removeChild(iframe);
      }
    }

    // Remove iframe to avoid browser requesting them till clicked.
    // The iframe is there as Blazy supports non-lazyloaded/ non-JS iframes.
    if (iframe !== null && iframe.parentNode != null) {
      iframe.parentNode.removeChild(iframe);
    }

    // Plays the media player.
    _db.on(t, 'click', '.media__icon--play', play);

    // Closes the video.
    _db.on(t, 'click', '.media__icon--close', stop);

    t.className += ' media--player--on';
  }
/**
   * Blazy media utility functions.
   *
   * @param {HTMLElement} media
   *   The media player HTML element.
   */
Blazy media utility functions.
@param {HTMLElement} media
The media player HTML element.
Blazy media utility functions . @param { HTMLElement } media The media player HTML element .
function blazyMedia(media) {
    var t = media;
    var iframe = t.querySelector('iframe');
    var btn = t.querySelector('.media__icon--play');
    if (btn === null) {
      return;
    }
    var url = btn.getAttribute('data-url');
    var newIframe;
    function play(event) {
      event.preventDefault();
      if (url === '') {
        return false;
      }
      var target = this;
      var player = target.parentNode;
      var playing = document.querySelector('.is-playing');
      var iframe = player.querySelector('iframe');
      url = target.getAttribute('data-url');
      if (playing !== null) {
        var played = document.querySelector('.is-playing iframe');
        if (played !== null) {
          playing.removeChild(played);
        }
        playing.className = playing.className.replace(/(\S+)playing/, '');
      }
      player.className += ' is-playing';
      if (iframe !== null) {
        player.removeChild(iframe);
      }
      if (!newIframe) {
        newIframe = document.createElement('iframe');
        newIframe.className = 'media__iframe media__element';
        newIframe.setAttribute('src', url);
        newIframe.setAttribute('allowfullscreen', true);
      }
      player.appendChild(newIframe);
    }
    function stop(event) {
      event.preventDefault();
      var target = this;
      var player = target.parentNode;
      var iframe = player.querySelector('iframe');
      if (player.className.match('is-playing')) {
        player.className = player.className.replace(/(\S+)playing/, '');
      }
      if (iframe !== null) {
        player.removeChild(iframe);
      }
    }
    if (iframe !== null && iframe.parentNode != null) {
      iframe.parentNode.removeChild(iframe);
    }
    _db.on(t, 'click', '.media__icon--play', play);
    _db.on(t, 'click', '.media__icon--close', stop);
    t.className += ' media--player--on';
  }
function blazyMedia ( media ) { var t = media ; var iframe = t . querySelector ( 'iframe' ) ; var btn = t . querySelector ( '.media__icon--play' ) ; if ( btn === null ) { return ; } var url = btn . getAttribute ( 'data-url' ) ; var newIframe ; function play ( event ) { event . preventDefault ( ) ; if ( url === '' ) { return false ; } var target = this ; var player = target . parentNode ; var playing = document . querySelector ( '.is-playing' ) ; var iframe = player . querySelector ( 'iframe' ) ; url = target . getAttribute ( 'data-url' ) ; if ( playing !== null ) { var played = document . querySelector ( '.is-playing iframe' ) ; if ( played !== null ) { playing . removeChild ( played ) ; } playing . className = playing . className . replace ( / (\S+)playing / , '' ) ; } player . className += ' is-playing' ; if ( iframe !== null ) { player . removeChild ( iframe ) ; } if ( ! newIframe ) { newIframe = document . createElement ( 'iframe' ) ; newIframe . className = 'media__iframe media__element' ; newIframe . setAttribute ( 'src' , url ) ; newIframe . setAttribute ( 'allowfullscreen' , true ) ; } player . appendChild ( newIframe ) ; } function stop ( event ) { event . preventDefault ( ) ; var target = this ; var player = target . parentNode ; var iframe = player . querySelector ( 'iframe' ) ; if ( player . className . match ( 'is-playing' ) ) { player . className = player . className . replace ( / (\S+)playing / , '' ) ; } if ( iframe !== null ) { player . removeChild ( iframe ) ; } } if ( iframe !== null && iframe . parentNode != null ) { iframe . parentNode . removeChild ( iframe ) ; } _db . on ( t , 'click' , '.media__icon--play' , play ) ; _db . on ( t , 'click' , '.media__icon--close' , stop ) ; t . className += ' media--player--on' ; }
Blazy media utility functions.
Blazy media utility functions .
// Media player toggler is disabled, just display iframe. /**
     * Play the media.
     *
     * @param {Event} event
     *   The event triggered by a `click` event.
     *
     * @return {bool}|{mixed}
     *   Return false if url is not available.
     */ // oEmbed/ Soundcloud needs internet, fails on disconnected local. // First, reset any video to avoid multiple videos from playing. // Remove the previous iframe. // Appends the iframe. // Remove the existing iframe on the current clicked iframe. // Cache iframe for the potential repeating clicks. /**
     * Close the media.
     *
     * @param {Event} event
     *   The event triggered by a `click` event.
     */ // Remove iframe to avoid browser requesting them till clicked. // The iframe is there as Blazy supports non-lazyloaded/ non-JS iframes. // Plays the media player. // Closes the video.