// Copyright 2006 Google Inc. // All Rights Reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in // the documentation and/or other materials provided with the // distribution. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // NOTE: This file has been changed from the one on doctype. The following // changes were made: // - Removed goog.globalEval because it calls eval() which is not allowed from // inside v8 extensions. If we ever need to use globalEval, we will need to // find a way to work around this problem. // - Remove Function.prototype.apply() emulation for the same reason. This one // is useless anyway because V8 supports apply() natively. /** * @fileoverview Bootstrap for the Google JS Library */ /** * @define {boolean} Overridden to true by the compiler when * --mark_as_compiled is specified. */ var COMPILED = true; /** * Base namespace for the Google JS library. Checks to see goog is * already defined in the current scope before assigning to prevent * clobbering if base.js is loaded more than once. */ var goog = {}; // Check to see if already defined in current scope /** * Reference to the global context. In most cases this will be 'window'. */ goog.global = this; /** * Indicates whether or not we can call 'eval' directly to eval code in the * global scope. Set to a Boolean by the first call to goog.globalEval (which * empirically tests whether eval works for globals). @see goog.globalEval * @type {boolean?} * @private */ goog.evalWorksForGlobals_ = null; /** * Creates object stubs for a namespace. When present in a file, goog.provide * also indicates that the file defines the indicated object. * @param {string} name name of the object that this file defines. */ goog.provide = function(name) { if (!COMPILED) { // Ensure that the same namespace isn't provided twice. This is intended // to teach new developers that 'goog.provide' is effectively a variable // declaration. And when JSCompiler transforms goog.provide into a real // variable declaration, the compiled JS should work the same as the raw // JS--even when the raw JS uses goog.provide incorrectly. if (goog.getObjectByName(name) && !goog.implicitNamespaces_[name]) { throw 'Namespace "' + name + '" already declared.'; } var namespace = name; while ((namespace = namespace.substr(0, namespace.lastIndexOf('.')))) { goog.implicitNamespaces_[namespace] = true; } } goog.exportPath_(name); }; if (!COMPILED) { /** * Namespaces implicitly defined by goog.provide. For example, * goog.provide('goog.events.Event') implicitly declares * that 'goog' and 'goog.events' must be namespaces. * * @type {Object} * @private */ goog.implicitNamespaces_ = {}; } /** * Builds an object structure for the provided namespace path, * ensuring that names that already exist are not overwritten. For * example: * "a.b.c" -> a = {};a.b={};a.b.c={}; * Used by goog.provide and goog.exportSymbol. * @param {string} name name of the object that this file defines. * @param {Object} opt_object the object to expose at the end of the path. * @private */ goog.exportPath_ = function(name, opt_object) { var parts = name.split('.'); var cur = goog.global; var part; // Internet Explorer exhibits strange behavior when throwing errors from // methods externed in this manner. See the testExportSymbolExceptions in // base_test.html for an example. if (!(parts[0] in cur) && cur.execScript) { cur.execScript('var ' + parts[0]); } // Parentheses added to eliminate strict JS warning in Firefox. while ((part = parts.shift())) { if (!parts.length && goog.isDef(opt_object)) { // last part and we have an object; use it cur[part] = opt_object; } else if (cur[part]) { cur = cur[part]; } else { cur = cur[part] = {}; } } }; /** * Returns an object based on its fully qualified name * @param {string} name The fully qualified name. * @return {Object?} The object or, if not found, null. */ goog.getObjectByName = function(name) { var parts = name.split('.'); var cur = goog.global; for (var part; part = parts.shift(); ) { if (cur[part]) { cur = cur[part]; } else { return null; } } return cur; }; /** * Globalizes a whole namespace, such as goog or goog.lang. * * @param {Object} obj The namespace to globalize. * @param {Object} opt_global The object to add the properties to. * @deprecated Properties may be explicitly exported to the global scope, but * this should no longer be done in bulk. */ goog.globalize = function(obj, opt_global) { var global = opt_global || goog.global; for (var x in obj) { global[x] = obj[x]; } }; /** * Adds a dependency from a file to the files it requires. * @param {string} relPath The path to the js file. * @param {Array} provides An array of strings with the names of the objects * this file provides. * @param {Array} requires An array of strings with the names of the objects * this file requires. */ goog.addDependency = function(relPath, provides, requires) { if (!COMPILED) { var provide, require; var path = relPath.replace(/\\/g, '/'); var deps = goog.dependencies_; for (var i = 0; provide = provides[i]; i++) { deps.nameToPath[provide] = path; if (!(path in deps.pathToNames)) { deps.pathToNames[path] = {}; } deps.pathToNames[path][provide] = true; } for (var j = 0; require = requires[j]; j++) { if (!(path in deps.requires)) { deps.requires[path] = {}; } deps.requires[path][require] = true; } } }; /** * Implements a system for the dynamic resolution of dependencies * that works in parallel with the BUILD system. * @param {string} rule Rule to include, in the form goog.package.part. */ goog.require = function(rule) { // if the object already exists we do not need do do anything if (!COMPILED) { if (goog.getObjectByName(rule)) { return; } var path = goog.getPathFromDeps_(rule); if (path) { goog.included_[path] = true; goog.writeScripts_(); } else { // NOTE(nicksantos): We could throw an error, but this would break // legacy users that depended on this failing silently. Instead, the // compiler should warn us when there are invalid goog.require calls. } } }; /** * Path for included scripts * @type {string} */ goog.basePath = ''; /** * Null function used for default values of callbacks, etc. * @type {Function} */ goog.nullFunction = function() {}; /** * When defining a class Foo with an abstract method bar(), you can do: * * Foo.prototype.bar = goog.abstractMethod * * Now if a subclass of Foo fails to override bar(), an error * will be thrown when bar() is invoked. * * Note: This does not take the name of the function to override as * an argument because that would make it more difficult to obfuscate * our JavaScript code. * * @throws {Error} when invoked to indicate the method should be * overridden. */ goog.abstractMethod = function() { throw Error('unimplemented abstract method'); }; if (!COMPILED) { /** * Object used to keep track of urls that have already been added. This * record allows the prevention of circular dependencies. * @type {Object} * @private */ goog.included_ = {}; /** * This object is used to keep track of dependencies and other data that is * used for loading scripts * @private * @type {Object} */ goog.dependencies_ = { pathToNames: {}, // 1 to many nameToPath: {}, // 1 to 1 requires: {}, // 1 to many visited: {}, // used when resolving dependencies to prevent us from // visiting the file twice written: {} // used to keep track of script files we have written }; /** * Tries to detect the base path of the base.js script that bootstraps * Google JS Library * @private */ goog.findBasePath_ = function() { var doc = goog.global.document; if (typeof doc == 'undefined') { return; } if (goog.global.GOOG_BASE_PATH) { goog.basePath = goog.global.GOOG_BASE_PATH; return; } else { goog.global.GOOG_BASE_PATH = null; } var scripts = doc.getElementsByTagName('script'); for (var script, i = 0; script = scripts[i]; i++) { var src = script.src; var l = src.length; if (src.substr(l - 7) == 'base.js') { goog.basePath = src.substr(0, l - 7); return; } } }; /** * Writes a script tag if, and only if, that script hasn't already been added * to the document. (Must be called at execution time) * @param {string} src Script source. * @private */ goog.writeScriptTag_ = function(src) { var doc = goog.global.document; if (typeof doc != 'undefined' && !goog.dependencies_.written[src]) { goog.dependencies_.written[src] = true; doc.write('