2014-11-15 15:34:32 +01:00
|
|
|
define(["exports", "../dom", "../types"], function (exports, _dom, _types) {
|
2015-02-28 10:27:28 +01:00
|
|
|
"use strict";
|
|
|
|
|
2015-04-06 10:45:46 +02:00
|
|
|
var _createClass = (function () { function defineProperties(target, props) { for (var key in props) { var prop = props[key]; prop.configurable = true; if (prop.value) prop.writable = true; } Object.defineProperties(target, props); } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
2015-02-28 10:27:28 +01:00
|
|
|
|
|
|
|
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
|
|
|
|
|
2015-04-06 10:45:46 +02:00
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
2015-02-28 10:27:28 +01:00
|
|
|
var Dom = _dom.Dom;
|
|
|
|
var Types = _types.Types;
|
|
|
|
|
|
|
|
var global = window;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loading message/spinner
|
|
|
|
* @param {Object} tf TableFilter instance
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Loader = exports.Loader = (function () {
|
|
|
|
function Loader(tf) {
|
|
|
|
_classCallCheck(this, Loader);
|
|
|
|
|
|
|
|
// TableFilter configuration
|
|
|
|
var f = tf.config();
|
|
|
|
//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;
|
2015-04-12 09:52:19 +02:00
|
|
|
//loader div
|
|
|
|
this.prfxLoader = "load_";
|
2015-02-28 10:27:28 +01:00
|
|
|
|
|
|
|
this.tf = tf;
|
|
|
|
|
2015-04-12 09:52:19 +02:00
|
|
|
var containerDiv = Dom.create("div", ["id", this.prfxLoader + tf.id]);
|
2015-02-28 10:27:28 +01:00
|
|
|
containerDiv.className = this.loaderCssClass;
|
|
|
|
|
|
|
|
var targetEl = !this.loaderTgtId ? tf.tbl.parentNode : Dom.id(this.loaderTgtId);
|
|
|
|
if (!this.loaderTgtId) {
|
|
|
|
targetEl.insertBefore(containerDiv, tf.tbl);
|
|
|
|
} else {
|
|
|
|
targetEl.appendChild(containerDiv);
|
2015-01-11 11:22:52 +01:00
|
|
|
}
|
2015-04-12 09:52:19 +02:00
|
|
|
this.loaderDiv = Dom.id(this.prfxLoader + tf.id);
|
2015-02-28 10:27:28 +01:00
|
|
|
if (!this.loaderHtml) {
|
|
|
|
this.loaderDiv.appendChild(Dom.text(this.loaderText));
|
|
|
|
} else {
|
|
|
|
this.loaderDiv.innerHTML = this.loaderHtml;
|
2015-01-11 11:22:52 +01:00
|
|
|
}
|
2014-12-13 10:11:54 +01:00
|
|
|
}
|
2014-11-15 15:34:32 +01:00
|
|
|
|
2015-04-06 10:45:46 +02:00
|
|
|
_createClass(Loader, {
|
2015-02-28 10:27:28 +01:00
|
|
|
show: {
|
|
|
|
value: function show(p) {
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
if (!this.tf.loader || !this.loaderDiv || this.loaderDiv.style.display === p) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-26 11:48:13 +01:00
|
|
|
|
2015-02-28 10:27:28 +01:00
|
|
|
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);
|
2015-04-06 10:45:46 +02:00
|
|
|
}
|
2015-02-28 10:27:28 +01:00
|
|
|
},
|
|
|
|
remove: {
|
|
|
|
value: function remove() {
|
|
|
|
if (!this.loaderDiv) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var tf = this.tf,
|
|
|
|
targetEl = !this.loaderTgtId ? tf.gridLayout ? tf.Cpt.gridLayout.tblCont : tf.tbl.parentNode : Dom.id(this.loaderTgtId);
|
|
|
|
targetEl.removeChild(this.loaderDiv);
|
|
|
|
this.loaderDiv = null;
|
2015-04-06 10:45:46 +02:00
|
|
|
}
|
2015-02-28 10:27:28 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return Loader;
|
|
|
|
})();
|
|
|
|
});
|
|
|
|
//# sourceMappingURL=loader.js.map
|