Skip to content
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

chore: drop usage of jquery in install and update interfaces #3797

Merged
merged 3 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions framework/core/views/install/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,37 @@
</div>
</form>

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(function() {
$('form :input:first').select();
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('form input').select();

$('form').on('submit', function(e) {
e.preventDefault();
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();

var $button = $(this).find('button')
.text('Please Wait...')
.prop('disabled', true);
var button = this.querySelector('button');
button.textContent = 'Please Wait...';
button.disabled = true;

$.post('', $(this).serialize())
.done(function() {
window.location.reload();
fetch('', {
method: 'POST',
body: new FormData(this)
})
.fail(function(data) {
$('#error').show().text('Something went wrong:\n\n' + data.responseText);

$button.prop('disabled', false).text('Install Flarum');
});

return false;
.then(response => {
if (response.ok) {
window.location.reload();
} else {
response.text().then(errorMessage => {
var error = document.querySelector('#error');
error.style.display = 'block';
error.textContent = 'Something went wrong:\n\n' + errorMessage;
button.disabled = false;
button.textContent = 'Install Flarum';
});
}
});

return false;
});
});
});
</script>

46 changes: 27 additions & 19 deletions framework/core/views/install/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,37 @@
</div>
</form>

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(function() {
$('form :input:first').select();
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('form input').select();

$('form').on('submit', function(e) {
e.preventDefault();
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();

var $button = $(this).find('button')
.text('Please Wait...')
.prop('disabled', true);
var button = this.querySelector('button');
button.textContent = 'Please Wait...';
button.disabled = true;

$.post('', $(this).serialize())
.done(function() {
window.location.reload();
fetch('', {
method: 'POST',
body: new FormData(this)
})
.fail(function(data) {
$('#error').show().text('Something went wrong:\n\n' + data.responseText);

$button.prop('disabled', false).text('Update Flarum');
});

return false;
.then(response => {
if (response.ok) {
window.location.reload();
} else {
response.text().then(errorMessage => {
var error = document.querySelector('#error');
error.style.display = 'block';
error.textContent = 'Something went wrong:\n\n' + errorMessage;
button.disabled = false;
button.textContent = 'Update Flarum';
});
}
});

return false;
});
});
});
</script>