1/* global JSV:[] */ 2class JsvInstance { 3 constructor(node) { 4 this.data = this.getData(node); 5 this.mainHolderId = this.getMainHolderId(node); 6 this.mainImageId = this.getMainImageId(node); 7 if (window.JavascriptViewer !== undefined) { 8 this.jsv = new JavascriptViewer(this.data); 9 this.jsv.start() 10 .then() 11 .catch((reason => console.warn(reason))); 12 } else { 13 console.warn('JavascriptViewer is not loaded'); 14 } 15 } 16 17 destroy() { 18 if (this.jsv) { 19 this.jsv.destroy(); 20 } 21 } 22 23 getMainImageId(node) { 24 return node.getElementsByTagName('img')[0].id; 25 } 26 27 getMainHolderId(node) { 28 return node.id; 29 } 30 31 deepen(obj) { 32 const result = {}; 33 34 // For each object path (property key) in the object 35 for (const objectPath in obj) { 36 // Split path into component parts 37 const parts = objectPath.split('_'); 38 39 // Create sub-objects along path as needed 40 let target = result; 41 while (parts.length > 1) { 42 const part = parts.shift(); 43 target = target[this.camelCase(part)] = target[part] || {}; 44 } 45 46 // Set value at end of path 47 target[this.camelCase(parts[0])] = obj[objectPath] 48 } 49 50 return result; 51 } 52 53 camelCase(str) { 54 const delimiters = '-'; 55 const DEFAULT_REGEX = /[-_]+(.)?/g; 56 57 const toUpper = (match, group1) => { 58 return group1 ? group1.toUpperCase() : ''; 59 } 60 return str.replace(delimiters ? 61 new RegExp('[' + delimiters + ']+(.)?', 'g') : 62 DEFAULT_REGEX, toUpper); 63 }; 64 65 getData(node) { 66 let data = {}; 67 68 [].forEach.call(node.attributes, (attr) => { 69 if (/^data-/.test(attr.name)) { 70 let val = parseInt(attr.value) || attr.value; 71 val = val.toString().length === attr.value.length ? val : attr.value; 72 if (typeof val === 'string' && (val.toLowerCase() === 'true' || val.toLowerCase() === 'false')) { 73 val = val.toLowerCase() === 'true' 74 } 75 76 data[this.camelCase(attr.name.substr(5), '-')] = val; 77 78 } 79 }); 80 81 return this.deepen(data); 82 } 83} 84 85// Initialize the container for referencing the viewer. 86window.JSV = { 87 items: [], 88 errors: [] 89}; 90 91// Search for presentations. 92window.addEventListener('load', () => { 93 const nodes = document.getElementsByClassName('jsv-holder'); 94 for (let index = 0; index < nodes.length; ++index) { 95 const parent = nodes[index].parentElement; 96 if (!parent.classList.contains("360-viewer-ignore")) { 97 window.JSV.items.push(new JsvInstance(nodes[index])); 98 } 99 } 100});
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.