diff -r f11b234497f7 -r 61c384dda19e src/js/utils.js --- a/src/js/utils.js Fri Apr 27 19:18:21 2012 +0200 +++ b/src/js/utils.js Thu May 03 17:52:52 2012 +0200 @@ -1,5 +1,9 @@ /* utils.js - various utils that don't belong anywhere else */ +IriSP.jqEscape = function(_text) { + return text.replace(/(:|\.)/g,'\\$1'); +} + IriSP.getLib = function(lib) { if (IriSP.libFiles.useCdn && typeof IriSP.libFiles.cdn[lib] == "string") { return IriSP.libFiles.cdn[lib]; @@ -8,7 +12,7 @@ return IriSP.libFiles.locations[lib]; } if (typeof IriSP.libFiles.inDefaultDir[lib] == "string") { - return IriSP.libFiles.defaultDir + IriSP.libFiles.inDefaultDir[lib]; + return IriSP.libFiles.defaultDir + '/' + IriSP.libFiles.inDefaultDir[lib]; } } @@ -18,136 +22,4 @@ type : "text/css", href : _cssFile }).appendTo('head'); -} - -/* -IriSP.padWithZeros = function(num) { - if (Math.abs(num) < 10) { - return "0" + num.toString(); - } else { - return num.toString(); - } -}; - -/* convert a number of milliseconds to a tuple of the form - [hours, minutes, seconds] - -IriSP.msToTime = function(ms) { - return IriSP.secondsToTime(ms / 1000); -} - -/* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */ -IriSP.formatTweet = function(tweet) { - /* - an array of arrays which hold a regexp and its replacement. - */ - var regExps = [ - /* copied from http://codegolf.stackexchange.com/questions/464/shortest-url-regex-match-in-javascript/480#480 */ - [/((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi, "$1"], - [/@(\w+)/gi, "@$1"], // matches a @handle - [/#(\w+)/gi, "#$1"],// matches a hashtag - [/(\+\+)/gi, "$1"], - [/(--)/gi, "$1"], - [/(==)/gi, "$1"], - [/(\?\?)/gi, "$1"] - ]; - - var i = 0; - for(i = 0; i < regExps.length; i++) { - tweet = tweet.replace(regExps[i][0], regExps[i][1]); - } - - return tweet; -}; -/* -IriSP.countProperties = function(obj) { - var count = 0; - - for(var prop in obj) { - if(obj.hasOwnProperty(prop)) - ++count; - } - - return count; -}; - -// conversion de couleur Decimal vers HexaDecimal || 000 si fff -IriSP.DEC_HEXA_COLOR = function (dec) { - var val = +dec; - var str = val.toString(16); - var zeroes = ""; - if (str.length < 6) { - for (var i = 0; i < 6 - str.length; i++) - zeroes += "0"; - } - return zeroes + str; -}; - -/* shortcut to have global variables in templates -IriSP.templToHTML = function(template, values) { - var params = IriSP._.extend( - { - "l10n" : IriSP.i18n.getMessages() - }, - values); - return Mustache.to_html(template, params); -}; - -/* we need to be stricter than encodeURIComponent, - because of twitter -*/ -IriSP.encodeURI = function(str) { - return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). - replace(/\)/g, '%29').replace(/\*/g, '%2A'); -} - -IriSP.jqEscape = function(text) { - return text.replace(/(:|\.)/g,'\\$1') -} - -IriSP.jqId = function (text) { - return IriSP.jQuery('#' + IriSP.jqEscape(text)); - } - -/** returns an url to share on facebook */ -IriSP.mkFbUrl = function(url, text) { - if (typeof(text) === "undefined") - text = "I'm watching "; - - return "http://www.facebook.com/share.php?u=" + IriSP.encodeURI(text) + IriSP.shorten_url(url); -}; - -/** returns an url to share on twitter */ -IriSP.mkTweetUrl = function(url, text) { - if (typeof(text) === "undefined") - text = "I'm watching "; - - return "http://twitter.com/home?status=" + IriSP.encodeURI(text) + IriSP.shorten_url(url); -}; - -/** returns an url to share on google + */ -IriSP.mkGplusUrl = function(url, text) { - return "https://plusone.google.com/_/+1/confirm?hl=en&url=" + IriSP.shorten_url(url); -}; - -/** get a property that can have multiple names **/ - -/** issue a call to an url shortener and return the shortened url */ -IriSP.shorten_url = function(url) { - return encodeURIComponent(url); -}; - - -/* for ie compatibility -if (Object.prototype.__defineGetter__&&!Object.defineProperty) { - Object.defineProperty=function(obj,prop,desc) { - if ("get" in desc) obj.__defineGetter__(prop,desc.get); - if ("set" in desc) obj.__defineSetter__(prop,desc.set); - } -} -*/ - -/* Creates regexps from text */ -IriSP.regexpFromText = function(_text) { - return new RegExp('(' + _text.replace(/(\W)/gim,'\\$1') + ')','gim'); -} +} \ No newline at end of file