WICKET-6209 move try-catch into function which is invoked via #setTimeout(), so 
IE errors get caught

;removed workaround for WicketWICKET-5755, i.e. directly call #requestFocus() 
since it now always uses #setTimeout() to request focus (see WICKET-5858)


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b93e1ba5
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b93e1ba5
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b93e1ba5

Branch: refs/heads/master
Commit: b93e1ba557f85cdbf77fd44a14721918feb23910
Parents: 0d8ab84
Author: Sven Meier <svenme...@apache.org>
Authored: Tue Jul 19 22:47:15 2016 +0200
Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org>
Committed: Wed Jul 20 00:10:32 2016 +0200

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 47 +++++++++-----------
 1 file changed, 22 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/b93e1ba5/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js 
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index a7aa0d9..f0c5c12 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++ 
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -1098,13 +1098,7 @@
                                this._executeHandlers(attrs.sh, attrs, null, 
null, 'success');
                                
Wicket.Event.publish(Wicket.Event.Topic.AJAX_CALL_SUCCESS, attrs, null, null, 
'success');
 
-                               // set the focus to the last component
-                               if (Wicket.Browser.isIELessThan9()) {
-                                       // WICKET-5755
-                                       
window.setTimeout("Wicket.Focus.requestFocus();", 0);
-                               } else {
-                                       Wicket.Focus.requestFocus();
-                               }
+                               Wicket.Focus.requestFocus();
 
                                // continue to next step (which should make the 
processing stop, as success should be the final step)
                                return FunctionsExecuter.DONE;
@@ -2702,30 +2696,33 @@
 
                                        if (toFocus) {
                                                Wicket.Log.info("Calling focus 
on " + WF.lastFocusId);
-                                               try {
-                                                       if 
(WF.focusSetFromServer) {
-                                                               // WICKET-5858
-                                                               
window.setTimeout(function () { toFocus.focus(); }, 0);
-                                                       } else {
-                                                               // avoid loops 
like - onfocus triggering an event the modifies the tag => refocus => the event 
is triggered again
-                                                               var temp = 
toFocus.onfocus;
-                                                               toFocus.onfocus 
= null;
-                                                               
-                                                               // IE needs 
setTimeout (it seems not to call onfocus sync. when focus() is called
-                                                               
window.setTimeout(function () {toFocus.focus(); toFocus.onfocus = temp; }, 0);
+
+                                               var safeFocus = function() {
+                                                       try {
+                                                               toFocus.focus();
+                                                       } catch (ignore) {
+                                                               // WICKET-6209 
IE fails if toFocus is disabled
                                                        }
-                                               } catch (ignore) {
+                                               };
+
+                                               if (WF.focusSetFromServer) {
+                                                       // WICKET-5858
+                                                       
window.setTimeout(safeFocus, 0);
+                                               } else {
+                                                       // avoid loops like - 
onfocus triggering an event the modifies the tag => refocus => the event is 
triggered again
+                                                       var temp = 
toFocus.onfocus;
+                                                       toFocus.onfocus = null;
+
+                                                       // IE needs setTimeout 
(it seems not to call onfocus sync. when focus() is called
+                                                       
window.setTimeout(function () { safeFocus(); toFocus.onfocus = temp; }, 0);
                                                }
-                                       }
-                                       else {
+                                       } else {
                                                WF.lastFocusId = "";
                                                Wicket.Log.info("Couldn't set 
focus on element with id '" + WF.lastFocusId + "' because it is not in the page 
anymore");
                                        }
-                               }
-                               else if 
(WF.refocusLastFocusedComponentAfterResponse) {
+                               } else if 
(WF.refocusLastFocusedComponentAfterResponse) {
                                        Wicket.Log.info("last focus id was not 
set");
-                               }
-                               else {
+                               } else {
                                        Wicket.Log.info("refocus last focused 
component not needed/allowed");
                                }
                                
Wicket.Focus.refocusLastFocusedComponentAfterResponse = false;

Reply via email to