From c50a5fa61e157e11449dfea01689533f6b442fa7 Mon Sep 17 00:00:00 2001 From: Tom Holder Date: Fri, 22 Oct 2010 11:12:10 +0100 Subject: [PATCH 1/2] Fixed issue with \r not showing in Google Chrome --- CHANGELOG | 2 ++ jquery.labelify.js | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) 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..98c55bf 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 */ /** @@ -65,6 +66,7 @@ } return $(this).each(function() { + var $item = $(this), removeValuesOnExit; @@ -78,14 +80,14 @@ 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(/\r|\n/g, "") === $(this).data("label").replace(/\r|\n/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)); // strip label's newlines removeValuesOnExit = function() { $labelified_elements.each(function(){ - if (this.value.replace(/\n/g, "\r") === $(this).data("label")) { hideLabel(this); } + if (this.value.replace(/\r|\n/g, "") === $(this).data("label").replace(/\r|\n/g, "")) { hideLabel(this); } }); }; From afce9970b4684fe33687a57dfe63adb3245678ec Mon Sep 17 00:00:00 2001 From: Tom Holder Date: Fri, 22 Oct 2010 12:51:29 +0100 Subject: [PATCH 2/2] Fixed issue with labels not being removed due to possible null label --- jquery.labelify.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jquery.labelify.js b/jquery.labelify.js index 98c55bf..305439a 100644 --- a/jquery.labelify.js +++ b/jquery.labelify.js @@ -66,7 +66,6 @@ } return $(this).each(function() { - var $item = $(this), removeValuesOnExit; @@ -80,20 +79,21 @@ if (typeof lookup !== "function" || !lookup(this)) { return; } $item.bind('focus.label',function() { - if (this.value.replace(/\r|\n/g, "") === $(this).data("label").replace(/\r|\n/g, "")) { 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)); // 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(/\r|\n/g, "") === $(this).data("label").replace(/\r|\n/g, "")) { 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;