2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
2012-05-21 10:38:18 +00:00
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
2012-05-31 10:32:54 +00:00
|
|
|
Ox.LoadingIcon <f> Loading Icon Element
|
2011-05-16 08:24:46 +00:00
|
|
|
options <o> Options object
|
2012-06-20 09:37:47 +00:00
|
|
|
size <n|s|16> size of icon
|
2011-05-16 08:24:46 +00:00
|
|
|
self <o> Shared private variable
|
2012-07-04 11:29:18 +00:00
|
|
|
([options[, self]]) -> <o:Ox.Element> Loading Icon Element
|
2011-05-16 08:24:46 +00:00
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.LoadingIcon = function(options, self) {
|
2012-01-27 14:29:11 +00:00
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element('<img>', self)
|
2012-01-17 17:34:33 +00:00
|
|
|
.defaults({
|
2013-02-09 10:33:42 +00:00
|
|
|
size: 16,
|
|
|
|
video: false
|
2012-01-17 17:34:33 +00:00
|
|
|
})
|
|
|
|
.options(options || {})
|
2012-06-20 09:37:47 +00:00
|
|
|
.addClass('OxLoadingIcon')
|
2013-02-09 10:33:42 +00:00
|
|
|
.attr({
|
2014-09-26 12:31:20 +00:00
|
|
|
src: Ox.UI.getImageURL(
|
2013-02-09 10:33:42 +00:00
|
|
|
'symbolLoading',
|
2014-02-04 09:22:55 +00:00
|
|
|
self.options.video ? 'videoIcon' : null
|
2013-02-09 10:33:42 +00:00
|
|
|
)
|
|
|
|
});
|
2012-06-20 09:37:47 +00:00
|
|
|
|
|
|
|
Ox.isNumber(self.options.size)
|
|
|
|
? that.css({width: self.options.size, height: self.options.size})
|
|
|
|
: that.addClass('Ox' + Ox.toTitleCase(self.options.size));
|
2012-01-27 14:29:11 +00:00
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
|
|
|
start <f> Start loading animation
|
|
|
|
() -> <f> Loading Icon Element
|
|
|
|
@*/
|
2013-07-29 09:46:52 +00:00
|
|
|
that.start = function(callback) {
|
2012-05-24 13:43:46 +00:00
|
|
|
var css, deg = 0, previousTime = +new Date();
|
2016-08-09 12:11:43 +00:00
|
|
|
function step() {
|
|
|
|
var currentTime = +new Date(),
|
|
|
|
delta = (currentTime - previousTime) / 1000,
|
|
|
|
next = Math.round((deg + delta * 360) % 360 / 30) * 30;
|
|
|
|
if (deg != next) {
|
2012-05-24 13:43:46 +00:00
|
|
|
previousTime = currentTime;
|
2016-08-09 12:11:43 +00:00
|
|
|
deg = next;
|
2012-05-24 13:43:46 +00:00
|
|
|
css = 'rotate(' + deg + 'deg)';
|
2012-05-24 12:26:52 +00:00
|
|
|
that.css({
|
2012-05-24 13:43:46 +00:00
|
|
|
MozTransform: css,
|
2012-05-25 16:28:05 +00:00
|
|
|
MsTransform: css,
|
2012-05-24 17:12:02 +00:00
|
|
|
OTransform: css,
|
2013-08-08 12:21:44 +00:00
|
|
|
WebkitTransform: css,
|
|
|
|
transform: css
|
2012-05-24 12:26:52 +00:00
|
|
|
});
|
2016-08-09 12:11:43 +00:00
|
|
|
}
|
|
|
|
if (!self.stopping && !Ox.isUndefined(window.requestAnimationFrame)) {
|
|
|
|
self.loadingInterval = window.requestAnimationFrame(step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!self.loadingInterval) {
|
|
|
|
if (Ox.isUndefined(window.requestAnimationFrame)) {
|
|
|
|
self.loadingInterval = setInterval(step, 83);
|
|
|
|
} else {
|
|
|
|
self.loadingInterval = window.requestAnimationFrame(step);
|
|
|
|
}
|
|
|
|
that.animate({opacity: 1}, 250, function() {
|
2013-07-29 09:46:52 +00:00
|
|
|
callback && callback();
|
|
|
|
});
|
2012-05-24 12:26:52 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
|
|
|
};
|
2012-01-27 14:29:11 +00:00
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
|
|
|
stop <f> Stop loading animation
|
|
|
|
() -> <f> Loading Icon Element
|
|
|
|
@*/
|
2013-07-29 09:46:52 +00:00
|
|
|
that.stop = function(callback) {
|
2013-07-29 10:49:48 +00:00
|
|
|
if (self.loadingInterval && !self.stopping) {
|
|
|
|
self.stopping = true;
|
2016-08-09 12:11:43 +00:00
|
|
|
that.animate({opacity: 0}, 250, function() {
|
2013-07-29 09:46:52 +00:00
|
|
|
var css = 'rotate(0deg)';
|
2016-08-09 12:11:43 +00:00
|
|
|
if (Ox.isUndefined(window.cancelAnimationFrame)) {
|
|
|
|
clearInterval(self.loadingInterval);
|
|
|
|
} else {
|
|
|
|
window.cancelAnimationFrame(self.loadingInterval);
|
|
|
|
}
|
2013-07-29 10:49:48 +00:00
|
|
|
self.loadingInterval = null;
|
|
|
|
self.stopping = false;
|
2013-07-29 09:46:52 +00:00
|
|
|
that.css({
|
|
|
|
MozTransform: css,
|
|
|
|
MsTransform: css,
|
|
|
|
OTransform: css,
|
2013-08-08 12:21:44 +00:00
|
|
|
WebkitTransform: css,
|
|
|
|
transform: css
|
2013-07-29 09:46:52 +00:00
|
|
|
});
|
|
|
|
callback && callback();
|
2012-01-17 17:34:33 +00:00
|
|
|
});
|
2012-05-24 12:26:52 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|
2012-01-27 14:29:11 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
2012-01-27 14:29:11 +00:00
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|