-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.loading.js
53 lines (43 loc) · 1.36 KB
/
jquery.loading.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
/**
* 2012, ParkMe Inc. - Keith Hackbarth
*
**/
(function( $ ) {
$.fn.loading = function () {
// create loading element
var loadingElement = document.createElement('div');
loadingElement.id = 'loading';
loadingElement.className = 'loading';
loadingElement.innerHTML = 'Loading...';
// apply styles
loadingElement.style.position = 'fixed';
loadingElement.style.background = 'yellow';
loadingElement.style.width = '130px';
loadingElement.style.textAlign = 'center';
loadingElement.style.zIndex = '10000';
loadingElement.style.padding = '4px';
loadingElement.style.border = 'grey solid 1px';
loadingElement.style.display = 'none';
// attach it to DOM
$(this).append(loadingElement);
// position element
$("#loading").position({
my: "center top",
at: "center top",
of: window
});
// every time ajax is called
$(document).ajaxSend(function () {
$(loadingElement).show();
})
// every time ajax is completed
$(document).ajaxComplete(function () {
self.setTimeout(function (){
$(loadingElement).hide();
}, 4000);
});
};
})(jQuery);
$(document).ready(function () {
$('body').loading();
});