Skip to content

Commit

Permalink
Fix Placeholders.disable/enable methods when applied to all affected …
Browse files Browse the repository at this point in the history
…elements. Closes jamesallardice#23
  • Loading branch information
James Allardice committed Apr 29, 2013
1 parent 7b62d1f commit e98f764
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@

// Show the placeholder value on a single element. Returns true if the placeholder was shown and false if it was not (because it was already visible)
function showPlaceholder(elem) {
var type;
if (elem.value === "") {
var type,
val = elem.getAttribute(ATTR_CURRENT_VAL);
if (elem.value === "" && val) {
elem.setAttribute(ATTR_ACTIVE, "true");
elem.value = elem.getAttribute(ATTR_CURRENT_VAL);
elem.value = val;
elem.className += " " + placeholderClassName;

// If the type of element needs to change, change it (e.g. password inputs)
Expand All @@ -101,20 +102,20 @@

function handleElem(node, callback) {

var inputs, textareas, elem, len, i;
var handleInputs, handleTextareas, elem, len, i;

// Check if the passed in node is an input/textarea (in which case it can't have any affected descendants)
if (node && node.getAttribute(ATTR_CURRENT_VAL)) {
callback(node);
} else {

// If an element was passed in, get all affected descendants. Otherwise, get all affected elements in document
inputs = node ? node.getElementsByTagName("input") : inputs;
textareas = node ? node.getElementsByTagName("textarea") : textareas;
handleInputs = node ? node.getElementsByTagName("input") : inputs;
handleTextareas = node ? node.getElementsByTagName("textarea") : textareas;

// Run the callback for each element
for (i = 0, len = inputs.length + textareas.length; i < len; i++) {
elem = i < inputs.length ? inputs[i] : textareas[i - inputs.length];
for (i = 0, len = handleInputs.length + handleTextareas.length; i < len; i++) {
elem = i < handleInputs.length ? handleInputs[i] : handleTextareas[i - handleInputs.length];
callback(elem);
}
}
Expand Down

0 comments on commit e98f764

Please sign in to comment.