mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-13 11:56:46 +02:00
98 lines
3.1 KiB
JavaScript
98 lines
3.1 KiB
JavaScript
define(["exports", "../dom", "../types"], function (exports, _dom, _types) {
|
|
"use strict";
|
|
|
|
var _classProps = function (child, staticProps, instanceProps) {
|
|
if (staticProps) Object.defineProperties(child, staticProps);
|
|
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
|
};
|
|
|
|
var Dom = _dom.Dom;
|
|
var Types = _types.Types;
|
|
|
|
|
|
var global = window;
|
|
|
|
var Loader = (function () {
|
|
var Loader = function Loader(tf) {
|
|
// TableFilter configuration
|
|
var f = tf.fObj;
|
|
//id of container element
|
|
this.loaderTgtId = f.loader_target_id || null;
|
|
//div containing loader
|
|
this.loaderDiv = null;
|
|
//defines loader text
|
|
this.loaderText = f.loader_text || "Loading...";
|
|
//defines loader innerHtml
|
|
this.loaderHtml = f.loader_html || null;
|
|
//defines css class for loader div
|
|
this.loaderCssClass = f.loader_css_class || "loader";
|
|
//delay for hiding loader
|
|
this.loaderCloseDelay = 200;
|
|
//callback function before loader is displayed
|
|
this.onShowLoader = Types.isFn(f.on_show_loader) ? f.on_show_loader : null;
|
|
//callback function after loader is closed
|
|
this.onHideLoader = Types.isFn(f.on_hide_loader) ? f.on_hide_loader : null;
|
|
|
|
this.tf = tf;
|
|
|
|
var containerDiv = Dom.create("div", ["id", tf.prfxLoader + tf.id]);
|
|
containerDiv.className = this.loaderCssClass;
|
|
|
|
var targetEl = !this.loaderTgtId ? (tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) : Dom.id(this.loaderTgtId);
|
|
if (!this.loaderTgtId) {
|
|
targetEl.insertBefore(containerDiv, tf.tbl);
|
|
} else {
|
|
targetEl.appendChild(containerDiv);
|
|
}
|
|
this.loaderDiv = Dom.id(tf.prfxLoader + tf.id);
|
|
if (!this.loaderHtml) {
|
|
this.loaderDiv.appendChild(Dom.text(this.loaderText));
|
|
} else {
|
|
this.loaderDiv.innerHTML = this.loaderHtml;
|
|
}
|
|
};
|
|
|
|
_classProps(Loader, null, {
|
|
show: {
|
|
writable: true,
|
|
value: function (p) {
|
|
var _this = this;
|
|
if (!this.tf.loader || !this.loaderDiv || this.loaderDiv.style.display === p) {
|
|
return;
|
|
}
|
|
|
|
var displayLoader = function () {
|
|
if (!_this.loaderDiv) {
|
|
return;
|
|
}
|
|
if (_this.onShowLoader && p !== "none") {
|
|
_this.onShowLoader.call(null, _this);
|
|
}
|
|
_this.loaderDiv.style.display = p;
|
|
if (_this.onHideLoader && p === "none") {
|
|
_this.onHideLoader.call(null, _this);
|
|
}
|
|
};
|
|
|
|
var t = p === "none" ? this.loaderCloseDelay : 1;
|
|
global.setTimeout(displayLoader, t);
|
|
}
|
|
},
|
|
remove: {
|
|
writable: true,
|
|
value: function () {
|
|
if (!this.loaderDiv) {
|
|
return;
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
});
|
|
|
|
return Loader;
|
|
})();
|
|
|
|
exports.Loader = Loader;
|
|
}); |