gardr-host
Advanced tools
Comparing version
@@ -16,1 +16,2 @@ # Change Log | ||
- Added possibility to update url or data for each position, with dirty check that refreshes if position if already rendered | ||
- Added title attribute to iframes |
@@ -39,2 +39,3 @@ var VER = 2; | ||
this.allowfullscreen = options.allowfullscreen; | ||
this.title = options.title || 'Advertisement ' + this.id; | ||
this.setData(options.data || {}); | ||
@@ -120,2 +121,3 @@ } | ||
i.name = this.id + '-' + (+new Date()); | ||
i.title = this.title; | ||
i.src = this._getUrl(); | ||
@@ -122,0 +124,0 @@ i.className = TYPE + '-iframe'; |
@@ -319,2 +319,9 @@ /* jshint maxparams:4 */ | ||
proto.setUrlMap = function(urlMap, prioritized, callback) { | ||
Object.keys(urlMap).forEach(function(key){ | ||
this._update(key, {url: urlMap[key], updateOnNewData: false}); | ||
}.bind(this)); | ||
this.refreshAll(prioritized, callback); | ||
}; | ||
proto.setData = function(name, data, callback) { | ||
@@ -327,3 +334,3 @@ this._update(name, {data: data}, callback); | ||
var needsUpdate = item.updateData(options); | ||
if (needsUpdate && item.state === State.RESOLVED) { | ||
if (needsUpdate && item.state === State.RESOLVED && options.updateOnNewData !== false) { | ||
this.refresh(name, callback); | ||
@@ -330,0 +337,0 @@ } else if (callback) { |
23
make.js
@@ -29,5 +29,22 @@ #!/usr/bin/env node | ||
function setupPhantomPath() { | ||
if (!env['PHANTOMJS_BIN']) { | ||
try { | ||
var path = require('phantomjs2').path; | ||
if (path) { | ||
env['PHANTOMJS_BIN'] = path; | ||
} | ||
if (!path) { | ||
path = require('phantomjs').path; | ||
if (path) { | ||
env['PHANTOMJS_BIN'] = path; | ||
} | ||
} | ||
} catch(e){} | ||
} | ||
} | ||
target.test = function () { | ||
target.lint(); | ||
env['PHANTOMJS_BIN'] = require('phantomjs2').path; | ||
setupPhantomPath(); | ||
karma('start', '--single-run'); | ||
@@ -38,3 +55,3 @@ }; | ||
target.lint(); | ||
env['PHANTOMJS_BIN'] = require('phantomjs2').path; | ||
setupPhantomPath(); | ||
['ie', 'ienew', 'chrome', 'android', 'ios', 'firefox'].forEach(function(browserType){ | ||
@@ -48,4 +65,4 @@ env['BROWSER_TYPE'] = browserType; | ||
target.lint(); | ||
env['PHANTOMJS_BIN'] = require('phantomjs2').path; | ||
setupPhantomPath(); | ||
karma('start'); | ||
}; |
{ | ||
"name": "gardr-host", | ||
"version": "1.0.0-alpha.6", | ||
"version": "1.0.0-alpha.8", | ||
"description": "The js part of Gardr which insert and talks with the iframes on the host page", | ||
@@ -52,3 +52,3 @@ "main": "./lib/index.js", | ||
"mocha": "2.2.4", | ||
"phantomjs2": "^2.0.0", | ||
"phantomjs": "^1.9.17", | ||
"shelljs": "0.3.0" | ||
@@ -55,0 +55,0 @@ }, |
@@ -555,2 +555,80 @@ /*jshint expr: true, nonew: false*/ | ||
describe('setUrlMap', function() { | ||
it('should update url from urlmap object', function(done) { | ||
var name = 'iframe_update_url' + helpers.getRandomName(); | ||
var manager = helpers.testableManager(); | ||
var container = helpers.insertContainer(name); | ||
manager.queue(name, { | ||
'container': container, | ||
'url': SCRIPT_URL | ||
}); | ||
manager.render(name, function(err, item){ | ||
expect(item.state).to.equal(State.RESOLVED); | ||
var urlMap = {}; | ||
urlMap[name] = SCRIPT_URL; | ||
manager.setUrlMap(urlMap, function(err, item) { | ||
expect(item.rendered.times).to.equal(2); | ||
urlMap[name] = SCRIPT_URL + '?some=other'; | ||
manager.setUrlMap(urlMap, function(err, item) { | ||
expect(item.rendered.times).to.equal(3); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('should update multiple urls and always refresh', function(done) { | ||
var manager = helpers.testableManager(); | ||
var urlMap = {}; | ||
[SCRIPT_URL, SCRIPT_URL, SCRIPT_URL].forEach(function(name, i) { | ||
urlMap[i] = name + '?i=' + i; | ||
var container = helpers.insertContainer(i); | ||
manager.queue(name, { | ||
'container': container, | ||
'url': urlMap[i] | ||
}); | ||
}); | ||
var i = 3; | ||
var items = []; | ||
manager.renderAll(function(err, item){ | ||
expect(err).not.to.be.ok(); | ||
items.push(item); | ||
i--; | ||
if (i === 0) { | ||
items.forEach(function(item){ | ||
expect(item.rendered.times).to.be(1); | ||
}); | ||
ready(); | ||
} | ||
}); | ||
function ready() { | ||
var i = 3; | ||
manager.setUrlMap(urlMap, function(err){ | ||
expect(err).not.to.be.ok(); | ||
i--; | ||
if (i === 0) { | ||
items.forEach(function(item){ | ||
expect(item.rendered.times).to.be(2); | ||
}); | ||
done(); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
describe('setData', function() { | ||
@@ -557,0 +635,0 @@ it('should update data', function(done) { |
74540
2.2%1726
2.37%21
-4.55%