1// File#: _2_modal-video 2// Usage: codyhouse.co/license 3(function() { 4 var ModalVideo = function(element) { 5 this.element = element; 6 this.modalContent = this.element.getElementsByClassName('js-modal-video__content')[0]; 7 this.media = this.element.getElementsByClassName('js-modal-video__media')[0]; 8 this.contentIsIframe = this.media.tagName.toLowerCase() == 'iframe'; 9 this.modalIsOpen = false; 10 this.initModalVideo(); 11 }; 12 13 ModalVideo.prototype.initModalVideo = function() { 14 var self = this; 15 // reveal modal content when iframe is ready 16 this.addLoadListener(); 17 // listen for the modal element to be open -> set new iframe src attribute 18 this.element.addEventListener('modalIsOpen', function(event){ 19 self.modalIsOpen = true; 20 self.media.setAttribute('src', event.detail.closest('[aria-controls]').getAttribute('data-url')); 21 }); 22 // listen for the modal element to be close -> reset iframe and hide modal content 23 this.element.addEventListener('modalIsClose', function(event){ 24 self.modalIsOpen = false; 25 Util.addClass(self.element, 'modal--is-loading'); 26 self.media.setAttribute('src', ''); 27 }); 28 }; 29 30 ModalVideo.prototype.addLoadListener = function() { 31 var self = this; 32 if(this.contentIsIframe) { 33 this.media.onload = function () { 34 self.revealContent(); 35 }; 36 } else { 37 this.media.addEventListener('loadedmetadata', function(){ 38 self.revealContent(); 39 }); 40 } 41 42 }; 43 44 ModalVideo.prototype.revealContent = function() { 45 if( !this.modalIsOpen ) return; 46 Util.removeClass(this.element, 'modal--is-loading'); 47 this.contentIsIframe ? this.media.contentWindow.focus() : this.media.focus(); 48 }; 49 50 //initialize the ModalVideo objects 51 var modalVideos = document.getElementsByClassName('js-modal-video__media'); 52 if( modalVideos.length > 0 ) { 53 for( var i = 0; i < modalVideos.length; i++) { 54 (function(i){new ModalVideo(modalVideos[i].closest('.js-modal'));})(i); 55 } 56 } 57}());
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.