gardr-host
Advanced tools
Comparing version 1.0.0-alpha.5 to 1.0.0-alpha.6
@@ -5,3 +5,3 @@ # Change Log | ||
## [1.0.0] - 2015-07-02 | ||
## [1.0.0] - 2015-07-10 | ||
### Breaking Changes | ||
@@ -16,1 +16,2 @@ - `gardr-ext iframe.htm` introduces breaking change, see [Gardr-ext changelog](../gardr-ext/CHANGELOG.md). Gardr-host will bust the iframe url with query-parameter. | ||
- Trigger "item:queued" for the pluginApi on item queued (sgulseth) | ||
- Added possibility to update url or data for each position, with dirty check that refreshes if position if already rendered |
@@ -38,2 +38,3 @@ var VER = 2; | ||
this.hidden = options.hidden; | ||
this.allowfullscreen = options.allowfullscreen; | ||
this.setData(options.data || {}); | ||
@@ -140,2 +141,7 @@ } | ||
// Allow Fullscreen API | ||
if (this.allowfullscreen) { | ||
i.allowfullscreen = i.webkitallowfullscreen = i.mozallowfullscreen = true; | ||
} | ||
inner.appendChild(i); | ||
@@ -142,0 +148,0 @@ inner.className = TYPE + '-inner'; |
@@ -220,3 +220,2 @@ /* jshint maxparams:4 */ | ||
if (!item.iframe) { | ||
// todo, check if actually iframe is on different domain | ||
item.iframe = new Iframe(item.id, { | ||
@@ -228,2 +227,3 @@ iframeUrl: this.iframeUrl, | ||
classes: '', | ||
allowfullscreen: item.options.allowfullscreen, | ||
data: this._getItemData(item) | ||
@@ -317,2 +317,21 @@ }); | ||
proto.setUrl = function(name, url, callback) { | ||
this._update(name, {url: url}, callback); | ||
}; | ||
proto.setData = function(name, data, callback) { | ||
this._update(name, {data: data}, callback); | ||
}; | ||
proto._update = function(name, options, callback) { | ||
this._forEachWithName(name, function(item){ | ||
var needsUpdate = item.updateData(options); | ||
if (needsUpdate && item.state === State.RESOLVED) { | ||
this.refresh(name, callback); | ||
} else if (callback) { | ||
callback(null, item); | ||
} | ||
}); | ||
}; | ||
proto.refresh = function(name, cb) { | ||
@@ -319,0 +338,0 @@ this._forEachWithName(name, function (item) { |
@@ -105,4 +105,23 @@ var extend = require('util-extend'); | ||
proto.updateData = function(options) { | ||
var isDirty = false; | ||
for (var key in options) { | ||
if (key === 'data' && this.options.data) { | ||
for(var dataKey in options.data) { | ||
if (this.options.data[dataKey] !== options.data[dataKey]) { | ||
isDirty = true; | ||
this.options.data[dataKey] = options.data[dataKey]; | ||
} | ||
} | ||
} else { | ||
if (this.options[key] !== options[key]) { | ||
isDirty = true; | ||
this.options[key] = options[key]; | ||
} | ||
} | ||
} | ||
return isDirty; | ||
}; | ||
proto.getData = function() { | ||
var url = this.options.url; | ||
@@ -109,0 +128,0 @@ // We cannot use a global regex because of this bug: |
{ | ||
"name": "gardr-host", | ||
"version": "1.0.0-alpha.5", | ||
"version": "1.0.0-alpha.6", | ||
"description": "The js part of Gardr which insert and talks with the iframes on the host page", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -39,2 +39,3 @@ /*jshint expr: true, nonew: false*/ | ||
describe('Manager', function () { | ||
this.timeout(5000); | ||
@@ -292,2 +293,3 @@ it('should be defined', function () { | ||
describe('render', function () { | ||
this.timeout(5000); | ||
var manager = helpers.testableManager(); | ||
@@ -516,2 +518,121 @@ | ||
describe('setUrl', function() { | ||
it('should update url', 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); | ||
manager.setUrl(name, SCRIPT_URL, function(err, item) { | ||
expect(item.rendered.times).to.equal(1); | ||
manager.setUrl(name, SCRIPT_URL + '?some=other', function(err, item) { | ||
expect(item.rendered.times).to.equal(2); | ||
manager.refresh(name, function (err, item) { | ||
expect(item.options.url).to.equal( SCRIPT_URL + '?some=other'); | ||
expect(item.rendered.times).to.equal(3); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('setData', function() { | ||
it('should update data', function(done) { | ||
var name = 'iframe_update_state' + helpers.getRandomName(); | ||
var manager = helpers.testableManager(); | ||
var container = helpers.insertContainer(name); | ||
manager.queue(name, { | ||
'container': container, | ||
'url': SCRIPT_URL, | ||
'width': 123, | ||
'height': 123, | ||
'data': {another: 321} | ||
}); | ||
manager.render(name, function(err, item){ | ||
expect(item.state).to.equal(State.RESOLVED); | ||
manager.setData(name, {random: 123}, function(err, item) { | ||
expect(item.rendered.times).to.equal(2); | ||
manager.refresh(name, function (err, item) { | ||
expect(item.options.data.random).to.equal(123); | ||
expect(item.options.data.another).to.equal(321); | ||
expect(item.rendered.times).to.equal(3); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('_update', function() { | ||
it('should update state', function(done) { | ||
var name = 'iframe_update_state' + helpers.getRandomName(); | ||
var manager = helpers.testableManager(); | ||
var container = helpers.insertContainer(name); | ||
manager.queue(name, { | ||
'container': container, | ||
'url': SCRIPT_URL, | ||
'width': 123, | ||
'height': 123, | ||
'data': {another: 321} | ||
}); | ||
manager.render(name, function(err, item){ | ||
expect(item.state).to.equal(State.RESOLVED); | ||
expect(item.rendered.width).to.equal(123); | ||
manager._update(name, { | ||
width: 300, | ||
height: 300, | ||
url: SCRIPT_URL + '?param1=23', | ||
data: {random: 123} | ||
}); | ||
manager.refresh(name, function (err, item) { | ||
expect(item.options.data.random).to.equal(123); | ||
expect(item.options.data.another).to.equal(321); | ||
expect(item.options.width).to.equal(300); | ||
expect(item.options.height).to.equal(300); | ||
expect(item.options.url).to.equal(SCRIPT_URL + '?param1=23'); | ||
expect(item.rendered.times).to.equal(2); | ||
expect(item.rendered.width).to.equal(300); | ||
expect(item.rendered.height).to.equal(300); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('refresh', function () { | ||
@@ -729,2 +850,35 @@ | ||
var _i = document.createElement('iframe'); | ||
_i.allowfullscreen = _i.webkitallowfullscreen = _i.mozallowfullscreen = true; | ||
if (_i.allowfullscreen || _i.webkitallowfullscreen || _i.mozallowfullscreen) { | ||
it('should not enable fullcreen by default', function(done) { | ||
var name = helpers.getRandomName(); | ||
manager.queue(name, {url: 'about:blank'}); | ||
manager.render(name, function(err, item){ | ||
expect(item.iframe.element.allowfullscreen).not.to.be.ok(); | ||
expect(item.iframe.element.webkitallowfullscreen).not.to.be.ok(); | ||
expect(item.iframe.element.mozallowfullscreen).not.to.be.ok(); | ||
done(); | ||
}); | ||
}); | ||
it('should allow to pass allowfullscreen to iframe', function(done) { | ||
var name = helpers.getRandomName(); | ||
manager.queue(name, {url: 'about:blank', allowfullscreen: true}); | ||
manager.render(name, function(err, item){ | ||
expect( | ||
item.iframe.element.allowfullscreen|| | ||
item.iframe.element.webkitallowfullscreen|| | ||
item.iframe.element.mozallowfullscreen | ||
).to.be.ok(); | ||
done(); | ||
}); | ||
}); | ||
} | ||
it('should trigger item:afterrender when the iframe has been rendered', function (done) { | ||
@@ -731,0 +885,0 @@ var name = helpers.getRandomName(); |
Sorry, the diff of this file is not supported yet
72938
1686