Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Remove whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Godisemo committed Feb 20, 2012
1 parent 13f95ad commit abf1ef1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions example.html
Expand Up @@ -2,7 +2,7 @@
<head>
<meta charset="utf-8">
<title>jQuery auto-placeholders</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="min/jquery.auto-placeholders.js"></script>

Expand Down Expand Up @@ -35,18 +35,19 @@
<label for="phone">Phone:</label>
<input type="text" name="phone" id="phone" placeholder="123456" />
</div>


<div>
<label for="message">Message:</label>
<textarea cols="40" rows="8" name="message" placeholder="Put your message here!"></textarea>
</div>

<div>
<input type="submit" />
</div>

</form>

</body>
<script>
$("#example_form").autoPlaceholders()
Expand Down
5 changes: 3 additions & 2 deletions jquery.auto-placeholders.coffee
Expand Up @@ -29,19 +29,20 @@ $.fn.autoPlaceholders = ->

# Find all inputs and textareas in the selected element.
$("input, textarea", this).each ->

# Get their placeholder value(if they have any) and add it as value.
# Also add a CSS-class for blurred inputs to mimic the placeholder look.
if $(this).attr("placeholder")?
placeholder = $(this).attr "placeholder"

$(this).val(placeholder).addClass "placeholder"

# Bind focus event, so when user clicks the input the value disapears,
# if it's the same as placeholder.
$(this).bind "focus", ->
if $(this).hasClass("placeholder")
$(this).val("").removeClass "placeholder"


# Bind blur event, so when user exit the input the value resets if
# the input is empty.
Expand Down

0 comments on commit abf1ef1

Please sign in to comment.