Comparing version 0.0.4 to 0.1.0
{ | ||
"name": "gardr-ext", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "The js part of Gardr which embeds external content inside the iframe", | ||
@@ -50,3 +50,2 @@ "main": "./src/index.js", | ||
"dependencies": { | ||
"gardr-iframe-params": "0.0.1", | ||
"util-extend": "~1.0.1", | ||
@@ -53,0 +52,0 @@ "eventlistener": "0.0.1", |
# Garðr (ext) | ||
[![Build Status](https://api.travis-ci.org/gardr/ext.png?branch=master)](https://travis-ci.org/gardr/ext) | ||
[![NPM](https://nodei.co/npm/gardr-ext.png?stars=true&downloads=true)](https://npmjs.org/package/gardr-ext) | ||
This project is part of the [Garðr](http://gardr.github.io/) family of projets. | ||
`gardr-ext` is the part which embeds external content inside the iframe. It uses postMessage to communicate with the parent page. You will need to have `gardr-host` running there. |
/* jshint evil: true */ | ||
var hashData = require('gardr-iframe-params'); | ||
var extend = require('util-extend'); | ||
var comClient = require('./comClient.js'); | ||
@@ -10,8 +8,8 @@ var getAppender = require('./log/getAppender.js'); | ||
var bootStrap = function (hash) { | ||
hash = hash || global.location.hash; | ||
var bootStrap = function () { | ||
var gardr = {}; | ||
global.gardr = gardr; | ||
extend(gardr, hashData.decode(hash)); | ||
gardr.params = JSON.parse(window.name); | ||
gardr.id = gardr.params.id; | ||
gardr.log = logger.create(gardr.id, gardr.params.loglevel, getAppender(gardr.params.logto)); | ||
@@ -26,3 +24,3 @@ | ||
var com = comClient(gardr.id, window.parent, gardr.internal.origin); | ||
var com = comClient(gardr.id, window.parent, gardr.params.origin); | ||
eventListener.add(global, 'load', function () { | ||
@@ -29,0 +27,0 @@ // phantomjs doesn't calculate sizes correctly unless we give it a break |
/* jshint evil: true, expr: true */ | ||
/* global gardr:false */ | ||
var bootStrap = require('../src/index.js'); | ||
var hashTemplate = '#GARDR_|_pos-id_|_key=MANAGER&origin=http%3A%2F%2Fgardr.github.io_|_name=posname&minSize=100&timeo\ | ||
ut=200&url={url}&height=225'; | ||
var exampleHash = hashTemplate.replace('{url}', 'data:text/javascript;plain,void(0);'); | ||
var extend = require('util-extend'); | ||
var defaultParams = { | ||
id: 'pos-id', | ||
name: 'posname', | ||
minSize: 100, | ||
timeout: 200, | ||
url: 'data:text/javascript;plain,void(0);', | ||
height: 225, | ||
origin: 'http://gardr.github.io' | ||
}; | ||
function makeHash (data) { | ||
data = data || {}; | ||
return Object.keys(data).reduce(function (hash, key) { | ||
return hash.replace('{' + key + '}', encodeURIComponent(data[key])); | ||
}, hashTemplate); | ||
function setNameData (data) { | ||
window.name = JSON.stringify(extend(extend({}, defaultParams), data)); | ||
} | ||
@@ -42,2 +46,3 @@ | ||
bootStrap._setComClient(comClient); | ||
setNameData(); | ||
}); | ||
@@ -48,6 +53,7 @@ | ||
document.write = orgWrite; | ||
window.name = null; | ||
}); | ||
it('should define ‘gardr’ in global scope', function () { | ||
bootStrap(exampleHash); | ||
bootStrap(); | ||
@@ -58,13 +64,15 @@ expect(window.gardr).to.exist; | ||
it('should read parameters from location.href by default', function () { | ||
bootStrap(makeHash({url: 'http://gardr.github.io/ad|123'})); | ||
setNameData({url: 'http://gardr.github.io/ad|123'}); | ||
bootStrap(); | ||
expect(gardr.params).to.exist; | ||
expect(gardr.id).to.equal('pos-id'); | ||
expect(gardr.internal.origin).to.equal('http://gardr.github.io'); | ||
expect(gardr.params.origin).to.equal('http://gardr.github.io'); | ||
expect(gardr.params.url).to.equal('http://gardr.github.io/ad|123'); | ||
expect(gardr.params.timeout).to.equal('200'); | ||
expect(gardr.params.timeout).to.equal(200); | ||
}); | ||
it('should log to div by default', function () { | ||
bootStrap(exampleHash + '&loglevel=4'); | ||
setNameData({loglevel: 4}); | ||
bootStrap(); | ||
gardr.log.debug('test'); | ||
@@ -76,3 +84,3 @@ var logDiv = document.getElementById('logoutput'); | ||
it('should document.write out a gardr container to the document', function () { | ||
bootStrap(exampleHash); | ||
bootStrap(); | ||
document.write.should.have.been.calledWith('<span id="gardr">'); | ||
@@ -84,3 +92,4 @@ document.write.should.have.been.calledWith('</span>'); | ||
var scriptUrl = 'http://external.com/script.js?q=1'; | ||
bootStrap(makeHash({url: scriptUrl})); | ||
setNameData({url: scriptUrl}); | ||
bootStrap(); | ||
@@ -93,3 +102,3 @@ document.write.should.have.been.calledWithMatch(function (value) { | ||
it('should trigger comClient.rendered when all resources are loaded', function () { | ||
bootStrap(exampleHash); | ||
bootStrap(); | ||
@@ -105,3 +114,3 @@ expect(comClient).to.have.been.calledOnce; | ||
it('should detect the size of the rendered banner', function () { | ||
bootStrap(exampleHash); | ||
bootStrap(); | ||
var el = document.body.appendChild(document.createElement('span')); | ||
@@ -108,0 +117,0 @@ el.id = 'gardr'; |
28954
4
662
9
- Removedgardr-iframe-params@0.0.1
- Removedgardr-iframe-params@0.0.1(transitive)
- Removedquery-params@0.0.1(transitive)