Skip to content

Commit

Permalink
Added sweetalert for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
raidski20 committed Oct 22, 2023
1 parent 2d35821 commit 3aac25c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"bootstrap": "^5.3.1",
"jquery": "^3.7.1"
"jquery": "^3.7.1",
"sweetalert2": "^11.7.32"
}
}
11 changes: 11 additions & 0 deletions src/js/customSweetalertFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function showToastMessage(text, icon) {
Swal.fire({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
text: text,
icon: icon
});
}
6 changes: 3 additions & 3 deletions src/js/leetify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import vocabulary from './vocabulary.json';
import { showToastMessage } from './customSweetalertFunctions.js';

$(document).ready(function() {

Expand All @@ -15,12 +16,11 @@ $(document).ready(function() {
const encryptedText = $('#leetText').text().trim();
try {
await navigator.clipboard.writeText(encryptedText);
console.log('Content copied to clipboard');
showToastMessage('تم النسخ بنجاح', 'success');
} catch (err) {
console.error('Failed to copy: ', err);
showToastMessage('حدث خطأ ما أثناء النسخ', 'error', 'error');
}
});

});

function generateLeet(input) {
Expand Down
4 changes: 4 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Bootstrap
import 'bootstrap/dist/js/bootstrap.bundle.min';

// Sweetalert2
import Swal from 'sweetalert2';
window.Swal = Swal;

// Leetify code
import "./leetify.js"

Expand Down

0 comments on commit 3aac25c

Please sign in to comment.