| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 var singleton = element.init && element.init.apply(element, arguments); | 254 var singleton = element.init && element.init.apply(element, arguments); |
| 255 if (singleton) | 255 if (singleton) |
| 256 return singleton; | 256 return singleton; |
| 257 return element; | 257 return element; |
| 258 } | 258 } |
| 259 | 259 |
| 260 extended.prototype = prototype; | 260 extended.prototype = prototype; |
| 261 return extended; | 261 return extended; |
| 262 } | 262 } |
| 263 | 263 |
| 264 function createRelativeTimeDescriptor(divisorInMilliseconds, unit) | |
| 265 { | |
| 266 return function(delta) { | |
| 267 var deltaInUnits = delta / divisorInMilliseconds; | |
| 268 return (deltaInUnits).toFixed(0) + ' ' + unit + (deltaInUnits >= 1.5 ? '
s' : '') + ' ago'; | |
| 269 } | |
| 270 } | |
| 271 | |
| 272 var kMinuteInMilliseconds = 60 * 1000; | |
| 273 var kRelativeTimeSlots = [ | |
| 274 { | |
| 275 maxMilliseconds: kMinuteInMilliseconds, | |
| 276 describe: function(delta) { return 'Just now'; } | |
| 277 }, | |
| 278 { | |
| 279 maxMilliseconds: 60 * kMinuteInMilliseconds, | |
| 280 describe: createRelativeTimeDescriptor(kMinuteInMilliseconds, 'minute') | |
| 281 }, | |
| 282 { | |
| 283 maxMilliseconds: 24 * 60 * kMinuteInMilliseconds, | |
| 284 describe: createRelativeTimeDescriptor(60 * kMinuteInMilliseconds, 'hour
') | |
| 285 }, | |
| 286 { | |
| 287 maxMilliseconds: Number.MAX_VALUE, | |
| 288 describe: createRelativeTimeDescriptor(24 * 60 * kMinuteInMilliseconds,
'day') | |
| 289 } | |
| 290 ]; | |
| 291 | |
| 292 /* | |
| 293 Represent time as descriptive text, relative to now and gradually decreasing
in precision: | |
| 294 delta < 1 minutes => Just Now | |
| 295 delta < 60 minutes => X minute[s] ago | |
| 296 delta < 24 hours => X hour[s] ago | |
| 297 delta < inf => X day[s] ago | |
| 298 */ | |
| 299 base.relativizeTime = function(time) | |
| 300 { | |
| 301 var result; | |
| 302 var delta = new Date().getTime() - time; | |
| 303 kRelativeTimeSlots.some(function(slot) { | |
| 304 if (delta >= slot.maxMilliseconds) | |
| 305 return false; | |
| 306 | |
| 307 result = slot.describe(delta); | |
| 308 return true; | |
| 309 }); | |
| 310 return result; | |
| 311 } | |
| 312 | |
| 313 base.getURLParameter = function(name) | 264 base.getURLParameter = function(name) |
| 314 { | 265 { |
| 315 var match = RegExp(name + '=' + '(.+?)(&|$)').exec(location.search); | 266 var match = RegExp(name + '=' + '(.+?)(&|$)').exec(location.search); |
| 316 if (!match) | 267 if (!match) |
| 317 return null; | 268 return null; |
| 318 return decodeURI(match[1]) | 269 return decodeURI(match[1]) |
| 319 } | 270 } |
| 320 | 271 |
| 321 base.underscoredBuilderName = function(builderName) | 272 base.underscoredBuilderName = function(builderName) |
| 322 { | 273 { |
| 323 return builderName.replace(/[ .()]/g, '_'); | 274 return builderName.replace(/[ .()]/g, '_'); |
| 324 } | 275 } |
| 325 | 276 |
| 326 })(); | 277 })(); |
| OLD | NEW |