Ox.$: update documentation, add trigger method, add test
This commit is contained in:
parent
f1ccfa44f4
commit
b960ef3ea4
1 changed files with 16 additions and 3 deletions
|
@ -2,8 +2,10 @@
|
|||
|
||||
/*@
|
||||
Ox.$ <f> Generic HTML element, mimics jQuery
|
||||
(str) -> <o> Element object
|
||||
str <s> Tagname ('<tagname>') or selector ('tagname', '.classname', '#id')
|
||||
value <*> `window`, `document`, html element, tagname or selector
|
||||
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')
|
||||
true
|
||||
> Ox.$('<div>').addClass('red').removeClass('red').hasClass('red')
|
||||
|
@ -22,9 +24,11 @@ Ox.$ <f> Generic HTML element, mimics jQuery
|
|||
''
|
||||
> Ox.$('<input>').val('red').val()
|
||||
'red'
|
||||
> !!Ox.$('<div>').on({click: function(e) { Ox.test(e.type, 'click'); }}).trigger('click')
|
||||
true
|
||||
@*/
|
||||
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.getElementById(value.slice(1))
|
||||
: value[0] == '.' ? document.getElementsByClassName(value.slice(1))[0]
|
||||
|
@ -247,6 +251,15 @@ Ox.$ = Ox.element = function(value) {
|
|||
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
|
||||
() -> <s> Value
|
||||
(value) -> <o> This element
|
||||
|
|
Loading…
Reference in a new issue