Comparing version 0.4.3 to 0.4.5
@@ -1,2 +0,2 @@ | ||
/*! pym.js - v0.4.2 - 2015-04-24 */ | ||
/*! pym.js - v0.4.4 - 2015-07-16 */ | ||
/* | ||
@@ -180,3 +180,7 @@ * Pym.js is library that resizes an iframe based on the width of the parent and the resulting height of the child. | ||
// Append the initial width as a querystring parameter, and the fragment id | ||
this.iframe.src = this.url + 'initialWidth=' + width + '&childId=' + this.id + hash; | ||
this.iframe.src = this.url + | ||
'initialWidth=' + width + | ||
'&childId=' + this.id + | ||
'&parentUrl=' + encodeURIComponent(window.location.href) + | ||
hash; | ||
@@ -193,9 +197,16 @@ // Set some attributes to this proto-iframe. | ||
// Add an event listener that will handle redrawing the child on resize. | ||
var that = this; | ||
window.addEventListener('resize', function() { | ||
that.sendWidth(); | ||
}); | ||
window.addEventListener('resize', this._onResize); | ||
}; | ||
/** | ||
* Send width on resize. | ||
* | ||
* @memberof Parent.prototype | ||
* @method _onResize | ||
*/ | ||
this._onResize = function() { | ||
this.sendWidth(); | ||
}.bind(this); | ||
/** | ||
* Fire all event handlers for a given message type. | ||
@@ -217,2 +228,15 @@ * | ||
/** | ||
* Remove this parent from the page and unbind it's event handlers. | ||
* | ||
* @memberof Parent.prototype | ||
* @method remove | ||
*/ | ||
this.remove = function() { | ||
window.removeEventListener('message', this._processMessage); | ||
window.removeEventListener('resize', this._onResize); | ||
this.el.removeChild(this.iframe); | ||
}; | ||
/** | ||
* @callback Parent~onMessageCallback | ||
@@ -230,4 +254,12 @@ * @param {String} message The message data. | ||
this._processMessage = function(e) { | ||
if (!_isSafeMessage(e, this.settings)) { return; } | ||
// First, punt if this isn't from an acceptable xdomain. | ||
if (!_isSafeMessage(e, this.settings)) { | ||
return; | ||
} | ||
// Discard object messages, we only care about strings | ||
if (typeof e.data !== 'string') { | ||
return; | ||
} | ||
// Grab the message from the child and parse it. | ||
@@ -245,3 +277,3 @@ var match = e.data.match(this.messageRegex); | ||
this._fire(messageType, message); | ||
}; | ||
}.bind(this); | ||
@@ -332,6 +364,3 @@ /** | ||
// Add a listener for processing messages from the child. | ||
var that = this; | ||
window.addEventListener('message', function(e) { | ||
return that._processMessage(e); | ||
}, false); | ||
window.addEventListener('message', this._processMessage, false); | ||
@@ -353,2 +382,3 @@ // Construct the iframe in the container element. | ||
this.id = null; | ||
this.parentUrl = null; | ||
@@ -364,3 +394,3 @@ this.settings = { | ||
// ensure a config object | ||
// Ensure a config object | ||
config = (config || {}); | ||
@@ -422,4 +452,11 @@ | ||
// First, punt if this isn't from an acceptable xdomain. | ||
if (!_isSafeMessage(e, this.settings)) { return; } | ||
if (!_isSafeMessage(e, this.settings)) { | ||
return; | ||
} | ||
// Discard object messages, we only care about strings | ||
if (typeof e.data !== 'string') { | ||
return; | ||
} | ||
// Get the message from the parent. | ||
@@ -435,3 +472,3 @@ var match = e.data.match(this.messageRegex); | ||
this._fire(messageType, message); | ||
}; | ||
}.bind(this); | ||
@@ -489,7 +526,2 @@ /** | ||
this.sendHeight = function() { | ||
/* | ||
* Transmit the current iframe height to the parent. | ||
* Make this callable from external scripts in case they update the body out of sequence. | ||
*/ | ||
// Get the child's height. | ||
@@ -499,4 +531,4 @@ var height = document.getElementsByTagName('body')[0].offsetHeight.toString(); | ||
// Send the height to the parent. | ||
that.sendMessage('height', height); | ||
}; | ||
this.sendMessage('height', height); | ||
}.bind(this); | ||
@@ -532,2 +564,5 @@ /** | ||
// Get the url of the parent frame | ||
this.parentUrl = _getParameterByName('parentUrl'); | ||
// Bind the required message handlers | ||
@@ -542,6 +577,3 @@ this.onMessage('width', this._onWidthMessage); | ||
// Set up a listener to handle any incoming messages. | ||
var that = this; | ||
window.addEventListener('message', function(e) { | ||
that._processMessage(e); | ||
}, false); | ||
window.addEventListener('message', this._processMessage, false); | ||
@@ -548,0 +580,0 @@ // If there's a callback function, call it. |
@@ -1,2 +0,2 @@ | ||
/*! 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}); | ||
/*! pym.js - v0.4.4 - 2015-07-16 */ | ||
!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+"&parentUrl="+encodeURIComponent(window.location.href)+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),window.addEventListener("resize",this._onResize)},this._onResize=function(){this.sendWidth()}.bind(this),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.remove=function(){window.removeEventListener("message",this._processMessage),window.removeEventListener("resize",this._onResize),this.el.removeChild(this.iframe)},this._processMessage=function(a){if(d(a,this.settings)&&"string"==typeof a.data){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)}}.bind(this),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];return this.onMessage("height",this._onHeightMessage),this.onMessage("navigateTo",this._onNavigateToMessage),window.addEventListener("message",this._processMessage,!1),this._constructIframe(),this},b.Child=function(b){this.parentWidth=null,this.id=null,this.parentUrl=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)&&"string"==typeof a.data){var b=a.data.match(this.messageRegex);if(b&&3===b.length){var c=b[1],e=b[2];this._fire(c,e)}}}.bind(this),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();this.sendMessage("height",a)}.bind(this),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.parentUrl=c("parentUrl"),this.onMessage("width",this._onWidthMessage);for(var g in b)this.settings[g]=b[g];return window.addEventListener("message",this._processMessage,!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.3", | ||
"version": "0.4.5", | ||
"description": "Resize an iframe responsively depending on the height of its content and the width of its container.", | ||
@@ -5,0 +5,0 @@ "main": "dist/pym.js", |
@@ -61,2 +61,2 @@ # Pym.js | ||
* [Chris Amico](https://github.com/eyeseast) | ||
* [Ryan Murphy](https://github.com/rdmurphy)) | ||
* [Ryan Murphy](https://github.com/rdmurphy) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28836
495
0