src/js/utils.js
branchnew-model
changeset 875 43629caa77bc
parent 870 2c025db10a10
child 882 61c384dda19e
equal deleted inserted replaced
874:38b65761a7d5 875:43629caa77bc
     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. */
    36      tweet = tweet.replace(regExps[i][0], regExps[i][1]);
    57      tweet = tweet.replace(regExps[i][0], regExps[i][1]);
    37   }
    58   }
    38   
    59   
    39   return tweet;
    60   return tweet;
    40 };
    61 };
    41 
    62 /*
    42 IriSP.countProperties = function(obj) {
    63 IriSP.countProperties = function(obj) {
    43     var count = 0;
    64     var count = 0;
    44 
    65 
    45     for(var prop in obj) {
    66     for(var prop in obj) {
    46         if(obj.hasOwnProperty(prop))
    67         if(obj.hasOwnProperty(prop))
    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);