webfontloader 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/CHANGELOG +5 -0
  2. data/Rakefile +2 -1
  3. data/lib/webfontloader.rb +1 -1
  4. data/spec/core/font_spec.js +9 -4
  5. data/spec/core/fontruler_spec.js +3 -10
  6. data/spec/core/fontwatcher_spec.js +22 -23
  7. data/spec/core/fontwatchrunner_spec.js +206 -231
  8. data/spec/deps.js +27 -0
  9. data/spec/google/lastresortwebkitfontwatchrunner_spec.js +47 -58
  10. data/spec/index.html +14 -25
  11. data/src/ascender/ascender_script.js +52 -45
  12. data/src/core/browserinfo.js +54 -47
  13. data/src/core/cssclassname.js +27 -22
  14. data/src/core/cssfontfamilyname.js +23 -17
  15. data/src/core/domhelper.js +209 -203
  16. data/src/core/eventdispatcher.js +111 -103
  17. data/src/core/font.js +110 -68
  18. data/src/core/fontmoduleloader.js +56 -13
  19. data/src/core/fontruler.js +52 -43
  20. data/src/core/fontvariationdescription.js +82 -76
  21. data/src/core/fontwatcher.js +93 -88
  22. data/src/core/fontwatchrunner.js +161 -161
  23. data/src/core/initialize.js +22 -15
  24. data/src/core/namespace.js +0 -29
  25. data/src/core/size.js +31 -25
  26. data/src/core/useragent.js +63 -48
  27. data/src/core/useragentparser.js +317 -306
  28. data/src/custom/customcss.js +31 -24
  29. data/src/fontdeck/fontdeck_script.js +46 -37
  30. data/src/google/fontapiparser.js +105 -97
  31. data/src/google/fontapiurlbuilder.js +46 -41
  32. data/src/google/googlefontapi.js +48 -32
  33. data/src/google/lastresortwebkitfontwatchrunner.js +80 -67
  34. data/src/modules.yml +6 -6
  35. data/src/monotype/monotype_script.js +47 -40
  36. data/src/typekit/typekit_script.js +41 -35
  37. data/tools/compiler/base.js +1548 -0
  38. data/tools/compiler/compiler.jar +0 -0
  39. data/webfontloader.gemspec +4 -2
  40. metadata +18 -16
