New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gardr-host

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gardr-host - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

20

lib/iframe.js

@@ -1,2 +0,2 @@

var iframeParams = require('gardr-iframe-params');
var extend = require('util-extend');

@@ -7,3 +7,2 @@ var VER = 1;

var FAILED_CLASS = TYPE + '-failed';
var SEPARATOR = '_|_';

@@ -22,3 +21,11 @@ function validSize(v) {

function updateNameData (el, id, data) {
var nameData = extend({id: id}, data);
el.name = JSON.stringify(nameData);
}
function Iframe(id, options) {
if (typeof id !== 'string' || !id) {
throw new Error('Iframe missing id');
}
this.id = id;

@@ -37,3 +44,2 @@ if (!options || typeof options.iframeUrl === 'undefined') {

Iframe.prototype.SEPARATOR = SEPARATOR;
Iframe.prototype.remove = function() {

@@ -62,2 +68,3 @@ this.wrapper.parentNode.removeChild(this.wrapper);

Iframe.prototype.setData = function (data) {
data.origin = getOrigin(document.location);
this.data = data;

@@ -78,5 +85,3 @@ };

'&',
refresh,
// Wrapped args in predefined order
iframeParams.encode(this.id, {origin: getOrigin(document.location)}, this.data)
refresh
].join('');

@@ -86,2 +91,3 @@ };

Iframe.prototype.refresh = function () {
updateNameData(this.element, this.id, this.data);
this.element.src = this._getUrl(this.element.src);

@@ -111,3 +117,3 @@ };

i.setAttribute('data-automation-id', this.id);
updateNameData(this.element, this.id, this.data);
i.src = this._getUrl();

@@ -114,0 +120,0 @@ i.className = TYPE + '-iframe';

{
"name": "gardr-host",
"version": "0.0.2",
"version": "0.1.0",
"description": "The js part of Gardr which insert and talks with the iframes on the host page",

@@ -11,3 +11,4 @@ "main": "./lib/index.js",

"lint": "./node_modules/.bin/jshint --reporter node_modules/jshint-stylish/stylish.js lib test --exclude test/lib",
"test": "npm run lint && ./node_modules/karma/bin/karma start --single-run"
"test": "npm run lint && ./node_modules/karma/bin/karma start --single-run",
"dist": "mkdir -p dist && ./node_modules/.bin/browserify lib/index.js -d -s gardr.host -o dist/gardr.host.js && ./node_modules/.bin/uglifyjs dist/gardr.host.js -mc -o dist/gardr.host.min.js"
},

@@ -54,3 +55,4 @@ "homepage": "https://github.com/gardr/host",

"karma": "~0.10.9",
"karma-mocha": "~0.1.1"
"karma-mocha": "~0.1.1",
"uglifyjs": "~2.3.6"
},

@@ -60,3 +62,2 @@ "dependencies": {

"query-params": "0.0.1",
"gardr-iframe-params": "0.0.1",
"eventlistener": "0.0.1",

@@ -63,0 +64,0 @@ "cross-domain-events": "0.0.2"

# Garðr - the safe way to add third party content to your site
[![Build Status](https://travis-ci.org/gardr/host.png)](https://travis-ci.org/gardr/host)
[![Build Status](https://api.travis-ci.org/gardr/host.png?branch=master)](https://travis-ci.org/gardr/host)
[![NPM](https://nodei.co/npm/gardr-host.png?stars=true&downloads=true)](https://npmjs.org/package/gardr-host)

@@ -5,0 +6,0 @@ Garðr is a library for embedding content from external sources such as advertisements or similar third party content.

@@ -5,3 +5,10 @@ /* jshint nonew: false, expr: true */

describe('iframe', function () {
var iframeUrl = 'about:blank';
var id, iframe, testNr = 0;
beforeEach(function () {
id = 'iframe-' + (++testNr);
iframe = new Iframe(id, {iframeUrl: iframeUrl});
});
it('should be defined', function(){

@@ -11,24 +18,32 @@ expect(Iframe).to.exist;

it('should require id', function () {
expect(function(){
new Iframe(null, {iframeUrl: iframeUrl});
}).to.throw();
});
it('should require iframeUrl', function(){
expect(function(){
new Iframe('some-test-123');
new Iframe(id);
}).to.throw();
expect(function(){
new Iframe('some-test-123', {});
new Iframe(id, {});
}).to.throw();
});
var id = 'iframe1';
var iframeUrl = 'about:blank';
var frame = new Iframe(id, {iframeUrl: iframeUrl});
it('should set id as property on the instance', function () {
expect(iframe.id).to.equal(id);
});
expect(frame.id).to.equal(id);
it('should use iframeUrl for iframe src', function () {
iframe.makeIframe();
expect(iframe.element.src.indexOf(iframeUrl) === 0).to.equal(true);
});
frame.makeIframe('some=parameters&and=another');
expect(frame.element.src.indexOf(iframeUrl) === 0).to.equal(true);
//....
it('should set a JSON-string including the id as name-attribute on iframe element', function () {
iframe.makeIframe();
expect(iframe.element.name).to.exist;
var params = JSON.parse(iframe.element.name);
expect(params.id).to.equal(id);
});

@@ -39,3 +54,2 @@

iframe.makeIframe();
//expect(iframe.element.width).to.equal('100px');
expect(iframe.element.style.width).to.equal('100px');

@@ -45,4 +59,3 @@ expect(iframe.element.style.height).to.equal('200px');

it('should encode data object to query string', function () {
var iframe = new Iframe('data-test', {iframeUrl: 'about:blank'});
it('should encode data object to a JSON-string on the name-attribute on iframe element', function () {
iframe.setData({

@@ -53,5 +66,5 @@ aNumber: 100,

iframe.makeIframe();
var lastSepIndex = iframe.element.src.lastIndexOf(Iframe.prototype.SEPARATOR);
var dataStr = iframe.element.src.substring(lastSepIndex + Iframe.prototype.SEPARATOR.length);
expect(dataStr).to.equal('aNumber=100&encodeUrl=http%3A%2F%2Ftest.com%2Fpath%3Fa%3Db%26c%3D%C3%A6%C3%B8%C3%A5');
var params = JSON.parse(iframe.element.name);
expect(params).to.exist;
expect(params).to.contain.keys('aNumber', 'encodeUrl', 'origin');
});

@@ -58,0 +71,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc