-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathvue2-loading-bar.js
executable file
·238 lines (202 loc) · 5.58 KB
/
vue2-loading-bar.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["LoadingBar"] = factory();
else
root["LoadingBar"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "./build/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {
"use strict";
/*! Copyright (c) 2016 Naufal Rabbani (http://github.com/BosNaufal)
* Licensed Under MIT (http://opensource.org/licenses/MIT)
*
* Vue 2 Loading Bar - Version 0.0.1
*
*/
module.exports = {
name: "LoadingBar",
props: {
id: String,
customClass: String,
progress: {
type: Number,
default: 0
},
// the direction of loading bar
direction: {
type: String,
default: "right"
},
error: Boolean, // Loading Bar error state
onErrorDone: {
type: Function,
required: true
},
onProgressDone: {
type: Function,
required: true
}
},
data: function data() {
return {
// To show
show: true,
// binding class when it end
full: '',
// state to animate the width of loading bar
width: 0,
// indicate the loading bar is in 100% ( so, wait it till gone )
wait: false,
// Error State
myError: false
};
},
render: function render(h) {
var direction = this.direction;
var customClass = this.customClass;
var id = this.id;
var width = this.width;
var show = this.show;
var full = this.full;
var myError = this.myError;
var styling = this.styling;
return h(
"div",
null,
[show ? h(
"div",
{
attrs: {
id: id ? id : null
},
"class": 'LoadingBar LoadingBar--to_' + direction + ' ' + (customClass ? customClass : '') + (myError ? 'LoadingBar--error' : '') + (full ? 'LoadingBar--full' : ''),
style: styling() },
[h(
"div",
{ "class": "LoadingBar-glow" },
[]
)]
) : null]
);
},
watch: {
progress: function progress(val, old) {
var _this = this;
if (old !== val) {
this.width = val;
setTimeout(function () {
_this.isFull();
});
}
},
error: function error(val, old) {
var _this2 = this;
if (old !== val) {
if (val) {
this.width = 100;
this.myError = true;
setTimeout(function () {
_this2.isFull();
});
}
}
}
},
methods: {
// Check whether the proggress is full
isFull: function isFull() {
var _this3 = this;
// Full Indicator
var isFull = this.width === 100;
// When the progress end or full
if (isFull) {
// Prevent new progress change
this.wait = true;
// Start animate it
setTimeout(function () {
// animate when element removed
_this3.full = true;
_this3.myError = false;
_this3.onErrorDone();
setTimeout(function () {
//remove bar element
_this3.show = false;
// New Element is available to create now
_this3.width = 0;
_this3.wait = false;
setTimeout(function () {
// Show Bar
_this3.full = '';
_this3.show = true;
_this3.onProgressDone();
});
// Duration to Waiting for slick hiding animation
}, 250);
// Duration is depend on css animation-duration of loading-bar
}, 700);
}
},
styling: function styling() {
// When loading bar still in progress
if (!this.wait) {
return { width: this.width + "%" };
// When loading bar end
} else {
// Make it stuck at 100 to waiting the animation
return { width: "100%" };
}
}
}
};
/***/ }
/******/ ])
});
;
//# sourceMappingURL=vue2-loading-bar.js.map