forked from 0x2620/oxjs
various improvements in OxJS and OxUI
This commit is contained in:
parent
74b9a25387
commit
7380595c7e
48 changed files with 184 additions and 161 deletions
|
|
@ -16,24 +16,33 @@ Ox.Element = function() {
|
|||
|
||||
return function(options, self) {
|
||||
|
||||
/*
|
||||
// allow for 'Ox.Element()' instead of 'new Ox.Element()'
|
||||
if (!(this instanceof arguments.callee)) {
|
||||
return new arguments.callee(options, self);
|
||||
}
|
||||
*/
|
||||
|
||||
// create private object
|
||||
self = self || {};
|
||||
// create defaults and options objects
|
||||
self.defaults = {};
|
||||
self.options = options || {};
|
||||
// allow for Ox.Element('tagname', self)
|
||||
if (typeof self.options == 'string') {
|
||||
// allow for Ox.TestElement('<tagname>')
|
||||
// or Ox.TestElement('cssSelector')
|
||||
if (Ox.isString(self.options)) {
|
||||
self.options = {
|
||||
element: self.options
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
// create event handler
|
||||
if (!self.$eventHandler) {
|
||||
self.$eventHandler = $('<div>');
|
||||
}
|
||||
|
||||
// create public object
|
||||
var that = new Ox.JQueryElement(
|
||||
$('<' + (self.options.element || 'div') + '>')
|
||||
$(self.options.element || '<div>')
|
||||
)
|
||||
.mousedown(mousedown);
|
||||
|
||||
|
|
@ -149,16 +158,13 @@ Ox.Element = function() {
|
|||
}
|
||||
*/
|
||||
|
||||
self.onChange = function() {
|
||||
// self.onChange(key, value)
|
||||
self.setOption = function() {
|
||||
// self.setOptions(key, value)
|
||||
// is called when an option changes
|
||||
// (to be implemented by widget)
|
||||
// fixme: rename to self.setOption
|
||||
};
|
||||
|
||||
that._leakSelf = function() { // fixme: remove
|
||||
return self;
|
||||
}
|
||||
that._self = self; // fixme: remove
|
||||
|
||||
that.bindEvent = function() {
|
||||
/***
|
||||
|
|
@ -190,13 +196,9 @@ Ox.Element = function() {
|
|||
};
|
||||
|
||||
that.defaults = function(defaults) {
|
||||
/***
|
||||
sets the default options
|
||||
Usage
|
||||
that.defaults({key0: value0, key1: value1, ...})
|
||||
***/
|
||||
// sets the default options
|
||||
self.defaults = defaults;
|
||||
delete self.options; // fixme: hackish fix for that = Ox.Foo({...}, self).defaults({...}).options({...})
|
||||
self.options = defaults;
|
||||
return that;
|
||||
};
|
||||
|
||||
|
|
@ -223,45 +225,21 @@ Ox.Element = function() {
|
|||
return that;
|
||||
};
|
||||
|
||||
that.options = function() { // fixme: use Ox.getset
|
||||
/***
|
||||
get or set options
|
||||
Usage
|
||||
that.options() returns self.options
|
||||
that.options('foo') returns self.options.foo
|
||||
that.options('foo', x) sets self.options.foo,
|
||||
returns that
|
||||
that.options({foo: x, bar: y}) sets self.options.foo
|
||||
and self.options.bar,
|
||||
returns that
|
||||
***/
|
||||
var args,
|
||||
length = arguments.length,
|
||||
oldOptions,
|
||||
ret;
|
||||
if (length == 0) {
|
||||
// options()
|
||||
ret = self.options;
|
||||
} else if (length == 1 && typeof arguments[0] == 'string') {
|
||||
// options(str)
|
||||
ret = self.options ? self.options[arguments[0]] : options[arguments[0]];
|
||||
} else {
|
||||
// options (str, val) or options({str: val, ...})
|
||||
// translate (str, val) to ({str: val})
|
||||
args = Ox.makeObject.apply(that, arguments || {});
|
||||
oldOptions = $.extend({}, self.options);
|
||||
// if options have not been set, extend defaults,
|
||||
// otherwise, extend options
|
||||
//self.options = $.extend(self.options, self.options ? {} : self.defaults, args);
|
||||
self.options = $.extend({}, self.defaults, self.options, args);
|
||||
//self.options = $.extend(self.options || self.defaults, args);
|
||||
Ox.forEach(args, function(val, key) {
|
||||
// key == 'id' && id && Ox.Event.changeId(id, value);
|
||||
/*!Ox.equals(value, oldOptions[key]) &&*/ self.onChange(key, val);
|
||||
});
|
||||
ret = that;
|
||||
}
|
||||
return ret;
|
||||
that.options = function() {
|
||||
/*
|
||||
that.options()
|
||||
returns self.options
|
||||
that.options(key)
|
||||
returns self.options.key
|
||||
that.options(key, val)
|
||||
sets self.options.key to val, calls self.setOption(key, val)
|
||||
if the key has been added or its val has changed, returns that
|
||||
that.options({keyA: valA, keyB: valB})
|
||||
sets self.options.keyA to valA and self.options.keyB to valB,
|
||||
calls self.setOptions(key, val) for every key/value pair
|
||||
that has been added or modified, returns that
|
||||
*/
|
||||
return Ox.getset(self.options, arguments, self.setOption, that);
|
||||
};
|
||||
|
||||
that.removeElement = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue