Ox.$: update documentation, add trigger method, add test

This commit is contained in:
rolux 2012-05-30 22:38:48 +02:00
parent f1ccfa44f4
commit b960ef3ea4

View file

@ -2,8 +2,10 @@
/*@ /*@
Ox.$ <f> Generic HTML element, mimics jQuery Ox.$ <f> Generic HTML element, mimics jQuery
(str) -> <o> Element object value <*> `window`, `document`, html element, tagname or selector
str <s> Tagname ('<tagname>') or selector ('tagname', '.classname', '#id') Passing a tagname ('<tagname>') creates an element, passing a selector
('tagname', '.classname' or '#id') selects an element.
(value) -> <o> Element object
> Ox.$('<div>').addClass('red').hasClass('red') > Ox.$('<div>').addClass('red').hasClass('red')
true true
> Ox.$('<div>').addClass('red').removeClass('red').hasClass('red') > Ox.$('<div>').addClass('red').removeClass('red').hasClass('red')
@ -22,9 +24,11 @@ Ox.$ <f> Generic HTML element, mimics jQuery
'' ''
> Ox.$('<input>').val('red').val() > Ox.$('<input>').val('red').val()
'red' 'red'
> !!Ox.$('<div>').on({click: function(e) { Ox.test(e.type, 'click'); }}).trigger('click')
true
@*/ @*/
Ox.$ = Ox.element = function(value) { Ox.$ = Ox.element = function(value) {
var element = !Ox.isString(value) ? value // window or document var element = !Ox.isString(value) ? value // window, document or element
: value[0] == '<' ? document.createElement(value.slice(1, -1)) : value[0] == '<' ? document.createElement(value.slice(1, -1))
: value[0] == '#' ? document.getElementById(value.slice(1)) : value[0] == '#' ? document.getElementById(value.slice(1))
: value[0] == '.' ? document.getElementsByClassName(value.slice(1))[0] : value[0] == '.' ? document.getElementsByClassName(value.slice(1))[0]
@ -247,6 +251,15 @@ Ox.$ = Ox.element = function(value) {
return this.css({display: 'block'}); return this.css({display: 'block'});
}, },
/*@ /*@
trigger <f> Triggers an event
@*/
trigger: function(event) {
var e = document.createEvent('MouseEvents');
e.initEvent(event, true, true);
this[0].dispatchEvent(e);
return this;
},
/*@
val <f> Gets or sets the value property of this element val <f> Gets or sets the value property of this element
() -> <s> Value () -> <s> Value
(value) -> <o> This element (value) -> <o> This element