Ox.$: normalize mousewheel event names
This commit is contained in:
parent
6cb7269ce1
commit
9ea8e0352d
1 changed files with 27 additions and 7 deletions
|
|
@ -28,11 +28,30 @@ Ox.$ <f> Generic HTML element, mimics jQuery
|
||||||
true
|
true
|
||||||
@*/
|
@*/
|
||||||
Ox.$ = Ox.element = function(value) {
|
Ox.$ = Ox.element = function(value) {
|
||||||
|
|
||||||
var element = !Ox.isString(value) ? value // window, document or element
|
var element = !Ox.isString(value) ? value // window, document or element
|
||||||
: value[0] == '<' ? document.createElement(value.slice(1, -1))
|
: value[0] == '<' ? document.createElement(value.slice(1, -1))
|
||||||
: value[0] == '#' ? document.getElementById(value.slice(1))
|
: value[0] == '#' ? document.getElementById(value.slice(1))
|
||||||
: value[0] == '.' ? document.getElementsByClassName(value.slice(1))[0]
|
: value[0] == '.' ? document.getElementsByClassName(value.slice(1))[0]
|
||||||
: document.getElementsByTagName(value)[0];
|
: document.getElementsByTagName(value)[0],
|
||||||
|
mousewheelEvents = ['wheel', 'mousewheel'],
|
||||||
|
originalMousewheelEvents = 'onwheel' in document ? ['wheel']
|
||||||
|
: ['mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];
|
||||||
|
|
||||||
|
function normalizeEvents(args) {
|
||||||
|
var ret = {};
|
||||||
|
Ox.forEach(Ox.makeObject(args), function(callback, event) {
|
||||||
|
if (Ox.contains(mousewheelEvents, event)) {
|
||||||
|
originalMousewheelEvents.forEach(function(event) {
|
||||||
|
ret[event] = callback;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ret[event] = callback;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return element ? {
|
return element ? {
|
||||||
//@ 0 <h> The DOM element itself
|
//@ 0 <h> The DOM element itself
|
||||||
0: element,
|
0: element,
|
||||||
|
|
@ -225,7 +244,7 @@ Ox.$ = Ox.element = function(value) {
|
||||||
@*/
|
@*/
|
||||||
off: function(event, callback) {
|
off: function(event, callback) {
|
||||||
var that = this;
|
var that = this;
|
||||||
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
|
Ox.forEach(normalizeEvents(arguments), function(callback, event) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
that[0].removeEventListener(event, callback, false);
|
that[0].removeEventListener(event, callback, false);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -244,7 +263,7 @@ Ox.$ = Ox.element = function(value) {
|
||||||
@*/
|
@*/
|
||||||
on: function() {
|
on: function() {
|
||||||
var that = this;
|
var that = this;
|
||||||
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
|
Ox.forEach(normalizeEvents(arguments), function(callback, event) {
|
||||||
that[0].addEventListener(event, callback, false);
|
that[0].addEventListener(event, callback, false);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -260,7 +279,7 @@ Ox.$ = Ox.element = function(value) {
|
||||||
one: function(events) {
|
one: function(events) {
|
||||||
var args = Ox.slice(arguments),
|
var args = Ox.slice(arguments),
|
||||||
that = this;
|
that = this;
|
||||||
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
|
Ox.forEach(normalizeEvents(arguments), function(callback, event) {
|
||||||
that.on(event, function fn() {
|
that.on(event, function fn() {
|
||||||
that.off(event, fn);
|
that.off(event, fn);
|
||||||
return callback.apply(that, args);
|
return callback.apply(that, args);
|
||||||
|
|
@ -422,6 +441,7 @@ Ox.$ = Ox.element = function(value) {
|
||||||
return this[0].offsetWidth;
|
return this[0].offsetWidth;
|
||||||
}
|
}
|
||||||
} : null;
|
} : null;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue