Socket
Socket
Sign inDemoInstall

pym.js

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pym.js - npm Package Compare versions

Comparing version 0.4.1 to 0.4.3

102

dist/pym.js

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

/*! pym.js - v0.4.1 - 2014-12-12 */
/*! pym.js - v0.4.2 - 2015-04-24 */
/*

@@ -143,5 +143,8 @@ * Pym.js is library that resizes an iframe based on the width of the parent and the resulting height of the child.

this.messageRegex = _makeMessageRegex(this.id);
this.messageRegex = _makeMessageRegex(this.id);
this.messageHandlers = {};
// ensure a config object
config = (config || {});
/**

@@ -158,3 +161,3 @@ * Construct the iframe.

// Create an iframe element attached to the document.
this.iframe = document.createElement("iframe");
this.iframe = document.createElement('iframe');

@@ -177,3 +180,3 @@ // Save fragment id

}
// Append the initial width as a querystring parameter, and the fragment id

@@ -252,9 +255,22 @@ this.iframe.src = this.url + 'initialWidth=' + width + '&childId=' + this.id + hash;

/*
* Handle parent message from child.
* Handle parent height message from child.
*/
var height = parseInt(message);
this.iframe.setAttribute('height', height + 'px');
};
/**
* Navigate parent to a new url.
*
* @memberof Parent.prototype
* @method _onNavigateToMessage
* @param {String} message The url to navigate to.
*/
this._onNavigateToMessage = function(message) {
/*
* Handle parent scroll message from child.
*/
document.location.href = message;
};

