diff --git a/CHANGELOG b/CHANGELOG index 5ab34b9..96fcbb8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +- version: 2.0.4 + - tholder: fixed issue with \r's not working in Google Chrome. Now just strips \n or \r - version: 2.0.3 - glennfu: added support for title's with \r's in them - version: 2.0.3 diff --git a/jquery.labelify.js b/jquery.labelify.js index ba6c44e..305439a 100644 --- a/jquery.labelify.js +++ b/jquery.labelify.js @@ -7,7 +7,8 @@ * @author Stuart Langridge * @author Garrett LeSage * @author Glenn Sidney - * @version 2.0.3 + * @author Tom Holder + * @version 2.0.4 */ /** @@ -78,20 +79,21 @@ if (typeof lookup !== "function" || !lookup(this)) { return; } $item.bind('focus.label',function() { - if (this.value.replace(/\n/g, "\r") === $(this).data("label")) { hideLabel(this); } + if (this.value.replace(/\n|\r/g, "") === $(this).data("label").replace(/\n|\r/g, "")) { hideLabel(this); } }).bind('blur.label',function(){ if (this.value === '') { showLabel(this); } - }).data('label',lookup(this).replace(/\n/g,'')); // strip label's newlines - + }).data('label',lookup(this).replace(/\n/g,'\r')); // strip label's newlines + removeValuesOnExit = function() { $labelified_elements.each(function(){ - if (this.value.replace(/\n/g, "\r") === $(this).data("label")) { hideLabel(this); } + var $label = $(this).data("label"); + if ($label && this.value.replace(/\n|\r/g, "") === $label.replace(/\n|\r/g, "")) { hideLabel(this); } }); }; - + $item.parents("form").submit(removeValuesOnExit); $(window).unload(removeValuesOnExit); - + if (this.value !== '') { // user started typing; don't overwrite his/her text! return;