|
@@ -20,78 +20,86 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
var OverlayManager = {
|
|
|
overlays: {},
|
|
|
active: null,
|
|
|
- register: function overlayManagerRegister(name, element, callerCloseMethod, canForceClose) {
|
|
|
+ register: function register(name, element, callerCloseMethod, canForceClose) {
|
|
|
+ var _this = this;
|
|
|
+
|
|
|
return new Promise(function (resolve) {
|
|
|
var container;
|
|
|
if (!name || !element || !(container = element.parentNode)) {
|
|
|
throw new Error('Not enough parameters.');
|
|
|
- } else if (this.overlays[name]) {
|
|
|
+ } else if (_this.overlays[name]) {
|
|
|
throw new Error('The overlay is already registered.');
|
|
|
}
|
|
|
- this.overlays[name] = {
|
|
|
+ _this.overlays[name] = {
|
|
|
element: element,
|
|
|
container: container,
|
|
|
callerCloseMethod: callerCloseMethod || null,
|
|
|
canForceClose: canForceClose || false
|
|
|
};
|
|
|
resolve();
|
|
|
- }.bind(this));
|
|
|
+ });
|
|
|
},
|
|
|
- unregister: function overlayManagerUnregister(name) {
|
|
|
+ unregister: function unregister(name) {
|
|
|
+ var _this2 = this;
|
|
|
+
|
|
|
return new Promise(function (resolve) {
|
|
|
- if (!this.overlays[name]) {
|
|
|
+ if (!_this2.overlays[name]) {
|
|
|
throw new Error('The overlay does not exist.');
|
|
|
- } else if (this.active === name) {
|
|
|
+ } else if (_this2.active === name) {
|
|
|
throw new Error('The overlay cannot be removed while it is active.');
|
|
|
}
|
|
|
- delete this.overlays[name];
|
|
|
+ delete _this2.overlays[name];
|
|
|
resolve();
|
|
|
- }.bind(this));
|
|
|
+ });
|
|
|
},
|
|
|
- open: function overlayManagerOpen(name) {
|
|
|
+ open: function open(name) {
|
|
|
+ var _this3 = this;
|
|
|
+
|
|
|
return new Promise(function (resolve) {
|
|
|
- if (!this.overlays[name]) {
|
|
|
+ if (!_this3.overlays[name]) {
|
|
|
throw new Error('The overlay does not exist.');
|
|
|
- } else if (this.active) {
|
|
|
- if (this.overlays[name].canForceClose) {
|
|
|
- this._closeThroughCaller();
|
|
|
- } else if (this.active === name) {
|
|
|
+ } else if (_this3.active) {
|
|
|
+ if (_this3.overlays[name].canForceClose) {
|
|
|
+ _this3._closeThroughCaller();
|
|
|
+ } else if (_this3.active === name) {
|
|
|
throw new Error('The overlay is already active.');
|
|
|
} else {
|
|
|
throw new Error('Another overlay is currently active.');
|
|
|
}
|
|
|
}
|
|
|
- this.active = name;
|
|
|
- this.overlays[this.active].element.classList.remove('hidden');
|
|
|
- this.overlays[this.active].container.classList.remove('hidden');
|
|
|
- window.addEventListener('keydown', this._keyDown);
|
|
|
+ _this3.active = name;
|
|
|
+ _this3.overlays[_this3.active].element.classList.remove('hidden');
|
|
|
+ _this3.overlays[_this3.active].container.classList.remove('hidden');
|
|
|
+ window.addEventListener('keydown', _this3._keyDown);
|
|
|
resolve();
|
|
|
- }.bind(this));
|
|
|
+ });
|
|
|
},
|
|
|
- close: function overlayManagerClose(name) {
|
|
|
+ close: function close(name) {
|
|
|
+ var _this4 = this;
|
|
|
+
|
|
|
return new Promise(function (resolve) {
|
|
|
- if (!this.overlays[name]) {
|
|
|
+ if (!_this4.overlays[name]) {
|
|
|
throw new Error('The overlay does not exist.');
|
|
|
- } else if (!this.active) {
|
|
|
+ } else if (!_this4.active) {
|
|
|
throw new Error('The overlay is currently not active.');
|
|
|
- } else if (this.active !== name) {
|
|
|
+ } else if (_this4.active !== name) {
|
|
|
throw new Error('Another overlay is currently active.');
|
|
|
}
|
|
|
- this.overlays[this.active].container.classList.add('hidden');
|
|
|
- this.overlays[this.active].element.classList.add('hidden');
|
|
|
- this.active = null;
|
|
|
- window.removeEventListener('keydown', this._keyDown);
|
|
|
+ _this4.overlays[_this4.active].container.classList.add('hidden');
|
|
|
+ _this4.overlays[_this4.active].element.classList.add('hidden');
|
|
|
+ _this4.active = null;
|
|
|
+ window.removeEventListener('keydown', _this4._keyDown);
|
|
|
resolve();
|
|
|
- }.bind(this));
|
|
|
+ });
|
|
|
},
|
|
|
- _keyDown: function overlayManager_keyDown(evt) {
|
|
|
+ _keyDown: function _keyDown(evt) {
|
|
|
var self = OverlayManager;
|
|
|
if (self.active && evt.keyCode === 27) {
|
|
|
self._closeThroughCaller();
|
|
|
evt.preventDefault();
|
|
|
}
|
|
|
},
|
|
|
- _closeThroughCaller: function overlayManager_closeThroughCaller() {
|
|
|
+ _closeThroughCaller: function _closeThroughCaller() {
|
|
|
if (this.overlays[this.active].callerCloseMethod) {
|
|
|
this.overlays[this.active].callerCloseMethod();
|
|
|
}
|