Skip to content

Commit 8fbae63

Browse files
committed
Display loading indicators during ajax operations (voting, etc)
1 parent 52ddab7 commit 8fbae63

1 file changed

Lines changed: 25 additions & 8 deletions

File tree

styles/prosilver/template/ideas.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
voteDown: $('.minivotedown'),
3333
voteUp: $('.minivoteup'),
3434
voteRemove: $('#vote-remove')
35-
};
35+
}, $loadingIndicator;
3636

3737
function voteSuccess(result, $this) {
3838
if (typeof result === 'string') {
@@ -76,11 +76,12 @@
7676
return false;
7777
}
7878

79+
showLoadingIndicator();
7980
$.get(url, {v: vote}, function(data) {
8081
voteSuccess(data, $this);
8182
resetVoteButtons($this);
8283
$obj.voteRemove.show();
83-
}).fail(voteFailure);
84+
}).fail(voteFailure).always(hideLoadingIndicator);
8485
});
8586

8687
$obj.votes.on('click', function(e) {
@@ -101,11 +102,12 @@
101102
return false;
102103
}
103104

105+
showLoadingIndicator();
104106
$.get(url, function(data) {
105107
voteSuccess(data, $this);
106108
resetVoteButtons();
107109
$obj.voteRemove.hide();
108-
}).fail(voteFailure);
110+
}).fail(voteFailure).always(hideLoadingIndicator);
109111
});
110112

111113
$obj.status.on('change', function() {
@@ -119,6 +121,7 @@
119121
return;
120122
}
121123

124+
showLoadingIndicator();
122125
$.get($this.attr('data-url'), data, function(res) {
123126
if (res) {
124127
var anchor = $this.prev('a'),
@@ -134,7 +137,7 @@
134137
$obj.duplicateToggle.toggle(idea_is_duplicate());
135138
$obj.implementedToggle.toggle(idea_is_implemented());
136139
}
137-
});
140+
}).always(hideLoadingIndicator);
138141
});
139142

140143
$obj.rfcEdit.on('click', function(e) {
@@ -159,6 +162,7 @@
159162
return;
160163
}
161164

165+
showLoadingIndicator();
162166
$.get(url, {rfc: value}, function(res) {
163167
if (res) {
164168
$obj.rfcLink.text(value)
@@ -172,7 +176,7 @@
172176

173177
$obj.rfcEdit.toggleAddEdit(value);
174178
}
175-
});
179+
}).always(hideLoadingIndicator);
176180
} else if (e.keyCode === keymap.ESC) {
177181
e.preventDefault();
178182

@@ -213,6 +217,7 @@
213217
value = 'PHPBB3-' + info[1];
214218
}
215219

220+
showLoadingIndicator();
216221
$.get(url, {ticket: value && info[1]}, function(res) {
217222
if (res) {
218223
$obj.ticketLink.text(value)
@@ -227,7 +232,7 @@
227232
$obj.ticketEdit.toggleAddEdit(value);
228233
}
229234

230-
});
235+
}).always(hideLoadingIndicator);
231236
} else if (e.keyCode === keymap.ESC) {
232237
e.preventDefault();
233238

@@ -263,6 +268,7 @@
263268
return;
264269
}
265270

271+
showLoadingIndicator();
266272
$.get(url, {duplicate: Number(value)}, function(res) {
267273
if (res) {
268274
if (value) {
@@ -283,7 +289,7 @@
283289

284290
$obj.duplicateEdit.toggleAddEdit(value);
285291
}
286-
});
292+
}).always(hideLoadingIndicator);
287293
} else if (e.keyCode === keymap.ESC) {
288294
e.preventDefault();
289295

@@ -320,6 +326,7 @@
320326
return;
321327
}
322328

329+
showLoadingIndicator();
323330
$.get(url, {implemented: value}, function(res) {
324331
if (res) {
325332
$obj.implementedVersion.text(value);
@@ -332,7 +339,7 @@
332339

333340
$obj.implementedEdit.toggleAddEdit(value);
334341
}
335-
});
342+
}).always(hideLoadingIndicator);
336343
} else if (e.keyCode === keymap.ESC) {
337344
e.preventDefault();
338345

@@ -408,4 +415,14 @@
408415
}
409416
}
410417

418+
function showLoadingIndicator() {
419+
$loadingIndicator = phpbb.loadingIndicator();
420+
}
421+
422+
function hideLoadingIndicator() {
423+
if ($loadingIndicator && $loadingIndicator.is(':visible')) {
424+
$loadingIndicator.fadeOut(phpbb.alertTime);
425+
}
426+
}
427+
411428
})(jQuery); // Avoid conflicts with other libraries

0 commit comments

Comments
 (0)