|
|
@ -17,95 +17,129 @@ |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
|
|
value: true |
|
|
|
value: true |
|
|
|
}); |
|
|
|
}); |
|
|
|
var OverlayManager = { |
|
|
|
|
|
|
|
overlays: {}, |
|
|
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
|
|
|
active: null, |
|
|
|
|
|
|
|
register: function register(name, element, callerCloseMethod, canForceClose) { |
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var OverlayManager = function () { |
|
|
|
|
|
|
|
function OverlayManager() { |
|
|
|
|
|
|
|
_classCallCheck(this, OverlayManager); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._overlays = {}; |
|
|
|
|
|
|
|
this._active = null; |
|
|
|
|
|
|
|
this._keyDownBound = this._keyDown.bind(this); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_createClass(OverlayManager, [{ |
|
|
|
|
|
|
|
key: 'register', |
|
|
|
|
|
|
|
value: function register(name, element) { |
|
|
|
var _this = this; |
|
|
|
var _this = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var callerCloseMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; |
|
|
|
|
|
|
|
var canForceClose = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; |
|
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
var container; |
|
|
|
var container = void 0; |
|
|
|
if (!name || !element || !(container = element.parentNode)) { |
|
|
|
if (!name || !element || !(container = element.parentNode)) { |
|
|
|
throw new Error('Not enough parameters.'); |
|
|
|
throw new Error('Not enough parameters.'); |
|
|
|
} else if (_this.overlays[name]) { |
|
|
|
} else if (_this._overlays[name]) { |
|
|
|
throw new Error('The overlay is already registered.'); |
|
|
|
throw new Error('The overlay is already registered.'); |
|
|
|
} |
|
|
|
} |
|
|
|
_this.overlays[name] = { |
|
|
|
_this._overlays[name] = { |
|
|
|
element: element, |
|
|
|
element: element, |
|
|
|
container: container, |
|
|
|
container: container, |
|
|
|
callerCloseMethod: callerCloseMethod || null, |
|
|
|
callerCloseMethod: callerCloseMethod, |
|
|
|
canForceClose: canForceClose || false |
|
|
|
canForceClose: canForceClose |
|
|
|
}; |
|
|
|
}; |
|
|
|
resolve(); |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
unregister: function unregister(name) { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'unregister', |
|
|
|
|
|
|
|
value: function unregister(name) { |
|
|
|
var _this2 = this; |
|
|
|
var _this2 = this; |
|
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
if (!_this2.overlays[name]) { |
|
|
|
if (!_this2._overlays[name]) { |
|
|
|
throw new Error('The overlay does not exist.'); |
|
|
|
throw new Error('The overlay does not exist.'); |
|
|
|
} else if (_this2.active === name) { |
|
|
|
} else if (_this2._active === name) { |
|
|
|
throw new Error('The overlay cannot be removed while it is active.'); |
|
|
|
throw new Error('The overlay cannot be removed while it is active.'); |
|
|
|
} |
|
|
|
} |
|
|
|
delete _this2.overlays[name]; |
|
|
|
delete _this2._overlays[name]; |
|
|
|
resolve(); |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
open: function open(name) { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'open', |
|
|
|
|
|
|
|
value: function open(name) { |
|
|
|
var _this3 = this; |
|
|
|
var _this3 = this; |
|
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
if (!_this3.overlays[name]) { |
|
|
|
if (!_this3._overlays[name]) { |
|
|
|
throw new Error('The overlay does not exist.'); |
|
|
|
throw new Error('The overlay does not exist.'); |
|
|
|
} else if (_this3.active) { |
|
|
|
} else if (_this3._active) { |
|
|
|
if (_this3.overlays[name].canForceClose) { |
|
|
|
if (_this3._overlays[name].canForceClose) { |
|
|
|
_this3._closeThroughCaller(); |
|
|
|
_this3._closeThroughCaller(); |
|
|
|
} else if (_this3.active === name) { |
|
|
|
} else if (_this3._active === name) { |
|
|
|
throw new Error('The overlay is already active.'); |
|
|
|
throw new Error('The overlay is already active.'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
throw new Error('Another overlay is currently active.'); |
|
|
|
throw new Error('Another overlay is currently active.'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_this3.active = name; |
|
|
|
_this3._active = name; |
|
|
|
_this3.overlays[_this3.active].element.classList.remove('hidden'); |
|
|
|
_this3._overlays[_this3._active].element.classList.remove('hidden'); |
|
|
|
_this3.overlays[_this3.active].container.classList.remove('hidden'); |
|
|
|
_this3._overlays[_this3._active].container.classList.remove('hidden'); |
|
|
|
window.addEventListener('keydown', _this3._keyDown); |
|
|
|
window.addEventListener('keydown', _this3._keyDownBound); |
|
|
|
resolve(); |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
close: function close(name) { |
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'close', |
|
|
|
|
|
|
|
value: function close(name) { |
|
|
|
var _this4 = this; |
|
|
|
var _this4 = this; |
|
|
|
|
|
|
|
|
|
|
|
return new Promise(function (resolve) { |
|
|
|
return new Promise(function (resolve) { |
|
|
|
if (!_this4.overlays[name]) { |
|
|
|
if (!_this4._overlays[name]) { |
|
|
|
throw new Error('The overlay does not exist.'); |
|
|
|
throw new Error('The overlay does not exist.'); |
|
|
|
} else if (!_this4.active) { |
|
|
|
} else if (!_this4._active) { |
|
|
|
throw new Error('The overlay is currently not active.'); |
|
|
|
throw new Error('The overlay is currently not active.'); |
|
|
|
} else if (_this4.active !== name) { |
|
|
|
} else if (_this4._active !== name) { |
|
|
|
throw new Error('Another overlay is currently active.'); |
|
|
|
throw new Error('Another overlay is currently active.'); |
|
|
|
} |
|
|
|
} |
|
|
|
_this4.overlays[_this4.active].container.classList.add('hidden'); |
|
|
|
_this4._overlays[_this4._active].container.classList.add('hidden'); |
|
|
|
_this4.overlays[_this4.active].element.classList.add('hidden'); |
|
|
|
_this4._overlays[_this4._active].element.classList.add('hidden'); |
|
|
|
_this4.active = null; |
|
|
|
_this4._active = null; |
|
|
|
window.removeEventListener('keydown', _this4._keyDown); |
|
|
|
window.removeEventListener('keydown', _this4._keyDownBound); |
|
|
|
resolve(); |
|
|
|
resolve(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
_keyDown: function _keyDown(evt) { |
|
|
|
}, { |
|
|
|
var self = OverlayManager; |
|
|
|
key: '_keyDown', |
|
|
|
if (self.active && evt.keyCode === 27) { |
|
|
|
value: function _keyDown(evt) { |
|
|
|
self._closeThroughCaller(); |
|
|
|
if (this._active && evt.keyCode === 27) { |
|
|
|
|
|
|
|
this._closeThroughCaller(); |
|
|
|
evt.preventDefault(); |
|
|
|
evt.preventDefault(); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
_closeThroughCaller: function _closeThroughCaller() { |
|
|
|
|
|
|
|
if (this.overlays[this.active].callerCloseMethod) { |
|
|
|
|
|
|
|
this.overlays[this.active].callerCloseMethod(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (this.active) { |
|
|
|
}, { |
|
|
|
this.close(this.active); |
|
|
|
key: '_closeThroughCaller', |
|
|
|
|
|
|
|
value: function _closeThroughCaller() { |
|
|
|
|
|
|
|
if (this._overlays[this._active].callerCloseMethod) { |
|
|
|
|
|
|
|
this._overlays[this._active].callerCloseMethod(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (this._active) { |
|
|
|
|
|
|
|
this.close(this._active); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
}, { |
|
|
|
|
|
|
|
key: 'active', |
|
|
|
|
|
|
|
get: function get() { |
|
|
|
|
|
|
|
return this._active; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return OverlayManager; |
|
|
|
|
|
|
|
}(); |
|
|
|
|
|
|
|
|
|
|
|
exports.OverlayManager = OverlayManager; |
|
|
|
exports.OverlayManager = OverlayManager; |