1
0
Fork 0
forked from 0x2620/oxjs

add that.update to Ox.Element

This commit is contained in:
rlx 2012-05-28 16:16:23 +00:00
commit ab68c4a54f

View file

@ -90,13 +90,15 @@ Ox.Element = function(options, self) {
element: self.options element: self.options
}; };
} }
// array of callbacks bound to any event
self.eventCallbacks = [];
// create event handler // create event handler
// (this can be passed as part of self) // (this can be passed as part of self)
if (!self.$eventHandler) { if (!self.$eventHandler) {
self.$eventHandler = $('<div>'); self.$eventHandler = $('<div>');
} }
// array of callbacks bound to any event
self.eventCallbacks = [];
// stack of callbacks bound to option updates
self.updateCallbacks = [];
// create public object // create public object
var that = new Ox.JQueryElement($(self.options.element || '<div>')) var that = new Ox.JQueryElement($(self.options.element || '<div>'))
@ -282,14 +284,12 @@ Ox.Element = function(options, self) {
} }
} }
self.setOption = function(key, value) { function update(key, value) {
// self.setOption(key, value) // update is called whenever an option is modified or added
// is called when an option changes Ox.loop(self.updateCallbacks.length - 1, -1, -1, function(i) {
// (to be implemented by widget) self.updateCallbacks[i](key, value) === false && Ox.Break();
if (key == 'tooltip') { });
setTooltip(); }
}
};
/*@ /*@
bindEvent <function> Binds a function to an event bindEvent <function> Binds a function to an event
@ -399,7 +399,7 @@ Ox.Element = function(options, self) {
value <val> the value of the option value <val> the value of the option
@*/ @*/
that.options = function() { that.options = function() {
return Ox.getset(self.options, arguments, self.setOption, that); return Ox.getset(self.options, arguments, update, that);
}; };
/*@ /*@
@ -519,6 +519,27 @@ Ox.Element = function(options, self) {
return that; return that;
}; };
/*@
update <f> Adds one or more handlers for options updates
(callback) -> <o> that
(key, callback) -> <o> that
({key: callback, ...}) -> <o> that
@*/
that.update = function() {
var callbacks;
if (Ox.typeOf(arguments[0]) == 'function') {
self.updateCallbacks.push(arguments[0]);
} else {
callbacks = Ox.makeObject(arguments);
self.updateCallbacks.push(function(key) {
if (callbacks[key]) {
return callbacks[key]();
}
});
}
return that;
};
/*@ /*@
value <f> Shortcut to get or set self.options.value value <f> Shortcut to get or set self.options.value
@*/ @*/
@ -528,6 +549,10 @@ Ox.Element = function(options, self) {
); );
}; };
that.update({
tooltip: setTooltip
});
return that; return that;
}; };