gears_init.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2007, Google Inc.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright notice,
  10. * this list of conditions and the following disclaimer in the documentation
  11. * and/or other materials provided with the distribution.
  12. * 3. Neither the name of Google Inc. nor the names of its contributors may be
  13. * used to endorse or promote products derived from this software without
  14. * specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * Sets up google.gears.*, which is *the only* supported way to access Gears.
  28. *
  29. * Circumvent this file at your own risk!
  30. *
  31. * In the future, Gears may automatically define google.gears.* without this
  32. * file. Gears may use these objects to transparently fix bugs and compatibility
  33. * issues. Applications that use the code below will continue to work seamlessly
  34. * when that happens.
  35. */
  36. (function() {
  37. // We are already defined. Hooray!
  38. if (window.google && google.gears) {
  39. return;
  40. }
  41. var factory = null;
  42. // Firefox
  43. if (typeof GearsFactory != 'undefined') {
  44. factory = new GearsFactory();
  45. } else {
  46. // IE
  47. try {
  48. factory = new ActiveXObject('Gears.Factory');
  49. // privateSetGlobalObject is only required and supported on WinCE.
  50. if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
  51. factory.privateSetGlobalObject(this);
  52. }
  53. } catch (e) {
  54. // Safari
  55. if ((typeof navigator.mimeTypes != 'undefined')
  56. && navigator.mimeTypes["application/x-googlegears"]) {
  57. factory = document.createElement("object");
  58. factory.style.display = "none";
  59. factory.width = 0;
  60. factory.height = 0;
  61. factory.type = "application/x-googlegears";
  62. document.documentElement.appendChild(factory);
  63. }
  64. }
  65. }
  66. // *Do not* define any objects if Gears is not installed. This mimics the
  67. // behavior of Gears defining the objects in the future.
  68. if (!factory) {
  69. return;
  70. }
  71. // Now set up the objects, being careful not to overwrite anything.
  72. //
  73. // Note: In Internet Explorer for Windows Mobile, you can't add properties to
  74. // the window object. However, global objects are automatically added as
  75. // properties of the window object in all browsers.
  76. if (!window.google) {
  77. google = {};
  78. }
  79. if (!google.gears) {
  80. google.gears = {factory: factory};
  81. }
  82. })();