|
@@ -1,6 +1,8 @@
|
|
package h2d.comp;
|
|
package h2d.comp;
|
|
import h2d.css.Defs;
|
|
import h2d.css.Defs;
|
|
|
|
|
|
|
|
+private typedef Query = Array<CssClass>;
|
|
|
|
+
|
|
@:access(h2d.comp.Component)
|
|
@:access(h2d.comp.Component)
|
|
@:keep
|
|
@:keep
|
|
class JQuery {
|
|
class JQuery {
|
|
@@ -19,6 +21,87 @@ class JQuery {
|
|
for( s in select ) s.toggleClass(cl,flag);
|
|
for( s in select ) s.toggleClass(cl,flag);
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function find( q : Dynamic ) {
|
|
|
|
+ if( Std.is(q, Component) )
|
|
|
|
+ return new JQuery(root, Lambda.has(select, q) ? null : q);
|
|
|
|
+ if( Std.is(q, String) ) {
|
|
|
|
+ var q = parseQuery(q);
|
|
|
|
+ var out = [];
|
|
|
|
+ for( s in select )
|
|
|
|
+ lookupRec(s, q, out);
|
|
|
|
+ return new JQuery(root, out);
|
|
|
|
+ }
|
|
|
|
+ throw "Invalid JQuery " + q;
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function filter( q : Dynamic ) {
|
|
|
|
+ if( Std.is(q, Component) )
|
|
|
|
+ return new JQuery(root, Lambda.has(select, q) ? null : q);
|
|
|
|
+ if( Std.is(q, String) ) {
|
|
|
|
+ var q = parseQuery(q);
|
|
|
|
+ return new JQuery(root, [for( s in select ) if( matchQuery(q, s) ) s]);
|
|
|
|
+ }
|
|
|
|
+ if( Std.is(q, JQuery) ) {
|
|
|
|
+ var q : JQuery = q;
|
|
|
|
+ return new JQuery(root, [for( s in select ) if( Lambda.has(q.select, s) ) s]);
|
|
|
|
+ }
|
|
|
|
+ throw "Invalid JQuery " + q;
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function not( q : Dynamic ) {
|
|
|
|
+ if( Std.is(q, Component) )
|
|
|
|
+ return new JQuery(root, [for( s in select ) if( s != q ) s]);
|
|
|
|
+ if( Std.is(q, String) ) {
|
|
|
|
+ var q = parseQuery(q);
|
|
|
|
+ return new JQuery(root, [for( s in select ) if( !matchQuery(q, s) ) s]);
|
|
|
|
+ }
|
|
|
|
+ if( Std.is(q, JQuery) ) {
|
|
|
|
+ var q : JQuery = q;
|
|
|
|
+ return new JQuery(root, [for( s in select ) if( !Lambda.has(q.select, s) ) s]);
|
|
|
|
+ }
|
|
|
|
+ throw "Invalid JQuery " + q;
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function click( f : JQuery -> Void ) {
|
|
|
|
+ for( c in select ) {
|
|
|
|
+ var int = Std.instance(c, Interactive);
|
|
|
|
+ if( int == null ) throw c + " is not interactive";
|
|
|
|
+ int.onClick = function() f(new JQuery(root,c));
|
|
|
|
+ }
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function show() {
|
|
|
|
+ for( s in select )
|
|
|
|
+ s.getStyle(true).display = true;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function hide() {
|
|
|
|
+ for( s in select )
|
|
|
|
+ s.getStyle(true).display = false;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function toggle() {
|
|
|
|
+ for( s in select ) {
|
|
|
|
+ var s = s.getStyle(true);
|
|
|
|
+ s.display = !s.display;
|
|
|
|
+ }
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function iterator() {
|
|
|
|
+ var it = select.iterator();
|
|
|
|
+ return {
|
|
|
|
+ hasNext : it.hasNext,
|
|
|
|
+ next : function() return new JQuery(root, it.next()),
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
|
|
function _get_val() : Dynamic {
|
|
function _get_val() : Dynamic {
|
|
var c = select[0];
|
|
var c = select[0];
|
|
@@ -105,28 +188,35 @@ class JQuery {
|
|
var a : Array<Dynamic> = query;
|
|
var a : Array<Dynamic> = query;
|
|
for( v in a ) if( !Std.is(v, Component) ) throw "Invalid JQuery "+query;
|
|
for( v in a ) if( !Std.is(v, Component) ) throw "Invalid JQuery "+query;
|
|
set = a;
|
|
set = a;
|
|
- } else if( Std.is(query, String) ) {
|
|
|
|
- set = lookupSet(query);
|
|
|
|
- } else
|
|
|
|
|
|
+ } else if( Std.is(query, String) )
|
|
|
|
+ set = lookup(root, query);
|
|
|
|
+ else
|
|
throw "Invalid JQuery " + query;
|
|
throw "Invalid JQuery " + query;
|
|
return set;
|
|
return set;
|
|
}
|
|
}
|
|
|
|
|
|
- function lookupSet( query : String ) {
|
|
|
|
- var classes = new h2d.css.Parser().parseClasses(query);
|
|
|
|
|
|
+ function lookup( root : Component, query : String ) {
|
|
var set = [];
|
|
var set = [];
|
|
- lookupRec(root, classes, set);
|
|
|
|
|
|
+ lookupRec(root, parseQuery(query), set);
|
|
return set;
|
|
return set;
|
|
}
|
|
}
|
|
|
|
|
|
- function lookupRec(comp:Component, classes:Array<CssClass>, set : Array<Component> ) {
|
|
|
|
- for( c in classes )
|
|
|
|
- if( h2d.css.Engine.ruleMatch(c, comp) ) {
|
|
|
|
- set.push(comp);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ function parseQuery(q) : Query {
|
|
|
|
+ return new h2d.css.Parser().parseClasses(q);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function matchQuery(q:Query, comp:Component) {
|
|
|
|
+ for( r in q )
|
|
|
|
+ if( h2d.css.Engine.ruleMatch(r, comp) )
|
|
|
|
+ return true;
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function lookupRec(comp:Component, q, set : Array<Component> ) {
|
|
|
|
+ if( matchQuery(q, comp) )
|
|
|
|
+ set.push(comp);
|
|
for( s in comp.components )
|
|
for( s in comp.components )
|
|
- lookupRec(s, classes, set);
|
|
|
|
|
|
+ lookupRec(s, q, set);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|