vendor/assets/javascripts/xooie/event_handler.js in xooie-1.0.4 vs vendor/assets/javascripts/xooie/event_handler.js in xooie-1.0.5
- old
+ new
@@ -12,46 +12,44 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-define('xooie/event_handler', ['jquery', 'xooie/helpers'], function($, helpers) {
+define('xooie/event_handler', ['jquery', 'xooie/helpers'], function ($, helpers) {
+ 'use strict';
- var EventHandler = function(namespace) {
+ var EventHandler = function (namespace) {
this.namespace = namespace;
this.handlers = {};
this._callbacks = {};
};
function format(type, namespace) {
- if (!namespace) {
- return type;
- } else {
- return type + '.' + namespace;
- }
+ return !namespace ? type : type + '.' + namespace;
}
- EventHandler.prototype.add = function(type, method) {
- var self = this,
- formattedType, t;
+ EventHandler.prototype.add = function (type, method) {
+ var self, formattedType, t;
+ self = this;
+
if (helpers.isObject(type) && helpers.isUndefined(method)) {
- for(t in type) {
- if (helpers.isFunction(type[t])) {
+ for (t in type) {
+ if (type.hasOwnProperty(t) && helpers.isFunction(type[t])) {
this.add(t, type[t]);
}
}
return;
}
formattedType = format(type, this.namespace);
if (helpers.isUndefined(this.handlers[formattedType])) {
- this.handlers[formattedType] = function(e) {
+ this.handlers[formattedType] = function (e) {
self.fire(e, this, arguments);
};
}
if (helpers.isUndefined(this._callbacks[type])) {
@@ -59,18 +57,18 @@
}
this._callbacks[type].add(method);
};
- EventHandler.prototype.clear = function(type) {
- delete(this.handlers[format(type, this.namespace)]);
+ EventHandler.prototype.clear = function (type) {
+ delete (this.handlers[format(type, this.namespace)]);
if (!helpers.isUndefined(this._callbacks[type])) {
this._callbacks[type].empty();
}
};
- EventHandler.prototype.fire = function(event, context, args) {
+ EventHandler.prototype.fire = function (event, context, args) {
if (event.namespace && event.namespace !== this.namespace) {
return;
}
if (!helpers.isUndefined(this._callbacks[event.type])) {