2013-09-11 09:33:47 +03:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'jquery'
|
|
|
|
], function ($) {
|
|
|
|
'use strict';
|
|
|
|
|
2013-09-12 02:34:04 +03:00
|
|
|
$.fn.spinForPromise = function (promise) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (!promise || promise.state() !== 'pending') {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
promise.always(function () {
|
|
|
|
self.stopSpin();
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.startSpin();
|
|
|
|
};
|
|
|
|
|
2013-09-11 09:33:47 +03:00
|
|
|
$.fn.startSpin = function () {
|
|
|
|
|
2013-09-12 02:34:04 +03:00
|
|
|
var icon = this.find('i').andSelf('i');
|
2013-09-11 09:33:47 +03:00
|
|
|
|
|
|
|
var iconClasses = icon.attr('class').match(/(?:^|\s)icon\-.+?(?:$|\s)/);
|
|
|
|
|
|
|
|
if (iconClasses.length === 0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
var iconClass = $.trim(iconClasses[0]);
|
|
|
|
|
|
|
|
this.addClass('disabled');
|
|
|
|
|
|
|
|
if (icon.hasClass('icon-can-spin')) {
|
|
|
|
icon.addClass('icon-spin');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon.attr('data-idle-icon', iconClass);
|
|
|
|
icon.removeClass(iconClass);
|
|
|
|
icon.addClass('icon-nd-spinner');
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.stopSpin = function () {
|
2013-09-12 02:34:04 +03:00
|
|
|
var icon = this.find('i').andSelf('i');
|
2013-09-11 09:33:47 +03:00
|
|
|
|
|
|
|
this.removeClass('disabled');
|
|
|
|
icon.removeClass('icon-spin icon-nd-spinner');
|
|
|
|
var idleIcon = icon.attr('data-idle-icon');
|
|
|
|
|
|
|
|
if (idleIcon) {
|
|
|
|
icon.addClass(idleIcon);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
});
|