-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add modal for External Redirects (#1740)
* Add Modal for External Redirects * Add Translations * Apply fixes from StyleCI * Add system to always trust a domain * Show modal only if a has data-external-redirect * Move isExternalFile check in an Attribute * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io> Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
- Loading branch information
1 parent
1f5b83b
commit ac97a57
Showing
21 changed files
with
130 additions
and
13 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,48 @@ | ||
export default () => { | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const links = document.querySelectorAll('a[data-external-redirect]'); | ||
|
||
links.forEach((link) => { | ||
const href = link.getAttribute('href'); | ||
|
||
// Check if the link is external | ||
link.addEventListener('click', (e) => { | ||
let externalHost; | ||
if (link.getAttribute('data-external-redirect') !== 'true') { | ||
externalHost = new URL(link.getAttribute('data-external-redirect')).hostname; | ||
} else { | ||
externalHost = new URL(href).hostname; | ||
} | ||
|
||
// We check if the user has already trusted the domain | ||
const trustedDomains = window.localStorage.getItem('trustedDomains') ? JSON.parse(window.localStorage.getItem('trustedDomains')) : []; | ||
if (trustedDomains.includes(externalHost)) { | ||
return; | ||
} | ||
|
||
// We prevent the link from opening | ||
e.preventDefault(); | ||
|
||
$('#externalRedirectHost').html(externalHost); | ||
$('#externalRedirectUrl').attr('href', href); | ||
$('#externalRedirectModal').modal('show'); | ||
}); | ||
}); | ||
|
||
document.querySelector('#externalRedirectUrl') | ||
.addEventListener('click', () => { | ||
if (document.querySelector('#redirectAlwaysTrustThisDomain').checked) { | ||
const host = new URL(document.querySelector('#externalRedirectUrl').getAttribute('href')).hostname; | ||
const trustedDomains = window.localStorage.getItem('trustedDomains') ? JSON.parse(window.localStorage.getItem('trustedDomains')) : []; | ||
|
||
if (!trustedDomains.includes(host)) { | ||
trustedDomains.push(host); | ||
window.localStorage.setItem('trustedDomains', JSON.stringify(trustedDomains)); | ||
} | ||
} | ||
|
||
$('#externalRedirectModal') | ||
.modal('hide'); | ||
}); | ||
}); | ||
}; |
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
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
25 changes: 25 additions & 0 deletions
25
resources/views/layouts/default/external_redirect_modal.blade.php
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,25 @@ | ||
<div class="modal fade" id="externalRedirectModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title">@lang('common.external_redirection')</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
@lang('common.abouttoleave') <span class="text-primary" id="externalRedirectHost"></span>. @lang('common.wanttocontinue') | ||
<div class="input-group form-group-no-border mt-2"> | ||
<input id="redirectAlwaysTrustThisDomain" type="checkbox" value="1"> | ||
<label for="redirectAlwaysTrustThisDomain" class="control-label mb-0 ml-2"> | ||
@lang('common.alwaystrustdomain') | ||
</label> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" data-dismiss="modal">@lang('common.close')</button> | ||
<a href="#" target="_blank" class="btn btn-primary" id="externalRedirectUrl">@lang('common.continue')</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |