From ce10b6f8b46add764786e509296568ff5b01dc8f Mon Sep 17 00:00:00 2001
From: Bernard Labno <bernard.labno@itcrowd.pl>
Date: Mon, 3 Oct 2011 12:06:03 +0000
Subject: [PATCH] Fixed problem with not clearing watermarks on ajax form submit.

---
 src/main/resources/org/richfaces/renderkit/html/scripts/jquery.watermark.js | 90 +++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------
 1 file changed, 43 insertions(+), 47 deletions(-)

diff --git a/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.watermark.js b/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.watermark.js
index b1d11d9..eea04c8 100644
--- a/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.watermark.js
+++ b/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.watermark.js
@@ -447,53 +447,49 @@ $.fn.watermark = function (text, options) {
 				// we need to replace the form's submit function with our own
 				// function.  Otherwise watermarks won't be cleared when the form
 				// is submitted programmatically.
-				if (this.form) {
-					var form = this.form,
-						$form = $(form);
-					
-					if (!$form.data(dataFormSubmit)) {
-						$form.submit($.watermark.hideAll);
-						
-						// form.submit exists for all browsers except Google Chrome
-						// (see "else" below for explanation)
-						if (form.submit) {
-							$form.data(dataFormSubmit, form.submit);
-							
-							form.submit = (function (f, $f) {
-								return function () {
-									var nativeSubmit = $f.data(dataFormSubmit);
-									
-									$.watermark.hideAll();
-									
-									if (nativeSubmit.apply) {
-										nativeSubmit.apply(f, Array.prototype.slice.call(arguments));
-									}
-									else {
-										nativeSubmit();
-									}
-								};
-							})(form, $form);
-						}
-						else {
-							$form.data(dataFormSubmit, 1);
-							
-							// This strangeness is due to the fact that Google Chrome's
-							// form.submit function is not visible to JavaScript (identifies
-							// as "undefined").  I had to invent a solution here because hours
-							// of Googling (ironically) for an answer did not turn up anything
-							// useful.  Within my own form.submit function I delete the form's
-							// submit function, and then call the non-existent function --
-							// which, in the world of Google Chrome, still exists.
-							form.submit = (function (f) {
-								return function () {
-									$.watermark.hideAll();
-									delete f.submit;
-									f.submit();
-								};
-							})(form);
-						}
-					}
-				}
+                if (this.form) {
+                    var form = this.form,
+                            $form = $(form);
+
+                    if (!$form.data(dataFormSubmit)) {
+                        $form.submit($.watermark.hideAll);
+
+                        // form.submit exists for all browsers except Google Chrome
+                        // (see "else" below for explanation)
+                        if (form.submit) {
+                            $form.data(dataFormSubmit, form.onsubmit || 1);
+
+                            form.onsubmit = (function (f, $f) {
+                                return function () {
+                                    var nativeSubmit = $f.data(dataFormSubmit);
+                                    $.watermark.hideAll();
+                                    if (nativeSubmit instanceof Function) {
+                                        nativeSubmit();
+                                    } else {
+                                        eval(nativeSubmit);
+                                    }
+                                };
+                            })(form, $form);
+                        } else {
+                            $form.data(dataFormSubmit, 1);
+
+                            // This strangeness is due to the fact that Google Chrome's
+                            // form.submit function is not visible to JavaScript (identifies
+                            // as "undefined").  I had to invent a solution here because hours
+                            // of Googling (ironically) for an answer did not turn up anything
+                            // useful.  Within my own form.submit function I delete the form's
+                            // submit function, and then call the non-existent function --
+                            // which, in the world of Google Chrome, still exists.
+                            form.submit = (function (f) {
+                                return function () {
+                                    $.watermark.hideAll();
+                                    delete f.submit;
+                                    f.submit();
+                                };
+                            })(form);
+                        }
+                    }
+                }
 			}
 			
 			$.watermark._show($input);
--
libgit2 0.24.0