Permalink
Browse files

add a test for textareas

  • Loading branch information...
1 parent b100af3 commit bc651bd6f30303d97f939909a63fc196f2f37978 @madrobby committed Jan 7, 2009
Showing with 23 additions and 18 deletions.
  1. +18 −16 defaultValueActsAsHint/defaultvalueactsashint.js
  2. +5 −2 defaultValueActsAsHint/test.html
@@ -1,16 +1,18 @@
-Element.addMethods('input', {
-
- defaultValueActsAsHint: function(element){
- element = $(element);
- element._default = element.value;
-
- return element.observe('focus', function(){
- if(element._default != element.value) return;
- element.removeClassName('hint').value = '';
- }).observe('blur', function(){
- if(element.value.strip() != '') return;
- element.addClassName('hint').value = element._default;
- }).addClassName('hint');
- }
-
-});
+(function(){
+ var methods = {
+ defaultValueActsAsHint: function(element){
@haraldmartin

haraldmartin Jan 20, 2009

You could write this like:



Element.addMethods(['input', 'textarea'], {
  ...
});


instead.

+ element = $(element);
+ element._default = element.value;
+
+ return element.observe('focus', function(){
+ if(element._default != element.value) return;
+ element.removeClassName('hint').value = '';
+ }).observe('blur', function(){
+ if(element.value.strip() != '') return;
+ element.addClassName('hint').value = element._default;
+ }).addClassName('hint');
+ }
+ };
+
+ $w('input textarea').each(function(tag){ Element.addMethods(tag, methods) });
+})();
@@ -2,12 +2,12 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
- <title>blech</title>
+ <title>defaultValueActsAsHint functional test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="../lib/prototype/dist/prototype.js" type="text/javascript"></script>
<script src="defaultvalueactsashint.js" type="text/javascript"></script>
<style type="text/css" media="screen">
- input.hint {
+ .hint {
color: #aaa;
font-style: italic;
}
@@ -16,10 +16,13 @@
<body>
<input type="text" id="foo" name="foo" value="Enter something!"/>
<input type="text" id="bar" name="bar" value="Or something else!"/>
+ <textarea id="baz" name="baz">Replace this text with something else</textarea>
+
<script type="text/javascript" charset="utf-8">
$('foo').defaultValueActsAsHint();
$('bar').defaultValueActsAsHint();
+ $('baz').defaultValueActsAsHint();
</script>
</body>
</html>

0 comments on commit bc651bd

Please sign in to comment.