diff --git a/bower.json b/bower.json index 4533a8d..b8652be 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "Bellhop", - "version": "1.1.6", + "version": "1.1.7", "main": "dist/bellhop.min.js", "dependencies": { "bind-polyfill": "*" diff --git a/dist/bellhop.js b/dist/bellhop.js index c49ce57..755e61d 100644 --- a/dist/bellhop.js +++ b/dist/bellhop.js @@ -1,4 +1,4 @@ -/*! Bellhop 1.1.6 */ +/*! Bellhop 1.1.7 */ (function(window, undefined){ /** @@ -352,7 +352,7 @@ */ p.off = function(type, callback) { - if (type === undefined) + if (type === undefined || !this._listeners) { //remove all listeners this._listeners = {}; diff --git a/dist/bellhop.min.js b/dist/bellhop.min.js index 728dbb2..8353a99 100644 --- a/dist/bellhop.min.js +++ b/dist/bellhop.min.js @@ -1,2 +1,2 @@ -/*! Bellhop 1.1.6 */ -!function(){"use strict";!function(a,b){function c(a,b){return a._priority-b._priority}var d=function(){this.onReceive=this.receive.bind(this),this.target=null,this.connected=!1,this.name="",this.isChild=!0,this.connecting=!1,this.origin="*",this._listeners={},this._sendLater=[],this.supported=null},e=d.prototype={};e.receive=function(a){if(a.source===this.target){var b=a.data;if("connected"===b){this.connecting=!1,this.connected=!0,this.trigger("connected"),this.isChild||this.target.postMessage(b,this.origin);var c,e=this._sendLater.length;if(e>0){for(c=0;e>c;c++){var f=this._sendLater[c];this.send(f.type,f.data)}this._sendLater.length=0}}else{if(!this.connected)return;try{b=JSON.parse(b,d.reviver)}catch(g){return}"object"==typeof b&&b.type&&this.trigger(b)}}},e.trigger=function(a){"string"==typeof a&&(a={type:a});var c=this._listeners[a.type];if(c!==b)for(var d=c.length-1;d>=0;d--)c[d](a)},e.toString=function(){return"[Bellhop '"+this.name+"']"},e.connect=function(c,d){if(this.connecting)return this;this.disconnect(),this.connecting=!0,this._listeners||(this._listeners={}),this._sendLater||(this._sendLater=[]);var e=this.isChild=c===b,f=this.target=e?a.top:c.contentWindow||c;return this.supported=e?!!f&&a!=f:!!f,this.origin=d===b?"*":d,a.attachEvent?a.attachEvent("onmessage",this.onReceive):a.addEventListener("message",this.onReceive),e&&(a===f?this.trigger("failed"):"complete"===a.document.readyState?f.postMessage("connected",this.origin):a.onload=function(){f.postMessage("connected",this.origin)}.bind(this)),this},e.disconnect=function(){return this.connected=!1,this.connecting=!1,this.origin=null,this.target=null,this._listeners={},this._sendLater&&(this._sendLater.length=0),this.isChild=!0,a.detachEvent?a.detachEvent("onmessage",this.onReceive):a.removeEventListener("message",this.onReceive),this},e.on=function(a,b,d){if("string"!=typeof a)for(var e in a)this.on(e,a[e],d);else for(var f,g=a.split(" "),h=0,i=g.length;i>h;h++)a=g[h],f=this._listeners[g],f||(f=this._listeners[g]=[]),b._priority=parseInt(d)||0,-1===f.indexOf(b)&&(f.push(b),f.length>1&&f.sort(c));return this},e.off=function(a,c){if(a===b)return this._listeners={},this;if(this._listeners[a]===b)return this;if(c===b)delete this._listeners[a];else for(var d=this._listeners[a],e=0,f=d.length;f>e;e++)if(d[e]===c){d.splice(e,1);break}return this},e.send=function(a,c){if("string"!=typeof a)throw"The event type must be a string";if(a={type:a},c!==b&&(a.data=c),this.connecting)this._sendLater.push(a);else{if(!this.connected)return this;this.target.postMessage(JSON.stringify(a),this.origin)}return this},e.fetch=function(a,c,d,e){var f=this;if(!this.connecting&&!this.connected)throw"No connection, please call connect() first";e=e===b?!1:e;var g=function(a){e&&f.off(a.type,g),c(a)};return this.on(a,g),this.send(a,d),this},e.respond=function(a,c,d){d=d===b?!1:d;var e=this,f=function(b){d&&e.off(b.type,f),e.send(a,"function"==typeof c?c():c)};return this.on(a,f),this},e.destroy=function(){this.disconnect(),this._listeners=null,this._sendLater=null},d.reviver=function(a,b){if(b&&"string"==typeof b.__classname){var c=f(b.__classname);if(c){var d=new c;if(d.fromJSON)return d.fromJSON(b),d}}return b};var f=function(b){for(var c=b.split("."),d=a;c.length;)if(d=d[c.shift()],!d)return;return d};a.Bellhop=d}(window);}(); \ No newline at end of file +/*! Bellhop 1.1.7 */ +!function(){"use strict";!function(a,b){function c(a,b){return a._priority-b._priority}var d=function(){this.onReceive=this.receive.bind(this),this.target=null,this.connected=!1,this.name="",this.isChild=!0,this.connecting=!1,this.origin="*",this._listeners={},this._sendLater=[],this.supported=null},e=d.prototype={};e.receive=function(a){if(a.source===this.target){var b=a.data;if("connected"===b){this.connecting=!1,this.connected=!0,this.trigger("connected"),this.isChild||this.target.postMessage(b,this.origin);var c,e=this._sendLater.length;if(e>0){for(c=0;e>c;c++){var f=this._sendLater[c];this.send(f.type,f.data)}this._sendLater.length=0}}else{if(!this.connected)return;try{b=JSON.parse(b,d.reviver)}catch(g){return}"object"==typeof b&&b.type&&this.trigger(b)}}},e.trigger=function(a){"string"==typeof a&&(a={type:a});var c=this._listeners[a.type];if(c!==b)for(var d=c.length-1;d>=0;d--)c[d](a)},e.toString=function(){return"[Bellhop '"+this.name+"']"},e.connect=function(c,d){if(this.connecting)return this;this.disconnect(),this.connecting=!0,this._listeners||(this._listeners={}),this._sendLater||(this._sendLater=[]);var e=this.isChild=c===b,f=this.target=e?a.top:c.contentWindow||c;return this.supported=e?!!f&&a!=f:!!f,this.origin=d===b?"*":d,a.attachEvent?a.attachEvent("onmessage",this.onReceive):a.addEventListener("message",this.onReceive),e&&(a===f?this.trigger("failed"):"complete"===a.document.readyState?f.postMessage("connected",this.origin):a.onload=function(){f.postMessage("connected",this.origin)}.bind(this)),this},e.disconnect=function(){return this.connected=!1,this.connecting=!1,this.origin=null,this.target=null,this._listeners={},this._sendLater&&(this._sendLater.length=0),this.isChild=!0,a.detachEvent?a.detachEvent("onmessage",this.onReceive):a.removeEventListener("message",this.onReceive),this},e.on=function(a,b,d){if("string"!=typeof a)for(var e in a)this.on(e,a[e],d);else for(var f,g=a.split(" "),h=0,i=g.length;i>h;h++)a=g[h],f=this._listeners[g],f||(f=this._listeners[g]=[]),b._priority=parseInt(d)||0,-1===f.indexOf(b)&&(f.push(b),f.length>1&&f.sort(c));return this},e.off=function(a,c){if(a===b||!this._listeners)return this._listeners={},this;if(this._listeners[a]===b)return this;if(c===b)delete this._listeners[a];else for(var d=this._listeners[a],e=0,f=d.length;f>e;e++)if(d[e]===c){d.splice(e,1);break}return this},e.send=function(a,c){if("string"!=typeof a)throw"The event type must be a string";if(a={type:a},c!==b&&(a.data=c),this.connecting)this._sendLater.push(a);else{if(!this.connected)return this;this.target.postMessage(JSON.stringify(a),this.origin)}return this},e.fetch=function(a,c,d,e){var f=this;if(!this.connecting&&!this.connected)throw"No connection, please call connect() first";e=e===b?!1:e;var g=function(a){e&&f.off(a.type,g),c(a)};return this.on(a,g),this.send(a,d),this},e.respond=function(a,c,d){d=d===b?!1:d;var e=this,f=function(b){d&&e.off(b.type,f),e.send(a,"function"==typeof c?c():c)};return this.on(a,f),this},e.destroy=function(){this.disconnect(),this._listeners=null,this._sendLater=null},d.reviver=function(a,b){if(b&&"string"==typeof b.__classname){var c=f(b.__classname);if(c){var d=new c;if(d.fromJSON)return d.fromJSON(b),d}}return b};var f=function(b){for(var c=b.split("."),d=a;c.length;)if(d=d[c.shift()],!d)return;return d};a.Bellhop=d}(window);}(); \ No newline at end of file diff --git a/library.json b/library.json index 76b8347..8822f77 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Bellhop", - "version": "1.1.6", + "version": "1.1.7", "description": "Javascript event-based communication layer between DOM and iframe.", "url": "https://github.com/CloudKidStudio/Bellhop", "output": "bellhop", diff --git a/package.json b/package.json index f7c5c6d..a8d06d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": true, - "version": "1.1.6", + "version": "1.1.7", "dependencies": { "grunt": "~0.4.5", "library-grunt": "*" diff --git a/src/Bellhop.js b/src/Bellhop.js index d0ef111..b6b850f 100644 --- a/src/Bellhop.js +++ b/src/Bellhop.js @@ -351,7 +351,7 @@ */ p.off = function(type, callback) { - if (type === undefined) + if (type === undefined || !this._listeners) { //remove all listeners this._listeners = {};