1 /* utils.js - various utils that don't belong anywhere else */ |
1 /* utils.js - various utils that don't belong anywhere else */ |
2 |
2 |
|
3 IriSP.getLib = function(lib) { |
|
4 if (IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string") { |
|
5 return IriSP.libFiles.cdn[lib]; |
|
6 } |
|
7 if (typeof IriSP.libFiles.locations[lib] == "string") { |
|
8 return IriSP.libFiles.locations[lib]; |
|
9 } |
|
10 if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") { |
|
11 return IriSP.libFiles.defaultDir + IriSP.libFiles.inDefaultDir[lib]; |
|
12 } |
|
13 } |
|
14 |
|
15 IriSP.loadCss = function(_cssFile) { |
|
16 IriSP.jQuery("<link>", { |
|
17 rel : "stylesheet", |
|
18 type : "text/css", |
|
19 href : _cssFile |
|
20 }).appendTo('head'); |
|
21 } |
|
22 |
|
23 /* |
3 IriSP.padWithZeros = function(num) { |
24 IriSP.padWithZeros = function(num) { |
4 if (Math.abs(num) < 10) { |
25 if (Math.abs(num) < 10) { |
5 return "0" + num.toString(); |
26 return "0" + num.toString(); |
6 } else { |
27 } else { |
7 return num.toString(); |
28 return num.toString(); |
8 } |
29 } |
9 }; |
30 }; |
10 |
31 |
11 /* convert a number of milliseconds to a tuple of the form |
32 /* convert a number of milliseconds to a tuple of the form |
12 [hours, minutes, seconds] |
33 [hours, minutes, seconds] |
13 */ |
34 |
14 IriSP.msToTime = function(ms) { |
35 IriSP.msToTime = function(ms) { |
15 return IriSP.secondsToTime(ms / 1000); |
36 return IriSP.secondsToTime(ms / 1000); |
16 } |
37 } |
17 |
38 |
18 /* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */ |
39 /* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */ |
60 zeroes += "0"; |
81 zeroes += "0"; |
61 } |
82 } |
62 return zeroes + str; |
83 return zeroes + str; |
63 }; |
84 }; |
64 |
85 |
65 /* shortcut to have global variables in templates */ |
86 /* shortcut to have global variables in templates |
66 IriSP.templToHTML = function(template, values) { |
87 IriSP.templToHTML = function(template, values) { |
67 var params = IriSP.underscore.extend( |
88 var params = IriSP._.extend( |
68 { |
89 { |
69 "l10n" : IriSP.i18n.getMessages() |
90 "l10n" : IriSP.i18n.getMessages() |
70 }, |
91 }, |
71 values); |
92 values); |
72 return Mustache.to_html(template, params); |
93 return Mustache.to_html(template, params); |