add new methods to Ox.$ (width, height, show, hide)

This commit is contained in:
rolux 2012-04-12 21:21:03 +02:00
parent 42f0700a00
commit 49a16328f5

View file

@ -75,7 +75,7 @@ Ox.$ = Ox.element = function(val) {
// fixme: remove click and mousedown, // fixme: remove click and mousedown,
// add native css selector // add native css selector
// take all matches of getElementsBy... // take all matches of getElementsBy...
var element = Ox.isObject(val) ? val // window var element = Ox.isObject(val) ? val // window or document
: val[0] == '<' ? document.createElement(Ox.sub(val, 1, -1)) : val[0] == '<' ? document.createElement(Ox.sub(val, 1, -1))
: val[0] == '#' ? document.getElementById(Ox.sub(val, 1)) : val[0] == '#' ? document.getElementById(Ox.sub(val, 1))
: val[0] == '.' ? document.getElementsByClassName(Ox.sub(val, 1))[0] : val[0] == '.' ? document.getElementsByClassName(Ox.sub(val, 1))[0]
@ -187,8 +187,7 @@ Ox.$ = Ox.element = function(val) {
return ret; return ret;
}, },
empty: function() { empty: function() {
this.html(''); return this.html('');
return this;
}, },
/*@ /*@
hasClass <f> Returns true if the element has a given class hasClass <f> Returns true if the element has a given class
@ -198,6 +197,12 @@ Ox.$ = Ox.element = function(val) {
hasClass: function(str) { hasClass: function(str) {
return this[0].className.split(' ').indexOf(str) > -1; return this[0].className.split(' ').indexOf(str) > -1;
}, },
height: function() {
return this[0].offsetHeight;
},
hide: function() {
return this.css({display: 'none'});
},
/*@ /*@
html <f> Gets or sets the inner HTML html <f> Gets or sets the inner HTML
() -> <s> The inner HTML () -> <s> The inner HTML
@ -250,9 +255,15 @@ Ox.$ = Ox.element = function(val) {
).join(' '); ).join(' ');
return this; return this;
}, },
show: function() {
return this.css({display: 'block'});
},
unbind: function(event) { unbind: function(event) {
this[0]['on' + event] = null; this[0]['on' + event] = null;
return this; return this;
},
width: function() {
return this[0].offsetWidth;
} }
} : null; } : null;
}; };