forked from 0x2620/oxjs
better event handling in Ox.Element
This commit is contained in:
parent
506a2f2923
commit
5f417fa152
4 changed files with 60 additions and 71 deletions
53
source/Ox.js
53
source/Ox.js
|
|
@ -136,7 +136,8 @@ Ox.getset = function(obj, args, callback, context) {
|
|||
ret = obj[args[0]];
|
||||
} else {
|
||||
// getset([key, val]) or getset([{key: val, ...}])
|
||||
args = Ox.makeObject(Ox.isObject(args[0]) ? args[0] : args);
|
||||
args = Ox.makeObject(args);
|
||||
// args = Ox.makeObject(Ox.isObject(args[0]) ? args[0] : args);
|
||||
obj = Ox.extend(obj, args);
|
||||
Ox.forEach(args, function(val, key) {
|
||||
if (!obj_ || !Ox.isEqual(obj_[key], val)) {
|
||||
|
|
@ -629,44 +630,34 @@ Ox.loop = function() {
|
|||
}
|
||||
};
|
||||
|
||||
Ox.makeArray = function(arg) {
|
||||
Ox.makeArray = function(obj) {
|
||||
/*
|
||||
like $.makeArray()
|
||||
>>> Ox.makeArray('foo', 'bar')
|
||||
['foo', 'bar']
|
||||
>>> (function() { return Ox.makeArray(arguments); }('foo', 'bar'))
|
||||
['foo', 'bar']
|
||||
*/
|
||||
return Array.prototype.slice.call(
|
||||
Ox.isArguments(arg) ? arg : arguments
|
||||
);
|
||||
return Array.prototype.slice.call(obj);
|
||||
};
|
||||
|
||||
Ox.makeObject = function() {
|
||||
Ox.makeObject = function(obj) {
|
||||
/*
|
||||
>>> Ox.makeObject("foo", "bar").foo
|
||||
"bar"
|
||||
>>> Ox.makeObject(["foo", "bar"]).foo
|
||||
"bar"
|
||||
>>> Ox.makeObject({foo: "bar"}).foo
|
||||
"bar"
|
||||
>>> (function() { return Ox.makeObject(arguments); }("foo", "bar")).foo
|
||||
"bar"
|
||||
>>> (function() { return Ox.makeObject(arguments); }({foo: 'bar'})).foo
|
||||
'bar'
|
||||
>>> (function() { return Ox.makeObject(arguments); }('foo', 'bar')).foo
|
||||
'bar'
|
||||
>>> (function() { return Ox.makeObject(arguments); }('foo')).foo
|
||||
undefined
|
||||
>>> (function() { return Ox.makeObject(arguments); }()).foo
|
||||
undefined
|
||||
*/
|
||||
var obj = {};
|
||||
if (arguments.length == 1) {
|
||||
if (Ox.isObject(arguments[0])) {
|
||||
// ({foo: 'bar'})
|
||||
obj = arguments[0];
|
||||
} else {
|
||||
// (['foo', 'bar'])
|
||||
obj[arguments[0][0]] = arguments[0][1];
|
||||
}
|
||||
} else {
|
||||
var ret = {};
|
||||
if (obj.length == 1) {
|
||||
// ({foo: 'bar'})
|
||||
ret = obj[0];
|
||||
} else if (obj.length == 2){
|
||||
// ('foo', 'bar')
|
||||
obj[arguments[0]] = arguments[1];
|
||||
ret[obj[0]] = obj[1]
|
||||
}
|
||||
return obj;
|
||||
return ret;
|
||||
};
|
||||
|
||||
Ox.map = function(obj, fn) {
|
||||
|
|
@ -1320,7 +1311,7 @@ Ox.element = function(str) {
|
|||
if (arguments.length == 1 && Ox.isString(arguments[0])) {
|
||||
ret = this[0].getAttribute(arguments[0]);
|
||||
} else {
|
||||
Ox.forEach(Ox.makeObject.apply(null, arguments), function(v, k) {
|
||||
Ox.forEach(Ox.makeObject(arguments), function(v, k) {
|
||||
that[0].setAttribute(k, v);
|
||||
});
|
||||
ret = this;
|
||||
|
|
@ -1332,7 +1323,7 @@ Ox.element = function(str) {
|
|||
if (arguments.length == 1 && Ox.isString(arguments[0])) {
|
||||
ret = this[0].style[arguments[0]];
|
||||
} else {
|
||||
Ox.forEach(Ox.makeObject.apply(null, arguments), function(v, k) {
|
||||
Ox.forEach(Ox.makeObject(arguments), function(v, k) {
|
||||
that[0].style[k] = v;
|
||||
});
|
||||
ret = this;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue