From e81cf9a7772de2f4db2430ceea8d7541089cd103 Mon Sep 17 00:00:00 2001 From: Olivier Audard Date: Fri, 4 Apr 2014 18:48:44 +0200 Subject: [PATCH] Version 1.2.0 - Update vast-client.js to the latest master - Bump version numbers to 1.2.0 --- bower.json | 2 +- package.json | 2 +- vast-client.js | 563 +++++++++++++++++++++++++++++++------------------ 3 files changed, 365 insertions(+), 202 deletions(-) diff --git a/bower.json b/bower.json index 1e938458..3049bc16 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "vast-client-js", "author": ["Olivier Poitrey "], - "version": "1.1.2", + "version": "1.2.0", "main": "vast-client.js", "licenses": [{"type": "MIT", "url": "https://github.com/rs/vast-client-js/raw/master/LICENSE"}], "ignore": [ diff --git a/package.json b/package.json index e5839ce7..856ce481 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vast-client-js", "author": "Olivier Poitrey ", - "version": "1.1.2", + "version": "1.2.0", "description": "Javascript VAST Client", "keywords": ["vast", "ad", "advertising", "iab", "in-stream", "video"], "repository": {"type": "git", "url": "https://github.com/rs/vast-client-js"}, diff --git a/vast-client.js b/vast-client.js index e2745662..aefc3fed 100644 --- a/vast-client.js +++ b/vast-client.js @@ -301,10 +301,10 @@ function isUndefined(arg) { } },{}],2:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var VASTAd; VASTAd = (function() { - function VASTAd() { this.errorURLTemplates = []; this.impressionURLTemplates = []; @@ -318,6 +318,7 @@ VASTAd = (function() { module.exports = VASTAd; },{}],3:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var VASTClient, VASTParser, VASTUtil; VASTParser = _dereq_('./parser.coffee'); @@ -325,7 +326,6 @@ VASTParser = _dereq_('./parser.coffee'); VASTUtil = _dereq_('./util.coffee'); VASTClient = (function() { - function VASTClient() {} VASTClient.cappingFreeLunch = 0; @@ -335,8 +335,7 @@ VASTClient = (function() { VASTClient.timeout = 0; VASTClient.get = function(url, cb) { - var now, - _this = this; + var now; now = +new Date(); if (this.totalCallsTimeout < now) { this.totalCalls = 1; @@ -352,9 +351,11 @@ VASTClient = (function() { cb(null); return; } - return VASTParser.parse(url, function(response) { - return cb(response); - }); + return VASTParser.parse(url, (function(_this) { + return function(response) { + return cb(response); + }; + })(this)); }; (function() { @@ -373,8 +374,12 @@ VASTClient = (function() { enumerable: true }); }); - if (VASTClient.totalCalls == null) VASTClient.totalCalls = 0; - if (VASTClient.totalCallsTimeout == null) VASTClient.totalCallsTimeout = 0; + if (VASTClient.totalCalls == null) { + VASTClient.totalCalls = 0; + } + if (VASTClient.totalCallsTimeout == null) { + VASTClient.totalCallsTimeout = 0; + } })(); return VASTClient; @@ -383,13 +388,34 @@ VASTClient = (function() { module.exports = VASTClient; -},{"./parser.coffee":7,"./util.coffee":13}],4:[function(_dereq_,module,exports){ +},{"./parser.coffee":8,"./util.coffee":14}],4:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 +var VASTCompanionAd; + +VASTCompanionAd = (function() { + function VASTCompanionAd() { + this.id = null; + this.width = 0; + this.height = 0; + this.type = null; + this.staticResource = null; + this.companionClickThroughURLTemplate = null; + this.trackingEvents = {}; + } + + return VASTCompanionAd; + +})(); + +module.exports = VASTCompanionAd; + +},{}],5:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var VASTCreative, VASTCreativeCompanion, VASTCreativeLinear, VASTCreativeNonLinear, - __hasProp = Object.prototype.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; VASTCreative = (function() { - function VASTCreative() { this.trackingEvents = {}; } @@ -399,7 +425,6 @@ VASTCreative = (function() { })(); VASTCreativeLinear = (function(_super) { - __extends(VASTCreativeLinear, _super); function VASTCreativeLinear() { @@ -417,28 +442,25 @@ VASTCreativeLinear = (function(_super) { })(VASTCreative); VASTCreativeNonLinear = (function(_super) { - __extends(VASTCreativeNonLinear, _super); function VASTCreativeNonLinear() { - VASTCreativeNonLinear.__super__.constructor.apply(this, arguments); + return VASTCreativeNonLinear.__super__.constructor.apply(this, arguments); } return VASTCreativeNonLinear; })(VASTCreative); -VASTCreativeCompanion = (function(_super) { - - __extends(VASTCreativeCompanion, _super); - +VASTCreativeCompanion = (function() { function VASTCreativeCompanion() { - VASTCreativeCompanion.__super__.constructor.apply(this, arguments); + this.type = "companion"; + this.variations = []; } return VASTCreativeCompanion; -})(VASTCreative); +})(); module.exports = { VASTCreativeLinear: VASTCreativeLinear, @@ -446,7 +468,8 @@ module.exports = { VASTCreativeCompanion: VASTCreativeCompanion }; -},{}],5:[function(_dereq_,module,exports){ +},{}],6:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 module.exports = { client: _dereq_('./client.coffee'), tracker: _dereq_('./tracker.coffee'), @@ -454,11 +477,11 @@ module.exports = { util: _dereq_('./util.coffee') }; -},{"./client.coffee":3,"./parser.coffee":7,"./tracker.coffee":9,"./util.coffee":13}],6:[function(_dereq_,module,exports){ +},{"./client.coffee":3,"./parser.coffee":8,"./tracker.coffee":10,"./util.coffee":14}],7:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var VASTMediaFile; VASTMediaFile = (function() { - function VASTMediaFile() { this.fileURL = null; this.deliveryType = "progressive"; @@ -477,9 +500,10 @@ VASTMediaFile = (function() { module.exports = VASTMediaFile; -},{}],7:[function(_dereq_,module,exports){ -var URLHandler, VASTAd, VASTCreativeLinear, VASTMediaFile, VASTParser, VASTResponse, VASTUtil, - __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; +},{}],8:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 +var URLHandler, VASTAd, VASTCompanionAd, VASTCreativeCompanion, VASTCreativeLinear, VASTMediaFile, VASTParser, VASTResponse, VASTUtil, + __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; URLHandler = _dereq_('./urlhandler.coffee'); @@ -491,8 +515,12 @@ VASTUtil = _dereq_('./util.coffee'); VASTCreativeLinear = _dereq_('./creative.coffee').VASTCreativeLinear; +VASTCreativeCompanion = _dereq_('./creative.coffee').VASTCreativeCompanion; + VASTMediaFile = _dereq_('./mediafile.coffee'); +VASTCompanionAd = _dereq_('./companionad.coffee'); + VASTParser = (function() { var URLTemplateFilters; @@ -501,7 +529,9 @@ VASTParser = (function() { URLTemplateFilters = []; VASTParser.addURLTemplateFilter = function(func) { - if (typeof func === 'function') URLTemplateFilters.push(func); + if (typeof func === 'function') { + URLTemplateFilters.push(func); + } }; VASTParser.removeURLTemplateFilter = function() { @@ -523,119 +553,130 @@ VASTParser = (function() { }; VASTParser._parse = function(url, parentURLs, cb) { - var filter, _i, _len, - _this = this; + var filter, _i, _len; for (_i = 0, _len = URLTemplateFilters.length; _i < _len; _i++) { filter = URLTemplateFilters[_i]; url = filter(url); } - if (parentURLs == null) parentURLs = []; + if (parentURLs == null) { + parentURLs = []; + } parentURLs.push(url); - return URLHandler.get(url, function(err, xml) { - var ad, complete, loopIndex, node, response, _j, _k, _len2, _len3, _ref, _ref2; - if (err != null) return cb(err); - response = new VASTResponse(); - if (!(((xml != null ? xml.documentElement : void 0) != null) && xml.documentElement.nodeName === "VAST")) { - return cb(); - } - _ref = xml.documentElement.childNodes; - for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) { - node = _ref[_j]; - if (node.nodeName === 'Error') { - response.errorURLTemplates.push(node.textContent); + return URLHandler.get(url, (function(_this) { + return function(err, xml) { + var ad, complete, loopIndex, node, response, _j, _k, _len1, _len2, _ref, _ref1; + if (err != null) { + return cb(err); } - } - _ref2 = xml.documentElement.childNodes; - for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { - node = _ref2[_k]; - if (node.nodeName === 'Ad') { - ad = _this.parseAdElement(node); - if (ad != null) { - response.ads.push(ad); - } else { - VASTUtil.track(response.errorURLTemplates, { - ERRORCODE: 101 - }); - } + response = new VASTResponse(); + if (!(((xml != null ? xml.documentElement : void 0) != null) && xml.documentElement.nodeName === "VAST")) { + return cb(); } - } - complete = function() { - var ad, _l, _len4, _ref3; - if (!response) return; - _ref3 = response.ads; - for (_l = 0, _len4 = _ref3.length; _l < _len4; _l++) { - ad = _ref3[_l]; - if (ad.nextWrapperURL != null) return; + _ref = xml.documentElement.childNodes; + for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { + node = _ref[_j]; + if (node.nodeName === 'Error') { + response.errorURLTemplates.push(_this.parseNodeText(node)); + } } - if (response.ads.length === 0) { - VASTUtil.track(response.errorURLTemplates, { - ERRORCODE: 303 - }); - response = null; + _ref1 = xml.documentElement.childNodes; + for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { + node = _ref1[_k]; + if (node.nodeName === 'Ad') { + ad = _this.parseAdElement(node); + if (ad != null) { + response.ads.push(ad); + } else { + VASTUtil.track(response.errorURLTemplates, { + ERRORCODE: 101 + }); + } + } } - return cb(null, response); - }; - loopIndex = response.ads.length; - while (loopIndex--) { - ad = response.ads[loopIndex]; - if (ad.nextWrapperURL == null) continue; - (function(ad) { - var baseURL, _ref3; - if (parentURLs.length >= 10 || (_ref3 = ad.nextWrapperURL, __indexOf.call(parentURLs, _ref3) >= 0)) { - VASTUtil.track(ad.errorURLTemplates, { - ERRORCODE: 302 - }); - response.ads.splice(response.ads.indexOf(ad), 1); - complete(); + complete = function() { + var _l, _len3, _ref2; + if (!response) { return; } - if (ad.nextWrapperURL.indexOf('://') === -1) { - baseURL = url.slice(0, url.lastIndexOf('/')); - ad.nextWrapperURL = "" + baseURL + "/" + ad.nextWrapperURL; + _ref2 = response.ads; + for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) { + ad = _ref2[_l]; + if (ad.nextWrapperURL != null) { + return; + } + } + if (response.ads.length === 0) { + VASTUtil.track(response.errorURLTemplates, { + ERRORCODE: 303 + }); + response = null; } - return _this._parse(ad.nextWrapperURL, parentURLs, function(err, wrappedResponse) { - var creative, eventName, index, wrappedAd, _base, _l, _len4, _len5, _len6, _m, _n, _ref4, _ref5, _ref6; - if (err != null) { - VASTUtil.track(ad.errorURLTemplates, { - ERRORCODE: 301 - }); - response.ads.splice(response.ads.indexOf(ad), 1); - } else if (!(wrappedResponse != null)) { + return cb(null, response); + }; + loopIndex = response.ads.length; + while (loopIndex--) { + ad = response.ads[loopIndex]; + if (ad.nextWrapperURL == null) { + continue; + } + (function(ad) { + var baseURL, _ref2; + if (parentURLs.length >= 10 || (_ref2 = ad.nextWrapperURL, __indexOf.call(parentURLs, _ref2) >= 0)) { VASTUtil.track(ad.errorURLTemplates, { - ERRORCODE: 303 + ERRORCODE: 302 }); response.ads.splice(response.ads.indexOf(ad), 1); - } else { - response.errorURLTemplates = response.errorURLTemplates.concat(wrappedResponse.errorURLTemplates); - index = response.ads.indexOf(ad); - response.ads.splice(index, 1); - _ref4 = wrappedResponse.ads; - for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) { - wrappedAd = _ref4[_l]; - wrappedAd.errorURLTemplates = ad.errorURLTemplates.concat(wrappedAd.errorURLTemplates); - wrappedAd.impressionURLTemplates = ad.impressionURLTemplates.concat(wrappedAd.impressionURLTemplates); - if (ad.trackingEvents != null) { - _ref5 = wrappedAd.creatives; - for (_m = 0, _len5 = _ref5.length; _m < _len5; _m++) { - creative = _ref5[_m]; - _ref6 = Object.keys(ad.trackingEvents); - for (_n = 0, _len6 = _ref6.length; _n < _len6; _n++) { - eventName = _ref6[_n]; - (_base = creative.trackingEvents)[eventName] || (_base[eventName] = []); - creative.trackingEvents[eventName] = creative.trackingEvents[eventName].concat(ad.trackingEvents[eventName]); + complete(); + return; + } + if (ad.nextWrapperURL.indexOf('://') === -1) { + baseURL = url.slice(0, url.lastIndexOf('/')); + ad.nextWrapperURL = "" + baseURL + "/" + ad.nextWrapperURL; + } + return _this._parse(ad.nextWrapperURL, parentURLs, function(err, wrappedResponse) { + var creative, eventName, index, wrappedAd, _base, _l, _len3, _len4, _len5, _m, _n, _ref3, _ref4, _ref5; + if (err != null) { + VASTUtil.track(ad.errorURLTemplates, { + ERRORCODE: 301 + }); + response.ads.splice(response.ads.indexOf(ad), 1); + } else if (wrappedResponse == null) { + VASTUtil.track(ad.errorURLTemplates, { + ERRORCODE: 303 + }); + response.ads.splice(response.ads.indexOf(ad), 1); + } else { + response.errorURLTemplates = response.errorURLTemplates.concat(wrappedResponse.errorURLTemplates); + index = response.ads.indexOf(ad); + response.ads.splice(index, 1); + _ref3 = wrappedResponse.ads; + for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { + wrappedAd = _ref3[_l]; + wrappedAd.errorURLTemplates = ad.errorURLTemplates.concat(wrappedAd.errorURLTemplates); + wrappedAd.impressionURLTemplates = ad.impressionURLTemplates.concat(wrappedAd.impressionURLTemplates); + if (ad.trackingEvents != null) { + _ref4 = wrappedAd.creatives; + for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) { + creative = _ref4[_m]; + _ref5 = Object.keys(ad.trackingEvents); + for (_n = 0, _len5 = _ref5.length; _n < _len5; _n++) { + eventName = _ref5[_n]; + (_base = creative.trackingEvents)[eventName] || (_base[eventName] = []); + creative.trackingEvents[eventName] = creative.trackingEvents[eventName].concat(ad.trackingEvents[eventName]); + } } } + response.ads.splice(index, 0, wrappedAd); } - response.ads.splice(index, 0, wrappedAd); } - } - delete ad.nextWrapperURL; - return complete(); - }); - })(ad); - } - return complete(); - }); + delete ad.nextWrapperURL; + return complete(); + }); + })(ad); + } + return complete(); + }; + })(this)); }; VASTParser.childByName = function(node, name) { @@ -643,7 +684,9 @@ VASTParser = (function() { _ref = node.childNodes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { child = _ref[_i]; - if (child.nodeName === name) return child; + if (child.nodeName === name) { + return child; + } } }; @@ -653,7 +696,9 @@ VASTParser = (function() { _ref = node.childNodes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { child = _ref[_i]; - if (child.nodeName === name) childs.push(child); + if (child.nodeName === name) { + childs.push(child); + } } return childs; }; @@ -676,39 +721,49 @@ VASTParser = (function() { ad = this.parseInLineElement(wrapperElement); wrapperURLElement = this.childByName(wrapperElement, "VASTAdTagURI"); if (wrapperURLElement != null) { - ad.nextWrapperURL = wrapperURLElement.textContent; + ad.nextWrapperURL = this.parseNodeText(wrapperURLElement); } wrapperCreativeElement = ad.creatives[0]; if ((wrapperCreativeElement != null) && (wrapperCreativeElement.trackingEvents != null)) { ad.trackingEvents = wrapperCreativeElement.trackingEvents; } - if (ad.nextWrapperURL != null) return ad; + if (ad.nextWrapperURL != null) { + return ad; + } }; VASTParser.parseInLineElement = function(inLineElement) { - var ad, creative, creativeElement, creativeTypeElement, node, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3; + var ad, creative, creativeElement, creativeTypeElement, node, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2; ad = new VASTAd(); _ref = inLineElement.childNodes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { node = _ref[_i]; switch (node.nodeName) { case "Error": - ad.errorURLTemplates.push(node.textContent); + ad.errorURLTemplates.push(this.parseNodeText(node)); break; case "Impression": - ad.impressionURLTemplates.push(node.textContent); + ad.impressionURLTemplates.push(this.parseNodeText(node)); break; case "Creatives": - _ref2 = this.childsByName(node, "Creative"); - for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) { - creativeElement = _ref2[_j]; - _ref3 = creativeElement.childNodes; - for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) { - creativeTypeElement = _ref3[_k]; + _ref1 = this.childsByName(node, "Creative"); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + creativeElement = _ref1[_j]; + _ref2 = creativeElement.childNodes; + for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { + creativeTypeElement = _ref2[_k]; switch (creativeTypeElement.nodeName) { case "Linear": creative = this.parseCreativeLinearElement(creativeTypeElement); - if (creative) ad.creatives.push(creative); + if (creative) { + ad.creatives.push(creative); + } + break; + case "CompanionAds": + creative = this.parseCompanionAd(creativeTypeElement); + if (creative) { + ad.creatives.push(creative); + } } } } @@ -718,14 +773,14 @@ VASTParser = (function() { }; VASTParser.parseCreativeLinearElement = function(creativeElement) { - var creative, eventName, mediaFile, mediaFileElement, mediaFilesElement, percent, skipOffset, trackingElement, trackingEventsElement, trackingURLTemplate, videoClicksElement, _base, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7; + var creative, eventName, mediaFile, mediaFileElement, mediaFilesElement, percent, skipOffset, trackingElement, trackingEventsElement, trackingURLTemplate, videoClicksElement, _base, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3; creative = new VASTCreativeLinear(); - creative.duration = this.parseDuration((_ref = this.childByName(creativeElement, "Duration")) != null ? _ref.textContent : void 0); + creative.duration = this.parseDuration(this.parseNodeText(this.childByName(creativeElement, "Duration"))); if (creative.duration === -1 && creativeElement.parentNode.parentNode.parentNode.nodeName !== 'Wrapper') { return null; } skipOffset = creativeElement.getAttribute("skipoffset"); - if (!(skipOffset != null)) { + if (skipOffset == null) { creative.skipDelay = null; } else if (skipOffset.charAt(skipOffset.length - 1) === "%") { percent = parseInt(skipOffset, 10); @@ -735,17 +790,17 @@ VASTParser = (function() { } videoClicksElement = this.childByName(creativeElement, "VideoClicks"); if (videoClicksElement != null) { - creative.videoClickThroughURLTemplate = (_ref2 = this.childByName(videoClicksElement, "ClickThrough")) != null ? _ref2.textContent : void 0; - creative.videoClickTrackingURLTemplate = (_ref3 = this.childByName(videoClicksElement, "ClickTracking")) != null ? _ref3.textContent : void 0; + creative.videoClickThroughURLTemplate = this.parseNodeText(this.childByName(videoClicksElement, "ClickThrough")); + creative.videoClickTrackingURLTemplate = this.parseNodeText(this.childByName(videoClicksElement, "ClickTracking")); } - _ref4 = this.childsByName(creativeElement, "TrackingEvents"); - for (_i = 0, _len = _ref4.length; _i < _len; _i++) { - trackingEventsElement = _ref4[_i]; - _ref5 = this.childsByName(trackingEventsElement, "Tracking"); - for (_j = 0, _len2 = _ref5.length; _j < _len2; _j++) { - trackingElement = _ref5[_j]; + _ref = this.childsByName(creativeElement, "TrackingEvents"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + trackingEventsElement = _ref[_i]; + _ref1 = this.childsByName(trackingEventsElement, "Tracking"); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + trackingElement = _ref1[_j]; eventName = trackingElement.getAttribute("event"); - trackingURLTemplate = trackingElement.textContent; + trackingURLTemplate = this.parseNodeText(trackingElement); if ((eventName != null) && (trackingURLTemplate != null)) { if ((_base = creative.trackingEvents)[eventName] == null) { _base[eventName] = []; @@ -754,14 +809,14 @@ VASTParser = (function() { } } } - _ref6 = this.childsByName(creativeElement, "MediaFiles"); - for (_k = 0, _len3 = _ref6.length; _k < _len3; _k++) { - mediaFilesElement = _ref6[_k]; - _ref7 = this.childsByName(mediaFilesElement, "MediaFile"); - for (_l = 0, _len4 = _ref7.length; _l < _len4; _l++) { - mediaFileElement = _ref7[_l]; + _ref2 = this.childsByName(creativeElement, "MediaFiles"); + for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { + mediaFilesElement = _ref2[_k]; + _ref3 = this.childsByName(mediaFilesElement, "MediaFile"); + for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { + mediaFileElement = _ref3[_l]; mediaFile = new VASTMediaFile(); - mediaFile.fileURL = mediaFileElement.textContent; + mediaFile.fileURL = this.parseNodeText(mediaFileElement); mediaFile.deliveryType = mediaFileElement.getAttribute("delivery"); mediaFile.codec = mediaFileElement.getAttribute("codec"); mediaFile.mimeType = mediaFileElement.getAttribute("type"); @@ -776,14 +831,58 @@ VASTParser = (function() { return creative; }; + VASTParser.parseCompanionAd = function(creativeElement) { + var companionAd, companionResource, creative, eventName, staticElement, trackingElement, trackingEventsElement, trackingURLTemplate, _base, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3; + creative = new VASTCreativeCompanion(); + _ref = this.childsByName(creativeElement, "Companion"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + companionResource = _ref[_i]; + companionAd = new VASTCompanionAd(); + companionAd.id = companionResource.getAttribute("id") || null; + companionAd.width = companionResource.getAttribute("width"); + companionAd.height = companionResource.getAttribute("height"); + _ref1 = this.childsByName(companionResource, "StaticResource"); + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + staticElement = _ref1[_j]; + companionAd.type = staticElement.getAttribute("creativeType") || 0; + companionAd.staticResource = this.parseNodeText(staticElement); + } + _ref2 = this.childsByName(companionResource, "TrackingEvents"); + for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { + trackingEventsElement = _ref2[_k]; + _ref3 = this.childsByName(trackingEventsElement, "Tracking"); + for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) { + trackingElement = _ref3[_l]; + eventName = trackingElement.getAttribute("event"); + trackingURLTemplate = this.parseNodeText(trackingElement); + if ((eventName != null) && (trackingURLTemplate != null)) { + if ((_base = companionAd.trackingEvents)[eventName] == null) { + _base[eventName] = []; + } + companionAd.trackingEvents[eventName].push(trackingURLTemplate); + } + } + } + companionAd.companionClickThroughURLTemplate = this.parseNodeText(this.childByName(companionResource, "CompanionClickThrough")); + creative.variations.push(companionAd); + } + return creative; + }; + VASTParser.parseDuration = function(durationString) { var durationComponents, hours, minutes, seconds, secondsAndMS; - if (!(durationString != null)) return -1; + if (!(durationString != null)) { + return -1; + } durationComponents = durationString.split(":"); - if (durationComponents.length !== 3) return -1; + if (durationComponents.length !== 3) { + return -1; + } secondsAndMS = durationComponents[2].split("."); seconds = parseInt(secondsAndMS[0]); - if (secondsAndMS.length === 2) seconds += parseFloat("0." + secondsAndMS[1]); + if (secondsAndMS.length === 2) { + seconds += parseFloat("0." + secondsAndMS[1]); + } minutes = parseInt(durationComponents[1] * 60); hours = parseInt(durationComponents[0] * 60 * 60); if (isNaN(hours || isNaN(minutes || isNaN(seconds || minutes > 60 * 60 || seconds > 60)))) { @@ -792,17 +891,21 @@ VASTParser = (function() { return hours + minutes + seconds; }; + VASTParser.parseNodeText = function(node) { + return node && (node.textContent || node.text); + }; + return VASTParser; })(); module.exports = VASTParser; -},{"./ad.coffee":2,"./creative.coffee":4,"./mediafile.coffee":6,"./response.coffee":8,"./urlhandler.coffee":10,"./util.coffee":13}],8:[function(_dereq_,module,exports){ +},{"./ad.coffee":2,"./companionad.coffee":4,"./creative.coffee":5,"./mediafile.coffee":7,"./response.coffee":9,"./urlhandler.coffee":11,"./util.coffee":14}],9:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var VASTResponse; VASTResponse = (function() { - function VASTResponse() { this.ads = []; this.errorURLTemplates = []; @@ -814,10 +917,11 @@ VASTResponse = (function() { module.exports = VASTResponse; -},{}],9:[function(_dereq_,module,exports){ +},{}],10:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var EventEmitter, VASTClient, VASTCreativeLinear, VASTTracker, VASTUtil, - __hasProp = Object.prototype.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; VASTClient = _dereq_('./client.coffee'); @@ -828,7 +932,6 @@ VASTCreativeLinear = _dereq_('./creative.coffee').VASTCreativeLinear; EventEmitter = _dereq_('events').EventEmitter; VASTTracker = (function(_super) { - __extends(VASTTracker, _super); function VASTTracker(ad, creative) { @@ -886,25 +989,33 @@ VASTTracker = (function(_super) { _ref = this.quartiles; for (quartile in _ref) { time = _ref[quartile]; - if ((time <= progress && progress <= (time + 1))) events.push(quartile); + if ((time <= progress && progress <= (time + 1))) { + events.push(quartile); + } } } for (_i = 0, _len = events.length; _i < _len; _i++) { eventName = events[_i]; this.track(eventName, true); } - if (progress < this.progress) this.track("rewind"); + if (progress < this.progress) { + this.track("rewind"); + } } return this.progress = progress; }; VASTTracker.prototype.setMuted = function(muted) { - if (this.muted !== muted) this.track(muted ? "muted" : "unmuted"); + if (this.muted !== muted) { + this.track(muted ? "muted" : "unmuted"); + } return this.muted = muted; }; VASTTracker.prototype.setPaused = function(paused) { - if (this.paused !== paused) this.track(paused ? "pause" : "resume"); + if (this.paused !== paused) { + this.track(paused ? "pause" : "resume"); + } return this.paused = paused; }; @@ -916,7 +1027,9 @@ VASTTracker = (function(_super) { }; VASTTracker.prototype.setSkipDelay = function(duration) { - if (typeof duration === 'number') return this.skipDelay = duration; + if (typeof duration === 'number') { + return this.skipDelay = duration; + } }; VASTTracker.prototype.load = function() { @@ -964,8 +1077,10 @@ VASTTracker = (function(_super) { VASTTracker.prototype.track = function(eventName, once) { var idx, trackingURLTemplates; - if (once == null) once = false; - if (eventName === 'closeLinear' && (!(this.trackingEvents[eventName] != null) && (this.trackingEvents['close'] != null))) { + if (once == null) { + once = false; + } + if (eventName === 'closeLinear' && ((this.trackingEvents[eventName] == null) && (this.trackingEvents['close'] != null))) { eventName = 'close'; } trackingURLTemplates = this.trackingEvents[eventName]; @@ -978,13 +1093,19 @@ VASTTracker = (function(_super) { } if (once === true) { delete this.trackingEvents[eventName]; - if (idx > -1) this.emitAlwaysEvents.splice(idx, 1); + if (idx > -1) { + this.emitAlwaysEvents.splice(idx, 1); + } } }; VASTTracker.prototype.trackURLs = function(URLTemplates, variables) { - if (variables == null) variables = {}; - if (this.linear) variables["CONTENTPLAYHEAD"] = this.progressFormated(); + if (variables == null) { + variables = {}; + } + if (this.linear) { + variables["CONTENTPLAYHEAD"] = this.progressFormated(); + } return VASTUtil.track(URLTemplates, variables); }; @@ -992,11 +1113,17 @@ VASTTracker = (function(_super) { var h, m, ms, s, seconds; seconds = parseInt(this.progress); h = seconds / (60 * 60); - if (h.length < 2) h = "0" + h; + if (h.length < 2) { + h = "0" + h; + } m = seconds / 60 % 60; - if (m.length < 2) m = "0" + m; + if (m.length < 2) { + m = "0" + m; + } s = seconds % 60; - if (s.length < 2) s = "0" + m; + if (s.length < 2) { + s = "0" + m; + } ms = parseInt((this.progress - seconds) * 100); return "" + h + ":" + m + ":" + s + "." + ms; }; @@ -1007,7 +1134,8 @@ VASTTracker = (function(_super) { module.exports = VASTTracker; -},{"./client.coffee":3,"./creative.coffee":4,"./util.coffee":13,"events":1}],10:[function(_dereq_,module,exports){ +},{"./client.coffee":3,"./creative.coffee":5,"./util.coffee":14,"events":1}],11:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var URLHandler, flash, xhr; xhr = _dereq_('./urlhandlers/xmlhttprequest.coffee'); @@ -1015,16 +1143,17 @@ xhr = _dereq_('./urlhandlers/xmlhttprequest.coffee'); flash = _dereq_('./urlhandlers/flash.coffee'); URLHandler = (function() { - function URLHandler() {} URLHandler.get = function(url, cb) { - if (!(typeof window !== "undefined" && window !== null)) { + if (typeof window === "undefined" || window === null) { return _dereq_('./urlhandlers/' + 'node.coffee').get(url, cb); } else if (xhr.supported()) { return xhr.get(url, cb); - } else { + } else if (flash.supported()) { return flash.get(url, cb); + } else { + return cb(); } }; @@ -1034,15 +1163,39 @@ URLHandler = (function() { module.exports = URLHandler; -},{"./urlhandlers/flash.coffee":11,"./urlhandlers/xmlhttprequest.coffee":12}],11:[function(_dereq_,module,exports){ +},{"./urlhandlers/flash.coffee":12,"./urlhandlers/xmlhttprequest.coffee":13}],12:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var FlashURLHandler; FlashURLHandler = (function() { - function FlashURLHandler() {} + FlashURLHandler.xdr = function() { + var xdr; + if (window.XDomainRequest) { + xdr = new XDomainRequest(); + } + return xdr; + }; + + FlashURLHandler.supported = function() { + return !!this.xdr(); + }; + FlashURLHandler.get = function(url, cb) { - return cb('not supported'); + var xdr, xmlDocument; + if (xmlDocument = typeof window.ActiveXObject === "function" ? new window.ActiveXObject("Microsoft.XMLDOM") : void 0) { + xmlDocument.async = false; + } else { + return cb(); + } + xdr = this.xdr(); + xdr.open('GET', url); + xdr.send(); + return xdr.onload = function() { + xmlDocument.loadXML(xdr.responseText); + return cb(null, xmlDocument); + }; }; return FlashURLHandler; @@ -1051,17 +1204,19 @@ FlashURLHandler = (function() { module.exports = FlashURLHandler; -},{}],12:[function(_dereq_,module,exports){ +},{}],13:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var XHRURLHandler; XHRURLHandler = (function() { - function XHRURLHandler() {} XHRURLHandler.xhr = function() { var xhr; xhr = new window.XMLHttpRequest(); - if ('withCredentials' in xhr) return xhr; + if ('withCredentials' in xhr) { + return xhr; + } }; XHRURLHandler.supported = function() { @@ -1074,7 +1229,9 @@ XHRURLHandler = (function() { xhr.open('GET', url); xhr.send(); return xhr.onreadystatechange = function() { - if (xhr.readyState === 4) return cb(null, xhr.responseXML); + if (xhr.readyState === 4) { + return cb(null, xhr.responseXML); + } }; }; @@ -1084,11 +1241,11 @@ XHRURLHandler = (function() { module.exports = XHRURLHandler; -},{}],13:[function(_dereq_,module,exports){ +},{}],14:[function(_dereq_,module,exports){ +// Generated by CoffeeScript 1.7.1 var VASTUtil; VASTUtil = (function() { - function VASTUtil() {} VASTUtil.track = function(URLTemplates, variables) { @@ -1110,7 +1267,9 @@ VASTUtil = (function() { VASTUtil.resolveURLTemplates = function(URLTemplates, variables) { var URLTemplate, URLs, key, macro1, macro2, resolveURL, value, _i, _len; URLs = []; - if (variables == null) variables = {}; + if (variables == null) { + variables = {}; + } if (!("CACHEBUSTING" in variables)) { variables["CACHEBUSTING"] = Math.round(Math.random() * 1.0e+10); } @@ -1131,24 +1290,28 @@ VASTUtil = (function() { }; VASTUtil.storage = (function() { - var data, isDisabled, storage; + var data, isDisabled, storage, storageError; try { storage = typeof window !== "undefined" && window !== null ? window.localStorage || window.sessionStorage : null; - } catch (storageError) { + } catch (_error) { + storageError = _error; storage = null; } isDisabled = function(store) { - var testValue; + var e, testValue; try { testValue = '__VASTUtil__'; store.setItem(testValue, testValue); - if (store.getItem(testValue) !== testValue) return true; - } catch (e) { + if (store.getItem(testValue) !== testValue) { + return true; + } + } catch (_error) { + e = _error; return true; } return false; }; - if (!(storage != null) || isDisabled(storage)) { + if ((storage == null) || isDisabled(storage)) { data = {}; storage = { length: 0, @@ -1178,6 +1341,6 @@ VASTUtil = (function() { module.exports = VASTUtil; -},{}]},{},[5]) -(5) +},{}]},{},[6]) +(6) }); \ No newline at end of file