UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

146 lines (134 loc) 4.38 kB
// Generated by github.com/steida/coffee2closure 900.1.18 /** @fileoverview Base class for classes using events. */ var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.superClass_ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; goog.provide('este.Base'); goog.require('goog.asserts'); goog.require('goog.events.EventHandler'); goog.require('goog.events.EventTarget'); /** @constructor @extends {goog.events.EventTarget} */ este.Base = function() { este.Base.superClass_.constructor.call(this); } extend(este.Base, superClass); /** @type {goog.events.EventHandler} @private */ este.Base.prototype.handler_ = null; /** @type {Array.<este.Base>} @private */ este.Base.prototype.parents_ = null; /** Alias for .listen. @param {goog.events.ListenableType} src Event source. @param {string|Array.<string>} type Event type to listen for or array of event types. @param {Function|Object=} fn Optional callback function to be used as the listener or an object with handleEvent function. @param {boolean=} capture Optional whether to use capture phase. @param {Object=} handler Object in whose scope to call the listener. @protected */ este.Base.prototype.on = function(src, type, fn, capture, handler) { return this.getHandler().listen(src, type, fn, capture, handler); }; /** Alias for .listenOnce. @param {goog.events.ListenableType} src Event source. @param {string|Array.<string>} type Event type to listen for or array of event types. @param {Function|Object=} fn Optional callback function to be used as the listener or an object with handleEvent function. @param {boolean=} capture Optional whether to use capture phase. @param {Object=} handler Object in whose scope to call the listener. @protected */ este.Base.prototype.once = function(src, type, fn, capture, handler) { return this.getHandler().listenOnce(src, type, fn, capture, handler); }; /** Alias for .unlisten. @param {goog.events.ListenableType} src Event source. @param {string|Array.<string>} type Event type to listen for or array of event types. @param {Function|Object=} fn Optional callback function to be used as the listener or an object with handleEvent function. @param {boolean=} capture Optional whether to use capture phase. @param {Object=} handler Object in whose scope to call the listener. @protected */ este.Base.prototype.off = function(src, type, fn, capture, handler) { return this.getHandler().unlisten(src, type, fn, capture, handler); }; /** Add parent for dispatch event. @param {este.Base} parent @protected */ este.Base.prototype.addParent = function(parent) { return goog.array.insert(this.getParents(), parent); }; /** Remove parent for dispatch event. @param {este.Base} parent @return {boolean} True if a parent was removed. @protected */ este.Base.prototype.removeParent = function(parent) { return goog.array.remove(this.getParents(), parent); }; /** Return dispatch event parents. @return {Array.<este.Base>} @protected */ este.Base.prototype.getParents = function() { return this.parents_ || (this.parents_ = []); }; /** @protected */ este.Base.prototype.getHandler = function() { return this.handler_ != null ? this.handler_ : this.handler_ = new goog.events.EventHandler(this); }; /** Dispatch event on instance itself and also on its parents. Useful when one model is placed in several collection. It enabled multi-parent events bubbling. @override */ este.Base.prototype.dispatchEvent = function(e) { var i, len, parent, parentResult, ref, result; result = este.Base.superClass_.dispatchEvent.call(this, e); if (!this.parents_) { return result; } ref = this.getParents().slice(0); for (i = 0, len = ref.length; i < len; i++) { parent = ref[i]; parentResult = parent.dispatchEvent(e); if (parentResult === false) { result = false; } } return result; }; /** @override */ este.Base.prototype.disposeInternal = function() { var ref; if ((ref = this.handler_) != null) { ref.dispose(); } this.parents_ = null; este.Base.superClass_.disposeInternal.call(this); };