Skip to content

Commit 255c30a

Browse files
committed
mouse-event-basics
1 parent df0a6f2 commit 255c30a

File tree

5 files changed

+221
-226
lines changed

5 files changed

+221
-226
lines changed
Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,58 @@
1-
<!DOCTYPE HTML>
1+
<!DOCTYPE html>
22
<html>
3-
4-
<head>
5-
<meta charset="utf-8">
6-
<style>
7-
.selected {
8-
background: #0f0;
9-
}
10-
11-
li {
12-
cursor: pointer;
13-
}
14-
</style>
15-
</head>
16-
17-
<body>
18-
19-
Click on a list item to select it.
20-
<br>
21-
22-
<ul id="ul">
23-
<li>Christopher Robin</li>
24-
<li>Winnie-the-Pooh</li>
25-
<li>Tigger</li>
26-
<li>Kanga</li>
27-
<li>Rabbit. Just rabbit.</li>
28-
</ul>
29-
30-
<script>
31-
ul.onclick = function(event) {
32-
if (event.target.tagName != "LI") return;
33-
34-
if (event.ctrlKey || event.metaKey) {
35-
toggleSelect(event.target);
36-
} else {
37-
singleSelect(event.target);
38-
}
39-
40-
}
41-
42-
// prevent unneeded selection of list elements on clicks
43-
ul.onmousedown = function() {
44-
return false;
45-
};
46-
47-
function toggleSelect(li) {
48-
li.classList.toggle('selected');
49-
}
50-
51-
function singleSelect(li) {
52-
let selected = ul.querySelectorAll('.selected');
53-
for(let elem of selected) {
54-
elem.classList.remove('selected');
55-
}
56-
li.classList.add('selected');
57-
}
58-
59-
</script>
60-
61-
</body>
3+
<head>
4+
<meta charset="utf-8" />
5+
<style>
6+
.selected {
7+
background: #0f0;
8+
}
9+
10+
li {
11+
cursor: pointer;
12+
}
13+
</style>
14+
</head>
15+
16+
<body>
17+
18+
روی یک آیتم کلیک کنید تا انتخاب شود.
19+
<br />
20+
21+
<ul id="ul">
22+
<li>کریستوفر رابین</li>
23+
<li>وینی د پو</li>
24+
<li>ببری</li>
25+
<li>کانگا</li>
26+
<li>خرگوش. فقط، خرگوش</li>
27+
</ul>
28+
29+
<script>
30+
ul.onclick = function (event) {
31+
if (event.target.tagName != 'LI') return
32+
33+
if (event.ctrlKey || event.metaKey) {
34+
toggleSelect(event.target)
35+
} else {
36+
singleSelect(event.target)
37+
}
38+
}
39+
40+
// جلوگیری از انتخاب غیرضروری آیتم‌ها هنگام کلیک
41+
ul.onmousedown = function () {
42+
return false
43+
}
44+
45+
function toggleSelect(li) {
46+
li.classList.toggle('selected')
47+
}
48+
49+
function singleSelect(li) {
50+
let selected = ul.querySelectorAll('.selected')
51+
for (let elem of selected) {
52+
elem.classList.remove('selected')
53+
}
54+
li.classList.add('selected')
55+
}
56+
</script>
57+
</body>
6258
</html>

2-ui/3-event-details/1-mouse-events-basics/01-selectable-list/source.view/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
<body>
1818

19-
Click on a list item to select it.
19+
روی یک آیتم کلیک کنید تا انتخاب شود.
2020
<br>
2121

2222
<ul id="ul">
23-
<li>Christopher Robin</li>
24-
<li>Winnie-the-Pooh</li>
25-
<li>Tigger</li>
26-
<li>Kanga</li>
27-
<li>Rabbit. Just rabbit.</li>
23+
<li>کریستوفر رابین</li>
24+
<li>وینی د پو</li>
25+
<li>ببری</li>
26+
<li>کانگا</li>
27+
<li>خرگوش. فقط، خرگوش</li>
2828
</ul>
2929

3030
<script>
31-
// ...your code...
31+
// ...کد شما...
3232
</script>
3333

3434
</body>

2-ui/3-event-details/1-mouse-events-basics/01-selectable-list/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ importance: 5
22

33
---
44

5-
# Selectable list
5+
# لیست انتخاب‌شونده
66

7-
Create a list where elements are selectable, like in file-managers.
7+
یک لیست بسازید که عناصر آن قابل انتخاب باشند، مانند اپلیکیشن‌های مدیریت فایل.
88

9-
- A click on a list element selects only that element (adds the class `.selected`), deselects all others.
10-
- If a click is made with `key:Ctrl` (`key:Cmd` for Mac), then the selection is toggled on the element, but other elements are not modified.
9+
- کلیک روی عنصر لیست فقط آن عنصر را انتخاب می‌کند. (کلاس `.selected` را اضافه کند)، بقیه عناصر باید لغو انتخاب شوند.
10+
- اگر که کلیک همراه با `key:Ctrl` (`key:Cmd` برای مک) باشد، پس عمل انتخاب یا لغو انتخاب فقط برای آن عنصر عمل کند، درحالی که بقیه عنصرها تغییری نکنند.
1111

12-
The demo:
12+
دمو:
1313

1414
[iframe border="1" src="solution" height=180]
1515

16-
P.S. For this task we can assume that list items are text-only. No nested tags.
16+
پی‌نوشت: برای این تکلیف می‌توانیم در نظر بگیریم که آیتم‌های داخل لیست فقط متن هستند، و نه تگ‌های تو در تو.
1717

18-
P.P.S. Prevent the native browser selection of the text on clicks.
18+
پی‌پی‌نوشت: از رفتار پیش‌فرض مرورگر که باعث انتخاب متن هنگام کلیک کردن می‌شود جلوگیری کنید.

0 commit comments

Comments
 (0)