forked from 0x2620/oxjs
adding symbols
This commit is contained in:
parent
b55ade5687
commit
6da40d325c
9 changed files with 54 additions and 16 deletions
25
source/Ox.js
25
source/Ox.js
|
|
@ -171,13 +171,13 @@ Ox.compact = function(arr) {
|
|||
Ox.flatten = function(arr) {
|
||||
// fixme: can this work for objects too?
|
||||
var ret = [];
|
||||
arr.forEach(function(v) {
|
||||
if (Ox.isArray(v)) {
|
||||
Ox.flatten(v).forEach(function(v) {
|
||||
ret.push(v);
|
||||
arr.forEach(function(val) {
|
||||
if (Ox.isArray(val)) {
|
||||
Ox.flatten(val).forEach(function(val) {
|
||||
ret.push(val);
|
||||
});
|
||||
} else {
|
||||
ret.push(v);
|
||||
ret.push(val);
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
|
|
@ -468,6 +468,9 @@ Ox.forEach = function(obj, fn) {
|
|||
}
|
||||
for (key in obj) {
|
||||
key = isObject ? key : parseInt(key);
|
||||
// fixme: some code somewhere (jQuery wrapper?) relies on looping over the prototype
|
||||
// ... but the hasOwnProperty call should be uncommented!
|
||||
// +fixme: fn.call(context, obj[key], key, obj) may be more standard...
|
||||
if (/*hasOwnProperty.call(obj, key) && */fn(obj[key], key) === false) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -1640,6 +1643,7 @@ Ox.element = function(str) {
|
|||
return {
|
||||
//@ 0 <e> The DOM element itself
|
||||
0: str[0] == '<' ? document.createElement(str.substr(1, str.length - 2)) :
|
||||
// fixme: why only take the first match?
|
||||
str[0] == '.' ? document.getElementsByClassName(str.substr(1))[0] :
|
||||
str[0] == '#' ? document.getElementById(str.substr(1)) :
|
||||
document.getElementsByTagName(str)[0],
|
||||
|
|
@ -1651,7 +1655,7 @@ Ox.element = function(str) {
|
|||
addClass: function(str) {
|
||||
this[0].className = this[0].className ? Ox.unique(
|
||||
(this[0].className + ' ' + str).split(' ')
|
||||
) : str;
|
||||
).join(' ') : str;
|
||||
return this;
|
||||
},
|
||||
/*@
|
||||
|
|
@ -1713,6 +1717,14 @@ Ox.element = function(str) {
|
|||
return ret;
|
||||
},
|
||||
/*@
|
||||
hasClass <f> Returns true if the element has a given class
|
||||
(className) -> <b> True if the element has the class
|
||||
className <s> Class name
|
||||
@*/
|
||||
hasClass: function(str) {
|
||||
return this[0].className.split(' ').indexOf(str) > -1;
|
||||
},
|
||||
/*@
|
||||
html <f> Gets or sets the inner HTML
|
||||
() -> <s> The inner HTML
|
||||
(html) -> <o> This element
|
||||
|
|
@ -1734,6 +1746,7 @@ Ox.element = function(str) {
|
|||
callback <f> Callback function
|
||||
event <o> The DOM event
|
||||
@*/
|
||||
// fixme: why not a generic bind?
|
||||
mousedown: function(callback) {
|
||||
this[0].onmousedown = callback;
|
||||
return this;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue