Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
const AppState = {
|
| 2 |
-
currentLang: 'en',
|
| 3 |
currentTheme: 'dark',
|
| 4 |
currentSection: 'home',
|
| 5 |
isMenuOpen: false,
|
|
@@ -12,86 +11,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 12 |
|
| 13 |
function initializeApp() {
|
| 14 |
loadPreferences();
|
| 15 |
-
initLanguage();
|
| 16 |
initTheme();
|
| 17 |
initNavigation();
|
| 18 |
initScrollEffects();
|
| 19 |
initFormHandlers();
|
| 20 |
initMobileMenu();
|
| 21 |
-
updateLanguageUI();
|
| 22 |
updateThemeUI();
|
| 23 |
AppState.isLoaded = true;
|
| 24 |
}
|
| 25 |
|
| 26 |
function loadPreferences() {
|
| 27 |
-
const savedLang = localStorage.getItem('portfolio-lang');
|
| 28 |
const savedTheme = localStorage.getItem('portfolio-theme');
|
| 29 |
-
if (savedLang) AppState.currentLang = savedLang;
|
| 30 |
-
if (savedTheme) AppState.currentTheme = savedTheme;
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
function initLanguage() {
|
| 34 |
-
const langToggle = document.getElementById('langToggle');
|
| 35 |
-
if (langToggle) {
|
| 36 |
-
langToggle.addEventListener('click', toggleLanguage);
|
| 37 |
-
}
|
| 38 |
-
setLanguage(AppState.currentLang);
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
function toggleLanguage() {
|
| 42 |
-
const newLang = AppState.currentLang === 'en' ? 'ar' : 'en';
|
| 43 |
-
setLanguage(newLang);
|
| 44 |
-
localStorage.setItem('portfolio-lang', newLang);
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
function setLanguage(lang) {
|
| 48 |
-
AppState.currentLang = lang;
|
| 49 |
-
const html = document.documentElement;
|
| 50 |
-
const body = document.body;
|
| 51 |
-
|
| 52 |
-
if (lang === 'ar') {
|
| 53 |
-
html.setAttribute('lang', 'ar');
|
| 54 |
-
html.setAttribute('dir', 'rtl');
|
| 55 |
-
body.setAttribute('data-lang', 'ar');
|
| 56 |
-
body.setAttribute('data-dir', 'rtl');
|
| 57 |
-
} else {
|
| 58 |
-
html.setAttribute('lang', 'en');
|
| 59 |
-
html.setAttribute('dir', 'ltr');
|
| 60 |
-
body.setAttribute('data-lang', 'en');
|
| 61 |
-
body.setAttribute('data-dir', 'ltr');
|
| 62 |
-
}
|
| 63 |
-
updateLanguageUI();
|
| 64 |
-
}
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
textElements.forEach(element => {
|
| 69 |
-
const enText = element.getAttribute('data-text-en');
|
| 70 |
-
const arText = element.getAttribute('data-text-ar');
|
| 71 |
-
if (AppState.currentLang === 'ar' && arText) {
|
| 72 |
-
element.textContent = arText;
|
| 73 |
-
} else if (AppState.currentLang === 'en' && enText) {
|
| 74 |
-
element.textContent = enText;
|
| 75 |
-
}
|
| 76 |
-
});
|
| 77 |
-
|
| 78 |
-
const placeholderElements = document.querySelectorAll('[data-placeholder-en], [data-placeholder-ar]');
|
| 79 |
-
placeholderElements.forEach(element => {
|
| 80 |
-
const enPlaceholder = element.getAttribute('data-placeholder-en');
|
| 81 |
-
const arPlaceholder = element.getAttribute('data-placeholder-ar');
|
| 82 |
-
if (AppState.currentLang === 'ar' && arPlaceholder) {
|
| 83 |
-
element.setAttribute('placeholder', arPlaceholder);
|
| 84 |
-
} else if (AppState.currentLang === 'en' && enPlaceholder) {
|
| 85 |
-
element.setAttribute('placeholder', enPlaceholder);
|
| 86 |
-
}
|
| 87 |
-
});
|
| 88 |
-
|
| 89 |
-
const langToggle = document.getElementById('langToggle');
|
| 90 |
-
if (langToggle) {
|
| 91 |
-
const langText = langToggle.querySelector('.lang-text');
|
| 92 |
-
if (langText) {
|
| 93 |
-
langText.textContent = AppState.currentLang === 'en' ? 'AR' : 'EN';
|
| 94 |
-
}
|
| 95 |
}
|
| 96 |
}
|
| 97 |
|
|
@@ -229,9 +162,7 @@ function handleFormSubmit(e) {
|
|
| 229 |
const data = Object.fromEntries(formData);
|
| 230 |
console.log('Form submitted:', data);
|
| 231 |
|
| 232 |
-
const message =
|
| 233 |
-
? 'تم إرسال الرسالة بنجاح!'
|
| 234 |
-
: 'Message sent successfully!';
|
| 235 |
|
| 236 |
alert(message);
|
| 237 |
e.target.reset();
|
|
|
|
| 1 |
const AppState = {
|
|
|
|
| 2 |
currentTheme: 'dark',
|
| 3 |
currentSection: 'home',
|
| 4 |
isMenuOpen: false,
|
|
|
|
| 11 |
|
| 12 |
function initializeApp() {
|
| 13 |
loadPreferences();
|
|
|
|
| 14 |
initTheme();
|
| 15 |
initNavigation();
|
| 16 |
initScrollEffects();
|
| 17 |
initFormHandlers();
|
| 18 |
initMobileMenu();
|
|
|
|
| 19 |
updateThemeUI();
|
| 20 |
AppState.isLoaded = true;
|
| 21 |
}
|
| 22 |
|
| 23 |
function loadPreferences() {
|
|
|
|
| 24 |
const savedTheme = localStorage.getItem('portfolio-theme');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
if (savedTheme) {
|
| 27 |
+
AppState.currentTheme = savedTheme;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
|
|
|
| 162 |
const data = Object.fromEntries(formData);
|
| 163 |
console.log('Form submitted:', data);
|
| 164 |
|
| 165 |
+
const message = 'Message sent successfully!';
|
|
|
|
|
|
|
| 166 |
|
| 167 |
alert(message);
|
| 168 |
e.target.reset();
|