-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert the overlay manager to a class #8119
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,25 +25,35 @@ | |
} | ||
}(this, function (exports) { | ||
|
||
var OverlayManager = { | ||
overlays: {}, | ||
active: null, | ||
/** | ||
* @class | ||
*/ | ||
var OverlayManager = (function OverlayManagerClosure() { | ||
/** | ||
* @constructs OverlayManager | ||
*/ | ||
function OverlayManager() { | ||
this.overlays = {}; | ||
this.active = null; | ||
} | ||
|
||
OverlayManager.prototype = { | ||
/** | ||
* @param {string} name The name of the overlay that is registered. | ||
* @param {HTMLDivElement} element The overlay's DOM element. | ||
* @param {function} callerCloseMethod (optional) The method that, if present, | ||
* will call OverlayManager.close from the Object | ||
* @param {function} callerCloseMethod (optional) The method that, if | ||
* present, calls OverlayManager.close from the Object | ||
* registering the overlay. Access to this method is | ||
* necessary in order to run cleanup code when e.g. | ||
* the overlay is force closed. The default is null. | ||
* @param {boolean} canForceClose (optional) Indicates if opening the overlay | ||
* will close an active overlay. The default is false. | ||
* @param {boolean} canForceClose (optional) Indicates if opening the | ||
* overlay closes an active overlay. The default is false. | ||
* @returns {Promise} A promise that is resolved when the overlay has been | ||
* registered. | ||
*/ | ||
register: function overlayManagerRegister(name, element, | ||
callerCloseMethod, canForceClose) { | ||
register: | ||
function OverlayManager_register(name, element, callerCloseMethod, | ||
canForceClose) { | ||
return new Promise(function (resolve) { | ||
var container; | ||
if (!name || !element || !(container = element.parentNode)) { | ||
|
@@ -64,7 +74,7 @@ var OverlayManager = { | |
* @returns {Promise} A promise that is resolved when the overlay has been | ||
* unregistered. | ||
*/ | ||
unregister: function overlayManagerUnregister(name) { | ||
unregister: function OverlayManager_unregister(name) { | ||
return new Promise(function (resolve) { | ||
if (!this.overlays[name]) { | ||
throw new Error('The overlay does not exist.'); | ||
|
@@ -82,7 +92,7 @@ var OverlayManager = { | |
* @returns {Promise} A promise that is resolved when the overlay has been | ||
* opened. | ||
*/ | ||
open: function overlayManagerOpen(name) { | ||
open: function OverlayManager_open(name) { | ||
return new Promise(function (resolve) { | ||
if (!this.overlays[name]) { | ||
throw new Error('The overlay does not exist.'); | ||
|
@@ -99,7 +109,7 @@ var OverlayManager = { | |
this.overlays[this.active].element.classList.remove('hidden'); | ||
this.overlays[this.active].container.classList.remove('hidden'); | ||
|
||
window.addEventListener('keydown', this._keyDown); | ||
window.addEventListener('keydown', this._keyDown.bind(this)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately you'll not be able to remove the event listener if you define it like this. |
||
resolve(); | ||
}.bind(this)); | ||
}, | ||
|
@@ -109,7 +119,7 @@ var OverlayManager = { | |
* @returns {Promise} A promise that is resolved when the overlay has been | ||
* closed. | ||
*/ | ||
close: function overlayManagerClose(name) { | ||
close: function OverlayManager_close(name) { | ||
return new Promise(function (resolve) { | ||
if (!this.overlays[name]) { | ||
throw new Error('The overlay does not exist.'); | ||
|
@@ -122,34 +132,36 @@ var OverlayManager = { | |
this.overlays[this.active].element.classList.add('hidden'); | ||
this.active = null; | ||
|
||
window.removeEventListener('keydown', this._keyDown); | ||
window.removeEventListener('keydown', this._keyDown.bind(this)); | ||
resolve(); | ||
}.bind(this)); | ||
}, | ||
|
||
/** | ||
* @private | ||
*/ | ||
_keyDown: function overlayManager_keyDown(evt) { | ||
var self = OverlayManager; | ||
if (self.active && evt.keyCode === 27) { // Esc key. | ||
self._closeThroughCaller(); | ||
_keyDown: function OverlayManager_keyDown(evt) { | ||
if (this.active && evt.keyCode === 27) { // Esc key. | ||
this._closeThroughCaller(); | ||
evt.preventDefault(); | ||
} | ||
}, | ||
|
||
/** | ||
* @private | ||
*/ | ||
_closeThroughCaller: function overlayManager_closeThroughCaller() { | ||
_closeThroughCaller: function OverlayManager_closeThroughCaller() { | ||
if (this.overlays[this.active].callerCloseMethod) { | ||
this.overlays[this.active].callerCloseMethod(); | ||
} | ||
if (this.active) { | ||
this.close(this.active); | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
return OverlayManager; | ||
})(); | ||
|
||
exports.OverlayManager = OverlayManager; | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm wondering if it might not be a bit cleaner to just have this definition at the top of the file instead (like it currently is).