Ox.$.bind -> Ox.$.on, Ox.$.unbind -> Ox.$.off

This commit is contained in:
rolux 2012-05-28 15:53:10 +02:00
parent 3208ab35b9
commit a80534a1bd

View file

@ -88,21 +88,6 @@ Ox.$ = Ox.element = function(value) {
return ret; return ret;
}, },
/*@ /*@
bind <f> Binds a callback to an event
(event, callback) -> <o> This element
({event0: callback0, event1: callback1, ...}) -> <o> This element
event <s> Event name
callback <f> Callback function
e <o> Event properties
@*/
bind: function() {
var that = this;
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
that[0].addEventListener(event, callback);
});
return this;
},
/*@
css <f> Gets or sets a CSS attribute css <f> Gets or sets a CSS attribute
(key) -> <s> Value (key) -> <s> Value
(key, value) -> <o> This element (key, value) -> <o> This element
@ -168,6 +153,21 @@ Ox.$ = Ox.element = function(value) {
return ret; return ret;
}, },
/*@ /*@
on <f> Binds a callback to an event
(event, callback) -> <o> This element
({event0: callback0, event1: callback1, ...}) -> <o> This element
event <s> Event name
callback <f> Callback function
e <o> Event properties
@*/
on: function() {
var that = this;
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
that[0].addEventListener(event, callback);
});
return this;
},
/*@
one <f> Binds a callback to an event and unbinds it on first invocation one <f> Binds a callback to an event and unbinds it on first invocation
(event, callback) -> <o> This element (event, callback) -> <o> This element
({event0: callback0, event1: callback1, ...}) -> <o> This element ({event0: callback0, event1: callback1, ...}) -> <o> This element
@ -178,14 +178,33 @@ Ox.$ = Ox.element = function(value) {
one: function(events) { one: function(events) {
var that = this; var that = this;
Ox.forEach(Ox.makeObject(arguments), function(callback, event) { Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
that.bind(event, function fn() { that.on(event, function fn() {
that.unbind(event, fn); that.off(event, fn);
callback(); callback();
}); });
}); });
return this; return this;
}, },
/*@ /*@
off <f> Unbinds a callback from an event
(event) -> <o> This element (unbinds all callbacks)
(event, callback) -> <o> This element
({event0: callback0, event1: callback1, ...}) -> <o> This element
event <s> Event name
callback <f> Callback function
@*/
off: function(event, callback) {
var that = this;
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
if (callback) {
that[0].removeEventListener(event, callback);
} else {
that[0]['on' + event] = null;
}
});
return this;
},
/*@
remove <f> Removes this element from the DOM remove <f> Removes this element from the DOM
() -> <o> This element () -> <o> This element
@*/ @*/
@ -228,25 +247,6 @@ Ox.$ = Ox.element = function(value) {
return this.css({display: 'block'}); return this.css({display: 'block'});
}, },
/*@ /*@
unbind <f> Unbinds a callback from an event
(event) -> <o> This element (unbinds all callbacks)
(event, callback) -> <o> This element
({event0: callback0, event1: callback1, ...}) -> <o> This element
event <s> Event name
callback <f> Callback function
@*/
unbind: function(event, callback) {
var that = this;
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
if (callback) {
that[0].removeEventListener(event, callback);
} else {
that[0]['on' + event] = null;
}
});
return this;
},
/*@
val <f> Gets or sets the value property of this element val <f> Gets or sets the value property of this element
() -> <s> Value () -> <s> Value
(value) -> <o> This element (value) -> <o> This element