1/** 2 * TMBI Video Utils. 3 * 4 * Common utility functions used by video player scripts. 5 * 6 * @package pup-video 7 */ 8 9/* global jQuery */ 10var tmbi_video_utils = (function () { 11 /** 12 * This function is used to check the portion of a video is in the current viewport. 13 * 14 * @param {HTMLElement|jQuery} video Video to get in view percentage for. 15 * @returns {number|*} 16 */ 17 var isAnyPartInViewport = function ( video ) { 18 // Make sure video is a jQuery object. 19 video = jQuery( video ); 20 21 var x = video.offset().left; 22 var y = video.offset().top; 23 var w = video.width(); 24 var h = video.height(); 25 var xw = x + w; 26 var yh = y + h; 27 var visibleX, visibleY, visible; 28 29 visibleX = Math.max( 0, Math.min( w, window.pageXOffset + window.innerWidth - x, xw - window.pageXOffset ) ); 30 visibleY = Math.max( 0, Math.min( h, window.pageYOffset + window.innerHeight - y, yh - window.pageYOffset ) ); 31 32 visible = visibleX * visibleY / (w * h); 33 return visible; 34 }; 35 36 /** 37 * Get the value of a query parameter from a URL. 38 * 39 * @param {string} url URL. 40 * @param {string} param Parameter name. 41 * 42 * @return {string} 43 */ 44 function getUrlParameter( url, param ) { 45 var match = url.match( new RegExp( '[?&]' + param + '=([^&]+)' ) ); 46 47 if ( match ) { 48 return match[1]; 49 } 50 51 return ''; 52 } 53 54 return { 55 isAnyPartInViewport: isAnyPartInViewport, 56 mobileWidth: 768, 57 viewportWidth: Math.max( document.documentElement.clientWidth, window.innerWidth || 0 ), 58 getUrlParameter: getUrlParameter, 59 }; 60})();
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.