1(function ($, Drupal, once) { 2 "use strict"; 3 4 Drupal.behaviors.DX8MediaElement = { 5 attach: function (context) { 6 // Ensure hidden elements do not get automatically run when in a hidden 'something' (only applicable to native HTML5 videos) 7 $.each( 8 $( 9 ".coh-video > .coh-video-inner:not(.mejs__container):hidden", 10 context 11 ), 12 function () { 13 // Handle Embeds (YouTube, Vimeo etc) 14 if ($(this)[0].player && $(this)[0].player.media) { 15 $(this)[0].player.media.pause(); 16 } 17 18 // HTML5 players 19 this.pause(); 20 } 21 ); 22 23 var elements = $('.coh-video > .coh-video-inner:not(.mejs__container)', context).filter(':visible'); 24 25 $(once("dx8-js-mediaelement-init", elements)).each(function () { 26 var $this = $(this); 27 var $videoContainer = $this.closest(".coh-video"); 28 var options = $this.data("cohVideo"); 29 var videoSrc = $this.attr("src"); 30 var videoType = mejs.Utils.getTypeFromFile(videoSrc); 31 32 options.success = function (mediaElement) { 33 // add video renderer class to video container 34 $videoContainer.addClass( 35 "coh-video-" + mediaElement.rendererN
35ame 36 ); 37 38 // hide center play button if toggled off in sidebar editor 39 if (options.showPlayCenter === false) { 40 $videoContainer.addClass( 41 "coh-video-hide-center-play" 42 ); 43 } 44 45 // ensure center play button is still clickable if `clickToPlayPause` is disabled 46 if (options.clickToPlayPause === false) { 47 $videoContainer 48 .find( 49 ".mejs__overlay-play .mejs__overlay-button" 50 ) 51 .on("click", function () { 52 mediaElement.play(); 53 }); 54 } 55 56 // add control hide class to video container if all controls toggled off in sidebar editor 57 if (!options.features.length) { 58 $videoContainer.addClass("coh-video-hide-controls"); 59 } 60 61 function playVideoHover() { 62 $videoContainer.addClass("coh-video-hover"); 63 mediaElement.play(); 64 } 65 66 function pauseVideoHover() { 67 $videoContainer.removeClass("coh-video-hover"); 68 mediaElement.pause(); 69 } 70 71 // Play video on hover if setting enabled 72 if (options.playOnHover === true) { 73 $videoContainer.on("mouseenter", playVideoHover); 74 $videoContainer.on("mouseleave", pauseVideoHover); 75 } 76 77 $("body").on("tabs-activate", function (e) { 78 //If the tab contains this media element, fire a window resize event to ensure the video fills the tab. 79 if (e.target.contains(e.target)) { 80 window.dispatchEvent(new Event("resize")); 81 } 82 }); 83 }; 84 85 // If Vimeo embed, hide mediaelement controls 86 if ( 87 videoType === "video/x-vimeo" || 88 videoType === "video/vimeo" 89 ) { 90 options.features = []; 91 options.showPlayCenter = false; 92 } 93 94 // If YouTube embed, hide mediaelement controls 95 if ( 96 videoType === "video/x-youtube" || 97 videoType === "video/youtube" 98 ) { 99 options.features = []; 100 options.showPlayCenter = false; 101 102 // If URL doesn't contain `controls=0`, show native controls 103 if (videoSrc.indexOf("controls=0") === -1) { 104 options.youtube = { 105 controls: 1, 106 }; 107 } 108 109 // If URL is a nocookie URL tell mediaelement to use nocookie domain. 110 if (videoSrc.includes("nocookie")) { 111 options.youtube = { 112 nocookie: 1, 113 }; 114 } 115 } 116 117 $this.mediaelementplayer(options); 118 }); 119 }, 120 121 detach: function (context, settings, cause) { 122 // Ensure when the video is unloaded or hidden from it is paused 123 $.each($("video", context), function () { 124 // Handle Embeds (YouTube, Vimeo etc) 125 if ($(this)[0].player && $(this)[0].player.media) { 126 $(this)[0].player.media.pause(); 127 } 128 129 // Handle native HTML5 videos 130 this.pause(); 131 }); 132 }, 133 }; 134})(jQuery, Drupal, once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.