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({
|
|
|
|
src: Ox.UI.getImageURL(
|
|
|
|
'symbolLoading',
|
|
|
|
self.options.video ? [255, 255, 255] : null
|
|
|
|
)
|
|
|
|
});
|
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
|
|
|
|
2013-07-29 09:46:52 +00:00
|
|
|
that.stopAnimation = that.stop;
|
|
|
|
|
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();
|
2012-05-24 12:26:52 +00:00
|
|
|
if (!self.loadingInterval) {
|
|
|
|
self.loadingInterval = setInterval(function() {
|
2012-05-24 13:43:46 +00:00
|
|
|
var currentTime = +new Date(),
|
|
|
|
delta = (currentTime - previousTime) / 1000;
|
|
|
|
previousTime = currentTime;
|
|
|
|
deg = Math.round((deg + delta * 360) % 360 / 30) * 30;
|
|
|
|
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,
|
2012-05-24 13:43:46 +00:00
|
|
|
WebkitTransform: css
|
2012-05-24 12:26:52 +00:00
|
|
|
});
|
2012-05-24 13:43:46 +00:00
|
|
|
}, 83);
|
2013-07-29 09:46:52 +00:00
|
|
|
that.stopAnimation().animate({opacity: 1}, 250, function() {
|
|
|
|
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;
|
2013-07-29 09:46:52 +00:00
|
|
|
that.stopAnimation().animate({opacity: 0}, 250, function() {
|
|
|
|
var css = 'rotate(0deg)';
|
2013-07-29 10:49:48 +00:00
|
|
|
clearInterval(self.loadingInterval);
|
|
|
|
self.loadingInterval = null;
|
|
|
|
self.stopping = false;
|
2013-07-29 09:46:52 +00:00
|
|
|
that.css({
|
|
|
|
MozTransform: css,
|
|
|
|
MsTransform: css,
|
|
|
|
OTransform: css,
|
|
|
|
WebkitTransform: css
|
|
|
|
});
|
|
|
|
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
|
|
|
};
|