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 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
tf.loaderTgtId = f.loader_target_id || null;
//div containing loader
tf.loaderDiv = null;
//defines loader text
tf.loaderText = f.loader_text || "Loading...";
//defines loader innerHtml
tf.loaderHtml = f.loader_html || null;
//defines css class for loader div
tf.loaderCssClass = f.loader_css_class || "loader";
//delay for hiding loader
tf.loaderCloseDelay = 200;
//callback function before loader is displayed
2014-11-16 01:29:07 +01:00
tf.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 01:29:07 +01:00
tf.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-15 15:34:32 +01:00
containerDiv.className = tf.loaderCssClass;
2014-10-27 08:01:33 +01:00
2014-11-16 01:29:07 +01:00
var targetEl = !tf.loaderTgtId ? (tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) : Dom.id(tf.loaderTgtId);
2014-11-15 15:34:32 +01:00
if (!tf.loaderTgtId) {
targetEl.insertBefore(containerDiv, tf.tbl);
} else {
targetEl.appendChild(containerDiv);
}
2014-11-16 01:29:07 +01:00
tf.loaderDiv = Dom.id(tf.prfxLoader + tf.id);
2014-11-15 15:34:32 +01:00
if (!tf.loaderHtml) {
2014-11-16 01:29:07 +01:00
tf.loaderDiv.appendChild(Dom.text(tf.loaderText));
2014-11-15 15:34:32 +01:00
} else {
tf.loaderDiv.innerHTML = tf.loaderHtml;
}
};
_classProps(Loader, null, {
show: {
writable: true,
value: function (p) {
if (!this.tf.loader || !this.tf.loaderDiv || this.tf.loaderDiv.style.display === p) {
2014-10-27 08:01:33 +01:00
return;
2014-11-15 15:34:32 +01:00
}
var o = this.tf;
2014-10-27 08:01:33 +01:00
2014-11-15 15:34:32 +01:00
function displayLoader() {
if (!o.loaderDiv) {
return;
2014-10-27 08:01:33 +01:00
}
2014-11-15 15:34:32 +01:00
if (o.onShowLoader && p !== "none") {
o.onShowLoader.call(null, o);
2014-10-27 08:01:33 +01:00
}
o.loaderDiv.style.display = p;
2014-11-15 15:34:32 +01:00
if (o.onHideLoader && p === "none") {
o.onHideLoader.call(null, o);
2014-10-27 08:01:33 +01:00
}
2014-11-15 15:34:32 +01:00
}
2014-10-27 08:01:33 +01:00
2014-11-15 15:34:32 +01:00
var t = p === "none" ? this.tf.loaderCloseDelay : 1;
global.setTimeout(displayLoader, t);
}
},
remove: {
writable: true,
value: function () {
if (!this.tf.loaderDiv) {
2014-10-27 08:01:33 +01:00
return;
2014-11-15 15:34:32 +01:00
}
2014-11-16 01:29:07 +01:00
var targetEl = !this.tf.loaderTgtId ? (this.tf.gridLayout ? this.tf.tblCont : this.tf.tbl.parentNode) : Dom.id(this.tf.loaderTgtId);
2014-11-15 15:34:32 +01:00
targetEl.removeChild(this.tf.loaderDiv);
this.tf.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
});