From 05585779ab70aa6017cbf38b704f8c7231d37883 Mon Sep 17 00:00:00 2001 From: Steven Bull Date: Fri, 10 Feb 2012 18:28:15 -0800 Subject: [PATCH] Avoid calling placeholder functions in valHooks unless .placeholder() has been invoked on the element. --- jquery.placeholder.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/jquery.placeholder.js b/jquery.placeholder.js index 209d200..8fea7f0 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -26,6 +26,7 @@ 'focus.placeholder': clearPlaceholder, 'blur.placeholder': setPlaceholder }) + .data('jquery-placeholder-enabled', true) .trigger('blur.placeholder').end(); }; @@ -34,17 +35,23 @@ hooks = { 'get': function(element) { - var $element = $(element); - return $element.hasClass('placeholder') ? '' : element.value; + var $element = $(element), + isPlaceholderEnabled = $element.data('jquery-placeholder-enabled'); + return (isPlaceholderEnabled && $element.hasClass('placeholder')) ? '' : element.value; }, 'set': function(element, value) { - var $element = $(element); - if (value == '') { - element.value = value; - // We can’t use `triggerHandler` here because of dummy text/password inputs :( - setPlaceholder.call(element); - } else if ($element.hasClass('placeholder')) { - clearPlaceholder.call(element, true, value) || (element.value = value); + var $element = $(element) + isPlaceholderEnabled = $element.data('jquery-placeholder-enabled'); + if (isPlaceholderEnabled) { + if (value == '') { + element.value = value; + // We can’t use `triggerHandler` here because of dummy text/password inputs :( + setPlaceholder.call(element); + } else if ($element.hasClass('placeholder')) { + clearPlaceholder.call(element, true, value) || (element.value = value); + } else { + element.value = value; + } } else { element.value = value; }