diff --git a/jquery.translate.js b/jquery.translate.js index 980c8fa..e919d00 100644 --- a/jquery.translate.js +++ b/jquery.translate.js @@ -14,10 +14,12 @@ $.fn.translate = function(options) { var that = this; //a reference to ourselves - + var settings = { css: "trn", - lang: "en"/*, + lang: "en", + tooltip: false, + langTooltip: "pt"/*, t: { "translate": { pt: "tradução", @@ -28,16 +30,16 @@ settings = $.extend(settings, options || {}); if (settings.css.lastIndexOf(".", 0) !== 0) //doesn't start with '.' settings.css = "." + settings.css; - + var t = settings.t; - + //public methods this.lang = function(l) { if (l) { settings.lang = l; this.translate(settings); //translate everything } - + return settings.lang; }; @@ -52,7 +54,7 @@ //not found, return index return index; } - + if (res) return res; else @@ -62,24 +64,45 @@ this.g = this.get; - + //main - this.find(settings.css).each(function(i) { - var $this = $(this); + if(settings.tooltip === false) { + this.find(settings.css).each(function(i) { + var $this = $(this); + + var trn_key = $this.attr("data-trn-key"); + if (!trn_key) { + trn_key = $this.html(); + $this.attr("data-trn-key", trn_key); //store key for next time + } + + $this.html(that.get(trn_key)); + }); + + return this; + + } else { + $(settings.css).hover(function(){ + $(this).css('cursor', 'pointer'); + + var index = $(this).data('trn-key'); + res = t[index][settings.langTooltip]; + + $(this).attr('rel', 'tooltip'); + $(this).attr('title', res); + + $(this).tooltip({placement: 'bottom',trigger: 'manual'}).tooltip('show'); + + }, function(){ + $(this).tooltip('destroy'); + + $(this).removeAttr('rel'); + $(this).removeAttr('title'); + }); + + } - var trn_key = $this.attr("data-trn-key"); - if (!trn_key) { - trn_key = $this.html(); - $this.attr("data-trn-key", trn_key); //store key for next time - } - $this.html(that.get(trn_key)); - }); - - - return this; - - }; -})(jQuery); \ No newline at end of file +})(jQuery);