Throbber.js
1.89 KB
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
/**
* Throbber.js
*
* Released under LGPL License.
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* This class enables you to display a Throbber for any element.
*
* @-x-less Throbber.less
* @class tinymce.ui.Throbber
*/
define("tinymce/ui/Throbber", [
"tinymce/dom/DomQuery",
"tinymce/ui/Control",
"tinymce/util/Delay"
], function($, Control, Delay) {
"use strict";
/**
* Constructs a new throbber.
*
* @constructor
* @param {Element} elm DOM Html element to display throbber in.
* @param {Boolean} inline Optional true/false state if the throbber should be appended to end of element for infinite scroll.
*/
return function(elm, inline) {
var self = this, state, classPrefix = Control.classPrefix, timer;
/**
* Shows the throbber.
*
* @method show
* @param {Number} [time] Time to wait before showing.
* @param {function} [callback] Optional callback to execute when the throbber is shown.
* @return {tinymce.ui.Throbber} Current throbber instance.
*/
self.show = function(time, callback) {
function render() {
if (state) {
$(elm).append(
'<div class="' + classPrefix + 'throbber' + (inline ? ' ' + classPrefix + 'throbber-inline' : '') + '"></div>'
);
if (callback) {
callback();
}
}
}
self.hide();
state = true;
if (time) {
timer = Delay.setTimeout(render, time);
} else {
render();
}
return self;
};
/**
* Hides the throbber.
*
* @method hide
* @return {tinymce.ui.Throbber} Current throbber instance.
*/
self.hide = function() {
var child = elm.lastChild;
Delay.clearTimeout(timer);
if (child && child.className.indexOf('throbber') != -1) {
child.parentNode.removeChild(child);
}
state = false;
return self;
};
};
});