Skip to content

Commit

Permalink
Code Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SupianIDz committed Jul 8, 2021
1 parent 6b7fdaa commit fa77ae2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion public/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

42 changes: 19 additions & 23 deletions resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection JSUnresolvedVariable

import $ from 'jquery';
import 'select2';

Expand All @@ -12,7 +14,7 @@ $(document).ready(() => {
const select = $('.impersonate-select');
const logout = $('.impersonate-logout');

toggle.on('click', function () {
toggle.on('click', () => {
$('.impersonate-interface').toggleClass('impersonate-hidden');

select.select2({
Expand All @@ -37,40 +39,34 @@ $(document).ready(() => {

select.select2().on('select2:open', () => {
$('.select2-search__field').attr('placeholder', ' Search...');
})
});

select.on('change', function () {
fetch('/impersonate/signin', {
const xhr = (url, body) => {
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
},
body: JSON.stringify({
user: window.impersonate.user,
take: $(this).val(),
_token: window.impersonate.csrf,
})
body: body
})
.then(() => {
window.location = '';
});
}

select.on('change', function () {
xhr('/impersonate/signin', JSON.stringify({
user: window.impersonate.user,
take: $(this).val(),
_token: window.impersonate.csrf,
}));
});

logout.on('click', function () {
fetch('/impersonate/logout', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
},
body: JSON.stringify({
_token: window.impersonate.csrf,
})
}).then(() => {
window.location = '';
});
logout.on('click', () => {
xhr('/impersonate/logout', JSON.stringify({
_token: window.impersonate.csrf,
}));
});
});
2 changes: 1 addition & 1 deletion src/Impersonate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Impersonate
/**
* @var string
*/
public const VERSION = 'v2.0.3';
public const VERSION = 'v2.0.6';

/**
* @var string
Expand Down

0 comments on commit fa77ae2

Please sign in to comment.