vendor/assets/javascripts/textext.plugin.prompt.js in textext-rails-0.1.0 vs vendor/assets/javascripts/textext.plugin.prompt.js in textext-rails-0.2.0

- old
+ new

@@ -1,10 +1,10 @@ /** * jQuery TextExt Plugin - * http://alexgorbatchev.com/textext + * http://textextjs.com * - * @version 1.2.0 + * @version 1.3.1 * @copyright Copyright (C) 2011 Alex Gorbatchev. All rights reserved. * @license MIT License */ (function($) { @@ -107,23 +107,36 @@ * @date 2011/08/18 * @id TextExtPrompt.init */ p.init = function(core) { - var self = this, - container + var self = this, + placeholderKey = 'placeholder', + container, + prompt ; self.baseInit(core, DEFAULT_OPTS); container = $(self.opts(OPT_HTML_PROMPT)); $(self).data('container', container); self.core().wrapElement().append(container); self.setPrompt(self.opts(OPT_PROMPT)); - if(self.val().length > 0) + prompt = core.input().attr(placeholderKey); + + if(!prompt) + prompt = self.opts(OPT_PROMPT); + + // clear placeholder attribute if set + core.input().attr(placeholderKey, ''); + + if(prompt) + self.setPrompt(prompt); + + if($.trim(self.val()).length > 0) self.hidePrompt(); self.on({ blur : self.onBlur, focus : self.onFocus, @@ -206,12 +219,11 @@ { var self = this; self.startTimer('prompt', 0.1, function() { - if(self.val().length === 0) - self.showPrompt(); + self.showPrompt(); }); }; /** * Shows prompt HTML element. @@ -222,10 +234,15 @@ * @date 2011/08/22 * @id TextExtPrompt.showPrompt */ p.showPrompt = function() { - this.containerElement().removeClass(CSS_HIDE_PROMPT); + var self = this, + input = self.input() + ; + + if($.trim(self.val()).length === 0 && !input.is(':focus')) + self.containerElement().removeClass(CSS_HIDE_PROMPT); }; /** * Hides prompt HTML element. *