iphoto.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2007 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. * @fileoverview Newer versions of iPhoto include a Safari plugin which allows
  16. * the browser to detect if iPhoto is installed. Adapted from detection code
  17. * built into the Mac.com Gallery RSS feeds.
  18. * @author brenneman@google.com (Shawn Brenneman)
  19. * @see ../demos/useragent.html
  20. */
  21. goog.provide('goog.userAgent.iphoto');
  22. goog.require('goog.string');
  23. goog.require('goog.userAgent');
  24. (function() {
  25. var hasIphoto = false;
  26. var version = '';
  27. /**
  28. * The plugin description string contains the version number as in the form
  29. * 'iPhoto 700'. This returns just the version number as a dotted string,
  30. * e.g., '7.0.0', compatible with {@code goog.string.compareVersions}.
  31. * @param {string} desc The version string.
  32. * @return {string} The dotted version.
  33. */
  34. function getIphotoVersion(desc) {
  35. var matches = desc.match(/\d/g);
  36. return matches.join('.');
  37. }
  38. if (goog.userAgent.WEBKIT && navigator.mimeTypes &&
  39. navigator.mimeTypes.length > 0) {
  40. var iphoto = navigator.mimeTypes['application/photo'];
  41. if (iphoto) {
  42. hasIphoto = true;
  43. var description = iphoto['description'];
  44. if (description) {
  45. version = getIphotoVersion(description);
  46. }
  47. }
  48. }
  49. /**
  50. * Whether we can detect that the user has iPhoto installed.
  51. * @type {boolean}
  52. */
  53. goog.userAgent.iphoto.HAS_IPHOTO = hasIphoto;
  54. /**
  55. * The version of iPhoto installed if found.
  56. * @type {string}
  57. */
  58. goog.userAgent.iphoto.VERSION = version;
  59. })();
  60. /**
  61. * Whether the installed version of iPhoto is as new or newer than a given
  62. * version.
  63. * @param {string} version The version to check.
  64. * @return {boolean} Whether the installed version of iPhoto is as new or newer
  65. * than a given version.
  66. */
  67. goog.userAgent.iphoto.isVersion = function(version) {
  68. return goog.string.compareVersions(goog.userAgent.iphoto.VERSION, version) >=
  69. 0;
  70. };