yellow-brick-road 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/README.rst +10 -5
  2. data/lib/yellow-brick-road/directive_processor.rb +10 -3
  3. data/lib/yellow-brick-road/version.rb +1 -1
  4. data/test/dummy/app/assets/javascripts/closure-deps.js +3 -3
  5. data/test/dummy/log/development.log +159 -0
  6. data/test/dummy/tmp/cache/assets/C1E/0C0/sprockets%2F9c2f7430126aff8d8514326208712832 +165 -0
  7. data/test/dummy/tmp/cache/assets/C29/5D0/sprockets%2F1498f4451d0836a53c7c302c49920996 +0 -0
  8. data/test/dummy/tmp/cache/assets/C7E/9F0/sprockets%2F89862076204c62c4593ac20de32da909 +6 -6
  9. data/test/dummy/tmp/cache/assets/CB4/5B0/sprockets%2Ff17618b71eca9a4621f68626572a75b2 +103 -0
  10. data/test/dummy/tmp/cache/assets/CC2/240/sprockets%2F9f41da672330830c3366594f7ff5e7f6 +590 -0
  11. data/test/dummy/tmp/cache/assets/CC4/2C0/sprockets%2F715db78c7d974ea64406ed9711793f42 +494 -0
  12. data/test/dummy/tmp/cache/assets/CE1/610/sprockets%2F50c01109ecf86153176ccf577595fab4 +53 -0
  13. data/test/dummy/tmp/cache/assets/CE1/C20/sprockets%2F58a7b0499656c97a2204b5821eadab84 +207 -0
  14. data/test/dummy/tmp/cache/assets/CE4/DE0/sprockets%2Fb3aab0604ee02598f339965ec583a746 +204 -0
  15. data/test/dummy/tmp/cache/assets/CE9/B00/sprockets%2F80b139f66661444d6a781bfe56aee076 +0 -0
  16. data/test/dummy/tmp/cache/assets/CEB/840/sprockets%2F38fe57c2a5963f36a49404f672cc707b +0 -0
  17. data/test/dummy/tmp/cache/assets/CEC/6C0/sprockets%2F01b982295748dbd09683557aebd358bd +0 -0
  18. data/test/dummy/tmp/cache/assets/CF0/140/sprockets%2F3974b046fe949e86ef851a0271eb9d50 +1545 -0
  19. data/test/dummy/tmp/cache/assets/D01/DF0/sprockets%2F2ce268622b41a173bb209465a2ced6b9 +806 -0
  20. data/test/dummy/tmp/cache/assets/D05/920/sprockets%2F909507434dcc270db4853e4c147f0aac +4 -5
  21. data/test/dummy/tmp/cache/assets/D0A/C10/sprockets%2Fd050d5ee6a2073aa708a26c589a4c974 +283 -0
  22. data/test/dummy/tmp/cache/assets/D0F/360/sprockets%2Fa18927874a5e02c58c14c5b5df19ec04 +300 -0
  23. data/test/dummy/tmp/cache/assets/D15/700/sprockets%2F2987192f402d2bdc72792b5ae17f9a2f +142 -0
  24. data/test/dummy/tmp/cache/assets/D15/F60/sprockets%2Fa28394e3f80365b5bc86794dd46daa22 +0 -0
  25. data/test/dummy/tmp/cache/assets/D1F/E60/sprockets%2Fe65796b72231e36f5573ce71e2c8bbf8 +511 -0
  26. data/test/dummy/tmp/cache/assets/D22/200/sprockets%2F874bd1079c304ae88fbec8434d6d7794 +187 -0
  27. data/test/dummy/tmp/cache/assets/D3B/6A0/sprockets%2Ff8a978a3672b4f7ba513303b91ad15fc +127 -0
  28. data/test/dummy/tmp/cache/assets/D3C/530/sprockets%2Fe6730ff143273d9a7471b4afc3e1c19d +0 -0
  29. data/test/dummy/tmp/cache/assets/D41/B30/sprockets%2Fba1b93913dd01d83ac9a96df334456f8 +0 -0
  30. data/test/dummy/tmp/cache/assets/D49/570/sprockets%2Fd76be81d59871518ea06d3668f2c4bbb +239 -0
  31. data/test/dummy/tmp/cache/assets/D49/DA0/sprockets%2Fa84f85a305cde80a4d53785d7be0892f +457 -0
  32. data/test/dummy/tmp/cache/assets/D5C/760/sprockets%2F5cd491e0f9106cfd4ec4938896c97de7 +256 -0
  33. data/test/dummy/tmp/cache/assets/D5C/A00/sprockets%2Fefe291b3012745251e2641defbe4cad0 +1529 -0
  34. data/test/dummy/tmp/cache/assets/D68/2B0/sprockets%2Fe51ab0aca893e08c40f9672edef71106 +0 -0
  35. data/test/dummy/tmp/cache/assets/D6E/EA0/sprockets%2Fb52cbc47414c9e60ad4c46824928fbbe +115 -0
  36. data/test/dummy/tmp/cache/assets/D70/0B0/sprockets%2F1ae574bacfb86b4d51281b5e47fe1892 +505 -0
  37. data/test/dummy/tmp/cache/assets/D75/A60/sprockets%2Fab64285176f11f975fb6bb40af8bce76 +0 -0
  38. data/test/dummy/tmp/cache/assets/D76/0A0/sprockets%2F3ad3bd078c47096b34d5bcce886d7b47 +794 -0
  39. data/test/dummy/tmp/cache/assets/D79/C00/sprockets%2F94449fa386c370a1ebd7628eba9afe72 +72 -0
  40. data/test/dummy/tmp/cache/assets/D7B/310/sprockets%2Ff56e44be18b2d65efda80e588e5229a4 +0 -0
  41. data/test/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +7 -8
  42. data/test/dummy/tmp/cache/assets/D95/D20/sprockets%2F05b19351f203fb1eadf8ef1f0e6f9a60 +173 -0
  43. data/test/dummy/tmp/cache/assets/D9F/250/sprockets%2F40dcbb8f852f0e6360c4afb1f39964eb +0 -0
  44. data/test/dummy/tmp/cache/assets/DA8/0E0/sprockets%2F1351359f5bbdb94ef7d247df9af38bd1 +2556 -0
  45. data/test/dummy/tmp/cache/assets/DB3/070/sprockets%2Fd98f91680433cec456e6eb7485dcfdbc +522 -0
  46. data/test/dummy/tmp/cache/assets/DC4/6E0/sprockets%2F72117f09fccb98e6aac4cd1124edae42 +2539 -0
  47. data/test/dummy/tmp/cache/assets/DCC/D50/sprockets%2F9b2b027991c15af6f8afeacdd183c14e +1260 -0
  48. data/test/dummy/tmp/cache/assets/DD9/FF0/sprockets%2Fdf5dcfe86e199b272742a52a4b7e5fbd +823 -0
  49. data/test/dummy/tmp/cache/assets/DE7/0D0/sprockets%2Fe4d9fe29b6d96cdeb070d9b595af83d7 +1354 -0
  50. data/test/dummy/tmp/cache/assets/E00/3A0/sprockets%2Fc1db8cbfbc94bd2736f9f067a4c06cc7 +811 -0
  51. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  52. data/test/dummy/tmp/cache/assets/E0C/C80/sprockets%2F55805edb5f27aaef88eef6632fd08ade +1277 -0
  53. data/test/dummy/tmp/cache/assets/E1B/CF0/sprockets%2Feb58b29b94f29d7da8d9fbe666e4a8dd +474 -0
  54. data/test/dummy/tmp/cache/assets/E1E/E00/sprockets%2Fb005d4fa3dc6cfc1c5098e0fdb3f6b2b +1371 -0
  55. data/test/dummy/tmp/cache/assets/E30/8E0/sprockets%2Fef4fdb83b3eefb027cbc8e19b274ec80 +607 -0
  56. metadata +96 -8
