1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-23 16:52:26 +02:00
TableFilter/src/modules/loader.js

98 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-11-15 15:34:32 +01:00
define(["exports", "../dom", "../types"], function (exports, _dom, _types) {
"use strict";
2014-10-27 08:01:33 +01:00
2014-11-15 15:34:32 +01:00
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
2014-10-27 08:01:33 +01:00
2014-11-16 01:29:07 +01:00
var Dom = _dom.Dom;
var Types = _types.Types;
2014-10-27 08:01:33 +01:00
2014-11-15 15:34:32 +01:00
var global = window;
2014-10-27 08:01:33 +01:00
2014-11-15 15:34:32 +01:00
var Loader = (function () {
var Loader = function Loader(tf) {
// TableFilter configuration
var f = tf.fObj;
//id of container element
2014-11-16 11:01:29 +01:00
this.loaderTgtId = f.loader_target_id || null;
2014-11-15 15:34:32 +01:00
//div containing loader
2014-11-16 11:01:29 +01:00
this.loaderDiv = null;
2014-11-15 15:34:32 +01:00
//defines loader text
2014-11-16 11:01:29 +01:00
this.loaderText = f.loader_text || "Loading...";
2014-11-15 15:34:32 +01:00
//defines loader innerHtml
2014-11-16 11:01:29 +01:00
this.loaderHtml = f.loader_html || null;
2014-11-15 15:34:32 +01:00
//defines css class for loader div
2014-11-16 11:01:29 +01:00
this.loaderCssClass = f.loader_css_class || "loader";
2014-11-15 15:34:32 +01:00
//delay for hiding loader
2014-11-16 11:01:29 +01:00
this.loaderCloseDelay = 200;
2014-11-15 15:34:32 +01:00
//callback function before loader is displayed
2014-11-16 11:01:29 +01:00
this.onShowLoader = Types.isFn(f.on_show_loader) ? f.on_show_loader : null;
2014-11-15 15:34:32 +01:00
//callback function after loader is closed
2014-11-16 11:01:29 +01:00
this.onHideLoader = Types.isFn(f.on_hide_loader) ? f.on_hide_loader : null;
2014-10-27 08:01:33 +01:00
2014-11-15 15:34:32 +01:00
this.tf = tf;
2014-11-16 01:29:07 +01:00
var containerDiv = Dom.create("div", ["id", tf.prfxLoader + tf.id]);
2014-11-16 11:01:29 +01:00
containerDiv.className = this.loaderCssClass;
2014-10-27 08:01:33 +01:00
2014-11-16 11:01:29 +01:00
var targetEl = !this.loaderTgtId ? (tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) : Dom.id(this.loaderTgtId);
if (!this.loaderTgtId) {
2014-11-15 15:34:32 +01:00
targetEl.insertBefore(containerDiv, tf.tbl);
} else {
targetEl.appendChild(containerDiv);
}
2014-11-16 11:01:29 +01:00
this.loaderDiv = Dom.id(tf.prfxLoader + tf.id);
if (!this.loaderHtml) {
this.loaderDiv.appendChild(Dom.text(this.loaderText));
2014-11-15 15:34:32 +01:00
} else {
2014-11-16 11:01:29 +01:00
this.loaderDiv.innerHTML = this.loaderHtml;
2014-11-15 15:34:32 +01:00
}
};
_classProps(Loader, null, {
show: {
writable: true,
value: function (p) {
2014-11-16 11:01:29 +01:00
var _this = this;
if (!this.tf.loader || !this.loaderDiv || this.loaderDiv.style.display === p) {
2014-10-27 08:01:33 +01:00
return;
2014-11-15 15:34:32 +01:00
}
2014-10-27 08:01:33 +01:00
2014-11-16 11:01:29 +01:00
var displayLoader = function () {
if (!_this.loaderDiv) {
2014-11-15 15:34:32 +01:00
return;
2014-10-27 08:01:33 +01:00
}
2014-11-16 11:01:29 +01:00
if (_this.onShowLoader && p !== "none") {
_this.onShowLoader.call(null, _this);
2014-10-27 08:01:33 +01:00
}
2014-11-16 11:01:29 +01:00
_this.loaderDiv.style.display = p;
if (_this.onHideLoader && p === "none") {
_this.onHideLoader.call(null, _this);
2014-10-27 08:01:33 +01:00
}
2014-11-16 11:01:29 +01:00
};
2014-10-27 08:01:33 +01:00
2014-11-16 11:01:29 +01:00
var t = p === "none" ? this.loaderCloseDelay : 1;
2014-11-15 15:34:32 +01:00
global.setTimeout(displayLoader, t);
}
},
remove: {
writable: true,
value: function () {
2014-11-16 11:01:29 +01:00
if (!this.loaderDiv) {
2014-10-27 08:01:33 +01:00
return;
2014-11-15 15:34:32 +01:00
}
2014-11-16 11:01:29 +01:00
var targetEl = !this.loaderTgtId ? (this.tf.gridLayout ? this.tf.tblCont : this.tf.tbl.parentNode) : Dom.id(this.loaderTgtId);
targetEl.removeChild(this.loaderDiv);
this.loaderDiv = null;
2014-10-27 08:01:33 +01:00
}
2014-11-15 15:34:32 +01:00
}
});
return Loader;
})();
2014-10-26 11:48:13 +01:00
2014-11-15 15:34:32 +01:00
exports.Loader = Loader;
2014-10-26 11:48:13 +01:00
});