-
Notifications
You must be signed in to change notification settings - Fork 0
/
disableComponentsOnAjaxCall.js
58 lines (56 loc) · 2.2 KB
/
disableComponentsOnAjaxCall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function undisableComponentsAfterAjaxCall(){
$(':input:disabled[data-disableComponentsOnAjaxCall=true]').each(function(){
var tag = $(this);
tag.prop('disabled', false);
tag.removeAttr('data-disableComponentsOnAjaxCall');
});
window.ajaxCallRunning = false;
if (!(typeof disableComponentsOnAjaxCall_activeElement === 'undefined')) {
var comp = $(window.disableComponentsOnAjaxCall_activeElement);
if(comp.is(':visible')){
comp.focus();
}
window.disableComponentsOnAjaxCall_activeElement = null;
}
}
function disableComponentsOnAjaxCall() {
if (typeof disableComponentsOnAjaxCallRegistered === 'undefined') {
window.disableComponentsOnAjaxCallRegistered = true;
window.ajaxCallRunning = false;
// see https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=87917 http://wicket.apache.org/guide/guide/ajax.html#ajax_3
//execute disable when ajax call starts
Wicket.Event.subscribe('/ajax/call/after', function(attributes,
jqXHR, settings) {
window.ajaxCallRunning = true;
// only disable components when we have an ajax indicator activated for this event
if (jqXHR.i) {
setTimeout(function(){
window.disableComponentsOnAjaxCall_activeElement = OptimalSelect.select(document.activeElement);
// do not disable file inputs, or their upload will fail!
$(':input:not(:disabled)').each(function(){
var tag = $(this);
tag.attr('data-disableComponentsOnAjaxCall', 'true')
tag.prop('disabled', true);
});
}, 1); //process after the focus might have traversed
}
});
//execute undisable when ajax call is finished
Wicket.Event.subscribe('/ajax/call/success', function(attributes, jqXHR, settings) {
// only undisable components when we had an ajax indicator activated for this event
if (jqXHR.i) {
undisableComponentsAfterAjaxCall();
}
});
Wicket.Event.subscribe('/ajax/call/failure', function(jqEvent, attributes, jqXHR, errorThrown, textStatus) {
// jqXHR might be null, so don't check it'
undisableComponentsAfterAjaxCall();
});
//see https://github.com/hubspot/offline
Offline.on("up", function(e) {
location.reload();
});
}
//execute undisable on any ondomready event
undisableComponentsAfterAjaxCall();
}