arefamer commited on
Commit
23d8f64
·
verified ·
1 Parent(s): 0300ff6

انشى لي تطبيق الهيكل خرافي html css java

Browse files
Files changed (4) hide show
  1. components/todo.js +176 -0
  2. components/weather.js +134 -0
  3. script.js +9 -2
  4. style.css +16 -5
components/todo.js ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class TodoApp extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ :host {
7
+ display: block;
8
+ max-width: 500px;
9
+ margin: 0 auto;
10
+ font-family: 'Inter', sans-serif;
11
+ }
12
+ .todo-container {
13
+ background: white;
14
+ border-radius: 12px;
15
+ padding: 24px;
16
+ box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
17
+ }
18
+ h2 {
19
+ margin-top: 0;
20
+ color: var(--dark);
21
+ text-align: center;
22
+ }
23
+ .todo-form {
24
+ display: flex;
25
+ gap: 10px;
26
+ margin-bottom: 20px;
27
+ }
28
+ .todo-input {
29
+ flex: 1;
30
+ padding: 12px 16px;
31
+ border: 2px solid #e2e8f0;
32
+ border-radius: 8px;
33
+ font-size: 16px;
34
+ outline: none;
35
+ transition: border-color 0.3s;
36
+ }
37
+ .todo-input:focus {
38
+ border-color: var(--primary);
39
+ }
40
+ .add-btn {
41
+ background: var(--primary);
42
+ color: white;
43
+ border: none;
44
+ border-radius: 8px;
45
+ padding: 0 20px;
46
+ font-size: 16px;
47
+ font-weight: 600;
48
+ cursor: pointer;
49
+ transition: all 0.3s;
50
+ }
51
+ .add-btn:hover {
52
+ background: var(--secondary);
53
+ transform: translateY(-2px);
54
+ }
55
+ .todo-list {
56
+ list-style: none;
57
+ padding: 0;
58
+ margin: 0;
59
+ }
60
+ .todo-item {
61
+ display: flex;
62
+ align-items: center;
63
+ padding: 12px 16px;
64
+ background: #f8fafc;
65
+ border-radius: 8px;
66
+ margin-bottom: 10px;
67
+ transition: all 0.3s;
68
+ }
69
+ .todo-item:hover {
70
+ transform: translateX(5px);
71
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
72
+ }
73
+ .todo-checkbox {
74
+ margin-right: 12px;
75
+ cursor: pointer;
76
+ }
77
+ .todo-text {
78
+ flex: 1;
79
+ margin: 0;
80
+ }
81
+ .todo-text.completed {
82
+ text-decoration: line-through;
83
+ color: #94a3b8;
84
+ }
85
+ .delete-btn {
86
+ background: none;
87
+ border: none;
88
+ color: #ef4444;
89
+ font-size: 18px;
90
+ cursor: pointer;
91
+ opacity: 0;
92
+ transition: opacity 0.3s;
93
+ }
94
+ .todo-item:hover .delete-btn {
95
+ opacity: 1;
96
+ }
97
+ </style>
98
+ <div class="todo-container">
99
+ <h2>Todo List</h2>
100
+ <form class="todo-form">
101
+ <input type="text" class="todo-input" placeholder="Add a new task..." required>
102
+ <button type="submit" class="add-btn">Add</button>
103
+ </form>
104
+ <ul class="todo-list"></ul>
105
+ </div>
106
+ `;
107
+
108
+ this.todos = JSON.parse(localStorage.getItem('todos')) || [];
109
+ this.renderTodos();
110
+
111
+ this.shadowRoot.querySelector('.todo-form').addEventListener('submit', (e) => {
112
+ e.preventDefault();
113
+ const input = this.shadowRoot.querySelector('.todo-input');
114
+ if (input.value.trim()) {
115
+ this.addTodo(input.value.trim());
116
+ input.value = '';
117
+ }
118
+ });
119
+ }
120
+
121
+ addTodo(text) {
122
+ const newTodo = {
123
+ id: Date.now(),
124
+ text,
125
+ completed: false
126
+ };
127
+ this.todos.push(newTodo);
128
+ this.saveTodos();
129
+ this.renderTodos();
130
+ }
131
+
132
+ toggleTodo(id) {
133
+ this.todos = this.todos.map(todo =>
134
+ todo.id === id ? { ...todo, completed: !todo.completed } : todo
135
+ );
136
+ this.saveTodos();
137
+ this.renderTodos();
138
+ }
139
+
140
+ deleteTodo(id) {
141
+ this.todos = this.todos.filter(todo => todo.id !== id);
142
+ this.saveTodos();
143
+ this.renderTodos();
144
+ }
145
+
146
+ saveTodos() {
147
+ localStorage.setItem('todos', JSON.stringify(this.todos));
148
+ }
149
+
150
+ renderTodos() {
151
+ const todoList = this.shadowRoot.querySelector('.todo-list');
152
+ todoList.innerHTML = '';
153
+
154
+ if (this.todos.length === 0) {
155
+ todoList.innerHTML = '<p style="text-align: center; color: #94a3b8;">No tasks yet. Add one above!</p>';
156
+ return;
157
+ }
158
+
159
+ this.todos.forEach(todo => {
160
+ const li = document.createElement('li');
161
+ li.className = 'todo-item';
162
+ li.innerHTML = `
163
+ <input type="checkbox" class="todo-checkbox" ${todo.completed ? 'checked' : ''}>
164
+ <p class="todo-text ${todo.completed ? 'completed' : ''}">${todo.text}</p>
165
+ <button class="delete-btn">×</button>
166
+ `;
167
+
168
+ li.querySelector('.todo-checkbox').addEventListener('change', () => this.toggleTodo(todo.id));
169
+ li.querySelector('.delete-btn').addEventListener('click', () => this.deleteTodo(todo.id));
170
+
171
+ todoList.appendChild(li);
172
+ });
173
+ }
174
+ }
175
+
176
+ customElements.define('todo-app', TodoApp);
components/weather.js ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class WeatherWidget extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ :host {
7
+ display: block;
8
+ font-family: 'Inter', sans-serif;
9
+ }
10
+ .weather-card {
11
+ background: linear-gradient(135deg, #667eea, #764ba2);
12
+ border-radius: 16px;
13
+ padding: 24px;
14
+ color: white;
15
+ box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
16
+ max-width: 350px;
17
+ margin: 0 auto;
18
+ }
19
+ .weather-header {
20
+ display: flex;
21
+ justify-content: space-between;
22
+ align-items: center;
23
+ margin-bottom: 20px;
24
+ }
25
+ .location {
26
+ font-size: 1.5rem;
27
+ font-weight: 600;
28
+ }
29
+ .date {
30
+ font-size: 0.9rem;
31
+ opacity: 0.8;
32
+ }
33
+ .weather-main {
34
+ display: flex;
35
+ align-items: center;
36
+ margin-bottom: 20px;
37
+ }
38
+ .temperature {
39
+ font-size: 3.5rem;
40
+ font-weight: 300;
41
+ margin-right: 20px;
42
+ }
43
+ .weather-icon {
44
+ width: 80px;
45
+ height: 80px;
46
+ }
47
+ .weather-details {
48
+ display: grid;
49
+ grid-template-columns: repeat(2, 1fr);
50
+ gap: 15px;
51
+ }
52
+ .detail-item {
53
+ display: flex;
54
+ align-items: center;
55
+ }
56
+ .detail-icon {
57
+ margin-right: 8px;
58
+ font-size: 1.2rem;
59
+ }
60
+ .loading {
61
+ text-align: center;
62
+ padding: 20px;
63
+ }
64
+ </style>
65
+ <div class="weather-card">
66
+ <div class="weather-header">
67
+ <div class="location">Loading...</div>
68
+ <div class="date">${new Date().toLocaleDateString()}</div>
69
+ </div>
70
+ <div class="weather-main">
71
+ <div class="temperature">--°</div>
72
+ <img class="weather-icon" src="" alt="Weather icon">
73
+ </div>
74
+ <div class="weather-details">
75
+ <div class="detail-item">
76
+ <i class="detail-icon fas fa-tint"></i>
77
+ <span class="humidity">--%</span>
78
+ </div>
79
+ <div class="detail-item">
80
+ <i class="detail-icon fas fa-wind"></i>
81
+ <span class="wind">-- km/h</span>
82
+ </div>
83
+ <div class="detail-item">
84
+ <i class="detail-icon fas fa-cloud"></i>
85
+ <span class="clouds">--%</span>
86
+ </div>
87
+ <div class="detail-item">
88
+ <i class="detail-icon fas fa-compress-alt"></i>
89
+ <span class="pressure">-- hPa</span>
90
+ </div>
91
+ </div>
92
+ </div>
93
+ `;
94
+ this.fetchWeather();
95
+ }
96
+
97
+ async fetchWeather() {
98
+ try {
99
+ // Get user's location
100
+ const position = await new Promise((resolve, reject) => {
101
+ navigator.geolocation.getCurrentPosition(resolve, reject);
102
+ });
103
+
104
+ // Fetch weather data
105
+ const response = await fetch(
106
+ `https://api.openweathermap.org/data/2.5/weather?lat=${position.coords.latitude}&lon=${position.coords.longitude}&units=metric&appid=YOUR_API_KEY`
107
+ );
108
+
109
+ if (!response.ok) throw new Error('Weather data not available');
110
+
111
+ const data = await response.json();
112
+ this.updateWeather(data);
113
+ } catch (error) {
114
+ console.error('Error fetching weather:', error);
115
+ this.shadowRoot.querySelector('.location').textContent = 'Weather unavailable';
116
+ }
117
+ }
118
+
119
+ updateWeather(data) {
120
+ const shadow = this.shadowRoot;
121
+ shadow.querySelector('.location').textContent = data.name;
122
+ shadow.querySelector('.temperature').textContent = `${Math.round(data.main.temp)}°C`;
123
+ shadow.querySelector('.humidity').textContent = `${data.main.humidity}%`;
124
+ shadow.querySelector('.wind').textContent = `${Math.round(data.wind.speed * 3.6)} km/h`;
125
+ shadow.querySelector('.clouds').textContent = `${data.clouds.all}%`;
126
+ shadow.querySelector('.pressure').textContent = `${data.main.pressure} hPa`;
127
+
128
+ const iconUrl = `https://openweathermap.org/img/wn/${data.weather[0].icon}@2x.png`;
129
+ shadow.querySelector('.weather-icon').src = iconUrl;
130
+ shadow.querySelector('.weather-icon').alt = data.weather[0].description;
131
+ }
132
+ }
133
+
134
+ customElements.define('weather-widget', WeatherWidget);
script.js CHANGED
@@ -26,7 +26,6 @@ if (localStorage.getItem('theme') === 'dark') {
26
  document.querySelectorAll('.current-year').forEach(el => {
27
  el.textContent = new Date().getFullYear();
28
  });
29
-
30
  // Animation on scroll
31
  const animateOnScroll = () => {
32
  const elements = document.querySelectorAll('.animate');
@@ -40,4 +39,12 @@ const animateOnScroll = () => {
40
  };
41
 
42
  window.addEventListener('scroll', animateOnScroll);
43
- window.addEventListener('load', animateOnScroll);
 
 
 
 
 
 
 
 
 
26
  document.querySelectorAll('.current-year').forEach(el => {
27
  el.textContent = new Date().getFullYear();
28
  });
 
29
  // Animation on scroll
30
  const animateOnScroll = () => {
31
  const elements = document.querySelectorAll('.animate');
 
39
  };
40
 
41
  window.addEventListener('scroll', animateOnScroll);
42
+ window.addEventListener('load', animateOnScroll);
43
+
44
+ // Weather widget API key (replace with your own)
45
+ const WEATHER_API_KEY = 'YOUR_OPENWEATHERMAP_API_KEY';
46
+
47
+ // Initialize weather widgets
48
+ document.querySelectorAll('weather-widget').forEach(widget => {
49
+ widget.setAttribute('api-key', WEATHER_API_KEY);
50
+ });
style.css CHANGED
@@ -21,12 +21,14 @@ main {
21
  max-width: 1200px;
22
  margin: 0 auto;
23
  }
24
-
25
  .hero {
26
  text-align: center;
27
  padding: 4rem 0;
 
 
 
 
28
  }
29
-
30
  .hero h1 {
31
  font-size: 3.5rem;
32
  font-weight: 800;
@@ -62,14 +64,23 @@ main {
62
  transform: translateY(-2px);
63
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
64
  }
65
-
66
  .features {
67
- display: grid;
68
- grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
 
69
  gap: 2rem;
70
  margin: 4rem 0;
 
 
 
71
  }
72
 
 
 
 
 
 
 
73
  .feature-card {
74
  background: white;
75
  border-radius: 0.5rem;
 
21
  max-width: 1200px;
22
  margin: 0 auto;
23
  }
 
24
  .hero {
25
  text-align: center;
26
  padding: 4rem 0;
27
+ display: flex;
28
+ flex-direction: column;
29
+ align-items: center;
30
+ gap: 2rem;
31
  }
 
32
  .hero h1 {
33
  font-size: 3.5rem;
34
  font-weight: 800;
 
64
  transform: translateY(-2px);
65
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
66
  }
 
67
  .features {
68
+ display: flex;
69
+ flex-direction: column;
70
+ align-items: center;
71
  gap: 2rem;
72
  margin: 4rem 0;
73
+ padding: 0 2rem;
74
+ max-width: 1200px;
75
+ margin: 4rem auto;
76
  }
77
 
78
+ .features h2 {
79
+ font-size: 2rem;
80
+ color: var(--dark);
81
+ margin-bottom: 1rem;
82
+ text-align: center;
83
+ }
84
  .feature-card {
85
  background: white;
86
  border-radius: 0.5rem;