From 482d76c7be0f47049e8ab3987873182b8848af2c Mon Sep 17 00:00:00 2001 From: lutangar Date: Fri, 3 Jun 2016 11:21:31 +0200 Subject: [PATCH 1/3] add package.json --- package.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..3c9d717 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "porthole", + "version": "1.0.0", + "description": "A proxy to safely communicate to cross-domain iframes in javascript.", + "main": "src/porthole", + "directories": { + "example": "example", + "lib": "src", + "doc": "jsdoc" + }, + "scripts": { + "test": "rake jasmine" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ternarylabs/porthole.git" + }, + "author": "Ternary Labs", + "license": "MIT", + "bugs": { + "url": "https://github.com/ternarylabs/porthole/issues" + }, + "homepage": "https://github.com/ternarylabs/porthole#readme" +} From 634b90cc394069465441c32c53a0ded3414490d4 Mon Sep 17 00:00:00 2001 From: lutangar Date: Fri, 3 Jun 2016 14:01:13 +0200 Subject: [PATCH 2/3] fix export to work on both node and the browser --- src/porthole.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/porthole.js b/src/porthole.js index 950275c..ef1c087 100644 --- a/src/porthole.js +++ b/src/porthole.js @@ -43,11 +43,12 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) * MIT Licensed. */ // Inspired by base2 and Prototype -(function(){ +(function(window){ + 'use strict'; var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) - this.PortholeClass = function(){}; + var PortholeClass = function(){}; // Create a new Class that inherits from this class PortholeClass.extend = function(prop) { @@ -97,14 +98,10 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) Class.prototype.constructor = Class; // And make this class extendable - Class.extend = arguments.callee; + Class.extend = PortholeClass.extend; return Class; }; -})(); - -(function (window) { - 'use strict'; /** * @overview Porthole, JavaScript Library for Secure Cross Domain iFrame Communication. @@ -509,9 +506,9 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) }; // Support testing in node.js: - if (typeof window.exports !== 'undefined') { - window.exports.Porthole = Porthole; + if (typeof exports !== 'undefined') { + module.exports = Porthole; } else { window.Porthole = Porthole; } -})(this); +})(typeof window !== "undefined" ? window : this); From 04e9482059b335855213fd1aa02977445e247643 Mon Sep 17 00:00:00 2001 From: lutangar Date: Fri, 3 Jun 2016 14:01:22 +0200 Subject: [PATCH 3/3] update build and demo files --- example/abc.com/js/porthole.js | 20 +++++++++---------- example/abc.com/js/porthole.min.js | 2 +- .../porthole/js/porthole.js | 20 +++++++++---------- .../porthole/js/porthole.min.js | 2 +- src/porthole.min.js | 2 +- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/example/abc.com/js/porthole.js b/example/abc.com/js/porthole.js index 84c3610..ef1c087 100644 --- a/example/abc.com/js/porthole.js +++ b/example/abc.com/js/porthole.js @@ -43,11 +43,12 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) * MIT Licensed. */ // Inspired by base2 and Prototype -(function(){ +(function(window){ + 'use strict'; var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) - this.PortholeClass = function(){}; + var PortholeClass = function(){}; // Create a new Class that inherits from this class PortholeClass.extend = function(prop) { @@ -97,14 +98,10 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) Class.prototype.constructor = Class; // And make this class extendable - Class.extend = arguments.callee; + Class.extend = PortholeClass.extend; return Class; }; -})(); - -(function (window) { - 'use strict'; /** * @overview Porthole, JavaScript Library for Secure Cross Domain iFrame Communication. @@ -132,7 +129,7 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) * @private */ error: function(s) { - if (window.console !== undefined) { + if (typeof window.console !== undefined && typeof window.console.error === 'function') { window.console.error('Porthole: ' + s); } } @@ -231,6 +228,7 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) try { this.eventListeners[i](event); } catch(e) { + Porthole.error(e); } } } @@ -508,9 +506,9 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) }; // Support testing in node.js: - if (typeof window.exports !== 'undefined') { - window.exports.Porthole = Porthole; + if (typeof exports !== 'undefined') { + module.exports = Porthole; } else { window.Porthole = Porthole; } -})(this); +})(typeof window !== "undefined" ? window : this); diff --git a/example/abc.com/js/porthole.min.js b/example/abc.com/js/porthole.min.js index 3cda48c..0acee2c 100644 --- a/example/abc.com/js/porthole.min.js +++ b/example/abc.com/js/porthole.min.js @@ -1 +1 @@ -(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.PortholeClass=function(){};PortholeClass.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=typeof g[d]=="function"&&typeof f[d]=="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}})(d,g[d]):g[d]}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.prototype.constructor=c;c.extend=arguments.callee;return c}})();(function(c){var b={debug:false,trace:function(d){if(this.debug&&c.console!==undefined){c.console.log("Porthole: "+d)}},error:function(d){if(c.console!==undefined){c.console.error("Porthole: "+d)}}};b.WindowProxy=function(){};b.WindowProxy.prototype={post:function(e,d){},addEventListener:function(d){},removeEventListener:function(d){}};b.WindowProxyBase=PortholeClass.extend({init:function(d){if(d===undefined){d=""}this.targetWindowName=d;this.origin=c.location.protocol+"//"+c.location.host;this.eventListeners=[]},getTargetWindowName:function(){return this.targetWindowName},getOrigin:function(){return this.origin},getTargetWindow:function(){return b.WindowProxy.getTargetWindow(this.targetWindowName)},post:function(e,d){if(d===undefined){d="*"}this.dispatchMessage({data:e,sourceOrigin:this.getOrigin(),targetOrigin:d,sourceWindowName:c.name,targetWindowName:this.getTargetWindowName()})},addEventListener:function(d){this.eventListeners.push(d);return d},removeEventListener:function(g){var d;try{d=this.eventListeners.indexOf(g);this.eventListeners.splice(d,1)}catch(h){this.eventListeners=[]}},dispatchEvent:function(f){var d;for(d=0;d50?50:100}}});b.WindowProxyHTML5=b.WindowProxyBase.extend({init:function(d,e){this._super(e);this.eventListenerCallback=null},dispatchMessage:function(d){this.getTargetWindow().postMessage(b.WindowProxy.serialize(d),d.targetOrigin)},addEventListener:function(e){if(this.eventListeners.length===0){var d=this;if(c.addEventListener){this.eventListenerCallback=function(f){d.eventListener(d,f)};c.addEventListener("message",this.eventListenerCallback,false)}else{if(c.attachEvent){this.eventListenerCallback=function(f){d.eventListener(d,c.event)};c.attachEvent("onmessage",this.eventListenerCallback)}}}return this._super(e)},removeEventListener:function(d){this._super(d);if(this.eventListeners.length===0){if(c.removeEventListener){c.removeEventListener("message",this.eventListenerCallback)}else{if(c.detachEvent){if(typeof c.onmessage==="undefined"){c.onmessage=null}c.detachEvent("onmessage",this.eventListenerCallback)}}this.eventListenerCallback=null}},eventListener:function(e,d){var f=b.WindowProxy.unserialize(d.data);if(f&&(e.targetWindowName===""||f.sourceWindowName==e.targetWindowName)){e.dispatchEvent(new b.MessageEvent(f.data,d.origin,e))}}});if(!c.postMessage){b.trace("Using legacy browser support");b.WindowProxy=b.WindowProxyLegacy.extend({})}else{b.trace("Using built-in browser support");b.WindowProxy=b.WindowProxyHTML5.extend({})}b.WindowProxy.serialize=function(d){if(typeof JSON==="undefined"){throw new Error("Porthole serialization depends on JSON!")}return JSON.stringify(d)};b.WindowProxy.unserialize=function(g){if(typeof JSON==="undefined"){throw new Error("Porthole unserialization dependens on JSON!")}try{var d=JSON.parse(g)}catch(f){return false}return d};b.WindowProxy.getTargetWindow=function(d){if(d===""){return parent}else{if(d==="top"||d==="parent"){return c[d]}}return c.frames[d]};b.MessageEvent=function a(f,d,e){this.data=f;this.origin=d;this.source=e};b.WindowProxyDispatcher={forwardMessageEvent:function(i){var g,h=c.decodeURIComponent,f,d;if(document.location.hash.length>0){g=b.WindowProxy.unserialize(h(document.location.hash.substr(1)));f=b.WindowProxy.getTargetWindow(g.targetWindowName);d=b.WindowProxyDispatcher.findWindowProxyObjectInWindow(f,g.sourceWindowName);if(d){if(d.origin===g.targetOrigin||g.targetOrigin==="*"){d.dispatchEvent(new b.MessageEvent(g.data,g.sourceOrigin,d))}else{b.error("Target origin "+d.origin+" does not match desired target of "+g.targetOrigin)}}else{b.error("Could not find window proxy object on the target window")}}},findWindowProxyObjectInWindow:function(d,g){var f;if(d){for(f in d){if(Object.prototype.hasOwnProperty.call(d,f)){try{if(d[f]!==null&&typeof d[f]==="object"&&d[f] instanceof d.Porthole.WindowProxy&&d[f].getTargetWindowName()===g){return d[f]}}catch(h){}}}}return null},start:function(){if(c.addEventListener){c.addEventListener("resize",b.WindowProxyDispatcher.forwardMessageEvent,false)}else{if(c.attachEvent&&c.postMessage!=="undefined"){c.attachEvent("onresize",b.WindowProxyDispatcher.forwardMessageEvent)}else{if(document.body.attachEvent){c.attachEvent("onresize",b.WindowProxyDispatcher.forwardMessageEvent)}else{b.error("Cannot attach resize event")}}}}};if(typeof c.exports!=="undefined"){c.exports.Porthole=b}else{c.Porthole=b}})(this); \ No newline at end of file +(function(f){var b=false,e=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;var c=function(){};c.extend=function(k){var j=this.prototype;b=true;var i=new this();b=false;for(var h in k){i[h]=typeof k[h]=="function"&&typeof j[h]=="function"&&e.test(k[h])?(function(l,m){return function(){var o=this._super;this._super=j[l];var n=m.apply(this,arguments);this._super=o;return n}})(h,k[h]):k[h]}function g(){if(!b&&this.init){this.init.apply(this,arguments)}}g.prototype=i;g.prototype.constructor=g;g.extend=c.extend;return g};var d={debug:false,trace:function(g){if(this.debug&&f.console!==undefined){f.console.log("Porthole: "+g)}},error:function(g){if(typeof f.console!==undefined&&typeof f.console.error==="function"){f.console.error("Porthole: "+g)}}};d.WindowProxy=function(){};d.WindowProxy.prototype={post:function(h,g){},addEventListener:function(g){},removeEventListener:function(g){}};d.WindowProxyBase=c.extend({init:function(g){if(g===undefined){g=""}this.targetWindowName=g;this.origin=f.location.protocol+"//"+f.location.host;this.eventListeners=[]},getTargetWindowName:function(){return this.targetWindowName},getOrigin:function(){return this.origin},getTargetWindow:function(){return d.WindowProxy.getTargetWindow(this.targetWindowName)},post:function(h,g){if(g===undefined){g="*"}this.dispatchMessage({data:h,sourceOrigin:this.getOrigin(),targetOrigin:g,sourceWindowName:f.name,targetWindowName:this.getTargetWindowName()})},addEventListener:function(g){this.eventListeners.push(g);return g},removeEventListener:function(h){var g;try{g=this.eventListeners.indexOf(h);this.eventListeners.splice(g,1)}catch(i){this.eventListeners=[]}},dispatchEvent:function(h){var g;for(g=0;g50?50:100}}});d.WindowProxyHTML5=d.WindowProxyBase.extend({init:function(g,h){this._super(h);this.eventListenerCallback=null},dispatchMessage:function(g){this.getTargetWindow().postMessage(d.WindowProxy.serialize(g),g.targetOrigin)},addEventListener:function(h){if(this.eventListeners.length===0){var g=this;if(f.addEventListener){this.eventListenerCallback=function(i){g.eventListener(g,i)};f.addEventListener("message",this.eventListenerCallback,false)}else{if(f.attachEvent){this.eventListenerCallback=function(i){g.eventListener(g,f.event)};f.attachEvent("onmessage",this.eventListenerCallback)}}}return this._super(h)},removeEventListener:function(g){this._super(g);if(this.eventListeners.length===0){if(f.removeEventListener){f.removeEventListener("message",this.eventListenerCallback)}else{if(f.detachEvent){if(typeof f.onmessage==="undefined"){f.onmessage=null}f.detachEvent("onmessage",this.eventListenerCallback)}}this.eventListenerCallback=null}},eventListener:function(h,g){var i=d.WindowProxy.unserialize(g.data);if(i&&(h.targetWindowName===""||i.sourceWindowName==h.targetWindowName)){h.dispatchEvent(new d.MessageEvent(i.data,g.origin,h))}}});if(!f.postMessage){d.trace("Using legacy browser support");d.WindowProxy=d.WindowProxyLegacy.extend({})}else{d.trace("Using built-in browser support");d.WindowProxy=d.WindowProxyHTML5.extend({})}d.WindowProxy.serialize=function(g){if(typeof JSON==="undefined"){throw new Error("Porthole serialization depends on JSON!")}return JSON.stringify(g)};d.WindowProxy.unserialize=function(i){if(typeof JSON==="undefined"){throw new Error("Porthole unserialization dependens on JSON!")}try{var g=JSON.parse(i)}catch(h){return false}return g};d.WindowProxy.getTargetWindow=function(g){if(g===""){return parent}else{if(g==="top"||g==="parent"){return f[g]}}return f.frames[g]};d.MessageEvent=function a(i,g,h){this.data=i;this.origin=g;this.source=h};d.WindowProxyDispatcher={forwardMessageEvent:function(k){var i,j=f.decodeURIComponent,h,g;if(document.location.hash.length>0){i=d.WindowProxy.unserialize(j(document.location.hash.substr(1)));h=d.WindowProxy.getTargetWindow(i.targetWindowName);g=d.WindowProxyDispatcher.findWindowProxyObjectInWindow(h,i.sourceWindowName);if(g){if(g.origin===i.targetOrigin||i.targetOrigin==="*"){g.dispatchEvent(new d.MessageEvent(i.data,i.sourceOrigin,g))}else{d.error("Target origin "+g.origin+" does not match desired target of "+i.targetOrigin)}}else{d.error("Could not find window proxy object on the target window")}}},findWindowProxyObjectInWindow:function(g,j){var h;if(g){for(h in g){if(Object.prototype.hasOwnProperty.call(g,h)){try{if(g[h]!==null&&typeof g[h]==="object"&&g[h] instanceof g.Porthole.WindowProxy&&g[h].getTargetWindowName()===j){return g[h]}}catch(k){}}}}return null},start:function(){if(f.addEventListener){f.addEventListener("resize",d.WindowProxyDispatcher.forwardMessageEvent,false)}else{if(f.attachEvent&&f.postMessage!=="undefined"){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{if(document.body.attachEvent){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{d.error("Cannot attach resize event")}}}}};if(typeof exports!=="undefined"){module.exports=d}else{f.Porthole=d}})(typeof window!=="undefined"?window:this); \ No newline at end of file diff --git a/example/sandbox.ternarylabs.com/porthole/js/porthole.js b/example/sandbox.ternarylabs.com/porthole/js/porthole.js index 84c3610..ef1c087 100644 --- a/example/sandbox.ternarylabs.com/porthole/js/porthole.js +++ b/example/sandbox.ternarylabs.com/porthole/js/porthole.js @@ -43,11 +43,12 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) * MIT Licensed. */ // Inspired by base2 and Prototype -(function(){ +(function(window){ + 'use strict'; var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; // The base Class implementation (does nothing) - this.PortholeClass = function(){}; + var PortholeClass = function(){}; // Create a new Class that inherits from this class PortholeClass.extend = function(prop) { @@ -97,14 +98,10 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) Class.prototype.constructor = Class; // And make this class extendable - Class.extend = arguments.callee; + Class.extend = PortholeClass.extend; return Class; }; -})(); - -(function (window) { - 'use strict'; /** * @overview Porthole, JavaScript Library for Secure Cross Domain iFrame Communication. @@ -132,7 +129,7 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) * @private */ error: function(s) { - if (window.console !== undefined) { + if (typeof window.console !== undefined && typeof window.console.error === 'function') { window.console.error('Porthole: ' + s); } } @@ -231,6 +228,7 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) try { this.eventListeners[i](event); } catch(e) { + Porthole.error(e); } } } @@ -508,9 +506,9 @@ iFrame proxy abc.com->abc.com: forwardMessageEvent(event) }; // Support testing in node.js: - if (typeof window.exports !== 'undefined') { - window.exports.Porthole = Porthole; + if (typeof exports !== 'undefined') { + module.exports = Porthole; } else { window.Porthole = Porthole; } -})(this); +})(typeof window !== "undefined" ? window : this); diff --git a/example/sandbox.ternarylabs.com/porthole/js/porthole.min.js b/example/sandbox.ternarylabs.com/porthole/js/porthole.min.js index 3cda48c..0acee2c 100644 --- a/example/sandbox.ternarylabs.com/porthole/js/porthole.min.js +++ b/example/sandbox.ternarylabs.com/porthole/js/porthole.min.js @@ -1 +1 @@ -(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.PortholeClass=function(){};PortholeClass.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=typeof g[d]=="function"&&typeof f[d]=="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}})(d,g[d]):g[d]}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.prototype.constructor=c;c.extend=arguments.callee;return c}})();(function(c){var b={debug:false,trace:function(d){if(this.debug&&c.console!==undefined){c.console.log("Porthole: "+d)}},error:function(d){if(c.console!==undefined){c.console.error("Porthole: "+d)}}};b.WindowProxy=function(){};b.WindowProxy.prototype={post:function(e,d){},addEventListener:function(d){},removeEventListener:function(d){}};b.WindowProxyBase=PortholeClass.extend({init:function(d){if(d===undefined){d=""}this.targetWindowName=d;this.origin=c.location.protocol+"//"+c.location.host;this.eventListeners=[]},getTargetWindowName:function(){return this.targetWindowName},getOrigin:function(){return this.origin},getTargetWindow:function(){return b.WindowProxy.getTargetWindow(this.targetWindowName)},post:function(e,d){if(d===undefined){d="*"}this.dispatchMessage({data:e,sourceOrigin:this.getOrigin(),targetOrigin:d,sourceWindowName:c.name,targetWindowName:this.getTargetWindowName()})},addEventListener:function(d){this.eventListeners.push(d);return d},removeEventListener:function(g){var d;try{d=this.eventListeners.indexOf(g);this.eventListeners.splice(d,1)}catch(h){this.eventListeners=[]}},dispatchEvent:function(f){var d;for(d=0;d50?50:100}}});b.WindowProxyHTML5=b.WindowProxyBase.extend({init:function(d,e){this._super(e);this.eventListenerCallback=null},dispatchMessage:function(d){this.getTargetWindow().postMessage(b.WindowProxy.serialize(d),d.targetOrigin)},addEventListener:function(e){if(this.eventListeners.length===0){var d=this;if(c.addEventListener){this.eventListenerCallback=function(f){d.eventListener(d,f)};c.addEventListener("message",this.eventListenerCallback,false)}else{if(c.attachEvent){this.eventListenerCallback=function(f){d.eventListener(d,c.event)};c.attachEvent("onmessage",this.eventListenerCallback)}}}return this._super(e)},removeEventListener:function(d){this._super(d);if(this.eventListeners.length===0){if(c.removeEventListener){c.removeEventListener("message",this.eventListenerCallback)}else{if(c.detachEvent){if(typeof c.onmessage==="undefined"){c.onmessage=null}c.detachEvent("onmessage",this.eventListenerCallback)}}this.eventListenerCallback=null}},eventListener:function(e,d){var f=b.WindowProxy.unserialize(d.data);if(f&&(e.targetWindowName===""||f.sourceWindowName==e.targetWindowName)){e.dispatchEvent(new b.MessageEvent(f.data,d.origin,e))}}});if(!c.postMessage){b.trace("Using legacy browser support");b.WindowProxy=b.WindowProxyLegacy.extend({})}else{b.trace("Using built-in browser support");b.WindowProxy=b.WindowProxyHTML5.extend({})}b.WindowProxy.serialize=function(d){if(typeof JSON==="undefined"){throw new Error("Porthole serialization depends on JSON!")}return JSON.stringify(d)};b.WindowProxy.unserialize=function(g){if(typeof JSON==="undefined"){throw new Error("Porthole unserialization dependens on JSON!")}try{var d=JSON.parse(g)}catch(f){return false}return d};b.WindowProxy.getTargetWindow=function(d){if(d===""){return parent}else{if(d==="top"||d==="parent"){return c[d]}}return c.frames[d]};b.MessageEvent=function a(f,d,e){this.data=f;this.origin=d;this.source=e};b.WindowProxyDispatcher={forwardMessageEvent:function(i){var g,h=c.decodeURIComponent,f,d;if(document.location.hash.length>0){g=b.WindowProxy.unserialize(h(document.location.hash.substr(1)));f=b.WindowProxy.getTargetWindow(g.targetWindowName);d=b.WindowProxyDispatcher.findWindowProxyObjectInWindow(f,g.sourceWindowName);if(d){if(d.origin===g.targetOrigin||g.targetOrigin==="*"){d.dispatchEvent(new b.MessageEvent(g.data,g.sourceOrigin,d))}else{b.error("Target origin "+d.origin+" does not match desired target of "+g.targetOrigin)}}else{b.error("Could not find window proxy object on the target window")}}},findWindowProxyObjectInWindow:function(d,g){var f;if(d){for(f in d){if(Object.prototype.hasOwnProperty.call(d,f)){try{if(d[f]!==null&&typeof d[f]==="object"&&d[f] instanceof d.Porthole.WindowProxy&&d[f].getTargetWindowName()===g){return d[f]}}catch(h){}}}}return null},start:function(){if(c.addEventListener){c.addEventListener("resize",b.WindowProxyDispatcher.forwardMessageEvent,false)}else{if(c.attachEvent&&c.postMessage!=="undefined"){c.attachEvent("onresize",b.WindowProxyDispatcher.forwardMessageEvent)}else{if(document.body.attachEvent){c.attachEvent("onresize",b.WindowProxyDispatcher.forwardMessageEvent)}else{b.error("Cannot attach resize event")}}}}};if(typeof c.exports!=="undefined"){c.exports.Porthole=b}else{c.Porthole=b}})(this); \ No newline at end of file +(function(f){var b=false,e=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;var c=function(){};c.extend=function(k){var j=this.prototype;b=true;var i=new this();b=false;for(var h in k){i[h]=typeof k[h]=="function"&&typeof j[h]=="function"&&e.test(k[h])?(function(l,m){return function(){var o=this._super;this._super=j[l];var n=m.apply(this,arguments);this._super=o;return n}})(h,k[h]):k[h]}function g(){if(!b&&this.init){this.init.apply(this,arguments)}}g.prototype=i;g.prototype.constructor=g;g.extend=c.extend;return g};var d={debug:false,trace:function(g){if(this.debug&&f.console!==undefined){f.console.log("Porthole: "+g)}},error:function(g){if(typeof f.console!==undefined&&typeof f.console.error==="function"){f.console.error("Porthole: "+g)}}};d.WindowProxy=function(){};d.WindowProxy.prototype={post:function(h,g){},addEventListener:function(g){},removeEventListener:function(g){}};d.WindowProxyBase=c.extend({init:function(g){if(g===undefined){g=""}this.targetWindowName=g;this.origin=f.location.protocol+"//"+f.location.host;this.eventListeners=[]},getTargetWindowName:function(){return this.targetWindowName},getOrigin:function(){return this.origin},getTargetWindow:function(){return d.WindowProxy.getTargetWindow(this.targetWindowName)},post:function(h,g){if(g===undefined){g="*"}this.dispatchMessage({data:h,sourceOrigin:this.getOrigin(),targetOrigin:g,sourceWindowName:f.name,targetWindowName:this.getTargetWindowName()})},addEventListener:function(g){this.eventListeners.push(g);return g},removeEventListener:function(h){var g;try{g=this.eventListeners.indexOf(h);this.eventListeners.splice(g,1)}catch(i){this.eventListeners=[]}},dispatchEvent:function(h){var g;for(g=0;g50?50:100}}});d.WindowProxyHTML5=d.WindowProxyBase.extend({init:function(g,h){this._super(h);this.eventListenerCallback=null},dispatchMessage:function(g){this.getTargetWindow().postMessage(d.WindowProxy.serialize(g),g.targetOrigin)},addEventListener:function(h){if(this.eventListeners.length===0){var g=this;if(f.addEventListener){this.eventListenerCallback=function(i){g.eventListener(g,i)};f.addEventListener("message",this.eventListenerCallback,false)}else{if(f.attachEvent){this.eventListenerCallback=function(i){g.eventListener(g,f.event)};f.attachEvent("onmessage",this.eventListenerCallback)}}}return this._super(h)},removeEventListener:function(g){this._super(g);if(this.eventListeners.length===0){if(f.removeEventListener){f.removeEventListener("message",this.eventListenerCallback)}else{if(f.detachEvent){if(typeof f.onmessage==="undefined"){f.onmessage=null}f.detachEvent("onmessage",this.eventListenerCallback)}}this.eventListenerCallback=null}},eventListener:function(h,g){var i=d.WindowProxy.unserialize(g.data);if(i&&(h.targetWindowName===""||i.sourceWindowName==h.targetWindowName)){h.dispatchEvent(new d.MessageEvent(i.data,g.origin,h))}}});if(!f.postMessage){d.trace("Using legacy browser support");d.WindowProxy=d.WindowProxyLegacy.extend({})}else{d.trace("Using built-in browser support");d.WindowProxy=d.WindowProxyHTML5.extend({})}d.WindowProxy.serialize=function(g){if(typeof JSON==="undefined"){throw new Error("Porthole serialization depends on JSON!")}return JSON.stringify(g)};d.WindowProxy.unserialize=function(i){if(typeof JSON==="undefined"){throw new Error("Porthole unserialization dependens on JSON!")}try{var g=JSON.parse(i)}catch(h){return false}return g};d.WindowProxy.getTargetWindow=function(g){if(g===""){return parent}else{if(g==="top"||g==="parent"){return f[g]}}return f.frames[g]};d.MessageEvent=function a(i,g,h){this.data=i;this.origin=g;this.source=h};d.WindowProxyDispatcher={forwardMessageEvent:function(k){var i,j=f.decodeURIComponent,h,g;if(document.location.hash.length>0){i=d.WindowProxy.unserialize(j(document.location.hash.substr(1)));h=d.WindowProxy.getTargetWindow(i.targetWindowName);g=d.WindowProxyDispatcher.findWindowProxyObjectInWindow(h,i.sourceWindowName);if(g){if(g.origin===i.targetOrigin||i.targetOrigin==="*"){g.dispatchEvent(new d.MessageEvent(i.data,i.sourceOrigin,g))}else{d.error("Target origin "+g.origin+" does not match desired target of "+i.targetOrigin)}}else{d.error("Could not find window proxy object on the target window")}}},findWindowProxyObjectInWindow:function(g,j){var h;if(g){for(h in g){if(Object.prototype.hasOwnProperty.call(g,h)){try{if(g[h]!==null&&typeof g[h]==="object"&&g[h] instanceof g.Porthole.WindowProxy&&g[h].getTargetWindowName()===j){return g[h]}}catch(k){}}}}return null},start:function(){if(f.addEventListener){f.addEventListener("resize",d.WindowProxyDispatcher.forwardMessageEvent,false)}else{if(f.attachEvent&&f.postMessage!=="undefined"){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{if(document.body.attachEvent){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{d.error("Cannot attach resize event")}}}}};if(typeof exports!=="undefined"){module.exports=d}else{f.Porthole=d}})(typeof window!=="undefined"?window:this); \ No newline at end of file diff --git a/src/porthole.min.js b/src/porthole.min.js index 3cda48c..0acee2c 100644 --- a/src/porthole.min.js +++ b/src/porthole.min.js @@ -1 +1 @@ -(function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.PortholeClass=function(){};PortholeClass.extend=function(g){var f=this.prototype;a=true;var e=new this();a=false;for(var d in g){e[d]=typeof g[d]=="function"&&typeof f[d]=="function"&&b.test(g[d])?(function(h,i){return function(){var k=this._super;this._super=f[h];var j=i.apply(this,arguments);this._super=k;return j}})(d,g[d]):g[d]}function c(){if(!a&&this.init){this.init.apply(this,arguments)}}c.prototype=e;c.prototype.constructor=c;c.extend=arguments.callee;return c}})();(function(c){var b={debug:false,trace:function(d){if(this.debug&&c.console!==undefined){c.console.log("Porthole: "+d)}},error:function(d){if(c.console!==undefined){c.console.error("Porthole: "+d)}}};b.WindowProxy=function(){};b.WindowProxy.prototype={post:function(e,d){},addEventListener:function(d){},removeEventListener:function(d){}};b.WindowProxyBase=PortholeClass.extend({init:function(d){if(d===undefined){d=""}this.targetWindowName=d;this.origin=c.location.protocol+"//"+c.location.host;this.eventListeners=[]},getTargetWindowName:function(){return this.targetWindowName},getOrigin:function(){return this.origin},getTargetWindow:function(){return b.WindowProxy.getTargetWindow(this.targetWindowName)},post:function(e,d){if(d===undefined){d="*"}this.dispatchMessage({data:e,sourceOrigin:this.getOrigin(),targetOrigin:d,sourceWindowName:c.name,targetWindowName:this.getTargetWindowName()})},addEventListener:function(d){this.eventListeners.push(d);return d},removeEventListener:function(g){var d;try{d=this.eventListeners.indexOf(g);this.eventListeners.splice(d,1)}catch(h){this.eventListeners=[]}},dispatchEvent:function(f){var d;for(d=0;d50?50:100}}});b.WindowProxyHTML5=b.WindowProxyBase.extend({init:function(d,e){this._super(e);this.eventListenerCallback=null},dispatchMessage:function(d){this.getTargetWindow().postMessage(b.WindowProxy.serialize(d),d.targetOrigin)},addEventListener:function(e){if(this.eventListeners.length===0){var d=this;if(c.addEventListener){this.eventListenerCallback=function(f){d.eventListener(d,f)};c.addEventListener("message",this.eventListenerCallback,false)}else{if(c.attachEvent){this.eventListenerCallback=function(f){d.eventListener(d,c.event)};c.attachEvent("onmessage",this.eventListenerCallback)}}}return this._super(e)},removeEventListener:function(d){this._super(d);if(this.eventListeners.length===0){if(c.removeEventListener){c.removeEventListener("message",this.eventListenerCallback)}else{if(c.detachEvent){if(typeof c.onmessage==="undefined"){c.onmessage=null}c.detachEvent("onmessage",this.eventListenerCallback)}}this.eventListenerCallback=null}},eventListener:function(e,d){var f=b.WindowProxy.unserialize(d.data);if(f&&(e.targetWindowName===""||f.sourceWindowName==e.targetWindowName)){e.dispatchEvent(new b.MessageEvent(f.data,d.origin,e))}}});if(!c.postMessage){b.trace("Using legacy browser support");b.WindowProxy=b.WindowProxyLegacy.extend({})}else{b.trace("Using built-in browser support");b.WindowProxy=b.WindowProxyHTML5.extend({})}b.WindowProxy.serialize=function(d){if(typeof JSON==="undefined"){throw new Error("Porthole serialization depends on JSON!")}return JSON.stringify(d)};b.WindowProxy.unserialize=function(g){if(typeof JSON==="undefined"){throw new Error("Porthole unserialization dependens on JSON!")}try{var d=JSON.parse(g)}catch(f){return false}return d};b.WindowProxy.getTargetWindow=function(d){if(d===""){return parent}else{if(d==="top"||d==="parent"){return c[d]}}return c.frames[d]};b.MessageEvent=function a(f,d,e){this.data=f;this.origin=d;this.source=e};b.WindowProxyDispatcher={forwardMessageEvent:function(i){var g,h=c.decodeURIComponent,f,d;if(document.location.hash.length>0){g=b.WindowProxy.unserialize(h(document.location.hash.substr(1)));f=b.WindowProxy.getTargetWindow(g.targetWindowName);d=b.WindowProxyDispatcher.findWindowProxyObjectInWindow(f,g.sourceWindowName);if(d){if(d.origin===g.targetOrigin||g.targetOrigin==="*"){d.dispatchEvent(new b.MessageEvent(g.data,g.sourceOrigin,d))}else{b.error("Target origin "+d.origin+" does not match desired target of "+g.targetOrigin)}}else{b.error("Could not find window proxy object on the target window")}}},findWindowProxyObjectInWindow:function(d,g){var f;if(d){for(f in d){if(Object.prototype.hasOwnProperty.call(d,f)){try{if(d[f]!==null&&typeof d[f]==="object"&&d[f] instanceof d.Porthole.WindowProxy&&d[f].getTargetWindowName()===g){return d[f]}}catch(h){}}}}return null},start:function(){if(c.addEventListener){c.addEventListener("resize",b.WindowProxyDispatcher.forwardMessageEvent,false)}else{if(c.attachEvent&&c.postMessage!=="undefined"){c.attachEvent("onresize",b.WindowProxyDispatcher.forwardMessageEvent)}else{if(document.body.attachEvent){c.attachEvent("onresize",b.WindowProxyDispatcher.forwardMessageEvent)}else{b.error("Cannot attach resize event")}}}}};if(typeof c.exports!=="undefined"){c.exports.Porthole=b}else{c.Porthole=b}})(this); \ No newline at end of file +(function(f){var b=false,e=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;var c=function(){};c.extend=function(k){var j=this.prototype;b=true;var i=new this();b=false;for(var h in k){i[h]=typeof k[h]=="function"&&typeof j[h]=="function"&&e.test(k[h])?(function(l,m){return function(){var o=this._super;this._super=j[l];var n=m.apply(this,arguments);this._super=o;return n}})(h,k[h]):k[h]}function g(){if(!b&&this.init){this.init.apply(this,arguments)}}g.prototype=i;g.prototype.constructor=g;g.extend=c.extend;return g};var d={debug:false,trace:function(g){if(this.debug&&f.console!==undefined){f.console.log("Porthole: "+g)}},error:function(g){if(typeof f.console!==undefined&&typeof f.console.error==="function"){f.console.error("Porthole: "+g)}}};d.WindowProxy=function(){};d.WindowProxy.prototype={post:function(h,g){},addEventListener:function(g){},removeEventListener:function(g){}};d.WindowProxyBase=c.extend({init:function(g){if(g===undefined){g=""}this.targetWindowName=g;this.origin=f.location.protocol+"//"+f.location.host;this.eventListeners=[]},getTargetWindowName:function(){return this.targetWindowName},getOrigin:function(){return this.origin},getTargetWindow:function(){return d.WindowProxy.getTargetWindow(this.targetWindowName)},post:function(h,g){if(g===undefined){g="*"}this.dispatchMessage({data:h,sourceOrigin:this.getOrigin(),targetOrigin:g,sourceWindowName:f.name,targetWindowName:this.getTargetWindowName()})},addEventListener:function(g){this.eventListeners.push(g);return g},removeEventListener:function(h){var g;try{g=this.eventListeners.indexOf(h);this.eventListeners.splice(g,1)}catch(i){this.eventListeners=[]}},dispatchEvent:function(h){var g;for(g=0;g50?50:100}}});d.WindowProxyHTML5=d.WindowProxyBase.extend({init:function(g,h){this._super(h);this.eventListenerCallback=null},dispatchMessage:function(g){this.getTargetWindow().postMessage(d.WindowProxy.serialize(g),g.targetOrigin)},addEventListener:function(h){if(this.eventListeners.length===0){var g=this;if(f.addEventListener){this.eventListenerCallback=function(i){g.eventListener(g,i)};f.addEventListener("message",this.eventListenerCallback,false)}else{if(f.attachEvent){this.eventListenerCallback=function(i){g.eventListener(g,f.event)};f.attachEvent("onmessage",this.eventListenerCallback)}}}return this._super(h)},removeEventListener:function(g){this._super(g);if(this.eventListeners.length===0){if(f.removeEventListener){f.removeEventListener("message",this.eventListenerCallback)}else{if(f.detachEvent){if(typeof f.onmessage==="undefined"){f.onmessage=null}f.detachEvent("onmessage",this.eventListenerCallback)}}this.eventListenerCallback=null}},eventListener:function(h,g){var i=d.WindowProxy.unserialize(g.data);if(i&&(h.targetWindowName===""||i.sourceWindowName==h.targetWindowName)){h.dispatchEvent(new d.MessageEvent(i.data,g.origin,h))}}});if(!f.postMessage){d.trace("Using legacy browser support");d.WindowProxy=d.WindowProxyLegacy.extend({})}else{d.trace("Using built-in browser support");d.WindowProxy=d.WindowProxyHTML5.extend({})}d.WindowProxy.serialize=function(g){if(typeof JSON==="undefined"){throw new Error("Porthole serialization depends on JSON!")}return JSON.stringify(g)};d.WindowProxy.unserialize=function(i){if(typeof JSON==="undefined"){throw new Error("Porthole unserialization dependens on JSON!")}try{var g=JSON.parse(i)}catch(h){return false}return g};d.WindowProxy.getTargetWindow=function(g){if(g===""){return parent}else{if(g==="top"||g==="parent"){return f[g]}}return f.frames[g]};d.MessageEvent=function a(i,g,h){this.data=i;this.origin=g;this.source=h};d.WindowProxyDispatcher={forwardMessageEvent:function(k){var i,j=f.decodeURIComponent,h,g;if(document.location.hash.length>0){i=d.WindowProxy.unserialize(j(document.location.hash.substr(1)));h=d.WindowProxy.getTargetWindow(i.targetWindowName);g=d.WindowProxyDispatcher.findWindowProxyObjectInWindow(h,i.sourceWindowName);if(g){if(g.origin===i.targetOrigin||i.targetOrigin==="*"){g.dispatchEvent(new d.MessageEvent(i.data,i.sourceOrigin,g))}else{d.error("Target origin "+g.origin+" does not match desired target of "+i.targetOrigin)}}else{d.error("Could not find window proxy object on the target window")}}},findWindowProxyObjectInWindow:function(g,j){var h;if(g){for(h in g){if(Object.prototype.hasOwnProperty.call(g,h)){try{if(g[h]!==null&&typeof g[h]==="object"&&g[h] instanceof g.Porthole.WindowProxy&&g[h].getTargetWindowName()===j){return g[h]}}catch(k){}}}}return null},start:function(){if(f.addEventListener){f.addEventListener("resize",d.WindowProxyDispatcher.forwardMessageEvent,false)}else{if(f.attachEvent&&f.postMessage!=="undefined"){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{if(document.body.attachEvent){f.attachEvent("onresize",d.WindowProxyDispatcher.forwardMessageEvent)}else{d.error("Cannot attach resize event")}}}}};if(typeof exports!=="undefined"){module.exports=d}else{f.Porthole=d}})(typeof window!=="undefined"?window:this); \ No newline at end of file