Debian Codegraph @

closure-library/closure/goog/useragent/iphoto.js

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