-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanelLoading.plugin.js
105 lines (94 loc) · 3.18 KB
/
panelLoading.plugin.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(function($){
"use strict";
$.fn.panelLoading = function( options ){
var settings = $.extend({
setLoading: null,
color: '#fff',
opacity: '0.8',
text: 'Loading...',
textClass: 'text-info',
loaderClass: 'progress-striped active',
loaderWidth: '100%',
fadeDuration: 500,
fromTop: false,
}, options);
// If .setLoading is unset, check if this panel is loading already:
if(settings.setLoading === null){
// It is loading, we will be stopping the load:
if(this.hasClass('panel-loading-base-element')){
settings.setLoading = false;
}
else{
settings.setLoading = true;
}
}
var setLoad = settings.setLoading,
fadeDuration = parseInt(settings.fadeDuration, 10),
removeLoadStuff = function( $basePanel ){
if($basePanel.hasClass('panel-loading-base-element')){
$basePanel.removeClass('panel-loading-base-element');
}
if($basePanel.children('.panel-loading-container').length > 0){
$basePanel.children('.panel-loading-container').contents().unwrap();
}
};
if(setLoad){
if(!this.hasClass('panel-loading-base-element')){
this.addClass('panel-loading-base-element');
}
// Initialize the loading panel
var $innerWrapper = $('<div class="panel-loading-container" />')
.height(this.outerHeight()),
$overlay = $('<div class="panel-loading-overlay" />')
.width(this.outerWidth() - parseFloat(this.css('border-left-width')) - parseFloat(this.css('border-right-width')))
.height(this.outerHeight() - parseFloat(this.css('border-top-width')) - parseFloat(this.css('border-bottom-width')))
.css({
'border-radius': this.css('border-radius'),
'background-color': settings.color,
'opacity': settings.opacity,
'filter': 'alpha(opacity=' + (parseInt(settings.opacity, 10) * 100 ).toString() + ')',
'left': '-'+this.css('padding-left'),
'top': '-'+this.css('padding-top')
})
.hide(),
$loadingPanel = $('<div class="panel-loading-info-panel" />')
.css({
'top': (settings.fromTop && typeof settings.fromTop === 'number') ? settings.fromTop+'px' : '50%',
})
.append(
$('<div class="progress '+settings.loaderClass+'" />').append(
$('<div class="bar" />').width(settings.loaderWidth)
)
)
.hide();
// Wrap the contents of the div in the container.
this.wrapInner($innerWrapper);
this.children(':first').append($overlay);
$overlay.fadeIn(fadeDuration);
if(settings.text){
$loadingPanel.prepend(
$('<span class="'+settings.textClass+'" />').html(settings.text)
);
}
this.children(':first').append($loadingPanel);
$loadingPanel.css('margin-top', ($loadingPanel.height() / 2) * -1)
.fadeIn(fadeDuration);
}
else{
var $overlay = this.find('div.panel-loading-overlay'),
$loadingPanel = this.find('div.panel-loading-info-panel'),
$basePanel = this;
if($overlay.length < 1){
removeLoadStuff($basePanel);
}
$loadingPanel.fadeOut(fadeDuration, function(){
$(this).remove();
});
$overlay.fadeOut(fadeDuration, function(){
$(this).remove();
removeLoadStuff($basePanel);
});
}
return this;
};
}( jQuery ));