/*
* IGAJAXIndicator v0.0.1 @adobrolyubov (Alexander Dobrolyubov)
* Based on Kendo UI Web v2013.1.319 (http://kendoui.com)
* Copyright 2013 Billtrust. All rights reserved.
*/
(function($, undefined) {
"use strict";
var kendo = window.kendo,
ui = kendo.ui,
Widget = ui.Widget,
proxy = $.proxy
;
var IGAJAXIndicator = Widget.extend({
indicator: null,
isEnabled: true,
isEnabledOnce: false,
timeout: null,
init: function(element, options) {
var that = this;
// base call to initialize widget
Widget.fn.init.call(this, element, options);
that.isEnabled = that.options.isEnabled;
$(document).ajaxSend(proxy(that._ajaxSend, that));
$(document).ajaxComplete(proxy(that._ajaxComplete, that));
},
options: {
name: "IGAJAXIndicator",
template: '
Loading ...
',
type: 'template', // or "spinner"
delay: 1000,
isEnabled: true,
isDisabledOnce: false
},
enableOnce: function()
{
var that = this;
that.isEnabledOnce = true;
},
disableOnce: function()
{
var that = this;
that.isDisabledOnce = true;
},
_ajaxSend : function()
{
var that = this;
if(that.isDisabledOnce) {
that.isDisabledOnce = false;
return;
}
that.timeout = setTimeout($.proxy(that._show, that), that.options.delay);
},
_ajaxComplete: function()
{
var that = this;
clearTimeout(that.timeout);
that._hide();
if(that.isEnabledOnce) {
that.isEnabledOnce = false;
}
},
_show: function()
{
var that = this;
if(!that.isEnabled && !that.isEnabledOnce) {
return;
}
if(that.options.type == 'template') {
if(!that.indicator) {
that.indicator = $(that.options.template);
that.element.prepend(that.indicator);
}
that.indicator.show();
}
else if(that.options.type == 'spinner') {
$('body').append('');
$('body').append('');
}
},
_hide: function()
{
var that = this;
if(that.options.type == 'template') {
that.indicator && that.indicator.hide();
}
else if(that.options.type == 'spinner') {
$('.i-overlay, .i-spinner-progress').remove();
}
}
});
ui.plugin(IGAJAXIndicator);
})(window.kendo.jQuery);