@@ -264,2 +280,4 @@ /**

*
* Reserved message names are: "height", "scrollTo" and "navigateTo".
*
* @memberof Parent.prototype

@@ -309,4 +327,5 @@ * @method onMessage

// Add height event callback
// Bind required message handlers
this.onMessage('height', this._onHeightMessage);
this.onMessage('navigateTo', this._onNavigateToMessage);

@@ -344,5 +363,10 @@ // Add a listener for processing messages from the child.

// ensure a config object
config = (config || {});
/**
* Bind a callback to a given messageType from the child.
*
* Reserved message names are: "width".
*
* @memberof Child.prototype

@@ -412,2 +436,29 @@ * @method onMessage

/**
* Resize iframe in response to new width message from parent.
*
* @memberof Child.prototype
* @method _onWidthMessage
* @param {String} message The new width.
*/
this._onWidthMessage = function(message) {
/*
* Handle width message from the child.
*/
var width = parseInt(message);
// Change the width if it's different.
if (width !== this.parentWidth) {
this.parentWidth = width;
// Call the callback function if it exists.
if (this.settings.renderCallback) {
this.settings.renderCallback(width);
}
// Send the height back to the parent.
this.sendHeight();
}
};
/**
* Send a message to the the Parent.

@@ -449,26 +500,21 @@ *

/**
* Resize iframe in response to new width message from parent.
* Scroll parent to a given element id.
*
* @memberof Child.prototype
* @method _onWidthMessage
* @param {String} message The new width.
* @method scrollParentTo
* @param {String} hash The id of the element to scroll to.
*/
this._onWidthMessage = function(message) {
/*
* Handle width message from the child.
*/
var width = parseInt(message);
this.scrollParentTo = function(hash) {
this.sendMessage('navigateTo', '#' + hash);
};
// Change the width if it's different.
if (width !== this.parentWidth) {
this.parentWidth = width;
// Call the callback function if it exists.
if (this.settings.renderCallback) {
this.settings.renderCallback(width);
}
// Send the height back to the parent.
this.sendHeight();
}
/**
* Navigate parent to a given url.
*
* @memberof Parent.prototype
* @method navigateParentTo
* @param {String} url The url to navigate to.
*/
this.navigateParentTo = function(url) {
this.sendMessage('navigateTo', url);
};

@@ -483,3 +529,3 @@

// Bind the width message handler
// Bind the required message handlers
this.onMessage('width', this._onWidthMessage);

@@ -486,0 +532,0 @@

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

/*! pym.js - v0.4.1 - 2014-12-12 */
!function(a){"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&module.exports?module.exports=a():window.pym=a.call(this)}(function(){var a="xPYMx",b={},c=function(a){var b=new RegExp("[\\?&]"+a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]")+"=([^&#]*)"),c=b.exec(location.search);return null===c?"":decodeURIComponent(c[1].replace(/\+/g," "))},d=function(a,b){return"*"===b.xdomain||a.origin.match(new RegExp(b.xdomain+"$"))?!0:void 0},e=function(b,c,d){var e=["pym",b,c,d];return e.join(a)},f=function(b){var c=["pym",b,"(\\S+)","(.+)"];return new RegExp("^"+c.join(a)+"$")},g=function(){for(var a=document.querySelectorAll("[data-pym-src]:not([data-pym-auto-initialized])"),c=a.length,d=0;c>d;++d){var e=a[d];e.setAttribute("data-pym-auto-initialized",""),""===e.id&&(e.id="pym-"+d);var f=e.getAttribute("data-pym-src"),g=e.getAttribute("data-pym-xdomain"),h={};g&&(h.xdomain=g),new b.Parent(e.id,f,h)}};return b.Parent=function(a,b,c){this.id=a,this.url=b,this.el=document.getElementById(a),this.iframe=null,this.settings={xdomain:"*"},this.messageRegex=f(this.id),this.messageHandlers={},this._constructIframe=function(){var a=this.el.offsetWidth.toString();this.iframe=document.createElement("iframe");var b="",c=this.url.indexOf("#");c>-1&&(b=this.url.substring(c,this.url.length),this.url=this.url.substring(0,c)),this.url+=this.url.indexOf("?")<0?"?":"&",this.iframe.src=this.url+"initialWidth="+a+"&childId="+this.id+b,this.iframe.setAttribute("width","100%"),this.iframe.setAttribute("scrolling","no"),this.iframe.setAttribute("marginheight","0"),this.iframe.setAttribute("frameborder","0"),this.el.appendChild(this.iframe);var d=this;window.addEventListener("resize",function(){d.sendWidth()})},this._fire=function(a,b){if(a in this.messageHandlers)for(var c=0;c<this.messageHandlers[a].length;c++)this.messageHandlers[a][c].call(this,b)},this._processMessage=function(a){if(d(a,this.settings)){var b=a.data.match(this.messageRegex);if(!b||3!==b.length)return!1;var c=b[1],e=b[2];this._fire(c,e)}},this._onHeightMessage=function(a){var b=parseInt(a);this.iframe.setAttribute("height",b+"px")},this.onMessage=function(a,b){a in this.messageHandlers||(this.messageHandlers[a]=[]),this.messageHandlers[a].push(b)},this.sendMessage=function(a,b){this.el.getElementsByTagName("iframe")[0].contentWindow.postMessage(e(this.id,a,b),"*")},this.sendWidth=function(){var a=this.el.offsetWidth.toString();this.sendMessage("width",a)};for(var g in c)this.settings[g]=c[g];this.onMessage("height",this._onHeightMessage);var h=this;return window.addEventListener("message",function(a){return h._processMessage(a)},!1),this._constructIframe(),this},b.Child=function(b){this.parentWidth=null,this.id=null,this.settings={renderCallback:null,xdomain:"*",polling:0},this.messageRegex=null,this.messageHandlers={},this.onMessage=function(a,b){a in this.messageHandlers||(this.messageHandlers[a]=[]),this.messageHandlers[a].push(b)},this._fire=function(a,b){if(a in this.messageHandlers)for(var c=0;c<this.messageHandlers[a].length;c++)this.messageHandlers[a][c].call(this,b)},this._processMessage=function(a){if(d(a,this.settings)){var b=a.data.match(this.messageRegex);if(b&&3===b.length){var c=b[1],e=b[2];this._fire(c,e)}}},this.sendMessage=function(a,b){window.parent.postMessage(e(this.id,a,b),"*")},this.sendHeight=function(){var a=document.getElementsByTagName("body")[0].offsetHeight.toString();h.sendMessage("height",a)},this._onWidthMessage=function(a){var b=parseInt(a);b!==this.parentWidth&&(this.parentWidth=b,this.settings.renderCallback&&this.settings.renderCallback(b),this.sendHeight())},this.id=c("childId")||b.id,this.messageRegex=new RegExp("^pym"+a+this.id+a+"(\\S+)"+a+"(.+)$");var f=parseInt(c("initialWidth"));this.onMessage("width",this._onWidthMessage);for(var g in b)this.settings[g]=b[g];var h=this;return window.addEventListener("message",function(a){h._processMessage(a)},!1),this.settings.renderCallback&&this.settings.renderCallback(f),this.sendHeight(),this.settings.polling&&window.setInterval(this.sendHeight,this.settings.polling),this},g(),b});
/*! pym.js - v0.4.2 - 2015-04-24 */
!function(a){"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&module.exports?module.exports=a():window.pym=a.call(this)}(function(){var a="xPYMx",b={},c=function(a){var b=new RegExp("[\\?&]"+a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]")+"=([^&#]*)"),c=b.exec(location.search);return null===c?"":decodeURIComponent(c[1].replace(/\+/g," "))},d=function(a,b){return"*"===b.xdomain||a.origin.match(new RegExp(b.xdomain+"$"))?!0:void 0},e=function(b,c,d){var e=["pym",b,c,d];return e.join(a)},f=function(b){var c=["pym",b,"(\\S+)","(.+)"];return new RegExp("^"+c.join(a)+"$")},g=function(){for(var a=document.querySelectorAll("[data-pym-src]:not([data-pym-auto-initialized])"),c=a.length,d=0;c>d;++d){var e=a[d];e.setAttribute("data-pym-auto-initialized",""),""===e.id&&(e.id="pym-"+d);var f=e.getAttribute("data-pym-src"),g=e.getAttribute("data-pym-xdomain"),h={};g&&(h.xdomain=g),new b.Parent(e.id,f,h)}};return b.Parent=function(a,b,c){this.id=a,this.url=b,this.el=document.getElementById(a),this.iframe=null,this.settings={xdomain:"*"},this.messageRegex=f(this.id),this.messageHandlers={},c=c||{},this._constructIframe=function(){var a=this.el.offsetWidth.toString();this.iframe=document.createElement("iframe");var b="",c=this.url.indexOf("#");c>-1&&(b=this.url.substring(c,this.url.length),this.url=this.url.substring(0,c)),this.url.indexOf("?")<0?this.url+="?":this.url+="&",this.iframe.src=this.url+"initialWidth="+a+"&childId="+this.id+b,this.iframe.setAttribute("width","100%"),this.iframe.setAttribute("scrolling","no"),this.iframe.setAttribute("marginheight","0"),this.iframe.setAttribute("frameborder","0"),this.el.appendChild(this.iframe);var d=this;window.addEventListener("resize",function(){d.sendWidth()})},this._fire=function(a,b){if(a in this.messageHandlers)for(var c=0;c<this.messageHandlers[a].length;c++)this.messageHandlers[a][c].call(this,b)},this._processMessage=function(a){if(d(a,this.settings)){var b=a.data.match(this.messageRegex);if(!b||3!==b.length)return!1;var c=b[1],e=b[2];this._fire(c,e)}},this._onHeightMessage=function(a){var b=parseInt(a);this.iframe.setAttribute("height",b+"px")},this._onNavigateToMessage=function(a){document.location.href=a},this.onMessage=function(a,b){a in this.messageHandlers||(this.messageHandlers[a]=[]),this.messageHandlers[a].push(b)},this.sendMessage=function(a,b){this.el.getElementsByTagName("iframe")[0].contentWindow.postMessage(e(this.id,a,b),"*")},this.sendWidth=function(){var a=this.el.offsetWidth.toString();this.sendMessage("width",a)};for(var g in c)this.settings[g]=c[g];this.onMessage("height",this._onHeightMessage),this.onMessage("navigateTo",this._onNavigateToMessage);var h=this;return window.addEventListener("message",function(a){return h._processMessage(a)},!1),this._constructIframe(),this},b.Child=function(b){this.parentWidth=null,this.id=null,this.settings={renderCallback:null,xdomain:"*",polling:0},this.messageRegex=null,this.messageHandlers={},b=b||{},this.onMessage=function(a,b){a in this.messageHandlers||(this.messageHandlers[a]=[]),this.messageHandlers[a].push(b)},this._fire=function(a,b){if(a in this.messageHandlers)for(var c=0;c<this.messageHandlers[a].length;c++)this.messageHandlers[a][c].call(this,b)},this._processMessage=function(a){if(d(a,this.settings)){var b=a.data.match(this.messageRegex);if(b&&3===b.length){var c=b[1],e=b[2];this._fire(c,e)}}},this._onWidthMessage=function(a){var b=parseInt(a);b!==this.parentWidth&&(this.parentWidth=b,this.settings.renderCallback&&this.settings.renderCallback(b),this.sendHeight())},this.sendMessage=function(a,b){window.parent.postMessage(e(this.id,a,b),"*")},this.sendHeight=function(){var a=document.getElementsByTagName("body")[0].offsetHeight.toString();h.sendMessage("height",a)},this.scrollParentTo=function(a){this.sendMessage("navigateTo","#"+a)},this.navigateParentTo=function(a){this.sendMessage("navigateTo",a)},this.id=c("childId")||b.id,this.messageRegex=new RegExp("^pym"+a+this.id+a+"(\\S+)"+a+"(.+)$");var f=parseInt(c("initialWidth"));this.onMessage("width",this._onWidthMessage);for(var g in b)this.settings[g]=b[g];var h=this;return window.addEventListener("message",function(a){h._processMessage(a)},!1),this.settings.renderCallback&&this.settings.renderCallback(f),this.sendHeight(),this.settings.polling&&window.setInterval(this.sendHeight,this.settings.polling),this},g(),b});
{
"name": "pym.js",
"version": "0.4.1",
"version": "0.4.3",
"description": "Resize an iframe responsively depending on the height of its content and the width of its container.",
"main": "src/pym.js",
"main": "dist/pym.js",
"directories": {

@@ -21,2 +21,5 @@ "example": "examples"

],
"files": [
"dist"
],
"author": "NPR",

@@ -23,0 +26,0 @@ "license": "MIT",

@@ -25,3 +25,3 @@ # Pym.js

Uniminifiedd source can be regenerated with:
Unminified source can be regenerated with:

@@ -44,2 +44,4 @@ ```

The release process is documented [on the wiki](https://github.com/nprapps/pym.js/wiki/Release-Process).
## License & Credits

@@ -53,3 +55,3 @@

* [Pierre-Yves Jamon](https://github.com/Pym)
* [Pierre-Yves Jamon](https://github.com/Pym)
* [jugglinmike](https://github.com/jugglinmike)

@@ -61,1 +63,3 @@ * [David Rogers](https://github.com/al-the-x)

* [Justin Dearing](https://github.com/zippy1981)
* [Chris Amico](https://github.com/eyeseast)
* [Ryan Murphy](https://github.com/rdmurphy))

Sorry, the diff of this file is not supported yet

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