OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview LIS Standalone hack | 6 * @fileoverview LIS Standalone hack |
7 * This file contains the code necessary to make the Touch LIS work | 7 * This file contains the code necessary to make the Touch LIS work |
8 * as a stand-alone application (as opposed to being embedded into chrome). | 8 * as a stand-alone application (as opposed to being embedded into chrome). |
9 * This is useful for rapid development and testing, but does not actually form | 9 * This is useful for rapid development and testing, but does not actually form |
10 * part of the product. | 10 * part of the product. |
(...skipping 16 matching lines...) Expand all Loading... |
27 * | 27 * |
28 * Note that the real chrome object also supplies data for most-viewed and | 28 * Note that the real chrome object also supplies data for most-viewed and |
29 * recently-closed pages, but the tangent LIS doesn't use that data so we | 29 * recently-closed pages, but the tangent LIS doesn't use that data so we |
30 * don't bother simulating it here. | 30 * don't bother simulating it here. |
31 * | 31 * |
32 * We create this object by applying an anonymous function so that we can have | 32 * We create this object by applying an anonymous function so that we can have |
33 * local variables (avoid polluting the global object) | 33 * local variables (avoid polluting the global object) |
34 */ | 34 */ |
35 chrome.send = (function() { | 35 chrome.send = (function() { |
36 var users = [ | 36 var users = [ |
37 { | 37 { |
38 name: 'Alan Beaker', | 38 name: 'Alan Beaker', |
39 emailAddress: 'beaker@chromium.org', | 39 emailAddress: 'beaker@chromium.org', |
40 imageUrl: '../../app/theme/avatar_beaker.png', | 40 imageUrl: '../../app/theme/avatar_beaker.png', |
41 canRemove: false | 41 canRemove: false |
42 }, | 42 }, |
43 { | 43 { |
44 name: 'Alex Briefcase', | 44 name: 'Alex Briefcase', |
45 emailAddress: 'briefcase@chromium.org', | 45 emailAddress: 'briefcase@chromium.org', |
46 imageUrl: '../../app/theme/avatar_briefcase.png', | 46 imageUrl: '../../app/theme/avatar_briefcase.png', |
47 canRemove: true | 47 canRemove: true |
48 }, | 48 }, |
49 { | 49 { |
50 name: 'Alex Circles', | 50 name: 'Alex Circles', |
51 emailAddress: 'circles@chromium.org', | 51 emailAddress: 'circles@chromium.org', |
52 imageUrl: '../../app/theme/avatar_circles.png', | 52 imageUrl: '../../app/theme/avatar_circles.png', |
53 canRemove: true | 53 canRemove: true |
54 }, | 54 }, |
55 { | 55 {name: 'Guest', emailAddress: '', imageUrl: '', canRemove: false} |
56 name: 'Guest', | |
57 emailAddress: '', | |
58 imageUrl: '', | |
59 canRemove: false | |
60 } | |
61 ]; | 56 ]; |
62 | 57 |
63 /** | 58 /** |
64 * Invoke the getAppsCallback function with a snapshot of the current app | 59 * Invoke the getAppsCallback function with a snapshot of the current app |
65 * database. | 60 * database. |
66 */ | 61 */ |
67 function sendGetUsersCallback() | 62 function sendGetUsersCallback() { |
68 { | |
69 // We don't want to hand out our array directly because the NTP will | 63 // We don't want to hand out our array directly because the NTP will |
70 // assume it owns the array and is free to modify it. For now we make a | 64 // assume it owns the array and is free to modify it. For now we make a |
71 // one-level deep copy of the array (since cloning the whole thing is | 65 // one-level deep copy of the array (since cloning the whole thing is |
72 // more work and unnecessary at the moment). | 66 // more work and unnecessary at the moment). |
73 getUsersCallback(users.slice(0)); | 67 getUsersCallback(users.slice(0)); |
74 } | 68 } |
75 | 69 |
76 /** | 70 /** |
77 * Like Array.prototype.indexOf but calls a predicate to test for match | 71 * Like Array.prototype.indexOf but calls a predicate to test for match |
78 * | 72 * |
(...skipping 11 matching lines...) Expand all Loading... |
90 } | 84 } |
91 | 85 |
92 /** | 86 /** |
93 * Get index into apps of an application object | 87 * Get index into apps of an application object |
94 * Requires the specified app to be present | 88 * Requires the specified app to be present |
95 * | 89 * |
96 * @param {string} id The ID of the application to locate. | 90 * @param {string} id The ID of the application to locate. |
97 * @return {number} The index in apps for an object with the specified ID. | 91 * @return {number} The index in apps for an object with the specified ID. |
98 */ | 92 */ |
99 function getUserIndex(name) { | 93 function getUserIndex(name) { |
100 var i = indexOfPred(apps, function(e) { return e.name === name;}); | 94 var i = indexOfPred(apps, function(e) { |
| 95 return e.name === name; |
| 96 }); |
101 if (i == -1) | 97 if (i == -1) |
102 alert('Error: got unexpected App ID'); | 98 alert('Error: got unexpected App ID'); |
103 return i; | 99 return i; |
104 } | 100 } |
105 | 101 |
106 /** | 102 /** |
107 * Get an user object given the user name | 103 * Get an user object given the user name |
108 * Requires | 104 * Requires |
109 * @param {string} name The user name to search for. | 105 * @param {string} name The user name to search for. |
110 * @return {Object} The corresponding user object. | 106 * @return {Object} The corresponding user object. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 }, true); | 215 }, true); |
220 })(); | 216 })(); |
221 } | 217 } |
222 | 218 |
223 /* Hack to add Element.classList to older browsers that don't yet support it. | 219 /* Hack to add Element.classList to older browsers that don't yet support it. |
224 From https://developer.mozilla.org/en/DOM/element.classList. | 220 From https://developer.mozilla.org/en/DOM/element.classList. |
225 */ | 221 */ |
226 if (typeof Element !== 'undefined' && | 222 if (typeof Element !== 'undefined' && |
227 !Element.prototype.hasOwnProperty('classList')) { | 223 !Element.prototype.hasOwnProperty('classList')) { |
228 (function() { | 224 (function() { |
229 var classListProp = 'classList', | 225 var classListProp = 'classList', protoProp = 'prototype', |
230 protoProp = 'prototype', | 226 elemCtrProto = Element[protoProp], objCtr = Object, |
231 elemCtrProto = Element[protoProp], | 227 strTrim = String[protoProp].trim || |
232 objCtr = Object, | 228 function() { |
233 strTrim = String[protoProp].trim || function() { | |
234 return this.replace(/^\s+|\s+$/g, ''); | 229 return this.replace(/^\s+|\s+$/g, ''); |
235 }, | 230 }, |
236 arrIndexOf = Array[protoProp].indexOf || function(item) { | 231 arrIndexOf = Array[protoProp].indexOf || |
| 232 function(item) { |
237 for (var i = 0, len = this.length; i < len; i++) { | 233 for (var i = 0, len = this.length; i < len; i++) { |
238 if (i in this && this[i] === item) { | 234 if (i in this && this[i] === item) { |
239 return i; | 235 return i; |
240 } | 236 } |
241 } | 237 } |
242 return -1; | 238 return -1; |
243 }, | 239 }, |
244 // Vendors: please allow content code to instantiate DOMExceptions | 240 // Vendors: please allow content code to instantiate DOMExceptions |
245 /** @constructor */ | 241 /** @constructor */ |
246 DOMEx = function(type, message) { | 242 DOMEx = |
| 243 function(type, message) { |
247 this.name = type; | 244 this.name = type; |
248 this.code = DOMException[type]; | 245 this.code = DOMException[type]; |
249 this.message = message; | 246 this.message = message; |
250 }, | 247 }, |
251 checkTokenAndGetIndex = function(classList, token) { | 248 checkTokenAndGetIndex = |
| 249 function(classList, token) { |
252 if (token === '') { | 250 if (token === '') { |
253 throw new DOMEx( | 251 throw new DOMEx( |
254 'SYNTAX_ERR', | 252 'SYNTAX_ERR', 'An invalid or illegal string was specified'); |
255 'An invalid or illegal string was specified' | |
256 ); | |
257 } | 253 } |
258 if (/\s/.test(token)) { | 254 if (/\s/.test(token)) { |
259 throw new DOMEx( | 255 throw new DOMEx( |
260 'INVALID_CHARACTER_ERR', | 256 'INVALID_CHARACTER_ERR', |
261 'String contains an invalid character' | 257 'String contains an invalid character'); |
262 ); | |
263 } | 258 } |
264 return arrIndexOf.call(classList, token); | 259 return arrIndexOf.call(classList, token); |
265 }, | 260 }, |
266 /** @constructor | 261 /** @constructor |
267 * @extends {Array} */ | 262 * @extends {Array} */ |
268 ClassList = function(elem) { | 263 ClassList = |
| 264 function(elem) { |
269 var trimmedClasses = strTrim.call(elem.className), | 265 var trimmedClasses = strTrim.call(elem.className), |
270 classes = trimmedClasses ? trimmedClasses.split(/\s+/) : []; | 266 classes = trimmedClasses ? trimmedClasses.split(/\s+/) : []; |
271 | 267 |
272 for (var i = 0, len = classes.length; i < len; i++) { | 268 for (var i = 0, len = classes.length; i < len; i++) { |
273 this.push(classes[i]); | 269 this.push(classes[i]); |
274 } | 270 } |
275 this._updateClassName = function() { | 271 this._updateClassName = function() { |
276 elem.className = this.toString(); | 272 elem.className = this.toString(); |
277 }; | 273 }; |
278 }, | 274 }, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 * @param {Object} selfObj Specifies the object which |this| should | 335 * @param {Object} selfObj Specifies the object which |this| should |
340 * point to when the function is run. If the value is null or undefined, | 336 * point to when the function is run. If the value is null or undefined, |
341 * it will default to the global object. | 337 * it will default to the global object. |
342 * @param {...*} var_args Additional arguments that are partially | 338 * @param {...*} var_args Additional arguments that are partially |
343 * applied to the function. | 339 * applied to the function. |
344 * @return {!Function} A partially-applied form of the function bind() was | 340 * @return {!Function} A partially-applied form of the function bind() was |
345 * invoked as a method of. | 341 * invoked as a method of. |
346 * @suppress {duplicate} | 342 * @suppress {duplicate} |
347 */ | 343 */ |
348 Function.prototype.bind = function(selfObj, var_args) { | 344 Function.prototype.bind = function(selfObj, var_args) { |
349 var slice = [].slice, | 345 var slice = [].slice, args = slice.call(arguments, 1), self = this, |
350 args = slice.call(arguments, 1), | |
351 self = this, | |
352 /** @constructor */ | 346 /** @constructor */ |
353 nop = function() {}, | 347 nop = function() {}, bound = function() { |
354 bound = function() { | 348 return self.apply( |
355 return self.apply(this instanceof nop ? this : (selfObj || {}), | 349 this instanceof nop ? this : (selfObj || {}), |
356 args.concat(slice.call(arguments))); | 350 args.concat(slice.call(arguments))); |
357 }; | 351 }; |
358 nop.prototype = self.prototype; | 352 nop.prototype = self.prototype; |
359 bound.prototype = new nop(); | 353 bound.prototype = new nop(); |
360 return bound; | 354 return bound; |
361 }; | 355 }; |
362 } | 356 } |
363 | |
OLD | NEW |