@@ -0,0 +1,2539 @@
1
+ o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1325729947.698592: @value{ I" length:EFi�CI" digest;
2
+ F"%727ecd3542acdd7f6cf9417a0cd1b810I" source;
3
+ FI"�C// Copyright 2006 The Closure Library Authors. All Rights Reserved.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS-IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+
17
+ /**
18
+ * @fileoverview Utilities for manipulating the browser's Document Object Model
19
+ * Inspiration taken *heavily* from mochikit (http://mochikit.com/).
20
+ *
21
+ * You can use {@link goog.dom.DomHelper} to create new dom helpers that refer
22
+ * to a different document object. This is useful if you are working with
23
+ * frames or multiple windows.
24
+ *
25
+ */
26
+
27
+
28
+ // TODO(arv): Rename/refactor getTextContent and getRawTextContent. The problem
29
+ // is that getTextContent should mimic the DOM3 textContent. We should add a
30
+ // getInnerText (or getText) which tries to return the visible text, innerText.
31
+
32
+
33
+ goog.provide('goog.dom');
34
+ goog.provide('goog.dom.DomHelper');
35
+ goog.provide('goog.dom.NodeType');
36
+
37
+ goog.require('goog.array');
38
+ goog.require('goog.dom.BrowserFeature');
39
+ goog.require('goog.dom.TagName');
40
+ goog.require('goog.dom.classes');
41
+ goog.require('goog.math.Coordinate');
42
+ goog.require('goog.math.Size');
43
+ goog.require('goog.object');
44
+ goog.require('goog.string');
45
+ goog.require('goog.userAgent');
46
+
47
+
48
+ /**
49
+ * @define {boolean} Whether we know at compile time that the browser is in
50
+ * quirks mode.
51
+ */
52
+ goog.dom.ASSUME_QUIRKS_MODE = false;
53
+
54
+
55
+ /**
56
+ * @define {boolean} Whether we know at compile time that the browser is in
57
+ * standards compliance mode.
58
+ */
59
+ goog.dom.ASSUME_STANDARDS_MODE = false;
60
+
61
+
62
+ /**
63
+ * Whether we know the compatibility mode at compile time.
64
+ * @type {boolean}
65
+ * @private
66
+ */
67
+ goog.dom.COMPAT_MODE_KNOWN_ =
68
+ goog.dom.ASSUME_QUIRKS_MODE || goog.dom.ASSUME_STANDARDS_MODE;
69
+
70
+
71
+ /**
72
+ * Enumeration for DOM node types (for reference)
73
+ * @enum {number}
74
+ */
75
+ goog.dom.NodeType = {
76
+ ELEMENT: 1,
77
+ ATTRIBUTE: 2,
78
+ TEXT: 3,
79
+ CDATA_SECTION: 4,
80
+ ENTITY_REFERENCE: 5,
81
+ ENTITY: 6,
82
+ PROCESSING_INSTRUCTION: 7,
83
+ COMMENT: 8,
84
+ DOCUMENT: 9,
85
+ DOCUMENT_TYPE: 10,
86
+ DOCUMENT_FRAGMENT: 11,
87
+ NOTATION: 12
88
+ };
89
+
90
+
91
+ /**
92
+ * Gets the DomHelper object for the document where the element resides.
93
+ * @param {Node|Window=} opt_element If present, gets the DomHelper for this
94
+ * element.
95
+ * @return {!goog.dom.DomHelper} The DomHelper.
96
+ */
97
+ goog.dom.getDomHelper = function(opt_element) {
98
+ return opt_element ?
99
+ new goog.dom.DomHelper(goog.dom.getOwnerDocument(opt_element)) :
100
+ (goog.dom.defaultDomHelper_ ||
101
+ (goog.dom.defaultDomHelper_ = new goog.dom.DomHelper()));
102
+ };
103
+
104
+
105
+ /**
106
+ * Cached default DOM helper.
107
+ * @type {goog.dom.DomHelper}
108
+ * @private
109
+ */
110
+ goog.dom.defaultDomHelper_;
111
+
112
+
113
+ /**
114
+ * Gets the document object being used by the dom library.
115
+ * @return {!Document} Document object.
116
+ */
117
+ goog.dom.getDocument = function() {
118
+ return document;
119
+ };
120
+
121
+
122
+ /**
123
+ * Alias for getElementById. If a DOM node is passed in then we just return
124
+ * that.
125
+ * @param {string|Element} element Element ID or a DOM node.
126
+ * @return {Element} The element with the given ID, or the node passed in.
127
+ */
128
+ goog.dom.getElement = function(element) {
129
+ return goog.isString(element) ?
130
+ document.getElementById(element) : element;
131
+ };
132
+
133
+
134
+ /**
135
+ * Alias for getElement.
136
+ * @param {string|Element} element Element ID or a DOM node.
137
+ * @return {Element} The element with the given ID, or the node passed in.
138
+ * @deprecated Use {@link goog.dom.getElement} instead.
139
+ */
140
+ goog.dom.$ = goog.dom.getElement;
141
+
142
+
143
+ /**
144
+ * Looks up elements by both tag and class name, using browser native functions
145
+ * ({@code querySelectorAll}, {@code getElementsByTagName} or
146
+ * {@code getElementsByClassName}) where possible. This function
147
+ * is a useful, if limited, way of collecting a list of DOM elements
148
+ * with certain characteristics. {@code goog.dom.query} offers a
149
+ * more powerful and general solution which allows matching on CSS3
150
+ * selector expressions, but at increased cost in code size. If all you
151
+ * need is particular tags belonging to a single class, this function
152
+ * is fast and sleek.
153
+ *
154
+ * @see {goog.dom.query}
155
+ *
156
+ * @param {?string=} opt_tag Element tag name.
157
+ * @param {?string=} opt_class Optional class name.
158
+ * @param {Document|Element=} opt_el Optional element to look in.
159
+ * @return { {length: number} } Array-like list of elements (only a length
160
+ * property and numerical indices are guaranteed to exist).
161
+ */
162
+ goog.dom.getElementsByTagNameAndClass = function(opt_tag, opt_class, opt_el) {
163
+ return goog.dom.getElementsByTagNameAndClass_(document, opt_tag, opt_class,
164
+ opt_el);
165
+ };
166
+
167
+
168
+ /**
169
+ * Returns an array of all the elements with the provided className.
170
+ * @see {goog.dom.query}
171
+ * @param {string} className the name of the class to look for.
172
+ * @param {Document|Element=} opt_el Optional element to look in.
173
+ * @return { {length: number} } The items found with the class name provided.
174
+ */
175
+ goog.dom.getElementsByClass = function(className, opt_el) {
176
+ var parent = opt_el || document;
177
+ if (goog.dom.canUseQuerySelector_(parent)) {
178
+ return parent.querySelectorAll('.' + className);
179
+ } else if (parent.getElementsByClassName) {
180
+ return parent.getElementsByClassName(className);
181
+ }
182
+ return goog.dom.getElementsByTagNameAndClass_(
183
+ document, '*', className, opt_el);
184
+ };
185
+
186
+
187
+ /**
188
+ * Returns the first element with the provided className.
189
+ * @see {goog.dom.query}
190
+ * @param {string} className the name of the class to look for.
191
+ * @param {Element|Document=} opt_el Optional element to look in.
192
+ * @return {Element} The first item with the class name provided.
193
+ */
194
+ goog.dom.getElementByClass = function(className, opt_el) {
195
+ var parent = opt_el || document;
196
+ var retVal = null;
197
+ if (goog.dom.canUseQuerySelector_(parent)) {
198
+ retVal = parent.querySelector('.' + className);
199
+ } else {
200
+ retVal = goog.dom.getElementsByClass(className, opt_el)[0];
201
+ }
202
+ return retVal || null;
203
+ };
204
+
205
+
206
+ /**
207
+ * Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and
208
+ * fast W3C Selectors API. However, the version of WebKit that shipped with
209
+ * Safari 3.1 and Chrome has a bug where it will not correctly match mixed-
210
+ * case class name selectors in quirks mode.
211
+ * @param {!Element|Document} parent The parent document object.
212
+ * @return {boolean} whether or not we can use parent.querySelector* APIs.
213
+ * @private
214
+ */
215
+ goog.dom.canUseQuerySelector_ = function(parent) {
216
+ return parent.querySelectorAll &&
217
+ parent.querySelector &&
218
+ (!goog.userAgent.WEBKIT || goog.dom.isCss1CompatMode_(document) ||
219
+ goog.userAgent.isVersion('528'));
220
+ };
221
+
222
+
223
+ /**
224
+ * Helper for {@code getElementsByTagNameAndClass}.
225
+ * @param {!Document} doc The document to get the elements in.
226
+ * @param {?string=} opt_tag Element tag name.
227
+ * @param {?string=} opt_class Optional class name.
228
+ * @param {Document|Element=} opt_el Optional element to look in.
229
+ * @return { {length: number} } Array-like list of elements (only a length
230
+ * property and numerical indices are guaranteed to exist).
231
+ * @private
232
+ */
233
+ goog.dom.getElementsByTagNameAndClass_ = function(doc, opt_tag, opt_class,
234
+ opt_el) {
235
+ var parent = opt_el || doc;
236
+ var tagName = (opt_tag && opt_tag != '*') ? opt_tag.toUpperCase() : '';
237
+
238
+ if (goog.dom.canUseQuerySelector_(parent) &&
239
+ (tagName || opt_class)) {
240
+ var query = tagName + (opt_class ? '.' + opt_class : '');
241
+ return parent.querySelectorAll(query);
242
+ }
243
+
244
+ // Use the native getElementsByClassName if available, under the assumption
245
+ // that even when the tag name is specified, there will be fewer elements to
246
+ // filter through when going by class than by tag name
247
+ if (opt_class && parent.getElementsByClassName) {
248
+ var els = parent.getElementsByClassName(opt_class);
249
+
250
+ if (tagName) {
251
+ var arrayLike = {};
252
+ var len = 0;
253
+
254
+ // Filter for specific tags if requested.
255
+ for (var i = 0, el; el = els[i]; i++) {
256
+ if (tagName == el.nodeName) {
257
+ arrayLike[len++] = el;
258
+ }
259
+ }
260
+ arrayLike.length = len;
261
+
262
+ return arrayLike;
263
+ } else {
264
+ return els;
265
+ }
266
+ }
267
+
268
+ var els = parent.getElementsByTagName(tagName || '*');
269
+
270
+ if (opt_class) {
271
+ var arrayLike = {};
272
+ var len = 0;
273
+ for (var i = 0, el; el = els[i]; i++) {
274
+ var className = el.className;
275
+ // Check if className has a split function since SVG className does not.
276
+ if (typeof className.split == 'function' &&
277
+ goog.array.contains(className.split(/\s+/), opt_class)) {
278
+ arrayLike[len++] = el;
279
+ }
280
+ }
281
+ arrayLike.length = len;
282
+ return arrayLike;
283
+ } else {
284
+ return els;
285
+ }
286
+ };
287
+
288
+
289
+ /**
290
+ * Alias for {@code getElementsByTagNameAndClass}.
291
+ * @param {?string=} opt_tag Element tag name.
292
+ * @param {?string=} opt_class Optional class name.
293
+ * @param {Element=} opt_el Optional element to look in.
294
+ * @return { {length: number} } Array-like list of elements (only a length
295
+ * property and numerical indices are guaranteed to exist).
296
+ * @deprecated Use {@link goog.dom.getElementsByTagNameAndClass} instead.
297
+ */
298
+ goog.dom.$$ = goog.dom.getElementsByTagNameAndClass;
299
+
300
+
301
+ /**
302
+ * Sets multiple properties on a node.
303
+ * @param {Element} element DOM node to set properties on.
304
+ * @param {Object} properties Hash of property:value pairs.
305
+ */
306
+ goog.dom.setProperties = function(element, properties) {
307
+ goog.object.forEach(properties, function(val, key) {
308
+ if (key == 'style') {
309
+ element.style.cssText = val;
310
+ } else if (key == 'class') {
311
+ element.className = val;
312
+ } else if (key == 'for') {
313
+ element.htmlFor = val;
314
+ } else if (key in goog.dom.DIRECT_ATTRIBUTE_MAP_) {
315
+ element.setAttribute(goog.dom.DIRECT_ATTRIBUTE_MAP_[key], val);
316
+ } else if (goog.string.startsWith(key, 'aria-')) {
317
+ element.setAttribute(key, val);
318
+ } else {
319
+ element[key] = val;
320
+ }
321
+ });
322
+ };
323
+
324
+
325
+ /**
326
+ * Map of attributes that should be set using
327
+ * element.setAttribute(key, val) instead of element[key] = val. Used
328
+ * by goog.dom.setProperties.
329
+ *
330
+ * @type {Object}
331
+ * @private
332
+ */
333
+ goog.dom.DIRECT_ATTRIBUTE_MAP_ = {
334
+ 'cellpadding': 'cellPadding',
335
+ 'cellspacing': 'cellSpacing',
336
+ 'colspan': 'colSpan',
337
+ 'rowspan': 'rowSpan',
338
+ 'valign': 'vAlign',
339
+ 'height': 'height',
340
+ 'width': 'width',
341
+ 'usemap': 'useMap',
342
+ 'frameborder': 'frameBorder',
343
+ 'maxlength': 'maxLength',
344
+ 'type': 'type'
345
+ };
346
+
347
+
348
+ /**
349
+ * Gets the dimensions of the viewport.
350
+ *
351
+ * Gecko Standards mode:
352
+ * docEl.clientWidth Width of viewport excluding scrollbar.
353
+ * win.innerWidth Width of viewport including scrollbar.
354
+ * body.clientWidth Width of body element.
355
+ *
356
+ * docEl.clientHeight Height of viewport excluding scrollbar.
357
+ * win.innerHeight Height of viewport including scrollbar.
358
+ * body.clientHeight Height of document.
359
+ *
360
+ * Gecko Backwards compatible mode:
361
+ * docEl.clientWidth Width of viewport excluding scrollbar.
362
+ * win.innerWidth Width of viewport including scrollbar.
363
+ * body.clientWidth Width of viewport excluding scrollbar.
364
+ *
365
+ * docEl.clientHeight Height of document.
366
+ * win.innerHeight Height of viewport including scrollbar.
367
+ * body.clientHeight Height of viewport excluding scrollbar.
368
+ *
369
+ * IE6/7 Standards mode:
370
+ * docEl.clientWidth Width of viewport excluding scrollbar.
371
+ * win.innerWidth Undefined.
372
+ * body.clientWidth Width of body element.
373
+ *
374
+ * docEl.clientHeight Height of viewport excluding scrollbar.
375
+ * win.innerHeight Undefined.
376
+ * body.clientHeight Height of document element.
377
+ *
378
+ * IE5 + IE6/7 Backwards compatible mode:
379
+ * docEl.clientWidth 0.
380
+ * win.innerWidth Undefined.
381
+ * body.clientWidth Width of viewport excluding scrollbar.
382
+ *
383
+ * docEl.clientHeight 0.
384
+ * win.innerHeight Undefined.
385
+ * body.clientHeight Height of viewport excluding scrollbar.
386
+ *
387
+ * Opera 9 Standards and backwards compatible mode:
388
+ * docEl.clientWidth Width of viewport excluding scrollbar.
389
+ * win.innerWidth Width of viewport including scrollbar.
390
+ * body.clientWidth Width of viewport excluding scrollbar.
391
+ *
392
+ * docEl.clientHeight Height of document.
393
+ * win.innerHeight Height of viewport including scrollbar.
394
+ * body.clientHeight Height of viewport excluding scrollbar.
395
+ *
396
+ * WebKit:
397
+ * Safari 2
398
+ * docEl.clientHeight Same as scrollHeight.
399
+ * docEl.clientWidth Same as innerWidth.
400
+ * win.innerWidth Width of viewport excluding scrollbar.
401
+ * win.innerHeight Height of the viewport including scrollbar.
402
+ * frame.innerHeight Height of the viewport exluding scrollbar.
403
+ *
404
+ * Safari 3 (tested in 522)
405
+ *
406
+ * docEl.clientWidth Width of viewport excluding scrollbar.
407
+ * docEl.clientHeight Height of viewport excluding scrollbar in strict mode.
408
+ * body.clientHeight Height of viewport excluding scrollbar in quirks mode.
409
+ *
410
+ * @param {Window=} opt_window Optional window element to test.
411
+ * @return {!goog.math.Size} Object with values 'width' and 'height'.
412
+ */
413
+ goog.dom.getViewportSize = function(opt_window) {
414
+ // TODO(arv): This should not take an argument
415
+ return goog.dom.getViewportSize_(opt_window || window);
416
+ };
417
+
418
+
419
+ /**
420
+ * Helper for {@code getViewportSize}.
421
+ * @param {Window} win The window to get the view port size for.
422
+ * @return {!goog.math.Size} Object with values 'width' and 'height'.
423
+ * @private
424
+ */
425
+ goog.dom.getViewportSize_ = function(win) {
426
+ var doc = win.document;
427
+
428
+ if (goog.userAgent.WEBKIT && !goog.userAgent.isVersion('500') &&
429
+ !goog.userAgent.MOBILE) {
430
+ // TODO(user): Sometimes we get something that isn't a valid window
431
+ // object. In this case we just revert to the current window. We need to
432
+ // figure out when this happens and find a real fix for it.
433
+ // See the comments on goog.dom.getWindow.
434
+ if (typeof win.innerHeight == 'undefined') {
435
+ win = window;
436
+ }
437
+ var innerHeight = win.innerHeight;
438
+ var scrollHeight = win.document.documentElement.scrollHeight;
439
+
440
+ if (win == win.top) {
441
+ if (scrollHeight < innerHeight) {
442
+ innerHeight -= 15; // Scrollbars are 15px wide on Mac
443
+ }
444
+ }
445
+ return new goog.math.Size(win.innerWidth, innerHeight);
446
+ }
447
+
448
+ var el = goog.dom.isCss1CompatMode_(doc) ? doc.documentElement : doc.body;
449
+
450
+ return new goog.math.Size(el.clientWidth, el.clientHeight);
451
+ };
452
+
453
+
454
+ /**
455
+ * Calculates the height of the document.
456
+ *
457
+ * @return {number} The height of the current document.
458
+ */
459
+ goog.dom.getDocumentHeight = function() {
460
+ return goog.dom.getDocumentHeight_(window);
461
+ };
462
+
463
+
464
+ /**
465
+ * Calculates the height of the document of the given window.
466
+ *
467
+ * Function code copied from the opensocial gadget api:
468
+ * gadgets.window.adjustHeight(opt_height)
469
+ *
470
+ * @private
471
+ * @param {Window} win The window whose document height to retrieve.
472
+ * @return {number} The height of the document of the given window.
473
+ */
474
+ goog.dom.getDocumentHeight_ = function(win) {
475
+ // NOTE(eae): This method will return the window size rather than the document
476
+ // size in webkit quirks mode.
477
+ var doc = win.document;
478
+ var height = 0;
479
+
480
+ if (doc) {
481
+ // Calculating inner content height is hard and different between
482
+ // browsers rendering in Strict vs. Quirks mode. We use a combination of
483
+ // three properties within document.body and document.documentElement:
484
+ // - scrollHeight
485
+ // - offsetHeight
486
+ // - clientHeight
487
+ // These values differ significantly between browsers and rendering modes.
488
+ // But there are patterns. It just takes a lot of time and persistence
489
+ // to figure out.
490
+
491
+ // Get the height of the viewport
492
+ var vh = goog.dom.getViewportSize_(win).height;
493
+ var body = doc.body;
494
+ var docEl = doc.documentElement;
495
+ if (goog.dom.isCss1CompatMode_(doc) && docEl.scrollHeight) {
496
+ // In Strict mode:
497
+ // The inner content height is contained in either:
498
+ // document.documentElement.scrollHeight
499
+ // document.documentElement.offsetHeight
500
+ // Based on studying the values output by different browsers,
501
+ // use the value that's NOT equal to the viewport height found above.
502
+ height = docEl.scrollHeight != vh ?
503
+ docEl.scrollHeight : docEl.offsetHeight;
504
+ } else {
505
+ // In Quirks mode:
506
+ // documentElement.clientHeight is equal to documentElement.offsetHeight
507
+ // except in IE. In most browsers, document.documentElement can be used
508
+ // to calculate the inner content height.
509
+ // However, in other browsers (e.g. IE), document.body must be used
510
+ // instead. How do we know which one to use?
511
+ // If document.documentElement.clientHeight does NOT equal
512
+ // document.documentElement.offsetHeight, then use document.body.
513
+ var sh = docEl.scrollHeight;
514
+ var oh = docEl.offsetHeight;
515
+ if (docEl.clientHeight != oh) {
516
+ sh = body.scrollHeight;
517
+ oh = body.offsetHeight;
518
+ }
519
+
520
+ // Detect whether the inner content height is bigger or smaller
521
+ // than the bounding box (viewport). If bigger, take the larger
522
+ // value. If smaller, take the smaller value.
523
+ if (sh > vh) {
524
+ // Content is larger
525
+ height = sh > oh ? sh : oh;
526
+ } else {
527
+ // Content is smaller
528
+ height = sh < oh ? sh : oh;
529
+ }
530
+ }
531
+ }
532
+
533
+ return height;
534
+ };
535
+
536
+
537
+ /**
538
+ * Gets the page scroll distance as a coordinate object.
539
+ *
540
+ * @param {Window=} opt_window Optional window element to test.
541
+ * @return {!goog.math.Coordinate} Object with values 'x' and 'y'.
542
+ * @deprecated Use {@link goog.dom.getDocumentScroll} instead.
543
+ */
544
+ goog.dom.getPageScroll = function(opt_window) {
545
+ var win = opt_window || goog.global || window;
546
+ return goog.dom.getDomHelper(win.document).getDocumentScroll();
547
+ };
548
+
549
+
550
+ /**
551
+ * Gets the document scroll distance as a coordinate object.
552
+ *
553
+ * @return {!goog.math.Coordinate} Object with values 'x' and 'y'.
554
+ */
555
+ goog.dom.getDocumentScroll = function() {
556
+ return goog.dom.getDocumentScroll_(document);
557
+ };
558
+
559
+
560
+ /**
561
+ * Helper for {@code getDocumentScroll}.
562
+ *
563
+ * @param {!Document} doc The document to get the scroll for.
564
+ * @return {!goog.math.Coordinate} Object with values 'x' and 'y'.
565
+ * @private
566
+ */
567
+ goog.dom.getDocumentScroll_ = function(doc) {
568
+ var el = goog.dom.getDocumentScrollElement_(doc);
569
+ var win = goog.dom.getWindow_(doc);
570
+ return new goog.math.Coordinate(win.pageXOffset || el.scrollLeft,
571
+ win.pageYOffset || el.scrollTop);
572
+ };
573
+
574
+
575
+ /**
576
+ * Gets the document scroll element.
577
+ * @return {Element} Scrolling element.
578
+ */
579
+ goog.dom.getDocumentScrollElement = function() {
580
+ return goog.dom.getDocumentScrollElement_(document);
581
+ };
582
+
583
+
584
+ /**
585
+ * Helper for {@code getDocumentScrollElement}.
586
+ * @param {!Document} doc The document to get the scroll element for.
587
+ * @return {Element} Scrolling element.
588
+ * @private
589
+ */
590
+ goog.dom.getDocumentScrollElement_ = function(doc) {
591
+ // Safari (2 and 3) needs body.scrollLeft in both quirks mode and strict mode.
592
+ return !goog.userAgent.WEBKIT && goog.dom.isCss1CompatMode_(doc) ?
593
+ doc.documentElement : doc.body;
594
+ };
595
+
596
+
597
+ /**
598
+ * Gets the window object associated with the given document.
599
+ *
600
+ * @param {Document=} opt_doc Document object to get window for.
601
+ * @return {!Window} The window associated with the given document.
602
+ */
603
+ goog.dom.getWindow = function(opt_doc) {
604
+ // TODO(arv): This should not take an argument.
605
+ return opt_doc ? goog.dom.getWindow_(opt_doc) : window;
606
+ };
607
+
608
+
609
+ /**
610
+ * Helper for {@code getWindow}.
611
+ *
612
+ * @param {!Document} doc Document object to get window for.
613
+ * @return {!Window} The window associated with the given document.
614
+ * @private
615
+ */
616
+ goog.dom.getWindow_ = function(doc) {
617
+ return doc.parentWindow || doc.defaultView;
618
+ };
619
+
620
+
621
+ /**
622
+ * Returns a dom node with a set of attributes. This function accepts varargs
623
+ * for subsequent nodes to be added. Subsequent nodes will be added to the
624
+ * first node as childNodes.
625
+ *
626
+ * So:
627
+ * <code>createDom('div', null, createDom('p'), createDom('p'));</code>
628
+ * would return a div with two child paragraphs
629
+ *
630
+ * @param {string} tagName Tag to create.
631
+ * @param {Object|Array.<string>|string=} opt_attributes If object, then a map
632
+ * of name-value pairs for attributes. If a string, then this is the
633
+ * className of the new element. If an array, the elements will be joined
634
+ * together as the className of the new element.
635
+ * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or
636
+ * strings for text nodes. If one of the var_args is an array or NodeList,i
637
+ * its elements will be added as childNodes instead.
638
+ * @return {!Element} Reference to a DOM node.
639
+ */
640
+ goog.dom.createDom = function(tagName, opt_attributes, var_args) {
641
+ return goog.dom.createDom_(document, arguments);
642
+ };
643
+
644
+
645
+ /**
646
+ * Helper for {@code createDom}.
647
+ * @param {!Document} doc The document to create the DOM in.
648
+ * @param {!Arguments} args Argument object passed from the callers. See
649
+ * {@code goog.dom.createDom} for details.
650
+ * @return {!Element} Reference to a DOM node.
651
+ * @private
652
+ */
653
+ goog.dom.createDom_ = function(doc, args) {
654
+ var tagName = args[0];
655
+ var attributes = args[1];
656
+
657
+ // Internet Explorer is dumb: http://msdn.microsoft.com/workshop/author/
658
+ // dhtml/reference/properties/name_2.asp
659
+ // Also does not allow setting of 'type' attribute on 'input' or 'button'.
660
+ if (!goog.dom.BrowserFeature.CAN_ADD_NAME_OR_TYPE_ATTRIBUTES && attributes &&
661
+ (attributes.name || attributes.type)) {
662
+ var tagNameArr = ['<', tagName];
663
+ if (attributes.name) {
664
+ tagNameArr.push(' name="', goog.string.htmlEscape(attributes.name),
665
+ '"');
666
+ }
667
+ if (attributes.type) {
668
+ tagNameArr.push(' type="', goog.string.htmlEscape(attributes.type),
669
+ '"');
670
+
671
+ // Clone attributes map to remove 'type' without mutating the input.
672
+ var clone = {};
673
+ goog.object.extend(clone, attributes);
674
+ attributes = clone;
675
+ delete attributes.type;
676
+ }
677
+ tagNameArr.push('>');
678
+ tagName = tagNameArr.join('');
679
+ }
680
+
681
+ var element = doc.createElement(tagName);
682
+
683
+ if (attributes) {
684
+ if (goog.isString(attributes)) {
685
+ element.className = attributes;
686
+ } else if (goog.isArray(attributes)) {
687
+ goog.dom.classes.add.apply(null, [element].concat(attributes));
688
+ } else {
689
+ goog.dom.setProperties(element, attributes);
690
+ }
691
+ }
692
+
693
+ if (args.length > 2) {
694
+ goog.dom.append_(doc, element, args, 2);
695
+ }
696
+
697
+ return element;
698
+ };
699
+
700
+
701
+ /**
702
+ * Appends a node with text or other nodes.
703
+ * @param {!Document} doc The document to create new nodes in.
704
+ * @param {!Node} parent The node to append nodes to.
705
+ * @param {!Arguments} args The values to add. See {@code goog.dom.append}.
706
+ * @param {number} startIndex The index of the array to start from.
707
+ * @private
708
+ */
709
+ goog.dom.append_ = function(doc, parent, args, startIndex) {
710
+ function childHandler(child) {
711
+ // TODO(user): More coercion, ala MochiKit?
712
+ if (child) {
713
+ parent.appendChild(goog.isString(child) ?
714
+ doc.createTextNode(child) : child);
715
+ }
716
+ }
717
+
718
+ for (var i = startIndex; i < args.length; i++) {
719
+ var arg = args[i];
720
+ // TODO(attila): Fix isArrayLike to return false for a text node.
721
+ if (goog.isArrayLike(arg) && !goog.dom.isNodeLike(arg)) {
722
+ // If the argument is a node list, not a real array, use a clone,
723
+ // because forEach can't be used to mutate a NodeList.
724
+ goog.array.forEach(goog.dom.isNodeList(arg) ?
725
+ goog.array.clone(arg) : arg,
726
+ childHandler);
727
+ } else {
728
+ childHandler(arg);
729
+ }
730
+ }
731
+ };
732
+
733
+
734
+ /**
735
+ * Alias for {@code createDom}.
736
+ * @param {string} tagName Tag to create.
737
+ * @param {string|Object=} opt_attributes If object, then a map of name-value
738
+ * pairs for attributes. If a string, then this is the className of the new
739
+ * element.
740
+ * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or
741
+ * strings for text nodes. If one of the var_args is an array, its
742
+ * children will be added as childNodes instead.
743
+ * @return {!Element} Reference to a DOM node.
744
+ * @deprecated Use {@link goog.dom.createDom} instead.
745
+ */
746
+ goog.dom.$dom = goog.dom.createDom;
747
+
748
+
749
+ /**
750
+ * Creates a new element.
751
+ * @param {string} name Tag name.
752
+ * @return {!Element} The new element.
753
+ */
754
+ goog.dom.createElement = function(name) {
755
+ return document.createElement(name);
756
+ };
757
+
758
+
759
+ /**
760
+ * Creates a new text node.
761
+ * @param {string} content Content.
762
+ * @return {!Text} The new text node.
763
+ */
764
+ goog.dom.createTextNode = function(content) {
765
+ return document.createTextNode(content);
766
+ };
767
+
768
+
769
+ /**
770
+ * Create a table.
771
+ * @param {number} rows The number of rows in the table. Must be >= 1.
772
+ * @param {number} columns The number of columns in the table. Must be >= 1.
773
+ * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps.
774
+ * @return {!Element} The created table.
775
+ */
776
+ goog.dom.createTable = function(rows, columns, opt_fillWithNbsp) {
777
+ return goog.dom.createTable_(document, rows, columns, !!opt_fillWithNbsp);
778
+ };
779
+
780
+
781
+ /**
782
+ * Create a table.
783
+ * @param {!Document} doc Document object to use to create the table.
784
+ * @param {number} rows The number of rows in the table. Must be >= 1.
785
+ * @param {number} columns The number of columns in the table. Must be >= 1.
786
+ * @param {boolean} fillWithNbsp If true, fills table entries with nsbps.
787
+ * @return {!Element} The created table.
788
+ * @private
789
+ */
790
+ goog.dom.createTable_ = function(doc, rows, columns, fillWithNbsp) {
791
+ var rowHtml = ['<tr>'];
792
+ for (var i = 0; i < columns; i++) {
793
+ rowHtml.push(fillWithNbsp ? '<td>&nbsp;</td>' : '<td></td>');
794
+ }
795
+ rowHtml.push('</tr>');
796
+ rowHtml = rowHtml.join('');
797
+ var totalHtml = ['<table>'];
798
+ for (i = 0; i < rows; i++) {
799
+ totalHtml.push(rowHtml);
800
+ }
801
+ totalHtml.push('</table>');
802
+
803
+ var elem = doc.createElement(goog.dom.TagName.DIV);
804
+ elem.innerHTML = totalHtml.join('');
805
+ return /** @type {!Element} */ (elem.removeChild(elem.firstChild));
806
+ };
807
+
808
+
809
+ /**
810
+ * Converts an HTML string into a document fragment.
811
+ *
812
+ * @param {string} htmlString The HTML string to convert.
813
+ * @return {!Node} The resulting document fragment.
814
+ */
815
+ goog.dom.htmlToDocumentFragment = function(htmlString) {
816
+ return goog.dom.htmlToDocumentFragment_(document, htmlString);
817
+ };
818
+
819
+
820
+ /**
821
+ * Helper for {@code htmlToDocumentFragment}.
822
+ *
823
+ * @param {!Document} doc The document.
824
+ * @param {string} htmlString The HTML string to convert.
825
+ * @return {!Node} The resulting document fragment.
826
+ * @private
827
+ */
828
+ goog.dom.htmlToDocumentFragment_ = function(doc, htmlString) {
829
+ var tempDiv = doc.createElement('div');
830
+ if (goog.dom.BrowserFeature.INNER_HTML_NEEDS_SCOPED_ELEMENT) {
831
+ tempDiv.innerHTML = '<br>' + htmlString;
832
+ tempDiv.removeChild(tempDiv.firstChild);
833
+ } else {
834
+ tempDiv.innerHTML = htmlString;
835
+ }
836
+ if (tempDiv.childNodes.length == 1) {
837
+ return /** @type {!Node} */ (tempDiv.removeChild(tempDiv.firstChild));
838
+ } else {
839
+ var fragment = doc.createDocumentFragment();
840
+ while (tempDiv.firstChild) {
841
+ fragment.appendChild(tempDiv.firstChild);
842
+ }
843
+ return fragment;
844
+ }
845
+ };
846
+
847
+
848
+ /**
849
+ * Returns the compatMode of the document.
850
+ * @return {string} The result is either CSS1Compat or BackCompat.
851
+ * @deprecated use goog.dom.isCss1CompatMode instead.
852
+ */
853
+ goog.dom.getCompatMode = function() {
854
+ return goog.dom.isCss1CompatMode() ? 'CSS1Compat' : 'BackCompat';
855
+ };
856
+
857
+
858
+ /**
859
+ * Returns true if the browser is in "CSS1-compatible" (standards-compliant)
860
+ * mode, false otherwise.
861
+ * @return {boolean} True if in CSS1-compatible mode.
862
+ */
863
+ goog.dom.isCss1CompatMode = function() {
864
+ return goog.dom.isCss1CompatMode_(document);
865
+ };
866
+
867
+
868
+ /**
869
+ * Returns true if the browser is in "CSS1-compatible" (standards-compliant)
870
+ * mode, false otherwise.
871
+ * @param {Document} doc The document to check.
872
+ * @return {boolean} True if in CSS1-compatible mode.
873
+ * @private
874
+ */
875
+ goog.dom.isCss1CompatMode_ = function(doc) {
876
+ if (goog.dom.COMPAT_MODE_KNOWN_) {
877
+ return goog.dom.ASSUME_STANDARDS_MODE;
878
+ }
879
+
880
+ return doc.compatMode == 'CSS1Compat';
881
+ };
882
+
883
+
884
+ /**
885
+ * Determines if the given node can contain children, intended to be used for
886
+ * HTML generation.
887
+ *
888
+ * IE natively supports node.canHaveChildren but has inconsistent behavior.
889
+ * Prior to IE8 the base tag allows children and in IE9 all nodes return true
890
+ * for canHaveChildren.
891
+ *
892
+ * In practice all non-IE browsers allow you to add children to any node, but
893
+ * the behavior is inconsistent:
894
+ *
895
+ * <pre>
896
+ * var a = document.createElement('br');
897
+ * a.appendChild(document.createTextNode('foo'));
898
+ * a.appendChild(document.createTextNode('bar'));
899
+ * console.log(a.childNodes.length); // 2
900
+ * console.log(a.innerHTML); // Chrome: "", IE9: "foobar", FF3.5: "foobar"
901
+ * </pre>
902
+ *
903
+ * TODO(user): Rename shouldAllowChildren() ?
904
+ *
905
+ * @param {Node} node The node to check.
906
+ * @return {boolean} Whether the node can contain children.
907
+ */
908
+ goog.dom.canHaveChildren = function(node) {
909
+ if (node.nodeType != goog.dom.NodeType.ELEMENT) {
910
+ return false;
911
+ }
912
+ switch (node.tagName) {
913
+ case goog.dom.TagName.APPLET:
914
+ case goog.dom.TagName.AREA:
915
+ case goog.dom.TagName.BASE:
916
+ case goog.dom.TagName.BR:
917
+ case goog.dom.TagName.COL:
918
+ case goog.dom.TagName.FRAME:
919
+ case goog.dom.TagName.HR:
920
+ case goog.dom.TagName.IMG:
921
+ case goog.dom.TagName.INPUT:
922
+ case goog.dom.TagName.IFRAME:
923
+ case goog.dom.TagName.ISINDEX:
924
+ case goog.dom.TagName.LINK:
925
+ case goog.dom.TagName.NOFRAMES:
926
+ case goog.dom.TagName.NOSCRIPT:
927
+ case goog.dom.TagName.META:
928
+ case goog.dom.TagName.OBJECT:
929
+ case goog.dom.TagName.PARAM:
930
+ case goog.dom.TagName.SCRIPT:
931
+ case goog.dom.TagName.STYLE:
932
+ return false;
933
+ }
934
+ return true;
935
+ };
936
+
937
+
938
+ /**
939
+ * Appends a child to a node.
940
+ * @param {Node} parent Parent.
941
+ * @param {Node} child Child.
942
+ */
943
+ goog.dom.appendChild = function(parent, child) {
944
+ parent.appendChild(child);
945
+ };
946
+
947
+
948
+ /**
949
+ * Appends a node with text or other nodes.
950
+ * @param {!Node} parent The node to append nodes to.
951
+ * @param {...goog.dom.Appendable} var_args The things to append to the node.
952
+ * If this is a Node it is appended as is.
953
+ * If this is a string then a text node is appended.
954
+ * If this is an array like object then fields 0 to length - 1 are appended.
955
+ */
956
+ goog.dom.append = function(parent, var_args) {
957
+ goog.dom.append_(goog.dom.getOwnerDocument(parent), parent, arguments, 1);
958
+ };
959
+
960
+
961
+ /**
962
+ * Removes all the child nodes on a DOM node.
963
+ * @param {Node} node Node to remove children from.
964
+ */
965
+ goog.dom.removeChildren = function(node) {
966
+ // Note: Iterations over live collections can be slow, this is the fastest
967
+ // we could find. The double parenthesis are used to prevent JsCompiler and
968
+ // strict warnings.
969
+ var child;
970
+ while ((child = node.firstChild)) {
971
+ node.removeChild(child);
972
+ }
973
+ };
974
+
975
+
976
+ /**
977
+ * Inserts a new node before an existing reference node (i.e. as the previous
978
+ * sibling). If the reference node has no parent, then does nothing.
979
+ * @param {Node} newNode Node to insert.
980
+ * @param {Node} refNode Reference node to insert before.
981
+ */
982
+ goog.dom.insertSiblingBefore = function(newNode, refNode) {
983
+ if (refNode.parentNode) {
984
+ refNode.parentNode.insertBefore(newNode, refNode);
985
+ }
986
+ };
987
+
988
+
989
+ /**
990
+ * Inserts a new node after an existing reference node (i.e. as the next
991
+ * sibling). If the reference node has no parent, then does nothing.
992
+ * @param {Node} newNode Node to insert.
993
+ * @param {Node} refNode Reference node to insert after.
994
+ */
995
+ goog.dom.insertSiblingAfter = function(newNode, refNode) {
996
+ if (refNode.parentNode) {
997
+ refNode.parentNode.insertBefore(newNode, refNode.nextSibling);
998
+ }
999
+ };
1000
+
1001
+
1002
+ /**
1003
+ * Insert a child at a given index. If index is larger than the number of child
1004
+ * nodes that the parent currently has, the node is inserted as the last child
1005
+ * node.
1006
+ * @param {Element} parent The element into which to insert the child.
1007
+ * @param {Node} child The element to insert.
1008
+ * @param {number} index The index at which to insert the new child node. Must
1009
+ * not be negative.
1010
+ */
1011
+ goog.dom.insertChildAt = function(parent, child, index) {
1012
+ // Note that if the second argument is null, insertBefore
1013
+ // will append the child at the end of the list of children.
1014
+ parent.insertBefore(child, parent.childNodes[index] || null);
1015
+ };
1016
+
1017
+
1018
+ /**
1019
+ * Removes a node from its parent.
1020
+ * @param {Node} node The node to remove.
1021
+ * @return {Node} The node removed if removed; else, null.
1022
+ */
1023
+ goog.dom.removeNode = function(node) {
1024
+ return node && node.parentNode ? node.parentNode.removeChild(node) : null;
1025
+ };
1026
+
1027
+
1028
+ /**
1029
+ * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no
1030
+ * parent.
1031
+ * @param {Node} newNode Node to insert.
1032
+ * @param {Node} oldNode Node to replace.
1033
+ */
1034
+ goog.dom.replaceNode = function(newNode, oldNode) {
1035
+ var parent = oldNode.parentNode;
1036
+ if (parent) {
1037
+ parent.replaceChild(newNode, oldNode);
1038
+ }
1039
+ };
1040
+
1041
+
1042
+ /**
1043
+ * Flattens an element. That is, removes it and replace it with its children.
1044
+ * Does nothing if the element is not in the document.
1045
+ * @param {Element} element The element to flatten.
1046
+ * @return {Element|undefined} The original element, detached from the document
1047
+ * tree, sans children; or undefined, if the element was not in the
1048
+ * document to begin with.
1049
+ */
1050
+ goog.dom.flattenElement = function(element) {
1051
+ var child, parent = element.parentNode;
1052
+ if (parent && parent.nodeType != goog.dom.NodeType.DOCUMENT_FRAGMENT) {
1053
+ // Use IE DOM method (supported by Opera too) if available
1054
+ if (element.removeNode) {
1055
+ return /** @type {Element} */ (element.removeNode(false));
1056
+ } else {
1057
+ // Move all children of the original node up one level.
1058
+ while ((child = element.firstChild)) {
1059
+ parent.insertBefore(child, element);
1060
+ }
1061
+
1062
+ // Detach the original element.
1063
+ return /** @type {Element} */ (goog.dom.removeNode(element));
1064
+ }
1065
+ }
1066
+ };
1067
+
1068
+
1069
+ /**
1070
+ * Returns an array containing just the element children of the given element.
1071
+ * @param {Element} element The element whose element children we want.
1072
+ * @return {Array|NodeList} An array or array-like list of just the element
1073
+ * children of the given element.
1074
+ */
1075
+ goog.dom.getChildren = function(element) {
1076
+ // We check if the children attribute is supported for child elements
1077
+ // since IE8 misuses the attribute by also including comments.
1078
+ if (goog.dom.BrowserFeature.CAN_USE_CHILDREN_ATTRIBUTE &&
1079
+ element.children != undefined) {
1080
+ return element.children;
1081
+ }
1082
+ // Fall back to manually filtering the element's child nodes.
1083
+ return goog.array.filter(element.childNodes, function(node) {
1084
+ return node.nodeType == goog.dom.NodeType.ELEMENT;
1085
+ });
1086
+ };
1087
+
1088
+
1089
+ /**
1090
+ * Returns the first child node that is an element.
1091
+ * @param {Node} node The node to get the first child element of.
1092
+ * @return {Element} The first child node of {@code node} that is an element.
1093
+ */
1094
+ goog.dom.getFirstElementChild = function(node) {
1095
+ if (node.firstElementChild != undefined) {
1096
+ return /** @type {Element} */(node).firstElementChild;
1097
+ }
1098
+ return goog.dom.getNextElementNode_(node.firstChild, true);
1099
+ };
1100
+
1101
+
1102
+ /**
1103
+ * Returns the last child node that is an element.
1104
+ * @param {Node} node The node to get the last child element of.
1105
+ * @return {Element} The last child node of {@code node} that is an element.
1106
+ */
1107
+ goog.dom.getLastElementChild = function(node) {
1108
+ if (node.lastElementChild != undefined) {
1109
+ return /** @type {Element} */(node).lastElementChild;
1110
+ }
1111
+ return goog.dom.getNextElementNode_(node.lastChild, false);
1112
+ };
1113
+
1114
+
1115
+ /**
1116
+ * Returns the first next sibling that is an element.
1117
+ * @param {Node} node The node to get the next sibling element of.
1118
+ * @return {Element} The next sibling of {@code node} that is an element.
1119
+ */
1120
+ goog.dom.getNextElementSibling = function(node) {
1121
+ if (node.nextElementSibling != undefined) {
1122
+ return /** @type {Element} */(node).nextElementSibling;
1123
+ }
1124
+ return goog.dom.getNextElementNode_(node.nextSibling, true);
1125
+ };
1126
+
1127
+
1128
+ /**
1129
+ * Returns the first previous sibling that is an element.
1130
+ * @param {Node} node The node to get the previous sibling element of.
1131
+ * @return {Element} The first previous sibling of {@code node} that is
1132
+ * an element.
1133
+ */
1134
+ goog.dom.getPreviousElementSibling = function(node) {
1135
+ if (node.previousElementSibling != undefined) {
1136
+ return /** @type {Element} */(node).previousElementSibling;
1137
+ }
1138
+ return goog.dom.getNextElementNode_(node.previousSibling, false);
1139
+ };
1140
+
1141
+
1142
+ /**
1143
+ * Returns the first node that is an element in the specified direction,
1144
+ * starting with {@code node}.
1145
+ * @param {Node} node The node to get the next element from.
1146
+ * @param {boolean} forward Whether to look forwards or backwards.
1147
+ * @return {Element} The first element.
1148
+ * @private
1149
+ */
1150
+ goog.dom.getNextElementNode_ = function(node, forward) {
1151
+ while (node && node.nodeType != goog.dom.NodeType.ELEMENT) {
1152
+ node = forward ? node.nextSibling : node.previousSibling;
1153
+ }
1154
+
1155
+ return /** @type {Element} */ (node);
1156
+ };
1157
+
1158
+
1159
+ /**
1160
+ * Returns the next node in source order from the given node.
1161
+ * @param {Node} node The node.
1162
+ * @return {Node} The next node in the DOM tree, or null if this was the last
1163
+ * node.
1164
+ */
1165
+ goog.dom.getNextNode = function(node) {
1166
+ if (!node) {
1167
+ return null;
1168
+ }
1169
+
1170
+ if (node.firstChild) {
1171
+ return node.firstChild;
1172
+ }
1173
+
1174
+ while (node && !node.nextSibling) {
1175
+ node = node.parentNode;
1176
+ }
1177
+
1178
+ return node ? node.nextSibling : null;
1179
+ };
1180
+
1181
+
1182
+ /**
1183
+ * Returns the previous node in source order from the given node.
1184
+ * @param {Node} node The node.
1185
+ * @return {Node} The previous node in the DOM tree, or null if this was the
1186
+ * first node.
1187
+ */
1188
+ goog.dom.getPreviousNode = function(node) {
1189
+ if (!node) {
1190
+ return null;
1191
+ }
1192
+
1193
+ if (!node.previousSibling) {
1194
+ return node.parentNode;
1195
+ }
1196
+
1197
+ node = node.previousSibling;
1198
+ while (node && node.lastChild) {
1199
+ node = node.lastChild;
1200
+ }
1201
+
1202
+ return node;
1203
+ };
1204
+
1205
+
1206
+ /**
1207
+ * Whether the object looks like a DOM node.
1208
+ * @param {*} obj The object being tested for node likeness.
1209
+ * @return {boolean} Whether the object looks like a DOM node.
1210
+ */
1211
+ goog.dom.isNodeLike = function(obj) {
1212
+ return goog.isObject(obj) && obj.nodeType > 0;
1213
+ };
1214
+
1215
+
1216
+ /**
1217
+ * Whether the object looks like an Element.
1218
+ * @param {*} obj The object being tested for Element likeness.
1219
+ * @return {boolean} Whether the object looks like an Element.
1220
+ */
1221
+ goog.dom.isElement = function(obj) {
1222
+ return goog.isObject(obj) && obj.nodeType == goog.dom.NodeType.ELEMENT;
1223
+ };
1224
+
1225
+
1226
+ /**
1227
+ * Returns true if the specified value is a Window object. This includes the
1228
+ * global window for HTML pages, and iframe windows.
1229
+ * @param {*} obj Variable to test.
1230
+ * @return {boolean} Whether the variable is a window.
1231
+ */
1232
+ goog.dom.isWindow = function(obj) {
1233
+ return goog.isObject(obj) && obj['window'] == obj;
1234
+ };
1235
+
1236
+
1237
+ /**
1238
+ * Returns an element's parent, if it's an Element.
1239
+ * @param {Element} element The DOM element.
1240
+ * @return {Element} The parent, or null if not an Element.
1241
+ */
1242
+ goog.dom.getParentElement = function(element) {
1243
+ if (goog.dom.BrowserFeature.CAN_USE_PARENT_ELEMENT_PROPERTY) {
1244
+ return element.parentElement;
1245
+ }
1246
+ var parent = element.parentNode;
1247
+ return goog.dom.isElement(parent) ? (/** @type {!Element} */ parent) : null;
1248
+ };
1249
+
1250
+
1251
+ /**
1252
+ * Whether a node contains another node.
1253
+ * @param {Node} parent The node that should contain the other node.
1254
+ * @param {Node} descendant The node to test presence of.
1255
+ * @return {boolean} Whether the parent node contains the descendent node.
1256
+ */
1257
+ goog.dom.contains = function(parent, descendant) {
1258
+ // We use browser specific methods for this if available since it is faster
1259
+ // that way.
1260
+
1261
+ // IE DOM
1262
+ if (parent.contains && descendant.nodeType == goog.dom.NodeType.ELEMENT) {
1263
+ return parent == descendant || parent.contains(descendant);
1264
+ }
1265
+
1266
+ // W3C DOM Level 3
1267
+ if (typeof parent.compareDocumentPosition != 'undefined') {
1268
+ return parent == descendant ||
1269
+ Boolean(parent.compareDocumentPosition(descendant) & 16);
1270
+ }
1271
+
1272
+ // W3C DOM Level 1
1273
+ while (descendant && parent != descendant) {
1274
+ descendant = descendant.parentNode;
1275
+ }
1276
+ return descendant == parent;
1277
+ };
1278
+
1279
+
1280
+ /**
1281
+ * Compares the document order of two nodes, returning 0 if they are the same
1282
+ * node, a negative number if node1 is before node2, and a positive number if
1283
+ * node2 is before node1. Note that we compare the order the tags appear in the
1284
+ * document so in the tree <b><i>text</i></b> the B node is considered to be
1285
+ * before the I node.
1286
+ *
1287
+ * @param {Node} node1 The first node to compare.
1288
+ * @param {Node} node2 The second node to compare.
1289
+ * @return {number} 0 if the nodes are the same node, a negative number if node1
1290
+ * is before node2, and a positive number if node2 is before node1.
1291
+ */
1292
+ goog.dom.compareNodeOrder = function(node1, node2) {
1293
+ // Fall out quickly for equality.
1294
+ if (node1 == node2) {
1295
+ return 0;
1296
+ }
1297
+
1298
+ // Use compareDocumentPosition where available
1299
+ if (node1.compareDocumentPosition) {
1300
+ // 4 is the bitmask for FOLLOWS.
1301
+ return node1.compareDocumentPosition(node2) & 2 ? 1 : -1;
1302
+ }
1303
+
1304
+ // Process in IE using sourceIndex - we check to see if the first node has
1305
+ // a source index or if its parent has one.
1306
+ if ('sourceIndex' in node1 ||
1307
+ (node1.parentNode && 'sourceIndex' in node1.parentNode)) {
1308
+ var isElement1 = node1.nodeType == goog.dom.NodeType.ELEMENT;
1309
+ var isElement2 = node2.nodeType == goog.dom.NodeType.ELEMENT;
1310
+
1311
+ if (isElement1 && isElement2) {
1312
+ return node1.sourceIndex - node2.sourceIndex;
1313
+ } else {
1314
+ var parent1 = node1.parentNode;
1315
+ var parent2 = node2.parentNode;
1316
+
1317
+ if (parent1 == parent2) {
1318
+ return goog.dom.compareSiblingOrder_(node1, node2);
1319
+ }
1320
+
1321
+ if (!isElement1 && goog.dom.contains(parent1, node2)) {
1322
+ return -1 * goog.dom.compareParentsDescendantNodeIe_(node1, node2);
1323
+ }
1324
+
1325
+
1326
+ if (!isElement2 && goog.dom.contains(parent2, node1)) {
1327
+ return goog.dom.compareParentsDescendantNodeIe_(node2, node1);
1328
+ }
1329
+
1330
+ return (isElement1 ? node1.sourceIndex : parent1.sourceIndex) -
1331
+ (isElement2 ? node2.sourceIndex : parent2.sourceIndex);
1332
+ }
1333
+ }
1334
+
1335
+ // For Safari, we compare ranges.
1336
+ var doc = goog.dom.getOwnerDocument(node1);
1337
+
1338
+ var range1, range2;
1339
+ range1 = doc.createRange();
1340
+ range1.selectNode(node1);
1341
+ range1.collapse(true);
1342
+
1343
+ range2 = doc.createRange();
1344
+ range2.selectNode(node2);
1345
+ range2.collapse(true);
1346
+
1347
+ return range1.compareBoundaryPoints(goog.global['Range'].START_TO_END,
1348
+ range2);
1349
+ };
1350
+
1351
+
1352
+ /**
1353
+ * Utility function to compare the position of two nodes, when
1354
+ * {@code textNode}'s parent is an ancestor of {@code node}. If this entry
1355
+ * condition is not met, this function will attempt to reference a null object.
1356
+ * @param {Node} textNode The textNode to compare.
1357
+ * @param {Node} node The node to compare.
1358
+ * @return {number} -1 if node is before textNode, +1 otherwise.
1359
+ * @private
1360
+ */
1361
+ goog.dom.compareParentsDescendantNodeIe_ = function(textNode, node) {
1362
+ var parent = textNode.parentNode;
1363
+ if (parent == node) {
1364
+ // If textNode is a child of node, then node comes first.
1365
+ return -1;
1366
+ }
1367
+ var sibling = node;
1368
+ while (sibling.parentNode != parent) {
1369
+ sibling = sibling.parentNode;
1370
+ }
1371
+ return goog.dom.compareSiblingOrder_(sibling, textNode);
1372
+ };
1373
+
1374
+
1375
+ /**
1376
+ * Utility function to compare the position of two nodes known to be non-equal
1377
+ * siblings.
1378
+ * @param {Node} node1 The first node to compare.
1379
+ * @param {Node} node2 The second node to compare.
1380
+ * @return {number} -1 if node1 is before node2, +1 otherwise.
1381
+ * @private
1382
+ */
1383
+ goog.dom.compareSiblingOrder_ = function(node1, node2) {
1384
+ var s = node2;
1385
+ while ((s = s.previousSibling)) {
1386
+ if (s == node1) {
1387
+ // We just found node1 before node2.
1388
+ return -1;
1389
+ }
1390
+ }
1391
+
1392
+ // Since we didn't find it, node1 must be after node2.
1393
+ return 1;
1394
+ };
1395
+
1396
+
1397
+ /**
1398
+ * Find the deepest common ancestor of the given nodes.
1399
+ * @param {...Node} var_args The nodes to find a common ancestor of.
1400
+ * @return {Node} The common ancestor of the nodes, or null if there is none.
1401
+ * null will only be returned if two or more of the nodes are from different
1402
+ * documents.
1403
+ */
1404
+ goog.dom.findCommonAncestor = function(var_args) {
1405
+ var i, count = arguments.length;
1406
+ if (!count) {
1407
+ return null;
1408
+ } else if (count == 1) {
1409
+ return arguments[0];
1410
+ }
1411
+
1412
+ var paths = [];
1413
+ var minLength = Infinity;
1414
+ for (i = 0; i < count; i++) {
1415
+ // Compute the list of ancestors.
1416
+ var ancestors = [];
1417
+ var node = arguments[i];
1418
+ while (node) {
1419
+ ancestors.unshift(node);
1420
+ node = node.parentNode;
1421
+ }
1422
+
1423
+ // Save the list for comparison.
1424
+ paths.push(ancestors);
1425
+ minLength = Math.min(minLength, ancestors.length);
1426
+ }
1427
+ var output = null;
1428
+ for (i = 0; i < minLength; i++) {
1429
+ var first = paths[0][i];
1430
+ for (var j = 1; j < count; j++) {
1431
+ if (first != paths[j][i]) {
1432
+ return output;
1433
+ }
1434
+ }
1435
+ output = first;
1436
+ }
1437
+ return output;
1438
+ };
1439
+
1440
+
1441
+ /**
1442
+ * Returns the owner document for a node.
1443
+ * @param {Node|Window} node The node to get the document for.
1444
+ * @return {!Document} The document owning the node.
1445
+ */
1446
+ goog.dom.getOwnerDocument = function(node) {
1447
+ // TODO(arv): Remove IE5 code.
1448
+ // IE5 uses document instead of ownerDocument
1449
+ return /** @type {!Document} */ (
1450
+ node.nodeType == goog.dom.NodeType.DOCUMENT ? node :
1451
+ node.ownerDocument || node.document);
1452
+ };
1453
+
1454
+
1455
+ /**
1456
+ * Cross-browser function for getting the document element of a frame or iframe.
1457
+ * @param {Element} frame Frame element.
1458
+ * @return {!Document} The frame content document.
1459
+ */
1460
+ goog.dom.getFrameContentDocument = function(frame) {
1461
+ var doc = frame.contentDocument || frame.contentWindow.document;
1462
+ return doc;
1463
+ };
1464
+
1465
+
1466
+ /**
1467
+ * Cross-browser function for getting the window of a frame or iframe.
1468
+ * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element.
1469
+ * @return {Window} The window associated with the given frame.
1470
+ */
1471
+ goog.dom.getFrameContentWindow = function(frame) {
1472
+ return frame.contentWindow ||
1473
+ goog.dom.getWindow_(goog.dom.getFrameContentDocument(frame));
1474
+ };
1475
+
1476
+
1477
+ /**
1478
+ * Cross-browser function for setting the text content of an element.
1479
+ * @param {Element} element The element to change the text content of.
1480
+ * @param {string} text The string that should replace the current element
1481
+ * content.
1482
+ */
1483
+ goog.dom.setTextContent = function(element, text) {
1484
+ if ('textContent' in element) {
1485
+ element.textContent = text;
1486
+ } else if (element.firstChild &&
1487
+ element.firstChild.nodeType == goog.dom.NodeType.TEXT) {
1488
+ // If the first child is a text node we just change its data and remove the
1489
+ // rest of the children.
1490
+ while (element.lastChild != element.firstChild) {
1491
+ element.removeChild(element.lastChild);
1492
+ }
1493
+ element.firstChild.data = text;
1494
+ } else {
1495
+ goog.dom.removeChildren(element);
1496
+ var doc = goog.dom.getOwnerDocument(element);
1497
+ element.appendChild(doc.createTextNode(text));
1498
+ }
1499
+ };
1500
+
1501
+
1502
+ /**
1503
+ * Gets the outerHTML of a node, which islike innerHTML, except that it
1504
+ * actually contains the HTML of the node itself.
1505
+ * @param {Element} element The element to get the HTML of.
1506
+ * @return {string} The outerHTML of the given element.
1507
+ */
1508
+ goog.dom.getOuterHtml = function(element) {
1509
+ // IE, Opera and WebKit all have outerHTML.
1510
+ if ('outerHTML' in element) {
1511
+ return element.outerHTML;
1512
+ } else {
1513
+ var doc = goog.dom.getOwnerDocument(element);
1514
+ var div = doc.createElement('div');
1515
+ div.appendChild(element.cloneNode(true));
1516
+ return div.innerHTML;
1517
+ }
1518
+ };
1519
+
1520
+
1521
+ /**
1522
+ * Finds the first descendant node that matches the filter function, using
1523
+ * a depth first search. This function offers the most general purpose way
1524
+ * of finding a matching element. You may also wish to consider
1525
+ * {@code goog.dom.query} which can express many matching criteria using
1526
+ * CSS selector expressions. These expressions often result in a more
1527
+ * compact representation of the desired result.
1528
+ * @see goog.dom.query
1529
+ *
1530
+ * @param {Node} root The root of the tree to search.
1531
+ * @param {function(Node) : boolean} p The filter function.
1532
+ * @return {Node|undefined} The found node or undefined if none is found.
1533
+ */
1534
+ goog.dom.findNode = function(root, p) {
1535
+ var rv = [];
1536
+ var found = goog.dom.findNodes_(root, p, rv, true);
1537
+ return found ? rv[0] : undefined;
1538
+ };
1539
+
1540
+
1541
+ /**
1542
+ * Finds all the descendant nodes that match the filter function, using a
1543
+ * a depth first search. This function offers the most general-purpose way
1544
+ * of finding a set of matching elements. You may also wish to consider
1545
+ * {@code goog.dom.query} which can express many matching criteria using
1546
+ * CSS selector expressions. These expressions often result in a more
1547
+ * compact representation of the desired result.
1548
+
1549
+ * @param {Node} root The root of the tree to search.
1550
+ * @param {function(Node) : boolean} p The filter function.
1551
+ * @return {Array.<Node>} The found nodes or an empty array if none are found.
1552
+ */
1553
+ goog.dom.findNodes = function(root, p) {
1554
+ var rv = [];
1555
+ goog.dom.findNodes_(root, p, rv, false);
1556
+ return rv;
1557
+ };
1558
+
1559
+
1560
+ /**
1561
+ * Finds the first or all the descendant nodes that match the filter function,
1562
+ * using a depth first search.
1563
+ * @param {Node} root The root of the tree to search.
1564
+ * @param {function(Node) : boolean} p The filter function.
1565
+ * @param {Array.<Node>} rv The found nodes are added to this array.
1566
+ * @param {boolean} findOne If true we exit after the first found node.
1567
+ * @return {boolean} Whether the search is complete or not. True in case findOne
1568
+ * is true and the node is found. False otherwise.
1569
+ * @private
1570
+ */
1571
+ goog.dom.findNodes_ = function(root, p, rv, findOne) {
1572
+ if (root != null) {
1573
+ var child = root.firstChild;
1574
+ while (child) {
1575
+ if (p(child)) {
1576
+ rv.push(child);
1577
+ if (findOne) {
1578
+ return true;
1579
+ }
1580
+ }
1581
+ if (goog.dom.findNodes_(child, p, rv, findOne)) {
1582
+ return true;
1583
+ }
1584
+ child = child.nextSibling;
1585
+ }
1586
+ }
1587
+ return false;
1588
+ };
1589
+
1590
+
1591
+ /**
1592
+ * Map of tags whose content to ignore when calculating text length.
1593
+ * @type {Object}
1594
+ * @private
1595
+ */
1596
+ goog.dom.TAGS_TO_IGNORE_ = {
1597
+ 'SCRIPT': 1,
1598
+ 'STYLE': 1,
1599
+ 'HEAD': 1,
1600
+ 'IFRAME': 1,
1601
+ 'OBJECT': 1
1602
+ };
1603
+
1604
+
1605
+ /**
1606
+ * Map of tags which have predefined values with regard to whitespace.
1607
+ * @type {Object}
1608
+ * @private
1609
+ */
1610
+ goog.dom.PREDEFINED_TAG_VALUES_ = {'IMG': ' ', 'BR': '\n'};
1611
+
1612
+
1613
+ /**
1614
+ * Returns true if the element has a tab index that allows it to receive
1615
+ * keyboard focus (tabIndex >= 0), false otherwise. Note that form elements
1616
+ * natively support keyboard focus, even if they have no tab index.
1617
+ * @param {Element} element Element to check.
1618
+ * @return {boolean} Whether the element has a tab index that allows keyboard
1619
+ * focus.
1620
+ * @see http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
1621
+ */
1622
+ goog.dom.isFocusableTabIndex = function(element) {
1623
+ // IE returns 0 for an unset tabIndex, so we must use getAttributeNode(),
1624
+ // which returns an object with a 'specified' property if tabIndex is
1625
+ // specified. This works on other browsers, too.
1626
+ var attrNode = element.getAttributeNode('tabindex'); // Must be lowercase!
1627
+ if (attrNode && attrNode.specified) {
1628
+ var index = element.tabIndex;
1629
+ // NOTE: IE9 puts tabIndex in 16-bit int, e.g. -2 is 65534.
1630
+ return goog.isNumber(index) && index >= 0 && index < 32768;
1631
+ }
1632
+ return false;
1633
+ };
1634
+
1635
+
1636
+ /**
1637
+ * Enables or disables keyboard focus support on the element via its tab index.
1638
+ * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true
1639
+ * (or elements that natively support keyboard focus, like form elements) can
1640
+ * receive keyboard focus. See http://go/tabindex for more info.
1641
+ * @param {Element} element Element whose tab index is to be changed.
1642
+ * @param {boolean} enable Whether to set or remove a tab index on the element
1643
+ * that supports keyboard focus.
1644
+ */
1645
+ goog.dom.setFocusableTabIndex = function(element, enable) {
1646
+ if (enable) {
1647
+ element.tabIndex = 0;
1648
+ } else {
1649
+ // Set tabIndex to -1 first, then remove it. This is a workaround for
1650
+ // Safari (confirmed in version 4 on Windows). When removing the attribute
1651
+ // without setting it to -1 first, the element remains keyboard focusable
1652
+ // despite not having a tabIndex attribute anymore.
1653
+ element.tabIndex = -1;
1654
+ element.removeAttribute('tabIndex'); // Must be camelCase!
1655
+ }
1656
+ };
1657
+
1658
+
1659
+ /**
1660
+ * Returns the text content of the current node, without markup and invisible
1661
+ * symbols. New lines are stripped and whitespace is collapsed,
1662
+ * such that each character would be visible.
1663
+ *
1664
+ * In browsers that support it, innerText is used. Other browsers attempt to
1665
+ * simulate it via node traversal. Line breaks are canonicalized in IE.
1666
+ *
1667
+ * @param {Node} node The node from which we are getting content.
1668
+ * @return {string} The text content.
1669
+ */
1670
+ goog.dom.getTextContent = function(node) {
1671
+ var textContent;
1672
+ // Note(arv): IE9, Opera, and Safari 3 support innerText but they include
1673
+ // text nodes in script tags. So we revert to use a user agent test here.
1674
+ if (goog.dom.BrowserFeature.CAN_USE_INNER_TEXT && ('innerText' in node)) {
1675
+ textContent = goog.string.canonicalizeNewlines(node.innerText);
1676
+ // Unfortunately .innerText() returns text with &shy; symbols
1677
+ // We need to filter it out and then remove duplicate whitespaces
1678
+ } else {
1679
+ var buf = [];
1680
+ goog.dom.getTextContent_(node, buf, true);
1681
+ textContent = buf.join('');
1682
+ }
1683
+
1684
+ // Strip &shy; entities. goog.format.insertWordBreaks inserts them in Opera.
1685
+ textContent = textContent.replace(/ \xAD /g, ' ').replace(/\xAD/g, '');
1686
+ // Strip &#8203; entities. goog.format.insertWordBreaks inserts them in IE8.
1687
+ textContent = textContent.replace(/\u200B/g, '');
1688
+
1689
+ // Skip this replacement on old browsers with working innerText, which
1690
+ // automatically turns &nbsp; into ' ' and / +/ into ' ' when reading
1691
+ // innerText.
1692
+ if (!goog.dom.BrowserFeature.CAN_USE_INNER_TEXT) {
1693
+ textContent = textContent.replace(/ +/g, ' ');
1694
+ }
1695
+ if (textContent != ' ') {
1696
+ textContent = textContent.replace(/^\s*/, '');
1697
+ }
1698
+
1699
+ return textContent;
1700
+ };
1701
+
1702
+
1703
+ /**
1704
+ * Returns the text content of the current node, without markup.
1705
+ *
1706
+ * Unlike {@code getTextContent} this method does not collapse whitespaces
1707
+ * or normalize lines breaks.
1708
+ *
1709
+ * @param {Node} node The node from which we are getting content.
1710
+ * @return {string} The raw text content.
1711
+ */
1712
+ goog.dom.getRawTextContent = function(node) {
1713
+ var buf = [];
1714
+ goog.dom.getTextContent_(node, buf, false);
1715
+
1716
+ return buf.join('');
1717
+ };
1718
+
1719
+
1720
+ /**
1721
+ * Recursive support function for text content retrieval.
1722
+ *
1723
+ * @param {Node} node The node from which we are getting content.
1724
+ * @param {Array} buf string buffer.
1725
+ * @param {boolean} normalizeWhitespace Whether to normalize whitespace.
1726
+ * @private
1727
+ */
1728
+ goog.dom.getTextContent_ = function(node, buf, normalizeWhitespace) {
1729
+ if (node.nodeName in goog.dom.TAGS_TO_IGNORE_) {
1730
+ // ignore certain tags
1731
+ } else if (node.nodeType == goog.dom.NodeType.TEXT) {
1732
+ if (normalizeWhitespace) {
1733
+ buf.push(String(node.nodeValue).replace(/(\r\n|\r|\n)/g, ''));
1734
+ } else {
1735
+ buf.push(node.nodeValue);
1736
+ }
1737
+ } else if (node.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) {
1738
+ buf.push(goog.dom.PREDEFINED_TAG_VALUES_[node.nodeName]);
1739
+ } else {
1740
+ var child = node.firstChild;
1741
+ while (child) {
1742
+ goog.dom.getTextContent_(child, buf, normalizeWhitespace);
1743
+ child = child.nextSibling;
1744
+ }
1745
+ }
1746
+ };
1747
+
1748
+
1749
+ /**
1750
+ * Returns the text length of the text contained in a node, without markup. This
1751
+ * is equivalent to the selection length if the node was selected, or the number
1752
+ * of cursor movements to traverse the node. Images & BRs take one space. New
1753
+ * lines are ignored.
1754
+ *
1755
+ * @param {Node} node The node whose text content length is being calculated.
1756
+ * @return {number} The length of {@code node}'s text content.
1757
+ */
1758
+ goog.dom.getNodeTextLength = function(node) {
1759
+ return goog.dom.getTextContent(node).length;
1760
+ };
1761
+
1762
+
1763
+ /**
1764
+ * Returns the text offset of a node relative to one of its ancestors. The text
1765
+ * length is the same as the length calculated by goog.dom.getNodeTextLength.
1766
+ *
1767
+ * @param {Node} node The node whose offset is being calculated.
1768
+ * @param {Node=} opt_offsetParent The node relative to which the offset will
1769
+ * be calculated. Defaults to the node's owner document's body.
1770
+ * @return {number} The text offset.
1771
+ */
1772
+ goog.dom.getNodeTextOffset = function(node, opt_offsetParent) {
1773
+ var root = opt_offsetParent || goog.dom.getOwnerDocument(node).body;
1774
+ var buf = [];
1775
+ while (node && node != root) {
1776
+ var cur = node;
1777
+ while ((cur = cur.previousSibling)) {
1778
+ buf.unshift(goog.dom.getTextContent(cur));
1779
+ }
1780
+ node = node.parentNode;
1781
+ }
1782
+ // Trim left to deal with FF cases when there might be line breaks and empty
1783
+ // nodes at the front of the text
1784
+ return goog.string.trimLeft(buf.join('')).replace(/ +/g, ' ').length;
1785
+ };
1786
+
1787
+
1788
+ /**
1789
+ * Returns the node at a given offset in a parent node. If an object is
1790
+ * provided for the optional third parameter, the node and the remainder of the
1791
+ * offset will stored as properties of this object.
1792
+ * @param {Node} parent The parent node.
1793
+ * @param {number} offset The offset into the parent node.
1794
+ * @param {Object=} opt_result Object to be used to store the return value. The
1795
+ * return value will be stored in the form {node: Node, remainder: number}
1796
+ * if this object is provided.
1797
+ * @return {Node} The node at the given offset.
1798
+ */
1799
+ goog.dom.getNodeAtOffset = function(parent, offset, opt_result) {
1800
+ var stack = [parent], pos = 0, cur;
1801
+ while (stack.length > 0 && pos < offset) {
1802
+ cur = stack.pop();
1803
+ if (cur.nodeName in goog.dom.TAGS_TO_IGNORE_) {
1804
+ // ignore certain tags
1805
+ } else if (cur.nodeType == goog.dom.NodeType.TEXT) {
1806
+ var text = cur.nodeValue.replace(/(\r\n|\r|\n)/g, '').replace(/ +/g, ' ');
1807
+ pos += text.length;
1808
+ } else if (cur.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) {
1809
+ pos += goog.dom.PREDEFINED_TAG_VALUES_[cur.nodeName].length;
1810
+ } else {
1811
+ for (var i = cur.childNodes.length - 1; i >= 0; i--) {
1812
+ stack.push(cur.childNodes[i]);
1813
+ }
1814
+ }
1815
+ }
1816
+ if (goog.isObject(opt_result)) {
1817
+ opt_result.remainder = cur ? cur.nodeValue.length + offset - pos - 1 : 0;
1818
+ opt_result.node = cur;
1819
+ }
1820
+
1821
+ return cur;
1822
+ };
1823
+
1824
+
1825
+ /**
1826
+ * Returns true if the object is a {@code NodeList}. To qualify as a NodeList,
1827
+ * the object must have a numeric length property and an item function (which
1828
+ * has type 'string' on IE for some reason).
1829
+ * @param {Object} val Object to test.
1830
+ * @return {boolean} Whether the object is a NodeList.
1831
+ */
1832
+ goog.dom.isNodeList = function(val) {
1833
+ // TODO(attila): Now the isNodeList is part of goog.dom we can use
1834
+ // goog.userAgent to make this simpler.
1835
+ // A NodeList must have a length property of type 'number' on all platforms.
1836
+ if (val && typeof val.length == 'number') {
1837
+ // A NodeList is an object everywhere except Safari, where it's a function.
1838
+ if (goog.isObject(val)) {
1839
+ // A NodeList must have an item function (on non-IE platforms) or an item
1840
+ // property of type 'string' (on IE).
1841
+ return typeof val.item == 'function' || typeof val.item == 'string';
1842
+ } else if (goog.isFunction(val)) {
1843
+ // On Safari, a NodeList is a function with an item property that is also
1844
+ // a function.
1845
+ return typeof val.item == 'function';
1846
+ }
1847
+ }
1848
+
1849
+ // Not a NodeList.
1850
+ return false;
1851
+ };
1852
+
1853
+
1854
+ /**
1855
+ * Walks up the DOM hierarchy returning the first ancestor that has the passed
1856
+ * tag name and/or class name. If the passed element matches the specified
1857
+ * criteria, the element itself is returned.
1858
+ * @param {Node} element The DOM node to start with.
1859
+ * @param {?string=} opt_tag The tag name to match (or null/undefined to match
1860
+ * any node regardless of tag name). Must be uppercase (goog.dom.TagName).
1861
+ * @param {?string=} opt_class The class name to match (or null/undefined to
1862
+ * match any node regardless of class name).
1863
+ * @return {Node} The first ancestor that matches the passed criteria, or
1864
+ * null if none match.
1865
+ */
1866
+ goog.dom.getAncestorByTagNameAndClass = function(element, opt_tag, opt_class) {
1867
+ var tagName = opt_tag ? opt_tag.toUpperCase() : null;
1868
+ return goog.dom.getAncestor(element,
1869
+ function(node) {
1870
+ return (!tagName || node.nodeName == tagName) &&
1871
+ (!opt_class || goog.dom.classes.has(node, opt_class));
1872
+ }, true);
1873
+ };
1874
+
1875
+
1876
+ /**
1877
+ * Walks up the DOM hierarchy returning the first ancestor that has the passed
1878
+ * class name. If the passed element matches the specified criteria, the
1879
+ * element itself is returned.
1880
+ * @param {Node} element The DOM node to start with.
1881
+ * @param {?string=} opt_class The class name to match (or null/undefined to
1882
+ * match any node regardless of class name).
1883
+ * @return {Node} The first ancestor that matches the passed criteria, or
1884
+ * null if none match.
1885
+ */
1886
+ goog.dom.getAncestorByClass = function(element, opt_class) {
1887
+ return goog.dom.getAncestorByTagNameAndClass(element, null, opt_class);
1888
+ };
1889
+
1890
+
1891
+ /**
1892
+ * Walks up the DOM hierarchy returning the first ancestor that passes the
1893
+ * matcher function.
1894
+ * @param {Node} element The DOM node to start with.
1895
+ * @param {function(Node) : boolean} matcher A function that returns true if the
1896
+ * passed node matches the desired criteria.
1897
+ * @param {boolean=} opt_includeNode If true, the node itself is included in
1898
+ * the search (the first call to the matcher will pass startElement as
1899
+ * the node to test).
1900
+ * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the
1901
+ * dom.
1902
+ * @return {Node} DOM node that matched the matcher, or null if there was
1903
+ * no match.
1904
+ */
1905
+ goog.dom.getAncestor = function(
1906
+ element, matcher, opt_includeNode, opt_maxSearchSteps) {
1907
+ if (!opt_includeNode) {
1908
+ element = element.parentNode;
1909
+ }
1910
+ var ignoreSearchSteps = opt_maxSearchSteps == null;
1911
+ var steps = 0;
1912
+ while (element && (ignoreSearchSteps || steps <= opt_maxSearchSteps)) {
1913
+ if (matcher(element)) {
1914
+ return element;
1915
+ }
1916
+ element = element.parentNode;
1917
+ steps++;
1918
+ }
1919
+ // Reached the root of the DOM without a match
1920
+ return null;
1921
+ };
1922
+
1923
+
1924
+ /**
1925
+ * Determines the active element in the given document.
1926
+ * @param {Document} doc The document to look in.
1927
+ * @return {Element} The active element.
1928
+ */
1929
+ goog.dom.getActiveElement = function(doc) {
1930
+ try {
1931
+ return doc && doc.activeElement;
1932
+ } catch (e) {
1933
+ // NOTE(nicksantos): Sometimes, evaluating document.activeElement in IE
1934
+ // throws an exception. I'm not 100% sure why, but I suspect it chokes
1935
+ // on document.activeElement if the activeElement has been recently
1936
+ // removed from the DOM by a JS operation.
1937
+ //
1938
+ // We assume that an exception here simply means
1939
+ // "there is no active element."
1940
+ }
1941
+
1942
+ return null;
1943
+ };
1944
+
1945
+
1946
+
1947
+ /**
1948
+ * Create an instance of a DOM helper with a new document object.
1949
+ * @param {Document=} opt_document Document object to associate with this
1950
+ * DOM helper.
1951
+ * @constructor
1952
+ */
1953
+ goog.dom.DomHelper = function(opt_document) {
1954
+ /**
1955
+ * Reference to the document object to use
1956
+ * @type {!Document}
1957
+ * @private
1958
+ */
1959
+ this.document_ = opt_document || goog.global.document || document;
1960
+ };
1961
+
1962
+
1963
+ /**
1964
+ * Gets the dom helper object for the document where the element resides.
1965
+ * @param {Node=} opt_node If present, gets the DomHelper for this node.
1966
+ * @return {!goog.dom.DomHelper} The DomHelper.
1967
+ */
1968
+ goog.dom.DomHelper.prototype.getDomHelper = goog.dom.getDomHelper;
1969
+
1970
+
1971
+ /**
1972
+ * Sets the document object.
1973
+ * @param {!Document} document Document object.
1974
+ */
1975
+ goog.dom.DomHelper.prototype.setDocument = function(document) {
1976
+ this.document_ = document;
1977
+ };
1978
+
1979
+
1980
+ /**
1981
+ * Gets the document object being used by the dom library.
1982
+ * @return {!Document} Document object.
1983
+ */
1984
+ goog.dom.DomHelper.prototype.getDocument = function() {
1985
+ return this.document_;
1986
+ };
1987
+
1988
+
1989
+ /**
1990
+ * Alias for {@code getElementById}. If a DOM node is passed in then we just
1991
+ * return that.
1992
+ * @param {string|Element} element Element ID or a DOM node.
1993
+ * @return {Element} The element with the given ID, or the node passed in.
1994
+ */
1995
+ goog.dom.DomHelper.prototype.getElement = function(element) {
1996
+ if (goog.isString(element)) {
1997
+ return this.document_.getElementById(element);
1998
+ } else {
1999
+ return element;
2000
+ }
2001
+ };
2002
+
2003
+
2004
+ /**
2005
+ * Alias for {@code getElement}.
2006
+ * @param {string|Element} element Element ID or a DOM node.
2007
+ * @return {Element} The element with the given ID, or the node passed in.
2008
+ * @deprecated Use {@link goog.dom.DomHelper.prototype.getElement} instead.
2009
+ */
2010
+ goog.dom.DomHelper.prototype.$ = goog.dom.DomHelper.prototype.getElement;
2011
+
2012
+
2013
+ /**
2014
+ * Looks up elements by both tag and class name, using browser native functions
2015
+ * ({@code querySelectorAll}, {@code getElementsByTagName} or
2016
+ * {@code getElementsByClassName}) where possible. The returned array is a live
2017
+ * NodeList or a static list depending on the code path taken.
2018
+ *
2019
+ * @see goog.dom.query
2020
+ *
2021
+ * @param {?string=} opt_tag Element tag name or * for all tags.
2022
+ * @param {?string=} opt_class Optional class name.
2023
+ * @param {Document|Element=} opt_el Optional element to look in.
2024
+ * @return { {length: number} } Array-like list of elements (only a length
2025
+ * property and numerical indices are guaranteed to exist).
2026
+ */
2027
+ goog.dom.DomHelper.prototype.getElementsByTagNameAndClass = function(opt_tag,
2028
+ opt_class,
2029
+ opt_el) {
2030
+ return goog.dom.getElementsByTagNameAndClass_(this.document_, opt_tag,
2031
+ opt_class, opt_el);
2032
+ };
2033
+
2034
+
2035
+ /**
2036
+ * Returns an array of all the elements with the provided className.
2037
+ * @see {goog.dom.query}
2038
+ * @param {string} className the name of the class to look for.
2039
+ * @param {Element|Document=} opt_el Optional element to look in.
2040
+ * @return { {length: number} } The items found with the class name provided.
2041
+ */
2042
+ goog.dom.DomHelper.prototype.getElementsByClass = function(className, opt_el) {
2043
+ var doc = opt_el || this.document_;
2044
+ return goog.dom.getElementsByClass(className, doc);
2045
+ };
2046
+
2047
+
2048
+ /**
2049
+ * Returns the first element we find matching the provided class name.
2050
+ * @see {goog.dom.query}
2051
+ * @param {string} className the name of the class to look for.
2052
+ * @param {Element|Document=} opt_el Optional element to look in.
2053
+ * @return {Element} The first item found with the class name provided.
2054
+ */
2055
+ goog.dom.DomHelper.prototype.getElementByClass = function(className, opt_el) {
2056
+ var doc = opt_el || this.document_;
2057
+ return goog.dom.getElementByClass(className, doc);
2058
+ };
2059
+
2060
+
2061
+ /**
2062
+ * Alias for {@code getElementsByTagNameAndClass}.
2063
+ * @deprecated Use DomHelper getElementsByTagNameAndClass.
2064
+ * @see goog.dom.query
2065
+ *
2066
+ * @param {?string=} opt_tag Element tag name.
2067
+ * @param {?string=} opt_class Optional class name.
2068
+ * @param {Element=} opt_el Optional element to look in.
2069
+ * @return { {length: number} } Array-like list of elements (only a length
2070
+ * property and numerical indices are guaranteed to exist).
2071
+ */
2072
+ goog.dom.DomHelper.prototype.$$ =
2073
+ goog.dom.DomHelper.prototype.getElementsByTagNameAndClass;
2074
+
2075
+
2076
+ /**
2077
+ * Sets a number of properties on a node.
2078
+ * @param {Element} element DOM node to set properties on.
2079
+ * @param {Object} properties Hash of property:value pairs.
2080
+ */
2081
+ goog.dom.DomHelper.prototype.setProperties = goog.dom.setProperties;
2082
+
2083
+
2084
+ /**
2085
+ * Gets the dimensions of the viewport.
2086
+ * @param {Window=} opt_window Optional window element to test. Defaults to
2087
+ * the window of the Dom Helper.
2088
+ * @return {!goog.math.Size} Object with values 'width' and 'height'.
2089
+ */
2090
+ goog.dom.DomHelper.prototype.getViewportSize = function(opt_window) {
2091
+ // TODO(arv): This should not take an argument. That breaks the rule of a
2092
+ // a DomHelper representing a single frame/window/document.
2093
+ return goog.dom.getViewportSize(opt_window || this.getWindow());
2094
+ };
2095
+
2096
+
2097
+ /**
2098
+ * Calculates the height of the document.
2099
+ *
2100
+ * @return {number} The height of the document.
2101
+ */
2102
+ goog.dom.DomHelper.prototype.getDocumentHeight = function() {
2103
+ return goog.dom.getDocumentHeight_(this.getWindow());
2104
+ };
2105
+
2106
+
2107
+ /**
2108
+ * Typedef for use with goog.dom.createDom and goog.dom.append.
2109
+ * @typedef {Object|string|Array|NodeList}
2110
+ */
2111
+ goog.dom.Appendable;
2112
+
2113
+
2114
+ /**
2115
+ * Returns a dom node with a set of attributes. This function accepts varargs
2116
+ * for subsequent nodes to be added. Subsequent nodes will be added to the
2117
+ * first node as childNodes.
2118
+ *
2119
+ * So:
2120
+ * <code>createDom('div', null, createDom('p'), createDom('p'));</code>
2121
+ * would return a div with two child paragraphs
2122
+ *
2123
+ * An easy way to move all child nodes of an existing element to a new parent
2124
+ * element is:
2125
+ * <code>createDom('div', null, oldElement.childNodes);</code>
2126
+ * which will remove all child nodes from the old element and add them as
2127
+ * child nodes of the new DIV.
2128
+ *
2129
+ * @param {string} tagName Tag to create.
2130
+ * @param {Object|string=} opt_attributes If object, then a map of name-value
2131
+ * pairs for attributes. If a string, then this is the className of the new
2132
+ * element.
2133
+ * @param {...goog.dom.Appendable} var_args Further DOM nodes or
2134
+ * strings for text nodes. If one of the var_args is an array or
2135
+ * NodeList, its elements will be added as childNodes instead.
2136
+ * @return {!Element} Reference to a DOM node.
2137
+ */
2138
+ goog.dom.DomHelper.prototype.createDom = function(tagName,
2139
+ opt_attributes,
2140
+ var_args) {
2141
+ return goog.dom.createDom_(this.document_, arguments);
2142
+ };
2143
+
2144
+
2145
+ /**
2146
+ * Alias for {@code createDom}.
2147
+ * @param {string} tagName Tag to create.
2148
+ * @param {Object|string=} opt_attributes If object, then a map of name-value
2149
+ * pairs for attributes. If a string, then this is the className of the new
2150
+ * element.
2151
+ * @param {...goog.dom.Appendable} var_args Further DOM nodes or strings for
2152
+ * text nodes. If one of the var_args is an array, its children will be
2153
+ * added as childNodes instead.
2154
+ * @return {!Element} Reference to a DOM node.
2155
+ * @deprecated Use {@link goog.dom.DomHelper.prototype.createDom} instead.
2156
+ */
2157
+ goog.dom.DomHelper.prototype.$dom = goog.dom.DomHelper.prototype.createDom;
2158
+
2159
+
2160
+ /**
2161
+ * Creates a new element.
2162
+ * @param {string} name Tag name.
2163
+ * @return {!Element} The new element.
2164
+ */
2165
+ goog.dom.DomHelper.prototype.createElement = function(name) {
2166
+ return this.document_.createElement(name);
2167
+ };
2168
+
2169
+
2170
+ /**
2171
+ * Creates a new text node.
2172
+ * @param {string} content Content.
2173
+ * @return {!Text} The new text node.
2174
+ */
2175
+ goog.dom.DomHelper.prototype.createTextNode = function(content) {
2176
+ return this.document_.createTextNode(content);
2177
+ };
2178
+
2179
+
2180
+ /**
2181
+ * Create a table.
2182
+ * @param {number} rows The number of rows in the table. Must be >= 1.
2183
+ * @param {number} columns The number of columns in the table. Must be >= 1.
2184
+ * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps.
2185
+ * @return {!Element} The created table.
2186
+ */
2187
+ goog.dom.DomHelper.prototype.createTable = function(rows, columns,
2188
+ opt_fillWithNbsp) {
2189
+ return goog.dom.createTable_(this.document_, rows, columns,
2190
+ !!opt_fillWithNbsp);
2191
+ };
2192
+
2193
+
2194
+ /**
2195
+ * Converts an HTML string into a node or a document fragment. A single Node
2196
+ * is used if the {@code htmlString} only generates a single node. If the
2197
+ * {@code htmlString} generates multiple nodes then these are put inside a
2198
+ * {@code DocumentFragment}.
2199
+ *
2200
+ * @param {string} htmlString The HTML string to convert.
2201
+ * @return {!Node} The resulting node.
2202
+ */
2203
+ goog.dom.DomHelper.prototype.htmlToDocumentFragment = function(htmlString) {
2204
+ return goog.dom.htmlToDocumentFragment_(this.document_, htmlString);
2205
+ };
2206
+
2207
+
2208
+ /**
2209
+ * Returns the compatMode of the document.
2210
+ * @return {string} The result is either CSS1Compat or BackCompat.
2211
+ * @deprecated use goog.dom.DomHelper.prototype.isCss1CompatMode instead.
2212
+ */
2213
+ goog.dom.DomHelper.prototype.getCompatMode = function() {
2214
+ return this.isCss1CompatMode() ? 'CSS1Compat' : 'BackCompat';
2215
+ };
2216
+
2217
+
2218
+ /**
2219
+ * Returns true if the browser is in "CSS1-compatible" (standards-compliant)
2220
+ * mode, false otherwise.
2221
+ * @return {boolean} True if in CSS1-compatible mode.
2222
+ */
2223
+ goog.dom.DomHelper.prototype.isCss1CompatMode = function() {
2224
+ return goog.dom.isCss1CompatMode_(this.document_);
2225
+ };
2226
+
2227
+
2228
+ /**
2229
+ * Gets the window object associated with the document.
2230
+ * @return {!Window} The window associated with the given document.
2231
+ */
2232
+ goog.dom.DomHelper.prototype.getWindow = function() {
2233
+ return goog.dom.getWindow_(this.document_);
2234
+ };
2235
+
2236
+
2237
+ /**
2238
+ * Gets the document scroll element.
2239
+ * @return {Element} Scrolling element.
2240
+ */
2241
+ goog.dom.DomHelper.prototype.getDocumentScrollElement = function() {
2242
+ return goog.dom.getDocumentScrollElement_(this.document_);
2243
+ };
2244
+
2245
+
2246
+ /**
2247
+ * Gets the document scroll distance as a coordinate object.
2248
+ * @return {!goog.math.Coordinate} Object with properties 'x' and 'y'.
2249
+ */
2250
+ goog.dom.DomHelper.prototype.getDocumentScroll = function() {
2251
+ return goog.dom.getDocumentScroll_(this.document_);
2252
+ };
2253
+
2254
+
2255
+ /**
2256
+ * Appends a child to a node.
2257
+ * @param {Node} parent Parent.
2258
+ * @param {Node} child Child.
2259
+ */
2260
+ goog.dom.DomHelper.prototype.appendChild = goog.dom.appendChild;
2261
+
2262
+
2263
+ /**
2264
+ * Appends a node with text or other nodes.
2265
+ * @param {!Node} parent The node to append nodes to.
2266
+ * @param {...goog.dom.Appendable} var_args The things to append to the node.
2267
+ * If this is a Node it is appended as is.
2268
+ * If this is a string then a text node is appended.
2269
+ * If this is an array like object then fields 0 to length - 1 are appended.
2270
+ */
2271
+ goog.dom.DomHelper.prototype.append = goog.dom.append;
2272
+
2273
+
2274
+ /**
2275
+ * Removes all the child nodes on a DOM node.
2276
+ * @param {Node} node Node to remove children from.
2277
+ */
2278
+ goog.dom.DomHelper.prototype.removeChildren = goog.dom.removeChildren;
2279
+
2280
+
2281
+ /**
2282
+ * Inserts a new node before an existing reference node (i.e., as the previous
2283
+ * sibling). If the reference node has no parent, then does nothing.
2284
+ * @param {Node} newNode Node to insert.
2285
+ * @param {Node} refNode Reference node to insert before.
2286
+ */
2287
+ goog.dom.DomHelper.prototype.insertSiblingBefore = goog.dom.insertSiblingBefore;
2288
+
2289
+
2290
+ /**
2291
+ * Inserts a new node after an existing reference node (i.e., as the next
2292
+ * sibling). If the reference node has no parent, then does nothing.
2293
+ * @param {Node} newNode Node to insert.
2294
+ * @param {Node} refNode Reference node to insert after.
2295
+ */
2296
+ goog.dom.DomHelper.prototype.insertSiblingAfter = goog.dom.insertSiblingAfter;
2297
+
2298
+
2299
+ /**
2300
+ * Removes a node from its parent.
2301
+ * @param {Node} node The node to remove.
2302
+ * @return {Node} The node removed if removed; else, null.
2303
+ */
2304
+ goog.dom.DomHelper.prototype.removeNode = goog.dom.removeNode;
2305
+
2306
+
2307
+ /**
2308
+ * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no
2309
+ * parent.
2310
+ * @param {Node} newNode Node to insert.
2311
+ * @param {Node} oldNode Node to replace.
2312
+ */
2313
+ goog.dom.DomHelper.prototype.replaceNode = goog.dom.replaceNode;
2314
+
2315
+
2316
+ /**
2317
+ * Flattens an element. That is, removes it and replace it with its children.
2318
+ * @param {Element} element The element to flatten.
2319
+ * @return {Element|undefined} The original element, detached from the document
2320
+ * tree, sans children, or undefined if the element was already not in the
2321
+ * document.
2322
+ */
2323
+ goog.dom.DomHelper.prototype.flattenElement = goog.dom.flattenElement;
2324
+
2325
+
2326
+ /**
2327
+ * Returns the first child node that is an element.
2328
+ * @param {Node} node The node to get the first child element of.
2329
+ * @return {Element} The first child node of {@code node} that is an element.
2330
+ */
2331
+ goog.dom.DomHelper.prototype.getFirstElementChild =
2332
+ goog.dom.getFirstElementChild;
2333
+
2334
+
2335
+ /**
2336
+ * Returns the last child node that is an element.
2337
+ * @param {Node} node The node to get the last child element of.
2338
+ * @return {Element} The last child node of {@code node} that is an element.
2339
+ */
2340
+ goog.dom.DomHelper.prototype.getLastElementChild = goog.dom.getLastElementChild;
2341
+
2342
+
2343
+ /**
2344
+ * Returns the first next sibling that is an element.
2345
+ * @param {Node} node The node to get the next sibling element of.
2346
+ * @return {Element} The next sibling of {@code node} that is an element.
2347
+ */
2348
+ goog.dom.DomHelper.prototype.getNextElementSibling =
2349
+ goog.dom.getNextElementSibling;
2350
+
2351
+
2352
+ /**
2353
+ * Returns the first previous sibling that is an element.
2354
+ * @param {Node} node The node to get the previous sibling element of.
2355
+ * @return {Element} The first previous sibling of {@code node} that is
2356
+ * an element.
2357
+ */
2358
+ goog.dom.DomHelper.prototype.getPreviousElementSibling =
2359
+ goog.dom.getPreviousElementSibling;
2360
+
2361
+
2362
+ /**
2363
+ * Returns the next node in source order from the given node.
2364
+ * @param {Node} node The node.
2365
+ * @return {Node} The next node in the DOM tree, or null if this was the last
2366
+ * node.
2367
+ */
2368
+ goog.dom.DomHelper.prototype.getNextNode =
2369
+ goog.dom.getNextNode;
2370
+
2371
+
2372
+ /**
2373
+ * Returns the previous node in source order from the given node.
2374
+ * @param {Node} node The node.
2375
+ * @return {Node} The previous node in the DOM tree, or null if this was the
2376
+ * first node.
2377
+ */
2378
+ goog.dom.DomHelper.prototype.getPreviousNode =
2379
+ goog.dom.getPreviousNode;
2380
+
2381
+
2382
+ /**
2383
+ * Whether the object looks like a DOM node.
2384
+ * @param {*} obj The object being tested for node likeness.
2385
+ * @return {boolean} Whether the object looks like a DOM node.
2386
+ */
2387
+ goog.dom.DomHelper.prototype.isNodeLike = goog.dom.isNodeLike;
2388
+
2389
+
2390
+ /**
2391
+ * Whether a node contains another node.
2392
+ * @param {Node} parent The node that should contain the other node.
2393
+ * @param {Node} descendant The node to test presence of.
2394
+ * @return {boolean} Whether the parent node contains the descendent node.
2395
+ */
2396
+ goog.dom.DomHelper.prototype.contains = goog.dom.contains;
2397
+
2398
+
2399
+ /**
2400
+ * Returns the owner document for a node.
2401
+ * @param {Node} node The node to get the document for.
2402
+ * @return {!Document} The document owning the node.
2403
+ */
2404
+ goog.dom.DomHelper.prototype.getOwnerDocument = goog.dom.getOwnerDocument;
2405
+
2406
+
2407
+ /**
2408
+ * Cross browser function for getting the document element of an iframe.
2409
+ * @param {HTMLIFrameElement|HTMLFrameElement} iframe Iframe element.
2410
+ * @return {!HTMLDocument} The frame content document.
2411
+ */
2412
+ goog.dom.DomHelper.prototype.getFrameContentDocument =
2413
+ goog.dom.getFrameContentDocument;
2414
+
2415
+
2416
+ /**
2417
+ * Cross browser function for getting the window of a frame or iframe.
2418
+ * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element.
2419
+ * @return {Window} The window associated with the given frame.
2420
+ */
2421
+ goog.dom.DomHelper.prototype.getFrameContentWindow =
2422
+ goog.dom.getFrameContentWindow;
2423
+
2424
+
2425
+ /**
2426
+ * Cross browser function for setting the text content of an element.
2427
+ * @param {Element} element The element to change the text content of.
2428
+ * @param {string} text The string that should replace the current element
2429
+ * content with.
2430
+ */
2431
+ goog.dom.DomHelper.prototype.setTextContent = goog.dom.setTextContent;
2432
+
2433
+
2434
+ /**
2435
+ * Finds the first descendant node that matches the filter function. This does
2436
+ * a depth first search.
2437
+ * @param {Node} root The root of the tree to search.
2438
+ * @param {function(Node) : boolean} p The filter function.
2439
+ * @return {(Node, undefined)} The found node or undefined if none is found.
2440
+ */
2441
+ goog.dom.DomHelper.prototype.findNode = goog.dom.findNode;
2442
+
2443
+
2444
+ /**
2445
+ * Finds all the descendant nodes that matches the filter function. This does a
2446
+ * depth first search.
2447
+ * @param {Node} root The root of the tree to search.
2448
+ * @param {function(Node) : boolean} p The filter function.
2449
+ * @return {Array.<Node>} The found nodes or an empty array if none are found.
2450
+ */
2451
+ goog.dom.DomHelper.prototype.findNodes = goog.dom.findNodes;
2452
+
2453
+
2454
+ /**
2455
+ * Returns the text contents of the current node, without markup. New lines are
2456
+ * stripped and whitespace is collapsed, such that each character would be
2457
+ * visible.
2458
+ *
2459
+ * In browsers that support it, innerText is used. Other browsers attempt to
2460
+ * simulate it via node traversal. Line breaks are canonicalized in IE.
2461
+ *
2462
+ * @param {Node} node The node from which we are getting content.
2463
+ * @return {string} The text content.
2464
+ */
2465
+ goog.dom.DomHelper.prototype.getTextContent = goog.dom.getTextContent;
2466
+
2467
+
2468
+ /**
2469
+ * Returns the text length of the text contained in a node, without markup. This
2470
+ * is equivalent to the selection length if the node was selected, or the number
2471
+ * of cursor movements to traverse the node. Images & BRs take one space. New
2472
+ * lines are ignored.
2473
+ *
2474
+ * @param {Node} node The node whose text content length is being calculated.
2475
+ * @return {number} The length of {@code node}'s text content.
2476
+ */
2477
+ goog.dom.DomHelper.prototype.getNodeTextLength = goog.dom.getNodeTextLength;
2478
+
2479
+
2480
+ /**
2481
+ * Returns the text offset of a node relative to one of its ancestors. The text
2482
+ * length is the same as the length calculated by
2483
+ * {@code goog.dom.getNodeTextLength}.
2484
+ *
2485
+ * @param {Node} node The node whose offset is being calculated.
2486
+ * @param {Node=} opt_offsetParent Defaults to the node's owner document's body.
2487
+ * @return {number} The text offset.
2488
+ */
2489
+ goog.dom.DomHelper.prototype.getNodeTextOffset = goog.dom.getNodeTextOffset;
2490
+
2491
+
2492
+ /**
2493
+ * Walks up the DOM hierarchy returning the first ancestor that has the passed
2494
+ * tag name and/or class name. If the passed element matches the specified
2495
+ * criteria, the element itself is returned.
2496
+ * @param {Node} element The DOM node to start with.
2497
+ * @param {?string=} opt_tag The tag name to match (or null/undefined to match
2498
+ * any node regardless of tag name). Must be uppercase (goog.dom.TagName).
2499
+ * @param {?string=} opt_class The class name to match (or null/undefined to
2500
+ * match any node regardless of class name).
2501
+ * @return {Node} The first ancestor that matches the passed criteria, or
2502
+ * null if none match.
2503
+ */
2504
+ goog.dom.DomHelper.prototype.getAncestorByTagNameAndClass =
2505
+ goog.dom.getAncestorByTagNameAndClass;
2506
+
2507
+
2508
+ /**
2509
+ * Walks up the DOM hierarchy returning the first ancestor that has the passed
2510
+ * class name. If the passed element matches the specified criteria, the
2511
+ * element itself is returned.
2512
+ * @param {Node} element The DOM node to start with.
2513
+ * @param {?string=} opt_class The class name to match (or null/undefined to
2514
+ * match any node regardless of class name).
2515
+ * @return {Node} The first ancestor that matches the passed criteria, or
2516
+ * null if none match.
2517
+ */
2518
+ goog.dom.DomHelper.prototype.getAncestorByClass =
2519
+ goog.dom.getAncestorByClass;
2520
+
2521
+
2522
+ /**
2523
+ * Walks up the DOM hierarchy returning the first ancestor that passes the
2524
+ * matcher function.
2525
+ * @param {Node} element The DOM node to start with.
2526
+ * @param {function(Node) : boolean} matcher A function that returns true if the
2527
+ * passed node matches the desired criteria.
2528
+ * @param {boolean=} opt_includeNode If true, the node itself is included in
2529
+ * the search (the first call to the matcher will pass startElement as
2530
+ * the node to test).
2531
+ * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the
2532
+ * dom.
2533
+ * @return {Node} DOM node that matched the matcher, or null if there was
2534
+ * no match.
2535
+ */
2536
+ goog.dom.DomHelper.prototype.getAncestor = goog.dom.getAncestor;
2537
+ ;
2538
+ FI"
2539
+ F"%f84ee569bf8302371052cb63b4258c11