|
1 /* Copyright 2009 the Melange authors. |
|
2 * |
|
3 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 * you may not use this file except in compliance with the License. |
|
5 * You may obtain a copy of the License at |
|
6 * |
|
7 * http://www.apache.org/licenses/LICENSE-2.0 |
|
8 * |
|
9 * Unless required by applicable law or agreed to in writing, software |
|
10 * distributed under the License is distributed on an "AS IS" BASIS, |
|
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 * See the License for the specific language governing permissions and |
|
13 * limitations under the License. |
|
14 */ |
|
15 |
|
16 /* |
|
17 * |
|
18 * @author <a href="mailto:ajaksu@gmail.com">Daniel Diniz</a> |
|
19 * @author <a href="mailto:jamesalexanderlevy@gmail.com">James Levy</a> |
|
20 */ |
|
21 |
|
22 (function ($) { |
|
23 |
|
24 var map = []; |
|
25 |
|
26 $.preserveDefaultText = { |
|
27 |
|
28 ShowAll: function () { |
|
29 for (var i = 0; i < map.length; i = i + 1) { |
|
30 if (map[i].obj.val() === "") { |
|
31 map[i].obj.val(map[i].text); |
|
32 map[i].obj.css("color", map[i].WatermarkColor); |
|
33 } |
|
34 else { |
|
35 map[i].obj.css("color", map[i].DefaultColor); |
|
36 } |
|
37 } |
|
38 }, |
|
39 |
|
40 HideAll: function () { |
|
41 for (var i = 0; i < map.length; i = i + 1) { |
|
42 if (map[i].obj.val() === map[i].text) { |
|
43 map[i].obj.val(""); |
|
44 } |
|
45 } |
|
46 } |
|
47 }; |
|
48 |
|
49 $.fn.preserveDefaultText = function (text, color) { |
|
50 |
|
51 if (!color) { |
|
52 color = "#aaa"; |
|
53 } |
|
54 |
|
55 return this.each( |
|
56 function () { |
|
57 var input = $(this); |
|
58 var defaultColor = input.css("color"); |
|
59 |
|
60 map[map.length] = { |
|
61 text: text, |
|
62 obj: input, |
|
63 DefaultColor: defaultColor, |
|
64 WatermarkColor: color |
|
65 }; |
|
66 |
|
67 function clearMessage() { |
|
68 if (input.val() === text) { |
|
69 input.val(""); |
|
70 } |
|
71 input.css("color", defaultColor); |
|
72 } |
|
73 |
|
74 function insertMessage() { |
|
75 if (input.val().length === 0 || input.val() === text) { |
|
76 input.val(text); |
|
77 input.css("color", color); |
|
78 } |
|
79 else { |
|
80 input.css("color", defaultColor); |
|
81 } |
|
82 } |
|
83 |
|
84 input.focus(clearMessage); |
|
85 input.blur(insertMessage); |
|
86 input.change(insertMessage); |
|
87 |
|
88 insertMessage(); |
|
89 }); |
|
90 }; |
|
91 }(jQuery)); |