Fixing types and getting rid of evt.touches warning.
This commit is contained in:
+43
-39
@@ -11,7 +11,7 @@ goog.require('goog.style');
|
|||||||
/**
|
/**
|
||||||
* Determine whether event was caused by a single touch
|
* Determine whether event was caused by a single touch
|
||||||
*
|
*
|
||||||
* @param {goog.events.BrowserEvent} evt
|
* @param {Event} evt
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
ol.event.isSingleTouch = function(evt) {
|
ol.event.isSingleTouch = function(evt) {
|
||||||
@@ -21,7 +21,7 @@ ol.event.isSingleTouch = function(evt) {
|
|||||||
/**
|
/**
|
||||||
* Determine whether event was caused by a multi touch
|
* Determine whether event was caused by a multi touch
|
||||||
*
|
*
|
||||||
* @param {goog.events.BrowserEvent} evt
|
* @param {Event} evt
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
ol.event.isMultiTouch = function(evt) {
|
ol.event.isMultiTouch = function(evt) {
|
||||||
@@ -49,27 +49,26 @@ ol.event.Events = function(object, opt_element, opt_includeXY) {
|
|||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @private
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
* The object that this instance is bound to.
|
* The object that this instance is bound to.
|
||||||
*/
|
*/
|
||||||
this.object_ = object;
|
this.object_ = object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {EventTarget|undefined}
|
* @private
|
||||||
|
* @type {EventTarget}
|
||||||
* The element that this instance listens to mouse events on.
|
* The element that this instance listens to mouse events on.
|
||||||
*/
|
*/
|
||||||
this.element_ = opt_element;
|
this.element_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @private
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
this.includeXY_ = goog.isDef(opt_includeXY) ? opt_includeXY : false;
|
this.includeXY_ = goog.isDef(opt_includeXY) ? opt_includeXY : false;
|
||||||
|
|
||||||
// if a dom element is specified, add a listeners list
|
this.setElement(opt_element);
|
||||||
// for browser events on the element and register them
|
|
||||||
if (goog.isDef(opt_element)) {
|
|
||||||
this.attachToElement_(opt_element);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.event.Events, goog.events.EventTarget);
|
goog.inherits(ol.event.Events, goog.events.EventTarget);
|
||||||
|
|
||||||
@@ -81,41 +80,47 @@ ol.event.Events.prototype.getObject = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach this instance to a DOM element. If this is called, all browser events
|
* @param {boolean} includeXY
|
||||||
* fired on the provided element will be relayed by this instance.
|
|
||||||
*
|
|
||||||
* @param {!EventTarget} element A DOM element to attach
|
|
||||||
* browser events to.
|
|
||||||
*/
|
*/
|
||||||
ol.event.Events.prototype.attachToElement_ = function(element) {
|
ol.event.Events.prototype.setIncludeXY = function(includeXY) {
|
||||||
if (this.element_) {
|
this._includeXY = includeXY;
|
||||||
this.detachFromElement_();
|
|
||||||
}
|
|
||||||
this.element_ = element;
|
|
||||||
var t, types = goog.events.EventType;
|
|
||||||
for (t in types) {
|
|
||||||
// register the event cross-browser
|
|
||||||
goog.events.listen(
|
|
||||||
element, types[t], this.handleBrowserEvent_, false, this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach this instance from a DOM element.
|
* @return {EventTarget} The element that this instance currently
|
||||||
|
* listens to browser events on.
|
||||||
*/
|
*/
|
||||||
ol.event.Events.prototype.detachFromElement_ = function() {
|
ol.event.Events.prototype.getElement = function() {
|
||||||
var t, types = goog.events.EventType,
|
return this.element_;
|
||||||
element = this.element_;
|
};
|
||||||
if (goog.isDef(element)) {
|
|
||||||
|
/**
|
||||||
|
* Attach this instance to a DOM element. When called, all browser events fired
|
||||||
|
* on the provided element will be relayed by this instance.
|
||||||
|
*
|
||||||
|
* @param {EventTarget=} opt_element A DOM element to attach
|
||||||
|
* browser events to. If called without this argument, all browser events
|
||||||
|
* will be detached from the element they are currently attached to.
|
||||||
|
*/
|
||||||
|
ol.event.Events.prototype.setElement = function(opt_element) {
|
||||||
|
var t, types = goog.events.EventType;
|
||||||
|
if (this.element_) {
|
||||||
for (t in types) {
|
for (t in types) {
|
||||||
// register the event cross-browser
|
// register the event cross-browser
|
||||||
goog.events.unlisten(
|
goog.events.unlisten(
|
||||||
element, types[t], this.handleBrowserEvent_, false, this
|
this.element_, types[t], this.handleBrowserEvent, false, this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
delete this.element_;
|
delete this.element_;
|
||||||
|
}
|
||||||
|
if (goog.isDef(opt_element)) {
|
||||||
|
this.element_ = opt_element;
|
||||||
|
for (t in types) {
|
||||||
|
// register the event cross-browser
|
||||||
|
goog.events.listen(
|
||||||
|
opt_element, types[t], this.handleBrowserEvent, false, this
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -250,10 +255,9 @@ ol.event.Events.prototype.triggerEvent = function(type, evt) {
|
|||||||
* Basically just a wrapper to the triggerEvent() function, but takes
|
* Basically just a wrapper to the triggerEvent() function, but takes
|
||||||
* care to set a property 'xy' on the event with the current mouse position.
|
* care to set a property 'xy' on the event with the current mouse position.
|
||||||
*
|
*
|
||||||
* @private
|
* @param {Event} evt
|
||||||
* @param {goog.events.BrowserEvent} evt
|
|
||||||
*/
|
*/
|
||||||
ol.event.Events.prototype.handleBrowserEvent_ = function(evt) {
|
ol.event.Events.prototype.handleBrowserEvent = function(evt) {
|
||||||
if (!goog.isDef(this.element_)) {
|
if (!goog.isDef(this.element_)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -279,10 +283,10 @@ ol.event.Events.prototype.handleBrowserEvent_ = function(evt) {
|
|||||||
evt.clientX = x / num;
|
evt.clientX = x / num;
|
||||||
evt.clientY = y / num;
|
evt.clientY = y / num;
|
||||||
}
|
}
|
||||||
var element = /** @type {!Element} */ this._element;
|
|
||||||
if (this.includeXY) {
|
if (this.includeXY) {
|
||||||
|
var element = /** @type {!Element} */ this.element_;
|
||||||
evt.xy = goog.style.getRelativePosition(evt, element);
|
evt.xy = goog.style.getRelativePosition(evt, element);
|
||||||
}
|
}
|
||||||
this.dispatchEvent(evt);
|
this.dispatchEvent(evt);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user