-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Authress/graceful-handle-window-null
Handle window is null more gracefully.
- Loading branch information
Showing
5 changed files
with
106 additions
and
69 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class WindowManager { | ||
onLoad(callback) { | ||
if (typeof window !== 'undefined') { | ||
window.onload = callback; | ||
} | ||
} | ||
|
||
isLocalHost() { | ||
const isLocalHost = typeof window !== 'undefined' && window.location && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'); | ||
return isLocalHost; | ||
} | ||
|
||
getCurrentLocation() { | ||
return typeof window !== 'undefined' && new URL(window.location) || new URL('http://localhost:8080'); | ||
} | ||
|
||
assign(newLocationUrl) { | ||
if (typeof window === 'undefined') { | ||
return null; | ||
} | ||
return window.location.assign(newLocationUrl.toString()); | ||
} | ||
|
||
open(newLocationUrl) { | ||
if (typeof window === 'undefined') { | ||
return null; | ||
} | ||
return window.location.open(newLocationUrl.toString()); | ||
} | ||
} | ||
|
||
module.exports = new WindowManager(); |
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