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