@@ -0,0 +1,1548 @@
1
+ // Copyright 2006 The Closure Library Authors. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS-IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ /**
16
+ * @fileoverview Bootstrap for the Google JS Library (Closure).
17
+ *
18
+ * In uncompiled mode base.js will write out Closure's deps file, unless the
19
+ * global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects to
20
+ * include their own deps file(s) from different locations.
21
+ *
22
+ *
23
+ * @provideGoog
24
+ */
25
+
26
+
27
+ /**
28
+ * @define {boolean} Overridden to true by the compiler when --closure_pass
29
+ * or --mark_as_compiled is specified.
30
+ */
31
+ var COMPILED = false;
32
+
33
+
34
+ /**
35
+ * Base namespace for the Closure library. Checks to see goog is
36
+ * already defined in the current scope before assigning to prevent
37
+ * clobbering if base.js is loaded more than once.
38
+ *
39
+ * @const
40
+ */
41
+ var goog = goog || {}; // Identifies this file as the Closure base.
42
+
43
+
44
+ /**
45
+ * Reference to the global context. In most cases this will be 'window'.
46
+ */
47
+ goog.global = this;
48
+
49
+
50
+ /**
51
+ * @define {boolean} DEBUG is provided as a convenience so that debugging code
52
+ * that should not be included in a production js_binary can be easily stripped
53
+ * by specifying --define goog.DEBUG=false to the JSCompiler. For example, most
54
+ * toString() methods should be declared inside an "if (goog.DEBUG)" conditional
55
+ * because they are generally used for debugging purposes and it is difficult
56
+ * for the JSCompiler to statically determine whether they are used.
57
+ */
58
+ goog.DEBUG = true;
59
+
60
+
61
+ /**
62
+ * @define {string} LOCALE defines the locale being used for compilation. It is
63
+ * used to select locale specific data to be compiled in js binary. BUILD rule
64
+ * can specify this value by "--define goog.LOCALE=<locale_name>" as JSCompiler
65
+ * option.
66
+ *
67
+ * Take into account that the locale code format is important. You should use
68
+ * the canonical Unicode format with hyphen as a delimiter. Language must be
69
+ * lowercase, Language Script - Capitalized, Region - UPPERCASE.
70
+ * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN.
71
+ *
72
+ * See more info about locale codes here:
73
+ * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers
74
+ *
75
+ * For language codes you should use values defined by ISO 693-1. See it here
76
+ * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from
77
+ * this rule: the Hebrew language. For legacy reasons the old code (iw) should
78
+ * be used instead of the new code (he), see http://wiki/Main/IIISynonyms.
79
+ */
80
+ goog.LOCALE = 'en'; // default to en
81
+
82
+
83
+ /**
84
+ * @define {boolean} Whether this code is running on trusted sites.
85
+ *
86
+ * On untrusted sites, several native functions can be defined or overridden by
87
+ * external libraries like Prototype, Datejs, and JQuery and setting this flag
88
+ * to false forces closure to use its own implementations when possible.
89
+ *
90
+ * If your javascript can be loaded by a third party site and you are wary about
91
+ * relying on non-standard implementations, specify
92
+ * "--define goog.TRUSTED_SITE=false" to the JSCompiler.
93
+ */
94
+ goog.TRUSTED_SITE = true;
95
+
96
+
97
+ /**
98
+ * Creates object stubs for a namespace. The presence of one or more
99
+ * goog.provide() calls indicate that the file defines the given
100
+ * objects/namespaces. Build tools also scan for provide/require statements
101
+ * to discern dependencies, build dependency files (see deps.js), etc.
102
+ * @see goog.require
103
+ * @param {string} name Namespace provided by this file in the form
104
+ * "goog.package.part".
105
+ */
106
+ goog.provide = function(name) {
107
+ if (!COMPILED) {
108
+ // Ensure that the same namespace isn't provided twice. This is intended
109
+ // to teach new developers that 'goog.provide' is effectively a variable
110
+ // declaration. And when JSCompiler transforms goog.provide into a real
111
+ // variable declaration, the compiled JS should work the same as the raw
112
+ // JS--even when the raw JS uses goog.provide incorrectly.
113
+ if (goog.isProvided_(name)) {
114
+ throw Error('Namespace "' + name + '" already declared.');
115
+ }
116
+ delete goog.implicitNamespaces_[name];
117
+
118
+ var namespace = name;
119
+ while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {
120
+ if (goog.getObjectByName(namespace)) {
121
+ break;
122
+ }
123
+ goog.implicitNamespaces_[namespace] = true;
124
+ }
125
+ }
126
+
127
+ goog.exportPath_(name);
128
+ };
129
+
130
+
131
+ /**
132
+ * Marks that the current file should only be used for testing, and never for
133
+ * live code in production.
134
+ * @param {string=} opt_message Optional message to add to the error that's
135
+ * raised when used in production code.
136
+ */
137
+ goog.setTestOnly = function(opt_message) {
138
+ if (COMPILED && !goog.DEBUG) {
139
+ opt_message = opt_message || '';
140
+ throw Error('Importing test-only code into non-debug environment' +
141
+ opt_message ? ': ' + opt_message : '.');
142
+ }
143
+ };
144
+
145
+
146
+ if (!COMPILED) {
147
+
148
+ /**
149
+ * Check if the given name has been goog.provided. This will return false for
150
+ * names that are available only as implicit namespaces.
151
+ * @param {string} name name of the object to look for.
152
+ * @return {boolean} Whether the name has been provided.
153
+ * @private
154
+ */
155
+ goog.isProvided_ = function(name) {
156
+ return !goog.implicitNamespaces_[name] && !!goog.getObjectByName(name);
157
+ };
158
+
159
+ /**
160
+ * Namespaces implicitly defined by goog.provide. For example,
161
+ * goog.provide('goog.events.Event') implicitly declares
162
+ * that 'goog' and 'goog.events' must be namespaces.
163
+ *
164
+ * @type {Object}
165
+ * @private
166
+ */
167
+ goog.implicitNamespaces_ = {};
168
+ }
169
+
170
+
171
+ /**
172
+ * Builds an object structure for the provided namespace path,
173
+ * ensuring that names that already exist are not overwritten. For
174
+ * example:
175
+ * "a.b.c" -> a = {};a.b={};a.b.c={};
176
+ * Used by goog.provide and goog.exportSymbol.
177
+ * @param {string} name name of the object that this file defines.
178
+ * @param {*=} opt_object the object to expose at the end of the path.
179
+ * @param {Object=} opt_objectToExportTo The object to add the path to; default
180
+ * is |goog.global|.
181
+ * @private
182
+ */
183
+ goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) {
184
+ var parts = name.split('.');
185
+ var cur = opt_objectToExportTo || goog.global;
186
+
187
+ // Internet Explorer exhibits strange behavior when throwing errors from
188
+ // methods externed in this manner. See the testExportSymbolExceptions in
189
+ // base_test.html for an example.
190
+ if (!(parts[0] in cur) && cur.execScript) {
191
+ cur.execScript('var ' + parts[0]);
192
+ }
193
+
194
+ // Certain browsers cannot parse code in the form for((a in b); c;);
195
+ // This pattern is produced by the JSCompiler when it collapses the
196
+ // statement above into the conditional loop below. To prevent this from
197
+ // happening, use a for-loop and reserve the init logic as below.
198
+
199
+ // Parentheses added to eliminate strict JS warning in Firefox.
200
+ for (var part; parts.length && (part = parts.shift());) {
201
+ if (!parts.length && goog.isDef(opt_object)) {
202
+ // last part and we have an object; use it
203
+ cur[part] = opt_object;
204
+ } else if (cur[part]) {
205
+ cur = cur[part];
206
+ } else {
207
+ cur = cur[part] = {};
208
+ }
209
+ }
210
+ };
211
+
212
+
213
+ /**
214
+ * Returns an object based on its fully qualified external name. If you are
215
+ * using a compilation pass that renames property names beware that using this
216
+ * function will not find renamed properties.
217
+ *
218
+ * @param {string} name The fully qualified name.
219
+ * @param {Object=} opt_obj The object within which to look; default is
220
+ * |goog.global|.
221
+ * @return {?} The value (object or primitive) or, if not found, null.
222
+ */
223
+ goog.getObjectByName = function(name, opt_obj) {
224
+ var parts = name.split('.');
225
+ var cur = opt_obj || goog.global;
226
+ for (var part; part = parts.shift(); ) {
227
+ if (goog.isDefAndNotNull(cur[part])) {
228
+ cur = cur[part];
229
+ } else {
230
+ return null;
231
+ }
232
+ }
233
+ return cur;
234
+ };
235
+
236
+
237
+ /**
238
+ * Globalizes a whole namespace, such as goog or goog.lang.
239
+ *
240
+ * @param {Object} obj The namespace to globalize.
241
+ * @param {Object=} opt_global The object to add the properties to.
242
+ * @deprecated Properties may be explicitly exported to the global scope, but
243
+ * this should no longer be done in bulk.
244
+ */
245
+ goog.globalize = function(obj, opt_global) {
246
+ var global = opt_global || goog.global;
247
+ for (var x in obj) {
248
+ global[x] = obj[x];
249
+ }
250
+ };
251
+
252
+
253
+ /**
254
+ * Adds a dependency from a file to the files it requires.
255
+ * @param {string} relPath The path to the js file.
256
+ * @param {Array} provides An array of strings with the names of the objects
257
+ * this file provides.
258
+ * @param {Array} requires An array of strings with the names of the objects
259
+ * this file requires.
260
+ */
261
+ goog.addDependency = function(relPath, provides, requires) {
262
+ if (!COMPILED) {
263
+ var provide, require;
264
+ var path = relPath.replace(/\\/g, '/');
265
+ var deps = goog.dependencies_;
266
+ for (var i = 0; provide = provides[i]; i++) {
267
+ deps.nameToPath[provide] = path;
268
+ if (!(path in deps.pathToNames)) {
269
+ deps.pathToNames[path] = {};
270
+ }
271
+ deps.pathToNames[path][provide] = true;
272
+ }
273
+ for (var j = 0; require = requires[j]; j++) {
274
+ if (!(path in deps.requires)) {
275
+ deps.requires[path] = {};
276
+ }
277
+ deps.requires[path][require] = true;
278
+ }
279
+ }
280
+ };
281
+
282
+
283
+
284
+
285
+ // NOTE(nnaze): The debug DOM loader was included in base.js as an orignal
286
+ // way to do "debug-mode" development. The dependency system can sometimes
287
+ // be confusing, as can the debug DOM loader's asyncronous nature.
288
+ //
289
+ // With the DOM loader, a call to goog.require() is not blocking -- the
290
+ // script will not load until some point after the current script. If a
291
+ // namespace is needed at runtime, it needs to be defined in a previous
292
+ // script, or loaded via require() with its registered dependencies.
293
+ // User-defined namespaces may need their own deps file. See http://go/js_deps,
294
+ // http://go/genjsdeps, or, externally, DepsWriter.
295
+ // http://code.google.com/closure/library/docs/depswriter.html
296
+ //
297
+ // Because of legacy clients, the DOM loader can't be easily removed from
298
+ // base.js. Work is being done to make it disableable or replaceable for
299
+ // different environments (DOM-less JavaScript interpreters like Rhino or V8,
300
+ // for example). See bootstrap/ for more information.
301
+
302
+
303
+ /**
304
+ * @define {boolean} Whether to enable the debug loader.
305
+ *
306
+ * If enabled, a call to goog.require() will attempt to load the namespace by
307
+ * appending a script tag to the DOM (if the namespace has been registered).
308
+ *
309
+ * If disabled, goog.require() will simply assert that the namespace has been
310
+ * provided (and depend on the fact that some outside tool correctly ordered
311
+ * the script).
312
+ */
313
+ goog.ENABLE_DEBUG_LOADER = true;
314
+
315
+
316
+ /**
317
+ * Implements a system for the dynamic resolution of dependencies
318
+ * that works in parallel with the BUILD system. Note that all calls
319
+ * to goog.require will be stripped by the JSCompiler when the
320
+ * --closure_pass option is used.
321
+ * @see goog.provide
322
+ * @param {string} name Namespace to include (as was given in goog.provide())
323
+ * in the form "goog.package.part".
324
+ */
325
+ goog.require = function(name) {
326
+
327
+ // if the object already exists we do not need do do anything
328
+ // TODO(arv): If we start to support require based on file name this has
329
+ // to change
330
+ // TODO(arv): If we allow goog.foo.* this has to change
331
+ // TODO(arv): If we implement dynamic load after page load we should probably
332
+ // not remove this code for the compiled output
333
+ if (!COMPILED) {
334
+ if (goog.isProvided_(name)) {
335
+ return;
336
+ }
337
+
338
+ if (goog.ENABLE_DEBUG_LOADER) {
339
+ var path = goog.getPathFromDeps_(name);
340
+ if (path) {
341
+ goog.included_[path] = true;
342
+ goog.writeScripts_();
343
+ return;
344
+ }
345
+ }
346
+
347
+ var errorMessage = 'goog.require could not find: ' + name;
348
+ if (goog.global.console) {
349
+ goog.global.console['error'](errorMessage);
350
+ }
351
+
352
+
353
+ throw Error(errorMessage);
354
+
355
+ }
356
+ };
357
+
358
+
359
+ /**
360
+ * Path for included scripts
361
+ * @type {string}
362
+ */
363
+ goog.basePath = '';
364
+
365
+
366
+ /**
367
+ * A hook for overriding the base path.
368
+ * @type {string|undefined}
369
+ */
370
+ goog.global.CLOSURE_BASE_PATH;
371
+
372
+
373
+ /**
374
+ * Whether to write out Closure's deps file. By default,
375
+ * the deps are written.
376
+ * @type {boolean|undefined}
377
+ */
378
+ goog.global.CLOSURE_NO_DEPS = true;
379
+
380
+
381
+ /**
382
+ * A function to import a single script. This is meant to be overridden when
383
+ * Closure is being run in non-HTML contexts, such as web workers. It's defined
384
+ * in the global scope so that it can be set before base.js is loaded, which
385
+ * allows deps.js to be imported properly.
386
+ *
387
+ * The function is passed the script source, which is a relative URI. It should
388
+ * return true if the script was imported, false otherwise.
389
+ */
390
+ goog.global.CLOSURE_IMPORT_SCRIPT;
391
+
392
+
393
+ /**
394
+ * Null function used for default values of callbacks, etc.
395
+ * @return {void} Nothing.
396
+ */
397
+ goog.nullFunction = function() {};
398
+
399
+
400
+ /**
401
+ * The identity function. Returns its first argument.
402
+ *
403
+ * @param {*=} opt_returnValue The single value that will be returned.
404
+ * @param {...*} var_args Optional trailing arguments. These are ignored.
405
+ * @return {?} The first argument. We can't know the type -- just pass it along
406
+ * without type.
407
+ * @deprecated Use goog.functions.identity instead.
408
+ */
409
+ goog.identityFunction = function(opt_returnValue, var_args) {
410
+ return opt_returnValue;
411
+ };
412
+
413
+
414
+ /**
415
+ * When defining a class Foo with an abstract method bar(), you can do:
416
+ *
417
+ * Foo.prototype.bar = goog.abstractMethod
418
+ *
419
+ * Now if a subclass of Foo fails to override bar(), an error
420
+ * will be thrown when bar() is invoked.
421
+ *
422
+ * Note: This does not take the name of the function to override as
423
+ * an argument because that would make it more difficult to obfuscate
424
+ * our JavaScript code.
425
+ *
426
+ * @type {!Function}
427
+ * @throws {Error} when invoked to indicate the method should be
428
+ * overridden.
429
+ */
430
+ goog.abstractMethod = function() {
431
+ throw Error('unimplemented abstract method');
432
+ };
433
+
434
+
435
+ /**
436
+ * Adds a {@code getInstance} static method that always return the same instance
437
+ * object.
438
+ * @param {!Function} ctor The constructor for the class to add the static
439
+ * method to.
440
+ */
441
+ goog.addSingletonGetter = function(ctor) {
442
+ ctor.getInstance = function() {
443
+ if (ctor.instance_) {
444
+ return ctor.instance_;
445
+ }
446
+ if (goog.DEBUG) {
447
+ // NOTE: JSCompiler can't optimize away Array#push.
448
+ goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor;
449
+ }
450
+ return ctor.instance_ = new ctor;
451
+ };
452
+ };
453
+
454
+
455
+ /**
456
+ * All singleton classes that have been instantiated, for testing. Don't read
457
+ * it directly, use the {@code goog.testing.singleton} module. The compiler
458
+ * removes this variable if unused.
459
+ * @type {!Array.<!Function>}
460
+ * @private
461
+ */
462
+ goog.instantiatedSingletons_ = [];
463
+
464
+
465
+ if (!COMPILED && goog.ENABLE_DEBUG_LOADER) {
466
+ /**
467
+ * Object used to keep track of urls that have already been added. This
468
+ * record allows the prevention of circular dependencies.
469
+ * @type {Object}
470
+ * @private
471
+ */
472
+ goog.included_ = {};
473
+
474
+
475
+ /**
476
+ * This object is used to keep track of dependencies and other data that is
477
+ * used for loading scripts
478
+ * @private
479
+ * @type {Object}
480
+ */
481
+ goog.dependencies_ = {
482
+ pathToNames: {}, // 1 to many
483
+ nameToPath: {}, // 1 to 1
484
+ requires: {}, // 1 to many
485
+ // used when resolving dependencies to prevent us from
486
+ // visiting the file twice
487
+ visited: {},
488
+ written: {} // used to keep track of script files we have written
489
+ };
490
+
491
+
492
+ /**
493
+ * Tries to detect whether is in the context of an HTML document.
494
+ * @return {boolean} True if it looks like HTML document.
495
+ * @private
496
+ */
497
+ goog.inHtmlDocument_ = function() {
498
+ var doc = goog.global.document;
499
+ return typeof doc != 'undefined' &&
500
+ 'write' in doc; // XULDocument misses write.
501
+ };
502
+
503
+
504
+ /**
505
+ * Tries to detect the base path of the base.js script that bootstraps Closure
506
+ * @private
507
+ */
508
+ goog.findBasePath_ = function() {
509
+ if (goog.global.CLOSURE_BASE_PATH) {
510
+ goog.basePath = goog.global.CLOSURE_BASE_PATH;
511
+ return;
512
+ } else if (!goog.inHtmlDocument_()) {
513
+ return;
514
+ }
515
+ var doc = goog.global.document;
516
+ var scripts = doc.getElementsByTagName('script');
517
+ // Search backwards since the current script is in almost all cases the one
518
+ // that has base.js.
519
+ for (var i = scripts.length - 1; i >= 0; --i) {
520
+ var src = scripts[i].src;
521
+ var qmark = src.lastIndexOf('?');
522
+ var l = qmark == -1 ? src.length : qmark;
523
+ if (src.substr(l - 7, 7) == 'base.js') {
524
+ goog.basePath = src.substr(0, l - 7);
525
+ return;
526
+ }
527
+ }
528
+ };
529
+
530
+
531
+ /**
532
+ * Imports a script if, and only if, that script hasn't already been imported.
533
+ * (Must be called at execution time)
534
+ * @param {string} src Script source.
535
+ * @private
536
+ */
537
+ goog.importScript_ = function(src) {
538
+ var importScript = goog.global.CLOSURE_IMPORT_SCRIPT ||
539
+ goog.writeScriptTag_;
540
+ if (!goog.dependencies_.written[src] && importScript(src)) {
541
+ goog.dependencies_.written[src] = true;
542
+ }
543
+ };
544
+
545
+
546
+ /**
547
+ * The default implementation of the import function. Writes a script tag to
548
+ * import the script.
549
+ *
550
+ * @param {string} src The script source.
551
+ * @return {boolean} True if the script was imported, false otherwise.
552
+ * @private
553
+ */
554
+ goog.writeScriptTag_ = function(src) {
555
+ if (goog.inHtmlDocument_()) {
556
+ var doc = goog.global.document;
557
+
558
+ // If the user tries to require a new symbol after document load,
559
+ // something has gone terribly wrong. Doing a document.write would
560
+ // wipe out the page.
561
+ if (doc.readyState == 'complete') {
562
+ // Certain test frameworks load base.js multiple times, which tries
563
+ // to write deps.js each time. If that happens, just fail silently.
564
+ // These frameworks wipe the page between each load of base.js, so this
565
+ // is OK.
566
+ var isDeps = /\bdeps.js$/.test(src);
567
+ if (isDeps) {
568
+ return false;
569
+ } else {
570
+ throw Error('Cannot write "' + src + '" after document load');
571
+ }
572
+ }
573
+
574
+ doc.write(
575
+ '<script type="text/javascript" src="' + src + '"></' + 'script>');
576
+ return true;
577
+ } else {
578
+ return false;
579
+ }
580
+ };
581
+
582
+
583
+ /**
584
+ * Resolves dependencies based on the dependencies added using addDependency
585
+ * and calls importScript_ in the correct order.
586
+ * @private
587
+ */
588
+ goog.writeScripts_ = function() {
589
+ // the scripts we need to write this time
590
+ var scripts = [];
591
+ var seenScript = {};
592
+ var deps = goog.dependencies_;
593
+
594
+ function visitNode(path) {
595
+ if (path in deps.written) {
596
+ return;
597
+ }
598
+
599
+ // we have already visited this one. We can get here if we have cyclic
600
+ // dependencies
601
+ if (path in deps.visited) {
602
+ if (!(path in seenScript)) {
603
+ seenScript[path] = true;
604
+ scripts.push(path);
605
+ }
606
+ return;
607
+ }
608
+
609
+ deps.visited[path] = true;
610
+
611
+ if (path in deps.requires) {
612
+ for (var requireName in deps.requires[path]) {
613
+ // If the required name is defined, we assume that it was already
614
+ // bootstrapped by other means.
615
+ if (!goog.isProvided_(requireName)) {
616
+ if (requireName in deps.nameToPath) {
617
+ visitNode(deps.nameToPath[requireName]);
618
+ } else {
619
+ throw Error('Undefined nameToPath for ' + requireName);
620
+ }
621
+ }
622
+ }
623
+ }
624
+
625
+ if (!(path in seenScript)) {
626
+ seenScript[path] = true;
627
+ scripts.push(path);
628
+ }
629
+ }
630
+
631
+ for (var path in goog.included_) {
632
+ if (!deps.written[path]) {
633
+ visitNode(path);
634
+ }
635
+ }
636
+
637
+ for (var i = 0; i < scripts.length; i++) {
638
+ if (scripts[i]) {
639
+ goog.importScript_(goog.basePath + scripts[i]);
640
+ } else {
641
+ throw Error('Undefined script input');
642
+ }
643
+ }
644
+ };
645
+
646
+
647
+ /**
648
+ * Looks at the dependency rules and tries to determine the script file that
649
+ * fulfills a particular rule.
650
+ * @param {string} rule In the form goog.namespace.Class or project.script.
651
+ * @return {?string} Url corresponding to the rule, or null.
652
+ * @private
653
+ */
654
+ goog.getPathFromDeps_ = function(rule) {
655
+ if (rule in goog.dependencies_.nameToPath) {
656
+ return goog.dependencies_.nameToPath[rule];
657
+ } else {
658
+ return null;
659
+ }
660
+ };
661
+
662
+ goog.findBasePath_();
663
+
664
+ // Allow projects to manage the deps files themselves.
665
+ if (!goog.global.CLOSURE_NO_DEPS) {
666
+ goog.importScript_(goog.basePath + 'deps.js');
667
+ }
668
+ }
669
+
670
+
671
+
672
+ //==============================================================================
673
+ // Language Enhancements
674
+ //==============================================================================
675
+
676
+
677
+ /**
678
+ * This is a "fixed" version of the typeof operator. It differs from the typeof
679
+ * operator in such a way that null returns 'null' and arrays return 'array'.
680
+ * @param {*} value The value to get the type of.
681
+ * @return {string} The name of the type.
682
+ */
683
+ goog.typeOf = function(value) {
684
+ var s = typeof value;
685
+ if (s == 'object') {
686
+ if (value) {
687
+ // Check these first, so we can avoid calling Object.prototype.toString if
688
+ // possible.
689
+ //
690
+ // IE improperly marshals tyepof across execution contexts, but a
691
+ // cross-context object will still return false for "instanceof Object".
692
+ if (value instanceof Array) {
693
+ return 'array';
694
+ } else if (value instanceof Object) {
695
+ return s;
696
+ }
697
+
698
+ // HACK: In order to use an Object prototype method on the arbitrary
699
+ // value, the compiler requires the value be cast to type Object,
700
+ // even though the ECMA spec explicitly allows it.
701
+ var className = Object.prototype.toString.call(
702
+ /** @type {Object} */ (value));
703
+ // In Firefox 3.6, attempting to access iframe window objects' length
704
+ // property throws an NS_ERROR_FAILURE, so we need to special-case it
705
+ // here.
706
+ if (className == '[object Window]') {
707
+ return 'object';
708
+ }
709
+
710
+ // We cannot always use constructor == Array or instanceof Array because
711
+ // different frames have different Array objects. In IE6, if the iframe
712
+ // where the array was created is destroyed, the array loses its
713
+ // prototype. Then dereferencing val.splice here throws an exception, so
714
+ // we can't use goog.isFunction. Calling typeof directly returns 'unknown'
715
+ // so that will work. In this case, this function will return false and
716
+ // most array functions will still work because the array is still
717
+ // array-like (supports length and []) even though it has lost its
718
+ // prototype.
719
+ // Mark Miller noticed that Object.prototype.toString
720
+ // allows access to the unforgeable [[Class]] property.
721
+ // 15.2.4.2 Object.prototype.toString ( )
722
+ // When the toString method is called, the following steps are taken:
723
+ // 1. Get the [[Class]] property of this object.
724
+ // 2. Compute a string value by concatenating the three strings
725
+ // "[object ", Result(1), and "]".
726
+ // 3. Return Result(2).
727
+ // and this behavior survives the destruction of the execution context.
728
+ if ((className == '[object Array]' ||
729
+ // In IE all non value types are wrapped as objects across window
730
+ // boundaries (not iframe though) so we have to do object detection
731
+ // for this edge case
732
+ typeof value.length == 'number' &&
733
+ typeof value.splice != 'undefined' &&
734
+ typeof value.propertyIsEnumerable != 'undefined' &&
735
+ !value.propertyIsEnumerable('splice')
736
+
737
+ )) {
738
+ return 'array';
739
+ }
740
+ // HACK: There is still an array case that fails.
741
+ // function ArrayImpostor() {}
742
+ // ArrayImpostor.prototype = [];
743
+ // var impostor = new ArrayImpostor;
744
+ // this can be fixed by getting rid of the fast path
745
+ // (value instanceof Array) and solely relying on
746
+ // (value && Object.prototype.toString.vall(value) === '[object Array]')
747
+ // but that would require many more function calls and is not warranted
748
+ // unless closure code is receiving objects from untrusted sources.
749
+
750
+ // IE in cross-window calls does not correctly marshal the function type
751
+ // (it appears just as an object) so we cannot use just typeof val ==
752
+ // 'function'. However, if the object has a call property, it is a
753
+ // function.
754
+ if ((className == '[object Function]' ||
755
+ typeof value.call != 'undefined' &&
756
+ typeof value.propertyIsEnumerable != 'undefined' &&
757
+ !value.propertyIsEnumerable('call'))) {
758
+ return 'function';
759
+ }
760
+
761
+
762
+ } else {
763
+ return 'null';
764
+ }
765
+
766
+ } else if (s == 'function' && typeof value.call == 'undefined') {
767
+ // In Safari typeof nodeList returns 'function', and on Firefox
768
+ // typeof behaves similarly for HTML{Applet,Embed,Object}Elements
769
+ // and RegExps. We would like to return object for those and we can
770
+ // detect an invalid function by making sure that the function
771
+ // object has a call method.
772
+ return 'object';
773
+ }
774
+ return s;
775
+ };
776
+
777
+
778
+ /**
779
+ * Returns true if the specified value is not |undefined|.
780
+ * WARNING: Do not use this to test if an object has a property. Use the in
781
+ * operator instead. Additionally, this function assumes that the global
782
+ * undefined variable has not been redefined.
783
+ * @param {*} val Variable to test.
784
+ * @return {boolean} Whether variable is defined.
785
+ */
786
+ goog.isDef = function(val) {
787
+ return val !== undefined;
788
+ };
789
+
790
+
791
+ /**
792
+ * Returns true if the specified value is |null|
793
+ * @param {*} val Variable to test.
794
+ * @return {boolean} Whether variable is null.
795
+ */
796
+ goog.isNull = function(val) {
797
+ return val === null;
798
+ };
799
+
800
+
801
+ /**
802
+ * Returns true if the specified value is defined and not null
803
+ * @param {*} val Variable to test.
804
+ * @return {boolean} Whether variable is defined and not null.
805
+ */
806
+ goog.isDefAndNotNull = function(val) {
807
+ // Note that undefined == null.
808
+ return val != null;
809
+ };
810
+
811
+
812
+ /**
813
+ * Returns true if the specified value is an array
814
+ * @param {*} val Variable to test.
815
+ * @return {boolean} Whether variable is an array.
816
+ */
817
+ goog.isArray = function(val) {
818
+ return goog.typeOf(val) == 'array';
819
+ };
820
+
821
+
822
+ /**
823
+ * Returns true if the object looks like an array. To qualify as array like
824
+ * the value needs to be either a NodeList or an object with a Number length
825
+ * property.
826
+ * @param {*} val Variable to test.
827
+ * @return {boolean} Whether variable is an array.
828
+ */
829
+ goog.isArrayLike = function(val) {
830
+ var type = goog.typeOf(val);
831
+ return type == 'array' || type == 'object' && typeof val.length == 'number';
832
+ };
833
+
834
+
835
+ /**
836
+ * Returns true if the object looks like a Date. To qualify as Date-like
837
+ * the value needs to be an object and have a getFullYear() function.
838
+ * @param {*} val Variable to test.
839
+ * @return {boolean} Whether variable is a like a Date.
840
+ */
841
+ goog.isDateLike = function(val) {
842
+ return goog.isObject(val) && typeof val.getFullYear == 'function';
843
+ };
844
+
845
+
846
+ /**
847
+ * Returns true if the specified value is a string
848
+ * @param {*} val Variable to test.
849
+ * @return {boolean} Whether variable is a string.
850
+ */
851
+ goog.isString = function(val) {
852
+ return typeof val == 'string';
853
+ };
854
+
855
+
856
+ /**
857
+ * Returns true if the specified value is a boolean
858
+ * @param {*} val Variable to test.
859
+ * @return {boolean} Whether variable is boolean.
860
+ */
861
+ goog.isBoolean = function(val) {
862
+ return typeof val == 'boolean';
863
+ };
864
+
865
+
866
+ /**
867
+ * Returns true if the specified value is a number
868
+ * @param {*} val Variable to test.
869
+ * @return {boolean} Whether variable is a number.
870
+ */
871
+ goog.isNumber = function(val) {
872
+ return typeof val == 'number';
873
+ };
874
+
875
+
876
+ /**
877
+ * Returns true if the specified value is a function
878
+ * @param {*} val Variable to test.
879
+ * @return {boolean} Whether variable is a function.
880
+ */
881
+ goog.isFunction = function(val) {
882
+ return goog.typeOf(val) == 'function';
883
+ };
884
+
885
+
886
+ /**
887
+ * Returns true if the specified value is an object. This includes arrays
888
+ * and functions.
889
+ * @param {*} val Variable to test.
890
+ * @return {boolean} Whether variable is an object.
891
+ */
892
+ goog.isObject = function(val) {
893
+ var type = typeof val;
894
+ return type == 'object' && val != null || type == 'function';
895
+ // return Object(val) === val also works, but is slower, especially if val is
896
+ // not an object.
897
+ };
898
+
899
+
900
+ /**
901
+ * Gets a unique ID for an object. This mutates the object so that further
902
+ * calls with the same object as a parameter returns the same value. The unique
903
+ * ID is guaranteed to be unique across the current session amongst objects that
904
+ * are passed into {@code getUid}. There is no guarantee that the ID is unique
905
+ * or consistent across sessions. It is unsafe to generate unique ID for
906
+ * function prototypes.
907
+ *
908
+ * @param {Object} obj The object to get the unique ID for.
909
+ * @return {number} The unique ID for the object.
910
+ */
911
+ goog.getUid = function(obj) {
912
+ // TODO(arv): Make the type stricter, do not accept null.
913
+
914
+ // In Opera window.hasOwnProperty exists but always returns false so we avoid
915
+ // using it. As a consequence the unique ID generated for BaseClass.prototype
916
+ // and SubClass.prototype will be the same.
917
+ return obj[goog.UID_PROPERTY_] ||
918
+ (obj[goog.UID_PROPERTY_] = ++goog.uidCounter_);
919
+ };
920
+
921
+
922
+ /**
923
+ * Removes the unique ID from an object. This is useful if the object was
924
+ * previously mutated using {@code goog.getUid} in which case the mutation is
925
+ * undone.
926
+ * @param {Object} obj The object to remove the unique ID field from.
927
+ */
928
+ goog.removeUid = function(obj) {
929
+ // TODO(arv): Make the type stricter, do not accept null.
930
+
931
+ // DOM nodes in IE are not instance of Object and throws exception
932
+ // for delete. Instead we try to use removeAttribute
933
+ if ('removeAttribute' in obj) {
934
+ obj.removeAttribute(goog.UID_PROPERTY_);
935
+ }
936
+ /** @preserveTry */
937
+ try {
938
+ delete obj[goog.UID_PROPERTY_];
939
+ } catch (ex) {
940
+ }
941
+ };
942
+
943
+
944
+ /**
945
+ * Name for unique ID property. Initialized in a way to help avoid collisions
946
+ * with other closure javascript on the same page.
947
+ * @type {string}
948
+ * @private
949
+ */
950
+ goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0);
951
+
952
+
953
+ /**
954
+ * Counter for UID.
955
+ * @type {number}
956
+ * @private
957
+ */
958
+ goog.uidCounter_ = 0;
959
+
960
+
961
+ /**
962
+ * Adds a hash code field to an object. The hash code is unique for the
963
+ * given object.
964
+ * @param {Object} obj The object to get the hash code for.
965
+ * @return {number} The hash code for the object.
966
+ * @deprecated Use goog.getUid instead.
967
+ */
968
+ goog.getHashCode = goog.getUid;
969
+
970
+
971
+ /**
972
+ * Removes the hash code field from an object.
973
+ * @param {Object} obj The object to remove the field from.
974
+ * @deprecated Use goog.removeUid instead.
975
+ */
976
+ goog.removeHashCode = goog.removeUid;
977
+
978
+
979
+ /**
980
+ * Clones a value. The input may be an Object, Array, or basic type. Objects and
981
+ * arrays will be cloned recursively.
982
+ *
983
+ * WARNINGS:
984
+ * <code>goog.cloneObject</code> does not detect reference loops. Objects that
985
+ * refer to themselves will cause infinite recursion.
986
+ *
987
+ * <code>goog.cloneObject</code> is unaware of unique identifiers, and copies
988
+ * UIDs created by <code>getUid</code> into cloned results.
989
+ *
990
+ * @param {*} obj The value to clone.
991
+ * @return {*} A clone of the input value.
992
+ * @deprecated goog.cloneObject is unsafe. Prefer the goog.object methods.
993
+ */
994
+ goog.cloneObject = function(obj) {
995
+ var type = goog.typeOf(obj);
996
+ if (type == 'object' || type == 'array') {
997
+ if (obj.clone) {
998
+ return obj.clone();
999
+ }
1000
+ var clone = type == 'array' ? [] : {};
1001
+ for (var key in obj) {
1002
+ clone[key] = goog.cloneObject(obj[key]);
1003
+ }
1004
+ return clone;
1005
+ }
1006
+
1007
+ return obj;
1008
+ };
1009
+
1010
+
1011
+ /**
1012
+ * A native implementation of goog.bind.
1013
+ * @param {Function} fn A function to partially apply.
1014
+ * @param {Object|undefined} selfObj Specifies the object which |this| should
1015
+ * point to when the function is run.
1016
+ * @param {...*} var_args Additional arguments that are partially
1017
+ * applied to the function.
1018
+ * @return {!Function} A partially-applied form of the function bind() was
1019
+ * invoked as a method of.
1020
+ * @private
1021
+ * @suppress {deprecated} The compiler thinks that Function.prototype.bind
1022
+ * is deprecated because some people have declared a pure-JS version.
1023
+ * Only the pure-JS version is truly deprecated.
1024
+ */
1025
+ goog.bindNative_ = function(fn, selfObj, var_args) {
1026
+ return /** @type {!Function} */ (fn.call.apply(fn.bind, arguments));
1027
+ };
1028
+
1029
+
1030
+ /**
1031
+ * A pure-JS implementation of goog.bind.
1032
+ * @param {Function} fn A function to partially apply.
1033
+ * @param {Object|undefined} selfObj Specifies the object which |this| should
1034
+ * point to when the function is run.
1035
+ * @param {...*} var_args Additional arguments that are partially
1036
+ * applied to the function.
1037
+ * @return {!Function} A partially-applied form of the function bind() was
1038
+ * invoked as a method of.
1039
+ * @private
1040
+ */
1041
+ goog.bindJs_ = function(fn, selfObj, var_args) {
1042
+ if (!fn) {
1043
+ throw new Error();
1044
+ }
1045
+
1046
+ if (arguments.length > 2) {
1047
+ var boundArgs = Array.prototype.slice.call(arguments, 2);
1048
+ return function() {
1049
+ // Prepend the bound arguments to the current arguments.
1050
+ var newArgs = Array.prototype.slice.call(arguments);
1051
+ Array.prototype.unshift.apply(newArgs, boundArgs);
1052
+ return fn.apply(selfObj, newArgs);
1053
+ };
1054
+
1055
+ } else {
1056
+ return function() {
1057
+ return fn.apply(selfObj, arguments);
1058
+ };
1059
+ }
1060
+ };
1061
+
1062
+
1063
+ /**
1064
+ * Partially applies this function to a particular 'this object' and zero or
1065
+ * more arguments. The result is a new function with some arguments of the first
1066
+ * function pre-filled and the value of |this| 'pre-specified'.<br><br>
1067
+ *
1068
+ * Remaining arguments specified at call-time are appended to the pre-
1069
+ * specified ones.<br><br>
1070
+ *
1071
+ * Also see: {@link #partial}.<br><br>
1072
+ *
1073
+ * Usage:
1074
+ * <pre>var barMethBound = bind(myFunction, myObj, 'arg1', 'arg2');
1075
+ * barMethBound('arg3', 'arg4');</pre>
1076
+ *
1077
+ * @param {Function} fn A function to partially apply.
1078
+ * @param {Object|undefined} selfObj Specifies the object which |this| should
1079
+ * point to when the function is run.
1080
+ * @param {...*} var_args Additional arguments that are partially
1081
+ * applied to the function.
1082
+ * @return {!Function} A partially-applied form of the function bind() was
1083
+ * invoked as a method of.
1084
+ * @suppress {deprecated} See above.
1085
+ */
1086
+ goog.bind = function(fn, selfObj, var_args) {
1087
+ // TODO(nicksantos): narrow the type signature.
1088
+ if (Function.prototype.bind &&
1089
+ // NOTE(nicksantos): Somebody pulled base.js into the default
1090
+ // Chrome extension environment. This means that for Chrome extensions,
1091
+ // they get the implementation of Function.prototype.bind that
1092
+ // calls goog.bind instead of the native one. Even worse, we don't want
1093
+ // to introduce a circular dependency between goog.bind and
1094
+ // Function.prototype.bind, so we have to hack this to make sure it
1095
+ // works correctly.
1096
+ Function.prototype.bind.toString().indexOf('native code') != -1) {
1097
+ goog.bind = goog.bindNative_;
1098
+ } else {
1099
+ goog.bind = goog.bindJs_;
1100
+ }
1101
+ return goog.bind.apply(null, arguments);
1102
+ };
1103
+
1104
+
1105
+ /**
1106
+ * Like bind(), except that a 'this object' is not required. Useful when the
1107
+ * target function is already bound.
1108
+ *
1109
+ * Usage:
1110
+ * var g = partial(f, arg1, arg2);
1111
+ * g(arg3, arg4);
1112
+ *
1113
+ * @param {Function} fn A function to partially apply.
1114
+ * @param {...*} var_args Additional arguments that are partially
1115
+ * applied to fn.
1116
+ * @return {!Function} A partially-applied form of the function bind() was
1117
+ * invoked as a method of.
1118
+ */
1119
+ goog.partial = function(fn, var_args) {
1120
+ var args = Array.prototype.slice.call(arguments, 1);
1121
+ return function() {
1122
+ // Prepend the bound arguments to the current arguments.
1123
+ var newArgs = Array.prototype.slice.call(arguments);
1124
+ newArgs.unshift.apply(newArgs, args);
1125
+ return fn.apply(this, newArgs);
1126
+ };
1127
+ };
1128
+
1129
+
1130
+ /**
1131
+ * Copies all the members of a source object to a target object. This method
1132
+ * does not work on all browsers for all objects that contain keys such as
1133
+ * toString or hasOwnProperty. Use goog.object.extend for this purpose.
1134
+ * @param {Object} target Target.
1135
+ * @param {Object} source Source.
1136
+ */
1137
+ goog.mixin = function(target, source) {
1138
+ for (var x in source) {
1139
+ target[x] = source[x];
1140
+ }
1141
+
1142
+ // For IE7 or lower, the for-in-loop does not contain any properties that are
1143
+ // not enumerable on the prototype object (for example, isPrototypeOf from
1144
+ // Object.prototype) but also it will not include 'replace' on objects that
1145
+ // extend String and change 'replace' (not that it is common for anyone to
1146
+ // extend anything except Object).
1147
+ };
1148
+
1149
+
1150
+ /**
1151
+ * @return {number} An integer value representing the number of milliseconds
1152
+ * between midnight, January 1, 1970 and the current time.
1153
+ */
1154
+ goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {
1155
+ // Unary plus operator converts its operand to a number which in the case of
1156
+ // a date is done by calling getTime().
1157
+ return +new Date();
1158
+ });
1159
+
1160
+
1161
+ /**
1162
+ * Evals javascript in the global scope. In IE this uses execScript, other
1163
+ * browsers use goog.global.eval. If goog.global.eval does not evaluate in the
1164
+ * global scope (for example, in Safari), appends a script tag instead.
1165
+ * Throws an exception if neither execScript or eval is defined.
1166
+ * @param {string} script JavaScript string.
1167
+ */
1168
+ goog.globalEval = function(script) {
1169
+ if (goog.global.execScript) {
1170
+ goog.global.execScript(script, 'JavaScript');
1171
+ } else if (goog.global.eval) {
1172
+ // Test to see if eval works
1173
+ if (goog.evalWorksForGlobals_ == null) {
1174
+ goog.global.eval('var _et_ = 1;');
1175
+ if (typeof goog.global['_et_'] != 'undefined') {
1176
+ delete goog.global['_et_'];
1177
+ goog.evalWorksForGlobals_ = true;
1178
+ } else {
1179
+ goog.evalWorksForGlobals_ = false;
1180
+ }
1181
+ }
1182
+
1183
+ if (goog.evalWorksForGlobals_) {
1184
+ goog.global.eval(script);
1185
+ } else {
1186
+ var doc = goog.global.document;
1187
+ var scriptElt = doc.createElement('script');
1188
+ scriptElt.type = 'text/javascript';
1189
+ scriptElt.defer = false;
1190
+ // Note(user): can't use .innerHTML since "t('<test>')" will fail and
1191
+ // .text doesn't work in Safari 2. Therefore we append a text node.
1192
+ scriptElt.appendChild(doc.createTextNode(script));
1193
+ doc.body.appendChild(scriptElt);
1194
+ doc.body.removeChild(scriptElt);
1195
+ }
1196
+ } else {
1197
+ throw Error('goog.globalEval not available');
1198
+ }
1199
+ };
1200
+
1201
+
1202
+ /**
1203
+ * Indicates whether or not we can call 'eval' directly to eval code in the
1204
+ * global scope. Set to a Boolean by the first call to goog.globalEval (which
1205
+ * empirically tests whether eval works for globals). @see goog.globalEval
1206
+ * @type {?boolean}
1207
+ * @private
1208
+ */
1209
+ goog.evalWorksForGlobals_ = null;
1210
+
1211
+
1212
+ /**
1213
+ * Optional map of CSS class names to obfuscated names used with
1214
+ * goog.getCssName().
1215
+ * @type {Object|undefined}
1216
+ * @private
1217
+ * @see goog.setCssNameMapping
1218
+ */
1219
+ goog.cssNameMapping_;
1220
+
1221
+
1222
+ /**
1223
+ * Optional obfuscation style for CSS class names. Should be set to either
1224
+ * 'BY_WHOLE' or 'BY_PART' if defined.
1225
+ * @type {string|undefined}
1226
+ * @private
1227
+ * @see goog.setCssNameMapping
1228
+ */
1229
+ goog.cssNameMappingStyle_;
1230
+
1231
+
1232
+ /**
1233
+ * Handles strings that are intended to be used as CSS class names.
1234
+ *
1235
+ * This function works in tandem with @see goog.setCssNameMapping.
1236
+ *
1237
+ * Without any mapping set, the arguments are simple joined with a
1238
+ * hyphen and passed through unaltered.
1239
+ *
1240
+ * When there is a mapping, there are two possible styles in which
1241
+ * these mappings are used. In the BY_PART style, each part (i.e. in
1242
+ * between hyphens) of the passed in css name is rewritten according
1243
+ * to the map. In the BY_WHOLE style, the full css name is looked up in
1244
+ * the map directly. If a rewrite is not specified by the map, the
1245
+ * compiler will output a warning.
1246
+ *
1247
+ * When the mapping is passed to the compiler, it will replace calls
1248
+ * to goog.getCssName with the strings from the mapping, e.g.
1249
+ * var x = goog.getCssName('foo');
1250
+ * var y = goog.getCssName(this.baseClass, 'active');
1251
+ * becomes:
1252
+ * var x= 'foo';
1253
+ * var y = this.baseClass + '-active';
1254
+ *
1255
+ * If one argument is passed it will be processed, if two are passed
1256
+ * only the modifier will be processed, as it is assumed the first
1257
+ * argument was generated as a result of calling goog.getCssName.
1258
+ *
1259
+ * @param {string} className The class name.
1260
+ * @param {string=} opt_modifier A modifier to be appended to the class name.
1261
+ * @return {string} The class name or the concatenation of the class name and
1262
+ * the modifier.
1263
+ */
1264
+ goog.getCssName = function(className, opt_modifier) {
1265
+ var getMapping = function(cssName) {
1266
+ return goog.cssNameMapping_[cssName] || cssName;
1267
+ };
1268
+
1269
+ var renameByParts = function(cssName) {
1270
+ // Remap all the parts individually.
1271
+ var parts = cssName.split('-');
1272
+ var mapped = [];
1273
+ for (var i = 0; i < parts.length; i++) {
1274
+ mapped.push(getMapping(parts[i]));
1275
+ }
1276
+ return mapped.join('-');
1277
+ };
1278
+
1279
+ var rename;
1280
+ if (goog.cssNameMapping_) {
1281
+ rename = goog.cssNameMappingStyle_ == 'BY_WHOLE' ?
1282
+ getMapping : renameByParts;
1283
+ } else {
1284
+ rename = function(a) {
1285
+ return a;
1286
+ };
1287
+ }
1288
+
1289
+ if (opt_modifier) {
1290
+ return className + '-' + rename(opt_modifier);
1291
+ } else {
1292
+ return rename(className);
1293
+ }
1294
+ };
1295
+
1296
+
1297
+ /**
1298
+ * Sets the map to check when returning a value from goog.getCssName(). Example:
1299
+ * <pre>
1300
+ * goog.setCssNameMapping({
1301
+ * "goog": "a",
1302
+ * "disabled": "b",
1303
+ * });
1304
+ *
1305
+ * var x = goog.getCssName('goog');
1306
+ * // The following evaluates to: "a a-b".
1307
+ * goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')
1308
+ * </pre>
1309
+ * When declared as a map of string literals to string literals, the JSCompiler
1310
+ * will replace all calls to goog.getCssName() using the supplied map if the
1311
+ * --closure_pass flag is set.
1312
+ *
1313
+ * @param {!Object} mapping A map of strings to strings where keys are possible
1314
+ * arguments to goog.getCssName() and values are the corresponding values
1315
+ * that should be returned.
1316
+ * @param {string=} opt_style The style of css name mapping. There are two valid
1317
+ * options: 'BY_PART', and 'BY_WHOLE'.
1318
+ * @see goog.getCssName for a description.
1319
+ */
1320
+ goog.setCssNameMapping = function(mapping, opt_style) {
1321
+ goog.cssNameMapping_ = mapping;
1322
+ goog.cssNameMappingStyle_ = opt_style;
1323
+ };
1324
+
1325
+
1326
+ /**
1327
+ * To use CSS renaming in compiled mode, one of the input files should have a
1328
+ * call to goog.setCssNameMapping() with an object literal that the JSCompiler
1329
+ * can extract and use to replace all calls to goog.getCssName(). In uncompiled
1330
+ * mode, JavaScript code should be loaded before this base.js file that declares
1331
+ * a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is
1332
+ * to ensure that the mapping is loaded before any calls to goog.getCssName()
1333
+ * are made in uncompiled mode.
1334
+ *
1335
+ * A hook for overriding the CSS name mapping.
1336
+ * @type {Object|undefined}
1337
+ */
1338
+ goog.global.CLOSURE_CSS_NAME_MAPPING;
1339
+
1340
+
1341
+ if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {
1342
+ // This does not call goog.setCssNameMapping() because the JSCompiler
1343
+ // requires that goog.setCssNameMapping() be called with an object literal.
1344
+ goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING;
1345
+ }
1346
+
1347
+
1348
+ /**
1349
+ * Gets a localized message.
1350
+ *
1351
+ * This function is a compiler primitive. If you give the compiler a localized
1352
+ * message bundle, it will replace the string at compile-time with a localized
1353
+ * version, and expand goog.getMsg call to a concatenated string.
1354
+ *
1355
+ * Messages must be initialized in the form:
1356
+ * <code>
1357
+ * var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});
1358
+ * </code>
1359
+ *
1360
+ * @param {string} str Translatable string, places holders in the form {$foo}.
1361
+ * @param {Object=} opt_values Map of place holder name to value.
1362
+ * @return {string} message with placeholders filled.
1363
+ */
1364
+ goog.getMsg = function(str, opt_values) {
1365
+ var values = opt_values || {};
1366
+ for (var key in values) {
1367
+ var value = ('' + values[key]).replace(/\$/g, '$$$$');
1368
+ str = str.replace(new RegExp('\\{\\$' + key + '\\}', 'gi'), value);
1369
+ }
1370
+ return str;
1371
+ };
1372
+
1373
+
1374
+ /**
1375
+ * Gets a localized message. If the message does not have a translation, gives a
1376
+ * fallback message.
1377
+ *
1378
+ * This is useful when introducing a new message that has not yet been
1379
+ * translated into all languages.
1380
+ *
1381
+ * This function is a compiler primtive. Must be used in the form:
1382
+ * <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code>
1383
+ * where MSG_A and MSG_B were initialized with goog.getMsg.
1384
+ *
1385
+ * @param {string} a The preferred message.
1386
+ * @param {string} b The fallback message.
1387
+ * @return {string} The best translated message.
1388
+ */
1389
+ goog.getMsgWithFallback = function(a, b) {
1390
+ return a;
1391
+ };
1392
+
1393
+
1394
+ /**
1395
+ * Exposes an unobfuscated global namespace path for the given object.
1396
+ * Note that fields of the exported object *will* be obfuscated,
1397
+ * unless they are exported in turn via this function or
1398
+ * goog.exportProperty
1399
+ *
1400
+ * <p>Also handy for making public items that are defined in anonymous
1401
+ * closures.
1402
+ *
1403
+ * ex. goog.exportSymbol('public.path.Foo', Foo);
1404
+ *
1405
+ * ex. goog.exportSymbol('public.path.Foo.staticFunction',
1406
+ * Foo.staticFunction);
1407
+ * public.path.Foo.staticFunction();
1408
+ *
1409
+ * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod',
1410
+ * Foo.prototype.myMethod);
1411
+ * new public.path.Foo().myMethod();
1412
+ *
1413
+ * @param {string} publicPath Unobfuscated name to export.
1414
+ * @param {*} object Object the name should point to.
1415
+ * @param {Object=} opt_objectToExportTo The object to add the path to; default
1416
+ * is |goog.global|.
1417
+ */
1418
+ goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) {
1419
+ goog.exportPath_(publicPath, object, opt_objectToExportTo);
1420
+ };
1421
+
1422
+
1423
+ /**
1424
+ * Exports a property unobfuscated into the object's namespace.
1425
+ * ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction);
1426
+ * ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod);
1427
+ * @param {Object} object Object whose static property is being exported.
1428
+ * @param {string} publicName Unobfuscated name to export.
1429
+ * @param {*} symbol Object the name should point to.
1430
+ */
1431
+ goog.exportProperty = function(object, publicName, symbol) {
1432
+ object[publicName] = symbol;
1433
+ };
1434
+
1435
+
1436
+ /**
1437
+ * Inherit the prototype methods from one constructor into another.
1438
+ *
1439
+ * Usage:
1440
+ * <pre>
1441
+ * function ParentClass(a, b) { }
1442
+ * ParentClass.prototype.foo = function(a) { }
1443
+ *
1444
+ * function ChildClass(a, b, c) {
1445
+ * goog.base(this, a, b);
1446
+ * }
1447
+ * goog.inherits(ChildClass, ParentClass);
1448
+ *
1449
+ * var child = new ChildClass('a', 'b', 'see');
1450
+ * child.foo(); // works
1451
+ * </pre>
1452
+ *
1453
+ * In addition, a superclass' implementation of a method can be invoked
1454
+ * as follows:
1455
+ *
1456
+ * <pre>
1457
+ * ChildClass.prototype.foo = function(a) {
1458
+ * ChildClass.superClass_.foo.call(this, a);
1459
+ * // other code
1460
+ * };
1461
+ * </pre>
1462
+ *
1463
+ * @param {Function} childCtor Child class.
1464
+ * @param {Function} parentCtor Parent class.
1465
+ */
1466
+ goog.inherits = function(childCtor, parentCtor) {
1467
+ /** @constructor */
1468
+ function tempCtor() {};
1469
+ tempCtor.prototype = parentCtor.prototype;
1470
+ childCtor.superClass_ = parentCtor.prototype;
1471
+ childCtor.prototype = new tempCtor();
1472
+ /** @override */
1473
+ childCtor.prototype.constructor = childCtor;
1474
+ };
1475
+
1476
+
1477
+ /**
1478
+ * Call up to the superclass.
1479
+ *
1480
+ * If this is called from a constructor, then this calls the superclass
1481
+ * contructor with arguments 1-N.
1482
+ *
1483
+ * If this is called from a prototype method, then you must pass
1484
+ * the name of the method as the second argument to this function. If
1485
+ * you do not, you will get a runtime error. This calls the superclass'
1486
+ * method with arguments 2-N.
1487
+ *
1488
+ * This function only works if you use goog.inherits to express
1489
+ * inheritance relationships between your classes.
1490
+ *
1491
+ * This function is a compiler primitive. At compile-time, the
1492
+ * compiler will do macro expansion to remove a lot of
1493
+ * the extra overhead that this function introduces. The compiler
1494
+ * will also enforce a lot of the assumptions that this function
1495
+ * makes, and treat it as a compiler error if you break them.
1496
+ *
1497
+ * @param {!Object} me Should always be "this".
1498
+ * @param {*=} opt_methodName The method name if calling a super method.
1499
+ * @param {...*} var_args The rest of the arguments.
1500
+ * @return {*} The return value of the superclass method.
1501
+ */
1502
+ goog.base = function(me, opt_methodName, var_args) {
1503
+ var caller = arguments.callee.caller;
1504
+ if (caller.superClass_) {
1505
+ // This is a constructor. Call the superclass constructor.
1506
+ return caller.superClass_.constructor.apply(
1507
+ me, Array.prototype.slice.call(arguments, 1));
1508
+ }
1509
+
1510
+ var args = Array.prototype.slice.call(arguments, 2);
1511
+ var foundCaller = false;
1512
+ for (var ctor = me.constructor;
1513
+ ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
1514
+ if (ctor.prototype[opt_methodName] === caller) {
1515
+ foundCaller = true;
1516
+ } else if (foundCaller) {
1517
+ return ctor.prototype[opt_methodName].apply(me, args);
1518
+ }
1519
+ }
1520
+
1521
+ // If we did not find the caller in the prototype chain,
1522
+ // then one of two things happened:
1523
+ // 1) The caller is an instance method.
1524
+ // 2) This method was not called by the right caller.
1525
+ if (me[opt_methodName] === caller) {
1526
+ return me.constructor.prototype[opt_methodName].apply(me, args);
1527
+ } else {
1528
+ throw Error(
1529
+ 'goog.base called from a method of one name ' +
1530
+ 'to a method of a different name');
1531
+ }
1532
+ };
1533
+
1534
+
1535
+ /**
1536
+ * Allow for aliasing within scope functions. This function exists for
1537
+ * uncompiled code - in compiled code the calls will be inlined and the
1538
+ * aliases applied. In uncompiled code the function is simply run since the
1539
+ * aliases as written are valid JavaScript.
1540
+ * @param {function()} fn Function to call. This function can contain aliases
1541
+ * to namespaces (e.g. "var dom = goog.dom") or classes
1542
+ * (e.g. "var Timer = goog.Timer").
1543
+ */
1544
+ goog.scope = function(fn) {
1545
+ fn.call(goog.global);
1546
+ };
1547
+
1548
+