Showing
9 changed files
with
699 additions
and
0 deletions
pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | |
3 | + xmlns="http://maven.apache.org/POM/4.0.0" | |
4 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
5 | + <modelVersion>4.0.0</modelVersion> | |
6 | + <parent> | |
7 | + <groupId>org.richfaces.sandbox</groupId> | |
8 | + <artifactId>ui</artifactId> | |
9 | + <version>3.3.3.Final</version> | |
10 | + </parent> | |
11 | + <groupId>org.richfaces.sandbox.ui</groupId> | |
12 | + <artifactId>watermark</artifactId> | |
13 | + <name>watermark</name> | |
14 | + <build> | |
15 | + <plugins> | |
16 | + <plugin> | |
17 | + <groupId>org.richfaces.cdk</groupId> | |
18 | + <artifactId>maven-cdk-plugin</artifactId> | |
19 | + <version>${project.version}</version> | |
20 | + <executions> | |
21 | + <execution> | |
22 | + <phase>generate-sources</phase> | |
23 | + <goals> | |
24 | + <goal>generate</goal> | |
25 | + </goals> | |
26 | + </execution> | |
27 | + </executions> | |
28 | + <configuration> | |
29 | + <library> | |
30 | + <prefix>org.richfaces.sandbox.ui</prefix> | |
31 | + <taglib> | |
32 | + <shortName>watermark</shortName> | |
33 | + <uri>http://richfaces.org/watermark</uri> | |
34 | + </taglib> | |
35 | + </library> | |
36 | + </configuration> | |
37 | + </plugin> | |
38 | + <plugin> | |
39 | + <artifactId>maven-compiler-plugin</artifactId> | |
40 | + <inherited>true</inherited> | |
41 | + <configuration> | |
42 | + <source>1.5</source> | |
43 | + <target>1.5</target> | |
44 | + <encoding>${project.build.sourceEncoding}</encoding> | |
45 | + </configuration> | |
46 | + </plugin> | |
47 | + <plugin> | |
48 | + <groupId>org.apache.maven.plugins</groupId> | |
49 | + <artifactId>maven-resources-plugin</artifactId> | |
50 | + <version>2.2</version> | |
51 | + <configuration> | |
52 | + <encoding>${project.build.sourceEncoding}</encoding> | |
53 | + </configuration> | |
54 | + </plugin> | |
55 | + </plugins> | |
56 | + </build> | |
57 | + <dependencies> | |
58 | + <dependency> | |
59 | + <groupId>org.richfaces.framework</groupId> | |
60 | + <artifactId>richfaces-impl</artifactId> | |
61 | + <version>${project.version}</version> | |
62 | + </dependency> | |
63 | + </dependencies> | |
64 | + <properties> | |
65 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
66 | + </properties> | |
67 | +</project> | |
68 | + | ... | ... |
src/main/config/component/readme
0 → 100755
src/main/config/component/watermark.xml
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE components PUBLIC "-//AJAX4JSF//CDK Generator config/EN" | |
2 | + "http://labs.jboss.com/jbossrichfaces/component-config.dtd"> | |
3 | + | |
4 | +<components> | |
5 | + <component> | |
6 | + <name>org.richfaces.Watermark</name> | |
7 | + <family>org.richfaces.Watermark</family> | |
8 | + <classname>org.richfaces.component.html.HtmlWatermark</classname> | |
9 | + <superclass>org.richfaces.component.UIWatermark</superclass> | |
10 | + <description> | |
11 | + <![CDATA[]]> | |
12 | + </description> | |
13 | + <renderer generate="true" override="true"> | |
14 | + <name>org.richfaces.component.renderkit.html.WatermarkRenderer</name> | |
15 | + <template>htmlWatermark.jspx</template> | |
16 | + </renderer> | |
17 | + <tag> | |
18 | + <name>watermark</name> | |
19 | + <classname>org.richfaces.taglib.WatermarkTag</classname> | |
20 | + <superclass> | |
21 | + org.ajax4jsf.webapp.taglib.HtmlComponentTagBase | |
22 | + </superclass> | |
23 | + </tag> | |
24 | + <taghandler generate="true"> | |
25 | + <classname>org.richfaces.taglib.WatermarkTagHandler</classname> | |
26 | + <superclass>com.sun.facelets.tag.jsf.ComponentHandler</superclass> | |
27 | + </taghandler> &ui_output_attributes; | |
28 | + <property> | |
29 | + <name>for</name> | |
30 | + <classname>java.lang.String</classname> | |
31 | + <description> | |
32 | + Id of component that should be focused | |
33 | + </description> | |
34 | + <defaultvalue>""</defaultvalue> | |
35 | + </property> | |
36 | + </component> | |
37 | +</components> | ... | ... |
1 | +package org.richfaces.component; | |
2 | + | |
3 | +import javax.faces.component.UIOutput; | |
4 | + | |
5 | +public abstract class UIWatermark extends UIOutput { | |
6 | + | |
7 | + public static final String COMPONENT_TYPE = "org.richfaces.Watermark"; | |
8 | + public static final String COMPONENT_FAMILY = "org.richfaces.Watermark"; | |
9 | + | |
10 | + public abstract String getFor(); | |
11 | + | |
12 | + public abstract void setFor(String value); | |
13 | + | |
14 | +} | ... | ... |
src/main/java/org/richfaces/component/readme
0 → 100755
1 | +/* | |
2 | + Watermark plugin for jQuery | |
3 | + Version: 3.0.6 | |
4 | + http://jquery-watermark.googlecode.com/ | |
5 | + | |
6 | + Copyright (c) 2009-2010 Todd Northrop | |
7 | + http://www.speednet.biz/ | |
8 | + | |
9 | + June 21, 2010 | |
10 | + | |
11 | + Requires: jQuery 1.2.3+ | |
12 | + | |
13 | + Dual licensed under the MIT or GPL Version 2 licenses. | |
14 | + See mit-license.txt and gpl2-license.txt in the project root for details. | |
15 | +------------------------------------------------------*/ | |
16 | + | |
17 | +(function ($) { | |
18 | + | |
19 | +var | |
20 | + // Will speed up references to undefined | |
21 | + undefined, | |
22 | + | |
23 | + // String constants for data names | |
24 | + dataFlag = "watermark", | |
25 | + dataClass = "watermarkClass", | |
26 | + dataFocus = "watermarkFocus", | |
27 | + dataFormSubmit = "watermarkSubmit", | |
28 | + dataMaxLen = "watermarkMaxLength", | |
29 | + dataPassword = "watermarkPassword", | |
30 | + dataText = "watermarkText", | |
31 | + | |
32 | + // Includes only elements with watermark defined | |
33 | + selWatermarkDefined = ":data(" + dataFlag + ")", | |
34 | + | |
35 | + // Includes only elements capable of having watermark | |
36 | + selWatermarkAble = ":text,:password,:search,textarea", | |
37 | + | |
38 | + // triggerFns: | |
39 | + // Array of function names to look for in the global namespace. | |
40 | + // Any such functions found will be hijacked to trigger a call to | |
41 | + // hideAll() any time they are called. The default value is the | |
42 | + // ASP.NET function that validates the controls on the page | |
43 | + // prior to a postback. | |
44 | + // | |
45 | + // Am I missing other important trigger function(s) to look for? | |
46 | + // Please leave me feedback: | |
47 | + // http://code.google.com/p/jquery-watermark/issues/list | |
48 | + triggerFns = [ | |
49 | + "Page_ClientValidate" | |
50 | + ], | |
51 | + | |
52 | + // Holds a value of true if a watermark was displayed since the last | |
53 | + // hideAll() was executed. Avoids repeatedly calling hideAll(). | |
54 | + pageDirty = false; | |
55 | + | |
56 | +// Extends jQuery with a custom selector - ":data(...)" | |
57 | +// :data(<name>) Includes elements that have a specific name defined in the jQuery data collection. (Only the existence of the name is checked; the value is ignored.) | |
58 | +// :data(<name>=<value>) Includes elements that have a specific jQuery data name defined, with a specific value associated with it. | |
59 | +// :data(<name>!=<value>) Includes elements that have a specific jQuery data name defined, with a value that is not equal to the value specified. | |
60 | +// :data(<name>^=<value>) Includes elements that have a specific jQuery data name defined, with a value that starts with the value specified. | |
61 | +// :data(<name>$=<value>) Includes elements that have a specific jQuery data name defined, with a value that ends with the value specified. | |
62 | +// :data(<name>*=<value>) Includes elements that have a specific jQuery data name defined, with a value that contains the value specified. | |
63 | +$.extend($.expr[":"], { | |
64 | + "search": function (elem) { | |
65 | + return "search" === (elem.type || ""); | |
66 | + }, | |
67 | + | |
68 | + "data": function (element, index, matches, set) { | |
69 | + var data, parts = /^((?:[^=!^$*]|[!^$*](?!=))+)(?:([!^$*]?=)(.*))?$/.exec(matches[3]); | |
70 | + | |
71 | + if (parts) { | |
72 | + data = $(element).data(parts[1]); | |
73 | + | |
74 | + if (data !== undefined) { | |
75 | + | |
76 | + if (parts[2]) { | |
77 | + data = "" + data; | |
78 | + | |
79 | + switch (parts[2]) { | |
80 | + case "=": | |
81 | + return (data == parts[3]); | |
82 | + case "!=": | |
83 | + return (data != parts[3]); | |
84 | + case "^=": | |
85 | + return (data.slice(0, parts[3].length) == parts[3]); | |
86 | + case "$=": | |
87 | + return (data.slice(-parts[3].length) == parts[3]); | |
88 | + case "*=": | |
89 | + return (data.indexOf(parts[3]) !== -1); | |
90 | + } | |
91 | + } | |
92 | + | |
93 | + return true; | |
94 | + } | |
95 | + } | |
96 | + | |
97 | + return false; | |
98 | + } | |
99 | +}); | |
100 | + | |
101 | +$.watermark = { | |
102 | + | |
103 | + // Current version number of the plugin | |
104 | + version: "3.0.6", | |
105 | + | |
106 | + // Default options used when watermarks are instantiated. | |
107 | + // Can be changed to affect the default behavior for all | |
108 | + // new or updated watermarks. | |
109 | + // BREAKING CHANGE: The $.watermark.className | |
110 | + // property that was present prior to version 3.0.2 must | |
111 | + // be changed to $.watermark.options.className | |
112 | + options: { | |
113 | + | |
114 | + // Default class name for all watermarks | |
115 | + className: "watermark", | |
116 | + | |
117 | + // If true, plugin will detect and use native browser support for | |
118 | + // watermarks, if available. (e.g., WebKit's placeholder attribute.) | |
119 | + useNative: true | |
120 | + }, | |
121 | + | |
122 | + // Hide one or more watermarks by specifying any selector type | |
123 | + // i.e., DOM element, string selector, jQuery matched set, etc. | |
124 | + hide: function (selector) { | |
125 | + $(selector).filter(selWatermarkDefined).each( | |
126 | + function () { | |
127 | + $.watermark._hide($(this)); | |
128 | + } | |
129 | + ); | |
130 | + }, | |
131 | + | |
132 | + // Internal use only. | |
133 | + _hide: function ($input, focus) { | |
134 | + var inputVal = $input.val() || "", | |
135 | + inputWm = $input.data(dataText) || "", | |
136 | + maxLen = $input.data(dataMaxLen) || 0, | |
137 | + className = $input.data(dataClass); | |
138 | + | |
139 | + if ((inputWm.length) && (inputVal == inputWm)) { | |
140 | + $input.val(""); | |
141 | + | |
142 | + // Password type? | |
143 | + if ($input.data(dataPassword)) { | |
144 | + | |
145 | + if (($input.attr("type") || "") === "text") { | |
146 | + var $pwd = $input.data(dataPassword) || [], | |
147 | + $wrap = $input.parent() || []; | |
148 | + | |
149 | + if (($pwd.length) && ($wrap.length)) { | |
150 | + $wrap[0].removeChild($input[0]); // Can't use jQuery methods, because they destroy data | |
151 | + $wrap[0].appendChild($pwd[0]); | |
152 | + $input = $pwd; | |
153 | + } | |
154 | + } | |
155 | + } | |
156 | + | |
157 | + if (maxLen) { | |
158 | + $input.attr("maxLength", maxLen); | |
159 | + $input.removeData(dataMaxLen); | |
160 | + } | |
161 | + | |
162 | + if (focus) { | |
163 | + $input.attr("autocomplete", "off"); // Avoid NS_ERROR_XPC_JS_THREW_STRING error in Firefox | |
164 | + | |
165 | + window.setTimeout( | |
166 | + function () { | |
167 | + $input.select(); // Fix missing cursor in IE | |
168 | + } | |
169 | + , 1); | |
170 | + } | |
171 | + } | |
172 | + | |
173 | + className && $input.removeClass(className); | |
174 | + }, | |
175 | + | |
176 | + // Display one or more watermarks by specifying any selector type | |
177 | + // i.e., DOM element, string selector, jQuery matched set, etc. | |
178 | + // If conditions are not right for displaying a watermark, ensures that watermark is not shown. | |
179 | + show: function (selector) { | |
180 | + $(selector).filter(selWatermarkDefined).each( | |
181 | + function () { | |
182 | + $.watermark._show($(this)); | |
183 | + } | |
184 | + ); | |
185 | + }, | |
186 | + | |
187 | + // Internal use only. | |
188 | + _show: function ($input) { | |
189 | + var val = $input.val() || "", | |
190 | + text = $input.data(dataText) || "", | |
191 | + type = $input.attr("type") || "", | |
192 | + className = $input.data(dataClass); | |
193 | + | |
194 | + if (((val.length == 0) || (val == text)) && (!$input.data(dataFocus))) { | |
195 | + pageDirty = true; | |
196 | + | |
197 | + // Password type? | |
198 | + if ($input.data(dataPassword)) { | |
199 | + | |
200 | + if (type === "password") { | |
201 | + var $pwd = $input.data(dataPassword) || [], | |
202 | + $wrap = $input.parent() || []; | |
203 | + | |
204 | + if (($pwd.length) && ($wrap.length)) { | |
205 | + $wrap[0].removeChild($input[0]); // Can't use jQuery methods, because they destroy data | |
206 | + $wrap[0].appendChild($pwd[0]); | |
207 | + $input = $pwd; | |
208 | + $input.attr("maxLength", text.length); | |
209 | + } | |
210 | + } | |
211 | + } | |
212 | + | |
213 | + // Ensure maxLength big enough to hold watermark (input of type="text" or type="search" only) | |
214 | + if ((type === "text") || (type === "search")) { | |
215 | + var maxLen = $input.attr("maxLength") || 0; | |
216 | + | |
217 | + if ((maxLen > 0) && (text.length > maxLen)) { | |
218 | + $input.data(dataMaxLen, maxLen); | |
219 | + $input.attr("maxLength", text.length); | |
220 | + } | |
221 | + } | |
222 | + | |
223 | + className && $input.addClass(className); | |
224 | + $input.val(text); | |
225 | + } | |
226 | + else { | |
227 | + $.watermark._hide($input); | |
228 | + } | |
229 | + }, | |
230 | + | |
231 | + // Hides all watermarks on the current page. | |
232 | + hideAll: function () { | |
233 | + if (pageDirty) { | |
234 | + $.watermark.hide(selWatermarkAble); | |
235 | + pageDirty = false; | |
236 | + } | |
237 | + }, | |
238 | + | |
239 | + // Displays all watermarks on the current page. | |
240 | + showAll: function () { | |
241 | + $.watermark.show(selWatermarkAble); | |
242 | + } | |
243 | +}; | |
244 | + | |
245 | +$.fn.watermark = function (text, options) { | |
246 | + /// <summary> | |
247 | + /// Set watermark text and class name on all input elements of type="text/password/search" and | |
248 | + /// textareas within the matched set. If className is not specified in options, the default is | |
249 | + /// "watermark". Within the matched set, only input elements with type="text/password/search" | |
250 | + /// and textareas are affected; all other elements are ignored. | |
251 | + /// </summary> | |
252 | + /// <returns type="jQuery"> | |
253 | + /// Returns the original jQuery matched set (not just the input and texarea elements). | |
254 | + /// </returns> | |
255 | + /// <param name="text" type="String"> | |
256 | + /// Text to display as a watermark when the input or textarea element has an empty value and does not | |
257 | + /// have focus. The first time watermark() is called on an element, if this argument is empty (or not | |
258 | + /// a String type), then the watermark will have the net effect of only changing the class name when | |
259 | + /// the input or textarea element's value is empty and it does not have focus. | |
260 | + /// </param> | |
261 | + /// <param name="options" type="Object" optional="true"> | |
262 | + /// Provides the ability to override the default watermark options ($.watermark.options). For backward | |
263 | + /// compatibility, if a string value is supplied, it is used as the class name that overrides the class | |
264 | + /// name in $.watermark.options.className. Properties include: | |
265 | + /// className: When the watermark is visible, the element will be styled using this class name. | |
266 | + /// useNative (Boolean or Function): Specifies if native browser support for watermarks will supersede | |
267 | + /// plugin functionality. If useNative is a function, the return value from the function will | |
268 | + /// determine if native support is used. The function is passed one argument -- a jQuery object | |
269 | + /// containing the element being tested as the only element in its matched set -- and the DOM | |
270 | + /// element being tested is the object on which the function is invoked (the value of "this"). | |
271 | + /// </param> | |
272 | + /// <remarks> | |
273 | + /// The effect of changing the text and class name on an input element is called a watermark because | |
274 | + /// typically light gray text is used to provide a hint as to what type of input is required. However, | |
275 | + /// the appearance of the watermark can be something completely different: simply change the CSS style | |
276 | + /// pertaining to the supplied class name. | |
277 | + /// | |
278 | + /// The first time watermark() is called on an element, the watermark text and class name are initialized, | |
279 | + /// and the focus and blur events are hooked in order to control the display of the watermark. Also, as | |
280 | + /// of version 3.0, drag and drop events are hooked to guard against dropped text being appended to the | |
281 | + /// watermark. If native watermark support is provided by the browser, it is detected and used, unless | |
282 | + /// the useNative option is set to false. | |
283 | + /// | |
284 | + /// Subsequently, watermark() can be called again on an element in order to change the watermark text | |
285 | + /// and/or class name, and it can also be called without any arguments in order to refresh the display. | |
286 | + /// | |
287 | + /// For example, after changing the value of the input or textarea element programmatically, watermark() | |
288 | + /// should be called without any arguments to refresh the display, because the change event is only | |
289 | + /// triggered by user actions, not by programmatic changes to an input or textarea element's value. | |
290 | + /// | |
291 | + /// The one exception to programmatic updates is for password input elements: you are strongly cautioned | |
292 | + /// against changing the value of a password input element programmatically (after the page loads). | |
293 | + /// The reason is that some fairly hairy code is required behind the scenes to make the watermarks bypass | |
294 | + /// IE security and switch back and forth between clear text (for watermarks) and obscured text (for | |
295 | + /// passwords). It is *possible* to make programmatic changes, but it must be done in a certain way, and | |
296 | + /// overall it is not recommended. | |
297 | + /// </remarks> | |
298 | + | |
299 | + if (!this.length) { | |
300 | + return this; | |
301 | + } | |
302 | + | |
303 | + var hasClass = false, | |
304 | + hasText = (typeof(text) === "string"); | |
305 | + | |
306 | + if (typeof(options) === "object") { | |
307 | + hasClass = (typeof(options.className) === "string"); | |
308 | + options = $.extend({}, $.watermark.options, options); | |
309 | + } | |
310 | + else if (typeof(options) === "string") { | |
311 | + hasClass = true; | |
312 | + options = $.extend({}, $.watermark.options, {className: options}); | |
313 | + } | |
314 | + else { | |
315 | + options = $.watermark.options; | |
316 | + } | |
317 | + | |
318 | + if (typeof(options.useNative) !== "function") { | |
319 | + options.useNative = options.useNative? function () { return true; } : function () { return false; }; | |
320 | + } | |
321 | + | |
322 | + return this.each( | |
323 | + function () { | |
324 | + var $input = $(this); | |
325 | + | |
326 | + if (!$input.is(selWatermarkAble)) { | |
327 | + return; | |
328 | + } | |
329 | + | |
330 | + // Watermark already initialized? | |
331 | + if ($input.data(dataFlag)) { | |
332 | + | |
333 | + // If re-defining text or class, first remove existing watermark, then make changes | |
334 | + if (hasText || hasClass) { | |
335 | + $.watermark._hide($input); | |
336 | + | |
337 | + if (hasText) { | |
338 | + $input.data(dataText, text); | |
339 | + } | |
340 | + | |
341 | + if (hasClass) { | |
342 | + $input.data(dataClass, options.className); | |
343 | + } | |
344 | + } | |
345 | + } | |
346 | + else { | |
347 | + | |
348 | + // Detect and use native browser support, if enabled in options | |
349 | + if (options.useNative.call(this, $input)) { | |
350 | + | |
351 | + // Placeholder attribute (WebKit) | |
352 | + // Big thanks to Opera for the wacky test required | |
353 | + if ((("" + $input.css("-webkit-appearance")).replace("undefined", "") !== "") && (($input.attr("tagName") || "") !== "TEXTAREA")) { | |
354 | + | |
355 | + // className is not set because WebKit doesn't appear to have | |
356 | + // a separate class name property for placeholders (watermarks). | |
357 | + if (hasText) { | |
358 | + $input.attr("placeholder", text); | |
359 | + } | |
360 | + | |
361 | + // Only set data flag for non-native watermarks (purposely commented-out) | |
362 | + // $input.data(dataFlag, 1); | |
363 | + return; | |
364 | + } | |
365 | + } | |
366 | + | |
367 | + $input.data(dataText, hasText? text : ""); | |
368 | + $input.data(dataClass, options.className); | |
369 | + $input.data(dataFlag, 1); // Flag indicates watermark was initialized | |
370 | + | |
371 | + // Special processing for password type | |
372 | + if (($input.attr("type") || "") === "password") { | |
373 | + var $wrap = $input.wrap("<span>").parent(), | |
374 | + $wm = $($wrap.html().replace(/type=["']?password["']?/i, 'type="text"')); | |
375 | + | |
376 | + $wm.data(dataText, $input.data(dataText)); | |
377 | + $wm.data(dataClass, $input.data(dataClass)); | |
378 | + $wm.data(dataFlag, 1); | |
379 | + $wm.attr("maxLength", text.length); | |
380 | + | |
381 | + $wm.focus( | |
382 | + function () { | |
383 | + $.watermark._hide($wm, true); | |
384 | + } | |
385 | + ).bind("dragenter", | |
386 | + function () { | |
387 | + $.watermark._hide($wm); | |
388 | + } | |
389 | + ).bind("dragend", | |
390 | + function () { | |
391 | + window.setTimeout(function () { $wm.blur(); }, 1); | |
392 | + } | |
393 | + ); | |
394 | + $input.blur( | |
395 | + function () { | |
396 | + $.watermark._show($input); | |
397 | + } | |
398 | + ).bind("dragleave", | |
399 | + function () { | |
400 | + $.watermark._show($input); | |
401 | + } | |
402 | + ); | |
403 | + | |
404 | + $wm.data(dataPassword, $input); | |
405 | + $input.data(dataPassword, $wm); | |
406 | + } | |
407 | + else { | |
408 | + | |
409 | + $input.focus( | |
410 | + function () { | |
411 | + $input.data(dataFocus, 1); | |
412 | + $.watermark._hide($input, true); | |
413 | + } | |
414 | + ).blur( | |
415 | + function () { | |
416 | + $input.data(dataFocus, 0); | |
417 | + $.watermark._show($input); | |
418 | + } | |
419 | + ).bind("dragenter", | |
420 | + function () { | |
421 | + $.watermark._hide($input); | |
422 | + } | |
423 | + ).bind("dragleave", | |
424 | + function () { | |
425 | + $.watermark._show($input); | |
426 | + } | |
427 | + ).bind("dragend", | |
428 | + function () { | |
429 | + window.setTimeout(function () { $.watermark._show($input); }, 1); | |
430 | + } | |
431 | + ).bind("drop", | |
432 | + // Firefox makes this lovely function necessary because the dropped text | |
433 | + // is merged with the watermark before the drop event is called. | |
434 | + function (evt) { | |
435 | + var dropText = evt.originalEvent.dataTransfer.getData("Text"); | |
436 | + | |
437 | + if ($input.val().replace(dropText, "") === $input.data(dataText)) { | |
438 | + $input.val(dropText); | |
439 | + } | |
440 | + | |
441 | + $input.focus(); | |
442 | + } | |
443 | + ); | |
444 | + } | |
445 | + | |
446 | + // In order to reliably clear all watermarks before form submission, | |
447 | + // we need to replace the form's submit function with our own | |
448 | + // function. Otherwise watermarks won't be cleared when the form | |
449 | + // is submitted programmatically. | |
450 | + if (this.form) { | |
451 | + var form = this.form, | |
452 | + $form = $(form); | |
453 | + | |
454 | + if (!$form.data(dataFormSubmit)) { | |
455 | + $form.submit($.watermark.hideAll); | |
456 | + | |
457 | + // form.submit exists for all browsers except Google Chrome | |
458 | + // (see "else" below for explanation) | |
459 | + if (form.submit) { | |
460 | + $form.data(dataFormSubmit, form.submit); | |
461 | + | |
462 | + form.submit = (function (f, $f) { | |
463 | + return function () { | |
464 | + var nativeSubmit = $f.data(dataFormSubmit); | |
465 | + | |
466 | + $.watermark.hideAll(); | |
467 | + | |
468 | + if (nativeSubmit.apply) { | |
469 | + nativeSubmit.apply(f, Array.prototype.slice.call(arguments)); | |
470 | + } | |
471 | + else { | |
472 | + nativeSubmit(); | |
473 | + } | |
474 | + }; | |
475 | + })(form, $form); | |
476 | + } | |
477 | + else { | |
478 | + $form.data(dataFormSubmit, 1); | |
479 | + | |
480 | + // This strangeness is due to the fact that Google Chrome's | |
481 | + // form.submit function is not visible to JavaScript (identifies | |
482 | + // as "undefined"). I had to invent a solution here because hours | |
483 | + // of Googling (ironically) for an answer did not turn up anything | |
484 | + // useful. Within my own form.submit function I delete the form's | |
485 | + // submit function, and then call the non-existent function -- | |
486 | + // which, in the world of Google Chrome, still exists. | |
487 | + form.submit = (function (f) { | |
488 | + return function () { | |
489 | + $.watermark.hideAll(); | |
490 | + delete f.submit; | |
491 | + f.submit(); | |
492 | + }; | |
493 | + })(form); | |
494 | + } | |
495 | + } | |
496 | + } | |
497 | + } | |
498 | + | |
499 | + $.watermark._show($input); | |
500 | + } | |
501 | + ); | |
502 | +}; | |
503 | + | |
504 | +// Hijack any functions found in the triggerFns list | |
505 | +if (triggerFns.length) { | |
506 | + | |
507 | + // Wait until DOM is ready before searching | |
508 | + $(function () { | |
509 | + var i, name, fn; | |
510 | + | |
511 | + for (i=triggerFns.length-1; i>=0; i--) { | |
512 | + name = triggerFns[i]; | |
513 | + fn = window[name]; | |
514 | + | |
515 | + if (typeof(fn) === "function") { | |
516 | + window[name] = (function (origFn) { | |
517 | + return function () { | |
518 | + $.watermark.hideAll(); | |
519 | + return origFn.apply(null, Array.prototype.slice.call(arguments)); | |
520 | + }; | |
521 | + })(fn); | |
522 | + } | |
523 | + } | |
524 | + }); | |
525 | +} | |
526 | + | |
527 | +})(jQuery); | ... | ... |
src/main/templates/htmlWatermark.jspx
0 → 100755
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<f:root xmlns:f="http://ajax4jsf.org/cdk/template" xmlns:c="http://java.sun.com/jsf/core" | |
3 | + xmlns:ui="http://ajax4jsf.org/cdk/ui" | |
4 | + xmlns:u="http://ajax4jsf.org/cdk/u" xmlns:x="http://ajax4jsf.org/cdk/x" xmlns:jsp="http://ajax4jsf.org/cdk/jsp" | |
5 | + class="org.richfaces.renderkit.html.WatermarkRenderer" | |
6 | + baseclass="org.ajax4jsf.renderkit.HeaderResourcesRendererBase" | |
7 | + component="org.richfaces.component.UIWatermark" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
8 | + xsi:schemaLocation="http://ajax4jsf.org/cdk/template "> | |
9 | + | |
10 | + <h:scripts> | |
11 | + /org/richfaces/renderkit/html/scripts/jquery/jquery.js, | |
12 | + /org/richfaces/renderkit/html/scripts/jquery.watermark.js | |
13 | + /org/richfaces/renderkit/html/scripts/richfaces.watermark.js | |
14 | + </h:scripts> | |
15 | + | |
16 | + | |
17 | + <f:clientid var="clientId"/> | |
18 | + | |
19 | + | |
20 | + <jsp:scriptlet> | |
21 | + <![CDATA[ | |
22 | + String sid = (String) component.getAttributes().get("for"); | |
23 | + String target; | |
24 | + if (sid != null && ! "".equals(sid)) { | |
25 | + try { | |
26 | + UIComponent forcomp = getUtils().findComponentFor((UIComponent)component,sid); | |
27 | + if (forcomp != null) { | |
28 | + target = forcomp.getClientId(context); | |
29 | + } else { | |
30 | + target = sid; | |
31 | + } | |
32 | + }catch(IllegalArgumentException e) { | |
33 | + target = sid; | |
34 | + } | |
35 | + } else { | |
36 | + target = component.getParent().getClientId(context); | |
37 | + } | |
38 | + variables.setVariable("for",target); | |
39 | + ]]> | |
40 | + </jsp:scriptlet> | |
41 | + | |
42 | + <script type="text/javascript" id="#{clientId}"> | |
43 | + RichFaces.Watermark('#{for}', '#{component.attributes["value"]}'); | |
44 | + </script> | |
45 | +</f:root> | |
\ No newline at end of file | ... | ... |
src/main/templates/readme
0 → 100755
Please
register
or
login
to post a comment