-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvmap-js-node.js
1 lines (1 loc) · 3.23 KB
/
vmap-js-node.js
1
"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var a=0;a<e.length;a++){var n=e[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,a,n){return a&&e(t.prototype,a),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var n=a((function e(a){for(var n in t(this,e),this.id=a.getAttribute("id"),this.allowMultipleAds=a.getAttribute("allowMultipleAds"),this.followRedirects=a.getAttribute("followRedirects"),this.vastAdData=null,this.adTagURI=null,this.customData=null,a.childNodes){var i=a.childNodes[n];switch(i.localName){case"AdTagURI":this.adTagURI={templateType:i.getAttribute("templateType"),uri:(i.textContent||i.text||"").trim()};break;case"VASTAdData":for(this.vastAdData=i.firstChild;this.vastAdData&&1!==this.vastAdData.nodeType;)this.vastAdData=this.vastAdData.nextSibling;break;case"CustomAdData":this.customData=i}}}));function i(t,e){var a=[];for(var n in t.childNodes){var i=t.childNodes[n];i.nodeName!==e&&e!=="vmap:".concat(i.nodeName)&&i.nodeName!=="vmap:".concat(e)||a.push(i)}return a}function r(t){var e={attributes:{},children:{},value:{}};e.value=function(t){if(!t||!t.childNodes)return{};var e=t.childNodes,a=[];for(var n in e){var i=e[n];"#cdata-section"===i.nodeName&&a.push(i)}if(a&&a.length>0)try{return JSON.parse(a[0].data)}catch(t){}var r="";for(var s in e){var o=e[s];switch(o.nodeName){case"#text":r+=o.textContent.trim();break;case"#cdata-section":r+=o.data}}return r}(t);var a=t.attributes;if(a)for(var n in a){var i=a[n];i.nodeName&&void 0!==i.nodeValue&&null!==i.nodeValue&&(e.attributes[i.nodeName]=i.nodeValue)}var s=t.childNodes;if(s)for(var o in s){var c=s[o];c.nodeName&&"#"!==c.nodeName.substring(0,1)&&(e.children[c.nodeName]=r(c))}return e}var s=function(){function e(a){for(var s in t(this,e),this.timeOffset=a.getAttribute("timeOffset"),this.breakType=a.getAttribute("breakType"),this.breakId=a.getAttribute("breakId"),this.repeatAfter=a.getAttribute("repeatAfter"),this.adSource=null,this.trackingEvents=[],this.extensions=[],a.childNodes){var o=a.childNodes[s];switch(o.localName){case"AdSource":this.adSource=new n(o);break;case"TrackingEvents":for(var c in o.childNodes){var d=o.childNodes[c];"Tracking"===d.localName&&this.trackingEvents.push({event:d.getAttribute("event"),uri:(d.textContent||d.text||"").trim()})}break;case"Extensions":this.extensions=i(o,"Extension").map((function(t){return r(t)}))}}}return a(e,[{key:"track",value:function(t,e){for(var a in this.trackingEvents){var n=this.trackingEvents[a];if(n.event===t){var i=n.uri;"error"===n.event&&(i=i.replace("[ERRORCODE]",e)),this.tracker(i)}}}},{key:"tracker",value:function(t){"undefined"!=typeof window&&null!==window&&((new Image).src=t)}}]),e}(),o=a((function e(a){if(t(this,e),!a||!a.documentElement||"VMAP"!==a.documentElement.localName)throw new Error("Not a VMAP document");for(var n in this.version=a.documentElement.getAttribute("version"),this.adBreaks=[],this.extensions=[],a.documentElement.childNodes){var o=a.documentElement.childNodes[n];switch(o.localName){case"AdBreak":this.adBreaks.push(new s(o));break;case"Extensions":this.extensions=i(o,"Extension").map((function(t){return r(t)}))}}}));module.exports=o;