Skip to content

Commit 84bbb61

Browse files
Baptistelenybernard
authored andcommitted
Fix overlay fadeIn/fadeOut
1 parent b0dbd0a commit 84bbb61

File tree

1 file changed

+62
-64
lines changed

1 file changed

+62
-64
lines changed

Resources/public/js/ajax.js

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
$(document).ready(function() {
22
//Initialize a loader
33
if (window.loader == undefined) {
4-
window.loader = '<div id="canvasloader-container" style="display: none;"><img src="/bundles/troopersajax/img/three-dots.svg" style="width: 80%; padding-top: 15px;"/></div>';
4+
window.loader = '<div id="canvasloader-container" ><img src="/bundles/troopersajax/img/three-dots.svg" style="width: 80%; padding-top: 15px;"/></div>';
55
}
66
if (window.loaderOverlay == undefined) {
7-
window.loaderOverlay = '<div id="canvasloader-container--overlay" style="display: none;"></div>';
7+
window.loaderOverlay = '<div id="canvasloader-container--overlay"></div>';
88
}
9+
10+
$wrapper = $('<div style="display: none;"></div>');
911
$loader = $(window.loader);
10-
$loaderOverlay = $(window.loader);
11-
$('body').prepend($loader);
12-
$('body').prepend(loaderOverlay);
12+
$loaderOverlay = $(window.loaderOverlay);
13+
$wrapper.prepend($loader).prepend(loaderOverlay);
14+
$('body').prepend($wrapper);
1315

1416
/**
1517
* The clicked link or button is tagged with data-trigger=true. When a form is submitted,
@@ -52,60 +54,58 @@ $(document).ajaxComplete(function() {
5254
});
5355
});
5456
});
55-
$(document).on('submit', 'form[data-toggle="ajax"]', function(event) {
56-
if($(this).hasClass('confirm') || $(this).hasClass('confirm-waiting')){
57-
return false;
58-
}
59-
$($loader).fadeIn();
60-
$($loaderOverlay).fadeIn();
61-
event.preventDefault();
62-
$(this).trigger('ajax.form.initialize');
63-
//Guess what is the target to update
64-
if ($(this).attr('data-target')) {
65-
var update = $(this).attr('data-target');
66-
} else if ($(this).data('update')) {
67-
console.info('The use of data-update will be deprecated in next version, please use data-target instead.');
68-
var update = $(this).data('update');
69-
}
70-
var updateStrategy = $(this).data('update-strategy') ? $(this).data('update-strategy') : 'html';
71-
var form = $(this);
72-
var effect = guessEffect(this, "#" + update);
73-
ajaxFormSubmit(form, $(form).attr('action'), update, updateStrategy, effect);
57+
$(document).on('submit', 'form[data-toggle="ajax"]', function(event) {
58+
if($(this).hasClass('confirm') || $(this).hasClass('confirm-waiting')){
59+
return false;
60+
}
61+
$wrapper.fadeIn();
62+
event.preventDefault();
63+
$(this).trigger('ajax.form.initialize');
64+
//Guess what is the target to update
65+
if ($(this).attr('data-target')) {
66+
var update = $(this).attr('data-target');
67+
} else if ($(this).data('update')) {
68+
console.info('The use of data-update will be deprecated in next version, please use data-target instead.');
69+
var update = $(this).data('update');
70+
}
71+
var updateStrategy = $(this).data('update-strategy') ? $(this).data('update-strategy') : 'html';
72+
var form = $(this);
73+
var effect = guessEffect(this, "#" + update);
74+
ajaxFormSubmit(form, $(form).attr('action'), update, updateStrategy, effect);
7475

76+
return false;
77+
}).on('click', 'a[data-toggle="ajax"]', function(event) {
78+
if($(this).hasClass('confirm') || $(this).hasClass('confirm-waiting')){
7579
return false;
76-
}).on('click', 'a[data-toggle="ajax"]', function(event) {
77-
if($(this).hasClass('confirm') || $(this).hasClass('confirm-waiting')){
78-
return false;
79-
}
80-
$($loader).fadeIn();
81-
$($loaderOverlay).fadeIn();
82-
event.preventDefault();
80+
}
81+
$wrapper.fadeIn();
82+
event.preventDefault();
8383

84-
//is the link linked ot a form
85-
var formSelector = $(this).data('form');
84+
//is the link linked ot a form
85+
var formSelector = $(this).data('form');
8686

87-
$(this).trigger('ajax.link.initialize');
88-
//Guess what is the target to update
89-
if ($(this).attr('data-target')) {
90-
var update = $(this).attr('data-target');
91-
} else if ($(this).data('update')) {
92-
console.info('The use of data-update will be deprecated in next version, please use data-target instead.');
93-
var update = $(this).data('update');
94-
}
95-
var updateStrategy = $(this).data('update-strategy') ? $(this).data('update-strategy') : 'html';
96-
var link = $(this).attr('href');
97-
var effect = guessEffect(this, "#" + update);
87+
$(this).trigger('ajax.link.initialize');
88+
//Guess what is the target to update
89+
if ($(this).attr('data-target')) {
90+
var update = $(this).attr('data-target');
91+
} else if ($(this).data('update')) {
92+
console.info('The use of data-update will be deprecated in next version, please use data-target instead.');
93+
var update = $(this).data('update');
94+
}
95+
var updateStrategy = $(this).data('update-strategy') ? $(this).data('update-strategy') : 'html';
96+
var link = $(this).attr('href');
97+
var effect = guessEffect(this, "#" + update);
9898

99-
//if there is a form we submit this one with the href of the link
100-
if (formSelector === undefined) {
101-
ajaxLink(link, update, updateStrategy);
102-
} else {
103-
var form = $(formSelector);
104-
ajaxFormSubmit(form, link, update, updateStrategy, effect);
105-
}
99+
//if there is a form we submit this one with the href of the link
100+
if (formSelector === undefined) {
101+
ajaxLink(link, update, updateStrategy);
102+
} else {
103+
var form = $(formSelector);
104+
ajaxFormSubmit(form, link, update, updateStrategy, effect);
105+
}
106106

107-
return false;
108-
});
107+
return false;
108+
});
109109

110110
function ajaxFormSubmit(form, action, update, updateStrategy, effect) {
111111
$(form).trigger('ajax.ajaxFormSubmit.before');
@@ -155,12 +155,11 @@ function ajaxLink(link,update, updateStrategy, effect) {
155155
alert("Il semble s'être produit une erreur");
156156
} else {
157157
toastr.options = {
158-
"positionClass": "toast-bottom-left",
158+
"positionClass": "toast-bottom-left",
159159
}
160160
toastr.error("Il semble s'être produit une erreur");
161161
}
162-
$($loader).fadeOut();
163-
$($loaderOverlay).fadeOut();
162+
$wrapper.fadeOut();
164163
}
165164
});
166165
}
@@ -183,8 +182,7 @@ function ajaxify(jsonResponse, update, updateStrategy, effect) {
183182
}
184183
}
185184

186-
$($loader).fadeOut();
187-
$($loaderOverlay).fadeOut();
185+
$wrapper.fadeOut();
188186
$('*[data-toggle="ajax"]').each(function() {
189187
$(this).css({
190188
'pointer-events' : 'auto',
@@ -208,12 +206,12 @@ function handleJson(json, update, updateStrategy, effect) {
208206
// check if an ajax callback is given in the response, execute it
209207
if (json.hasOwnProperty("ajax-callback")) {
210208
$.post(json.callback,
211-
{
212-
params : json.data
213-
},
214-
function(data){
215-
eval('$("#" + update).' + updateStrategy + '(data)');
216-
});
209+
{
210+
params : json.data
211+
},
212+
function(data){
213+
eval('$("#" + update).' + updateStrategy + '(data)');
214+
});
217215
}
218216
// a callback is javascript code
219217
if (json.hasOwnProperty("callback")) {

0 commit comments

Comments
 (0)