@onefootprint/postmate
Advanced tools
Comparing version 2.1.1 to 2.1.2
/** | ||
@onefootprint/postmate - A powerful, simple, promise-based postMessage library | ||
@version v2.1.1 | ||
@version v2.1.2 | ||
@link https://github.com/dollarshaveclub/postmate | ||
@@ -307,2 +307,3 @@ @author Jacob Kelley <jakie8@gmail.com> | ||
allow = _ref2.allow, | ||
id = _ref2.id, | ||
_ref2$classListArray = _ref2.classListArray, | ||
@@ -320,2 +321,6 @@ classListArray = _ref2$classListArray === void 0 ? [] : _ref2$classListArray; | ||
if (id) { | ||
this.frame.id = id; | ||
} | ||
container.appendChild(this.frame); | ||
@@ -322,0 +327,0 @@ this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow; |
/** | ||
@onefootprint/postmate - A powerful, simple, promise-based postMessage library | ||
@version v2.1.1 | ||
@version v2.1.2 | ||
@link https://github.com/dollarshaveclub/postmate | ||
@@ -301,2 +301,3 @@ @author Jacob Kelley <jakie8@gmail.com> | ||
allow = _ref2.allow, | ||
id = _ref2.id, | ||
_ref2$classListArray = _ref2.classListArray, | ||
@@ -314,2 +315,6 @@ classListArray = _ref2$classListArray === void 0 ? [] : _ref2$classListArray; | ||
if (id) { | ||
this.frame.id = id; | ||
} | ||
container.appendChild(this.frame); | ||
@@ -316,0 +321,0 @@ this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow; |
/** | ||
@onefootprint/postmate - A powerful, simple, promise-based postMessage library | ||
@version v2.1.1 | ||
@version v2.1.2 | ||
@link https://github.com/dollarshaveclub/postmate | ||
@@ -303,2 +303,3 @@ @author Jacob Kelley <jakie8@gmail.com> | ||
allow = _ref2.allow, | ||
id = _ref2.id, | ||
_ref2$classListArray = _ref2.classListArray, | ||
@@ -316,2 +317,6 @@ classListArray = _ref2$classListArray === void 0 ? [] : _ref2$classListArray; | ||
if (id) { | ||
this.frame.id = id; | ||
} | ||
container.appendChild(this.frame); | ||
@@ -318,0 +323,0 @@ this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow; |
/** | ||
@onefootprint/postmate - A powerful, simple, promise-based postMessage library | ||
@version v2.1.1 | ||
@version v2.1.2 | ||
@link https://github.com/dollarshaveclub/postmate | ||
@@ -8,2 +8,2 @@ @author Jacob Kelley <jakie8@gmail.com> | ||
**/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Postmate=t()}(this,function(){"use strict";var h="application/x-postmate-v1+json",r=0,n={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},l=function(e,t){return("string"!=typeof t||e.origin===t)&&(!!e.data&&(("object"!=typeof e.data||"postmate"in e.data)&&(e.data.type===h&&!!n[e.data.postmate])))},p=function(){function e(e){var a=this;this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.events={},this.listener=function(e){if(!l(e,a.childOrigin))return!1;var t=((e||{}).data||{}).value||{},n=t.data,i=t.name;"emit"===e.data.postmate&&i in a.events&&a.events[i].forEach(function(e){e.call(a,n)})},this.parent.addEventListener("message",this.listener,!1)}var t=e.prototype;return t.get=function(e){var a=this;return new c.Promise(function(n){var i=++r;a.parent.addEventListener("message",function e(t){t.data.uid===i&&"reply"===t.data.postmate&&(a.parent.removeEventListener("message",e,!1),n(t.data.value))},!1),a.child.postMessage({postmate:"request",type:h,property:e,uid:i},a.childOrigin)})},t.call=function(e,t){this.child.postMessage({postmate:"call",type:h,property:e,data:t},this.childOrigin)},t.on=function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},e}(),s=function(){function e(e){var d=this;this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,this.child.addEventListener("message",function(t){if(l(t,d.parentOrigin)){var e,n,i,a=t.data,r=a.property,s=a.uid,o=a.data;if("call"!==t.data.postmate)(e=d.model,n=r,i="function"==typeof e[n]?e[n]():e[n],c.Promise.resolve(i)).then(function(e){return t.source.postMessage({property:r,postmate:"reply",type:h,uid:s,value:e},t.origin)});else r in d.model&&"function"==typeof d.model[r]&&d.model[r](o)}})}return e.prototype.emit=function(e,t){this.parent.postMessage({postmate:"emit",type:h,value:{name:e,data:t}},this.parentOrigin)},e}(),c=function(){function e(e){var t=e.container,n=void 0===t?void 0!==n?n:document.body:t,i=e.model,a=e.url,r=e.name,s=void 0===r?"":r,o=e.allow,d=e.classListArray,h=void 0===d?[]:d;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,h),o&&(this.frame.allow=o),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}return e.prototype.sendHandshake=function(a){var r,s=this,o=function(e){var t=document.createElement("a");t.href=e;var n=4<t.protocol.length?t.protocol:window.location.protocol,i=t.host.length?"80"===t.port||"443"===t.port?t.hostname:t.host:window.location.host;return t.origin||n+"//"+i}(a),d=0;return new e.Promise(function(n,i){s.parent.addEventListener("message",function e(t){return!!l(t,o)&&("handshake-reply"===t.data.postmate?(clearInterval(r),s.parent.removeEventListener("message",e,!1),s.childOrigin=t.origin,n(new p(s))):i("Failed handshake"))},!1);var e=function(){if(d++,s.child.postMessage({postmate:"handshake",type:h,model:s.model},o),5===d)return clearInterval(r),i("Failed to handshake")},t=function(){e(),r=setInterval(e,500)};s.frame.attachEvent?s.frame.attachEvent("onload",t):s.frame.addEventListener("load",t),s.frame.src=a})},e}();return c.debug=!1,c.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}(),c.Model=function(){function e(e){return this.child=window,this.model=e,this.parent=this.child.parent,this.sendHandshakeReply()}return e.prototype.sendHandshakeReply=function(){var r=this;return new c.Promise(function(i,a){r.child.addEventListener("message",function e(t){if(t.data.postmate){if("handshake"!==t.data.postmate)return a("Handshake Reply Failed");r.child.removeEventListener("message",e,!1),t.source.postMessage({postmate:"handshake-reply",type:h},t.origin),r.parentOrigin=t.origin;var n=t.data.model;return n&&Object.keys(n).forEach(function(e){r.model[e]=n[e]}),i(new s(r))}},!1)})},e}(),c}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Postmate=t()}(this,function(){"use strict";var h="application/x-postmate-v1+json",r=0,n={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},l=function(e,t){return("string"!=typeof t||e.origin===t)&&(!!e.data&&(("object"!=typeof e.data||"postmate"in e.data)&&(e.data.type===h&&!!n[e.data.postmate])))},p=function(){function e(e){var a=this;this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.events={},this.listener=function(e){if(!l(e,a.childOrigin))return!1;var t=((e||{}).data||{}).value||{},n=t.data,i=t.name;"emit"===e.data.postmate&&i in a.events&&a.events[i].forEach(function(e){e.call(a,n)})},this.parent.addEventListener("message",this.listener,!1)}var t=e.prototype;return t.get=function(e){var a=this;return new c.Promise(function(n){var i=++r;a.parent.addEventListener("message",function e(t){t.data.uid===i&&"reply"===t.data.postmate&&(a.parent.removeEventListener("message",e,!1),n(t.data.value))},!1),a.child.postMessage({postmate:"request",type:h,property:e,uid:i},a.childOrigin)})},t.call=function(e,t){this.child.postMessage({postmate:"call",type:h,property:e,data:t},this.childOrigin)},t.on=function(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},e}(),s=function(){function e(e){var d=this;this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,this.child.addEventListener("message",function(t){if(l(t,d.parentOrigin)){var e,n,i,a=t.data,r=a.property,s=a.uid,o=a.data;if("call"!==t.data.postmate)(e=d.model,n=r,i="function"==typeof e[n]?e[n]():e[n],c.Promise.resolve(i)).then(function(e){return t.source.postMessage({property:r,postmate:"reply",type:h,uid:s,value:e},t.origin)});else r in d.model&&"function"==typeof d.model[r]&&d.model[r](o)}})}return e.prototype.emit=function(e,t){this.parent.postMessage({postmate:"emit",type:h,value:{name:e,data:t}},this.parentOrigin)},e}(),c=function(){function e(e){var t=e.container,n=void 0===t?void 0!==n?n:document.body:t,i=e.model,a=e.url,r=e.name,s=void 0===r?"":r,o=e.allow,d=e.id,h=e.classListArray,l=void 0===h?[]:h;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,l),o&&(this.frame.allow=o),d&&(this.frame.id=d),n.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=i||{},this.sendHandshake(a)}return e.prototype.sendHandshake=function(a){var r,s=this,o=function(e){var t=document.createElement("a");t.href=e;var n=4<t.protocol.length?t.protocol:window.location.protocol,i=t.host.length?"80"===t.port||"443"===t.port?t.hostname:t.host:window.location.host;return t.origin||n+"//"+i}(a),d=0;return new e.Promise(function(n,i){s.parent.addEventListener("message",function e(t){return!!l(t,o)&&("handshake-reply"===t.data.postmate?(clearInterval(r),s.parent.removeEventListener("message",e,!1),s.childOrigin=t.origin,n(new p(s))):i("Failed handshake"))},!1);var e=function(){if(d++,s.child.postMessage({postmate:"handshake",type:h,model:s.model},o),5===d)return clearInterval(r),i("Failed to handshake")},t=function(){e(),r=setInterval(e,500)};s.frame.attachEvent?s.frame.attachEvent("onload",t):s.frame.addEventListener("load",t),s.frame.src=a})},e}();return c.debug=!1,c.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}(),c.Model=function(){function e(e){return this.child=window,this.model=e,this.parent=this.child.parent,this.sendHandshakeReply()}return e.prototype.sendHandshakeReply=function(){var r=this;return new c.Promise(function(i,a){r.child.addEventListener("message",function e(t){if(t.data.postmate){if("handshake"!==t.data.postmate)return a("Handshake Reply Failed");r.child.removeEventListener("message",e,!1),t.source.postMessage({postmate:"handshake-reply",type:h},t.origin),r.parentOrigin=t.origin;var n=t.data.model;return n&&Object.keys(n).forEach(function(e){r.model[e]=n[e]}),i(new s(r))}},!1)})},e}(),c}); |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "A powerful, simple, promise-based postMessage library", | ||
@@ -9,0 +9,0 @@ "main": "build/postmate.js", |
@@ -269,2 +269,3 @@ | ||
allow, | ||
id, | ||
classListArray = [], | ||
@@ -279,2 +280,5 @@ }) { // eslint-disable-line no-undef | ||
} | ||
if (id) { | ||
this.frame.id = id | ||
} | ||
container.appendChild(this.frame) | ||
@@ -281,0 +285,0 @@ this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow |
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
89669
2180