| OLD | NEW |
| (Empty) | |
| 1 part of angular; |
| 2 |
| 3 /** |
| 4 * A global write only variable which keeps track of objects attached to the ele
ments. |
| 5 * This is usefull for debugging AngularDart application from the browser's REPL
. |
| 6 */ |
| 7 Expando _elementExpando = new Expando('element'); |
| 8 |
| 9 /** |
| 10 * Return the closest [ElementProbe] object for a given [Element]. |
| 11 * |
| 12 * NOTE: This global method is here to make it easier to debug Angular applicati
on from |
| 13 * the browser's REPL, unit or end-to-end tests. The function is not inten
ded to |
| 14 * be called from Angular application. |
| 15 */ |
| 16 ElementProbe ngProbe(dom.Node node) { |
| 17 while(node != null) { |
| 18 var probe = _elementExpando[node]; |
| 19 if (probe != null) return probe; |
| 20 node = node.parent; |
| 21 } |
| 22 return null; |
| 23 } |
| 24 |
| 25 |
| 26 /** |
| 27 * Return the [Injector] associated with a current [Element]. |
| 28 * |
| 29 * **NOTE**: This global method is here to make it easier to debug Angular appli
cation from |
| 30 * the browser's REPL, unit or end-to-end tests. The function is not intended to
be called |
| 31 * from Angular application. |
| 32 */ |
| 33 Injector ngInjector(dom.Node node) => ngProbe(node).injector; |
| 34 |
| 35 |
| 36 /** |
| 37 * Return the [Scope] associated with a current [Element]. |
| 38 * |
| 39 * **NOTE**: This global method is here to make it easier to debug Angular appli
cation from |
| 40 * the browser's REPL, unit or end-to-end tests. The function is not intended to
be called |
| 41 * from Angular application. |
| 42 */ |
| 43 Scope ngScope(dom.Node node) => ngProbe(node).scope; |
| 44 |
| 45 |
| 46 List<dom.Element> ngQuery(dom.Node element, String selector, [String containsTex
t]) { |
| 47 var list = []; |
| 48 var children = [element]; |
| 49 while (!children.isEmpty) { |
| 50 var child = children.removeAt(0); |
| 51 child.querySelectorAll(selector).forEach((e) { |
| 52 if (containsText == null || e.text.contains(containsText)) list.add(e); |
| 53 }); |
| 54 child.querySelectorAll('*').forEach((e) { |
| 55 if (e.shadowRoot != null) children.add(e.shadowRoot); |
| 56 }); |
| 57 } |
| 58 return list; |
| 59 } |
| 60 |
| 61 /** |
| 62 * Return a List of directive controllers associated with a current [Element]. |
| 63 * |
| 64 * **NOTE**: This global method is here to make it easier to debug Angular appli
cation from |
| 65 * the browser's REPL, unit or end-to-end tests. The function is not intended to
be called |
| 66 * from Angular application. |
| 67 */ |
| 68 List<Object> ngDirectives(dom.Node node) { |
| 69 ElementProbe probe = _elementExpando[node]; |
| 70 return probe == null ? [] : probe.directives; |
| 71 } |
| 72 |
| 73 _publishToJavaScript() { |
| 74 js.context.ngProbe = (dom.Node node) => _jsProbe(ngProbe(node)); |
| 75 js.context.ngInjector = (dom.Node node) => _jsInjector(ngInjector(node)); |
| 76 js.context.ngScope = (dom.Node node) => _jsScope(ngScope(node)); |
| 77 js.context.ngQuery = (dom.Node node, String selector, [String containsText]) =
> |
| 78 new JsArray.from(ngQuery(node, selector, containsText)); |
| 79 } |
| 80 |
| 81 JsObject _jsProbe(ElementProbe probe) { |
| 82 return new JsObject.jsify({ |
| 83 "element": probe.element, |
| 84 "injector": _jsInjector(probe.injector), |
| 85 "scope": _jsScope(probe.scope), |
| 86 "directives": probe.directives.map((directive) => _jsDirective(directive)) |
| 87 })..['_dart_'] = probe; |
| 88 } |
| 89 |
| 90 JsObject _jsInjector(Injector injector) { |
| 91 return new JsObject.jsify({ |
| 92 "get": injector.get |
| 93 })..['_dart_'] = injector; |
| 94 } |
| 95 |
| 96 JsObject _jsScope(Scope scope) { |
| 97 return new JsObject.jsify({ |
| 98 "\$apply": scope.$apply, |
| 99 "\$digest": scope.$digest, |
| 100 "get": (name) => scope[name], |
| 101 "set": (name, value) => scope[name] = value |
| 102 })..['_dart_'] = scope; |
| 103 } |
| 104 |
| 105 _jsDirective(directive) => directive; |
| OLD | NEW |