-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Reusable Util for Opening OAuth Popup (#83)
* refactor: create reusable util for opening popup * chore: export util * chore: typing * chore: typing
- Loading branch information
1 parent
bf1005e
commit 75f95f5
Showing
4 changed files
with
36 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { openOAuthPopup } from './popupUtils'; | ||
|
||
export const utils = { | ||
openOAuthPopup, | ||
}; |
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,26 @@ | ||
import type ForumApplication from 'flarum/forum/ForumApplication'; | ||
|
||
export function openOAuthPopup(app: ForumApplication, attrs: Record<string, any>) { | ||
const fullscreen = app.forum.attribute('fof-oauth.fullscreenPopup'); | ||
if (fullscreen) { | ||
window.open(app.forum.attribute<string>('baseUrl') + attrs.path, 'logInPopup', 'fullscreen=yes'); | ||
} else { | ||
const defaultWidth = 580; | ||
const defaultHeight = 400; | ||
|
||
const width = app.forum.attribute<number>('fof-oauth.popupWidth') || defaultWidth; | ||
const height = app.forum.attribute<number>('fof-oauth.popupHeight') || defaultHeight; | ||
|
||
const windowHeight = $(window).height() ?? 0; | ||
const windowWidth = $(window).width() ?? 0; | ||
|
||
const top = windowHeight / 2 - height / 2; | ||
const left = windowWidth / 2 - width / 2; | ||
|
||
window.open( | ||
app.forum.attribute<string>('baseUrl') + attrs.path, | ||
'logInPopup', | ||
`width=${width},` + `height=${height},` + `top=${top},` + `left=${left},` + 'status=no,scrollbars=yes,resizable=no' | ||
); | ||
} | ||
} |