1 2class VideoResponser { 3 constructor(selector) { 4 5 const $video =selector; 6 7 this.options = { 8 selector, 9 breakpoints: { default: { src: $video.getAttribute('data-src') } } 10 }; 11 12 // get a list of video switching points and links to the videos themselves 13 $video.querySelectorAll('[data-src]').forEach(element => this.options.breakpoints[element.getAttribute('data-mw')] = { src: element.getAttribute('data-src') }); 14 $video.innerHTML = ''; // we clean up so that there is nothing superfluous 15 16 // run the handler and track the change in screen width 17 this.responseVideo(this.options); 18 this.resizer(); 19 } 20 21 /** Function runs on resize */ 22 resizer() { 23 window.addEventListener("resize", () => this.responseVideo(this.options)); 24 } 25 26 /** 27 * Change src value of video link to fit screen width 28 * 29 * @param {Object} options object with options 30 */ 31 responseVideo(options) { 32 const {selector, breakpoints} = options; // get options 33 let $video =selector; 34 const widthNow = $video.getAttribute('data-width-now') || null; 35 //const maxBreakpoint = Math.max.apply(Math, Object.keys(breakpoints).filter(key => key >= document.body.clientWidth).map(Number)); 36 // const nowBreakpoint = maxBreakpoint || 'default'; // choose either the maximum value, if not, then the default 37 // 38 // let nowBreakpoint = 'default'; // choose either the maximum value, if not, then the default 39 40 // if (maxBreakpoint && maxBreakpoint != -Infinity) { nowBreakpoint = maxBreakpoint; } 41 42 const maxBreakpoint = Math.max.apply(Math, Object.keys(breakpoints).filter(key => key >= document.body.clientWidth).map(Number)); 43 let nowBreakpoint = maxBreakpoint; // choose either the maximum value, if not, then the default 44 if (maxBreakpoint && maxBreakpoint == -Infinity) { nowBreakpoint = 'default'; } 45 //const nowBreakpoint = maxBreakpoint || 'default'; // choose either the maximum value, if not, then the default 46 //debugger; 47 if( widthNow == nowBreakpoint) return; // check if the video needs to be changed 48 49 $video.setAttribute('data-width-now', nowBreakpoint); 50 51 $video.src = breakpoints[nowBreakpoint].src; 52 } 53} 54 55
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.