1 | "use strict";
|
2 | var lib_1 = require('../lib');
|
3 | var ProxyElement = (function () {
|
4 | function ProxyElement(__zone) {
|
5 | this.__zone = __zone;
|
6 | }
|
7 | Object.defineProperty(ProxyElement.prototype, "_zone", {
|
8 | get: function () { return this.__zone || Zone.current; },
|
9 | enumerable: true,
|
10 | configurable: true
|
11 | });
|
12 | Object.defineProperty(ProxyElement.prototype, "querySelector", {
|
13 | get: function () {
|
14 | var parentElement = this._zone.get('parentElement');
|
15 | var _zone = this._zone.fork({
|
16 | name: 'ProxyElement.querySelector',
|
17 | properties: { parentElement: parentElement }
|
18 | });
|
19 | return _zone.wrap(querySelector, 'ProxyElement.querySelector');
|
20 | },
|
21 | enumerable: true,
|
22 | configurable: true
|
23 | });
|
24 | Object.defineProperty(ProxyElement.prototype, "querySelectorAll", {
|
25 | get: function () {
|
26 | var parentElement = this._zone.get('parentElement');
|
27 | var _zone = this._zone.fork({
|
28 | name: 'ProxyElement.querySelectorAll',
|
29 | properties: { parentElement: parentElement }
|
30 | });
|
31 | return _zone.wrap(querySelectorAll, 'ProxyElement.querySelector');
|
32 | },
|
33 | enumerable: true,
|
34 | configurable: true
|
35 | });
|
36 | Object.defineProperty(ProxyElement.prototype, "tagName", {
|
37 | get: function () {
|
38 | var el = this._zone.get('element');
|
39 | return el.tagName;
|
40 | },
|
41 | enumerable: true,
|
42 | configurable: true
|
43 | });
|
44 | Object.defineProperty(ProxyElement.prototype, "value", {
|
45 | get: function () {
|
46 | var el = this._zone.get('element');
|
47 | return el.value;
|
48 | },
|
49 | enumerable: true,
|
50 | configurable: true
|
51 | });
|
52 | Object.defineProperty(ProxyElement.prototype, "nodeName", {
|
53 | get: function () {
|
54 | var el = this._zone.get('element');
|
55 | return el.tagName;
|
56 | },
|
57 | enumerable: true,
|
58 | configurable: true
|
59 | });
|
60 | Object.defineProperty(ProxyElement.prototype, "nodeValue", {
|
61 | get: function () {
|
62 | var el = this._zone.get('element');
|
63 | return el.nodeValue;
|
64 | },
|
65 | enumerable: true,
|
66 | configurable: true
|
67 | });
|
68 | Object.defineProperty(ProxyElement.prototype, "firstChild", {
|
69 | get: function () {
|
70 | var DOM = lib_1.getDOM();
|
71 | var parentElement = this._zone.get('element');
|
72 | var _zone = this._zone.fork({
|
73 | name: 'ProxyElement.querySelector',
|
74 | properties: { parentElement: parentElement }
|
75 | });
|
76 | return _zone.run(function () { return DOM.firstChild(parentElement); });
|
77 | },
|
78 | enumerable: true,
|
79 | configurable: true
|
80 | });
|
81 | Object.defineProperty(ProxyElement.prototype, "nextSibling", {
|
82 | get: function () {
|
83 | var el = this._zone.get('element');
|
84 | return el.nextSibling;
|
85 | },
|
86 | enumerable: true,
|
87 | configurable: true
|
88 | });
|
89 | Object.defineProperty(ProxyElement.prototype, "parentElement", {
|
90 | get: function () {
|
91 | var el = this._zone.get('element');
|
92 | return el.parent;
|
93 | },
|
94 | enumerable: true,
|
95 | configurable: true
|
96 | });
|
97 | Object.defineProperty(ProxyElement.prototype, "childNodes", {
|
98 | get: function () {
|
99 | var DOM = lib_1.getDOM();
|
100 | var parentElement = this._zone.get('element');
|
101 | var _zone = this._zone.fork({
|
102 | name: 'ProxyElement.querySelector',
|
103 | properties: { parentElement: parentElement }
|
104 | });
|
105 | return _zone.run(function () { return DOM.childNodes(parentElement); });
|
106 | },
|
107 | enumerable: true,
|
108 | configurable: true
|
109 | });
|
110 | ProxyElement.prototype.createElement = function (tagName) {
|
111 | var DOM = lib_1.getDOM();
|
112 | return DOM.createElement(tagName);
|
113 | };
|
114 | return ProxyElement;
|
115 | }());
|
116 | exports.ProxyElement = ProxyElement;
|
117 | var ProxyDocument = (function () {
|
118 | function ProxyDocument(__zone) {
|
119 | this.__zone = __zone;
|
120 | }
|
121 | Object.defineProperty(ProxyDocument.prototype, "_zone", {
|
122 | get: function () { return this.__zone || Zone.current; },
|
123 | enumerable: true,
|
124 | configurable: true
|
125 | });
|
126 | Object.defineProperty(ProxyDocument.prototype, "querySelector", {
|
127 | get: function () {
|
128 | var document = this._zone.get('document');
|
129 | var zone = this._zone.fork({
|
130 | name: 'ProxyDocument.querySelector',
|
131 | properties: {
|
132 | parentElement: document
|
133 | }
|
134 | });
|
135 | return zone.wrap(querySelector, 'ProxyDocument.querySelector');
|
136 | },
|
137 | enumerable: true,
|
138 | configurable: true
|
139 | });
|
140 | Object.defineProperty(ProxyDocument.prototype, "querySelectorAll", {
|
141 | get: function () {
|
142 | var document = this._zone.get('document');
|
143 | var _zone = this._zone.fork({
|
144 | name: 'ProxyDocument.querySelectorAll',
|
145 | properties: {
|
146 | parentElement: document
|
147 | }
|
148 | });
|
149 | return _zone.wrap(querySelectorAll, 'ProxyDocument.querySelector');
|
150 | },
|
151 | enumerable: true,
|
152 | configurable: true
|
153 | });
|
154 | Object.defineProperty(ProxyDocument.prototype, "tagName", {
|
155 | get: function () {
|
156 | var el = this._zone.get('document');
|
157 | return el.tagName;
|
158 | },
|
159 | enumerable: true,
|
160 | configurable: true
|
161 | });
|
162 | Object.defineProperty(ProxyDocument.prototype, "cookie", {
|
163 | get: function () {
|
164 | var el = this._zone.get('cookie');
|
165 | return el.cookie;
|
166 | },
|
167 | enumerable: true,
|
168 | configurable: true
|
169 | });
|
170 | ProxyDocument.prototype.createElement = function (tagName) {
|
171 | var DOM = lib_1.getDOM();
|
172 | return DOM.createElement(tagName);
|
173 | };
|
174 | return ProxyDocument;
|
175 | }());
|
176 | exports.ProxyDocument = ProxyDocument;
|
177 | function createDocumentProxy() {
|
178 | return new ProxyDocument();
|
179 | }
|
180 | exports.createDocumentProxy = createDocumentProxy;
|
181 | function createGlobalProxy() {
|
182 | var originalDocumentRef = global.document;
|
183 | if (originalDocumentRef instanceof ProxyDocument) {
|
184 | return originalDocumentRef;
|
185 | }
|
186 | var document = createDocumentProxy();
|
187 | Object.defineProperty(global, 'document', {
|
188 | enumerable: false,
|
189 | configurable: false,
|
190 | get: function () {
|
191 | var doc = Zone.current.get('document');
|
192 | if (doc) {
|
193 | return document;
|
194 | }
|
195 | return originalDocumentRef;
|
196 | },
|
197 | set: function (_newValue) {
|
198 | }
|
199 | });
|
200 | return document;
|
201 | }
|
202 | exports.createGlobalProxy = createGlobalProxy;
|
203 | function querySelector(query) {
|
204 | var DOM = lib_1.getDOM();
|
205 | var parentElement = Zone.current.get('parentElement');
|
206 | var element = DOM.querySelector(parentElement, query);
|
207 | var zone = Zone.current.fork({
|
208 | name: 'querySelector',
|
209 | properties: { parentElement: parentElement, element: element }
|
210 | });
|
211 | return new ProxyElement(zone);
|
212 | }
|
213 | function querySelectorAll(query) {
|
214 | var DOM = lib_1.getDOM();
|
215 | var parentElement = Zone.current.get('parentElement');
|
216 | var element = DOM.querySelectorAll(parentElement, query);
|
217 | var zone = Zone.current.fork({
|
218 | name: 'querySelector',
|
219 | properties: { parentElement: parentElement, element: element }
|
220 | });
|
221 | return new ProxyElement(zone);
|
222 | }
|
223 |
|
\ | No newline at end of file |