1 goog.provide('lime.events.Event');
  2 
  3 goog.require('lime.events.Drag');
  4 
  5 /**
  6  * Dfkit Event object
  7  * @param {lime.events.EventDispatcher} dispatcher Dispatcher.
  8  * @constructor
  9  */
 10 lime.events.Event = function(dispatcher) {
 11     this.dispatcher_ = dispatcher;
 12 
 13     this.identifier = 0;
 14 };
 15 
 16 /**
 17  * Swallow an event. This means that next event from the same
 18  * interaction will be sent directly to handler without any search
 19  * @param {string|Array.<string>} type Event types to swallow.
 20  * @param {function(lime.events.Event)} handler Function to call on event.
 21  * @param {boolean=} opt_deny_shared Deny further actions for same event.
 22  */
 23 lime.events.Event.prototype.swallow = function(type, handler, opt_deny_shared) {
 24     type = goog.isArray(type) ? type : [type];
 25     for (var i = 0; i < type.length; i++)
 26     this.dispatcher_.swallow(this, type[i], handler);
 27 
 28     if (opt_deny_shared) {
 29         this.event.stopPropagation();
 30     }
 31 };
 32 
 33 /**
 34  * Release all swllowed handlers.
 35  * @param {string|Array.<string>} opt_type Event types to release.
 36  */
 37 lime.events.Event.prototype.release = function(opt_type) {
 38     var limit_type = goog.isDef(opt_type);
 39     var type = goog.isArray(opt_type) ? opt_type : [opt_type];
 40     var s = this.dispatcher_.swallows[this.identifier];
 41     if (!s) return;
 42 
 43     var e = this;
 44     var s2 = goog.array.filter(s, function(swallow) {
 45         if (!goog.isDef(e.targetObject) || (swallow[0] == e.targetObject &&
 46             (!limit_type || goog.array.contains(type, swallow[1])))) {
 47            goog.events.unlisten(swallow[0], swallow[1], swallow[2]);
 48            return false;
 49         }
 50         return true;
 51     });
 52 
 53     if (s2.length) {
 54         this.dispatcher_.swallows[this.identifier] = s2;
 55     }
 56     else {
 57         delete this.dispatcher_.swallows[this.identifier];
 58     }
 59 };
 60 
 61 /**
 62  * Start dragging sequence from current event
 63  * @param {boolean} snapToCenter Drag from center or not.
 64  * @param {goog.math.Box} box Limited area where dragging is possible.
 65  * @param {lime.Node=} opt_targetObject Different target object to drag.
 66  * @return {lime.events.Drag} New Drag object.
 67  */
 68 lime.events.Event.prototype.startDrag = function(snapToCenter, box,
 69         opt_targetObject) {
 70     return new lime.events.Drag(this, snapToCenter, box, opt_targetObject);
 71 };
 72 
 73 /**
 74  * Retunr new event with same parameters
 75  * @return {lime.events.Event} event.
 76  */
 77 lime.events.Event.prototype.clone = function() {
 78     var e = new lime.events.Event(this.dispatcher_);
 79     goog.object.extend(e, this);
 80     return e;
 81 };
 82