|
1 /* |
|
2 * Copyright (c) 2007 Josh Bush (digitalbush.com) |
|
3 * |
|
4 * Permission is hereby granted, free of charge, to any person |
|
5 * obtaining a copy of this software and associated documentation |
|
6 * files (the "Software"), to deal in the Software without |
|
7 * restriction, including without limitation the rights to use, |
|
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 * copies of the Software, and to permit persons to whom the |
|
10 * Software is furnished to do so, subject to the following |
|
11 * conditions: |
|
12 |
|
13 * The above copyright notice and this permission notice shall be |
|
14 * included in all copies or substantial portions of the Software. |
|
15 * |
|
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 * OTHER DEALINGS IN THE SOFTWARE. |
|
24 */ |
|
25 |
|
26 /* |
|
27 * Version: Beta 1 |
|
28 * Release: 2007-06-01 |
|
29 */ |
|
30 (function($) { |
|
31 var map=new Array(); |
|
32 $.Watermark = { |
|
33 ShowAll:function(){ |
|
34 for (var i=0;i<map.length;i++){ |
|
35 if(map[i].obj.val()==""){ |
|
36 map[i].obj.val(map[i].text); |
|
37 map[i].obj.css("color",map[i].WatermarkColor); |
|
38 }else{ |
|
39 map[i].obj.css("color",map[i].DefaultColor); |
|
40 } |
|
41 } |
|
42 }, |
|
43 HideAll:function(){ |
|
44 for (var i=0;i<map.length;i++){ |
|
45 if(map[i].obj.val()==map[i].text) |
|
46 map[i].obj.val(""); |
|
47 } |
|
48 } |
|
49 }; |
|
50 |
|
51 $.fn.Watermark = function(text,color) { |
|
52 if(!color) |
|
53 color="#cccccc"; |
|
54 return this.each( |
|
55 function(){ |
|
56 var input=$(this); |
|
57 var defaultColor=input.css("color"); |
|
58 map[map.length]={text:text,obj:input,DefaultColor:defaultColor,WatermarkColor:color}; |
|
59 function clearMessage(){ |
|
60 if(input.val()==text) |
|
61 input.val(""); |
|
62 input.css("color",defaultColor); |
|
63 } |
|
64 |
|
65 function insertMessage(){ |
|
66 if(input.val().length==0 || input.val()==text){ |
|
67 input.val(text); |
|
68 input.css("color",color); |
|
69 }else |
|
70 input.css("color",defaultColor); |
|
71 } |
|
72 |
|
73 input.focus(clearMessage); |
|
74 input.blur(insertMessage); |
|
75 input.change(insertMessage); |
|
76 |
|
77 insertMessage(); |
|
78 } |
|
79 ); |
|
80 }; |
|
81 })(jQuery); |