-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df0a6f2
commit 255c30a
Showing
5 changed files
with
221 additions
and
226 deletions.
There are no files selected for viewing
116 changes: 56 additions & 60 deletions
116
2-ui/3-event-details/1-mouse-events-basics/01-selectable-list/solution.view/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,58 @@ | ||
<!DOCTYPE HTML> | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<style> | ||
.selected { | ||
background: #0f0; | ||
} | ||
|
||
li { | ||
cursor: pointer; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
Click on a list item to select it. | ||
<br> | ||
|
||
<ul id="ul"> | ||
<li>Christopher Robin</li> | ||
<li>Winnie-the-Pooh</li> | ||
<li>Tigger</li> | ||
<li>Kanga</li> | ||
<li>Rabbit. Just rabbit.</li> | ||
</ul> | ||
|
||
<script> | ||
ul.onclick = function(event) { | ||
if (event.target.tagName != "LI") return; | ||
|
||
if (event.ctrlKey || event.metaKey) { | ||
toggleSelect(event.target); | ||
} else { | ||
singleSelect(event.target); | ||
} | ||
|
||
} | ||
|
||
// prevent unneeded selection of list elements on clicks | ||
ul.onmousedown = function() { | ||
return false; | ||
}; | ||
|
||
function toggleSelect(li) { | ||
li.classList.toggle('selected'); | ||
} | ||
|
||
function singleSelect(li) { | ||
let selected = ul.querySelectorAll('.selected'); | ||
for(let elem of selected) { | ||
elem.classList.remove('selected'); | ||
} | ||
li.classList.add('selected'); | ||
} | ||
|
||
</script> | ||
|
||
</body> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<style> | ||
.selected { | ||
background: #0f0; | ||
} | ||
|
||
li { | ||
cursor: pointer; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
روی یک آیتم کلیک کنید تا انتخاب شود. | ||
<br /> | ||
|
||
<ul id="ul"> | ||
<li>کریستوفر رابین</li> | ||
<li>وینی د پو</li> | ||
<li>ببری</li> | ||
<li>کانگا</li> | ||
<li>خرگوش. فقط، خرگوش</li> | ||
</ul> | ||
|
||
<script> | ||
ul.onclick = function (event) { | ||
if (event.target.tagName != 'LI') return | ||
|
||
if (event.ctrlKey || event.metaKey) { | ||
toggleSelect(event.target) | ||
} else { | ||
singleSelect(event.target) | ||
} | ||
} | ||
|
||
// جلوگیری از انتخاب غیرضروری آیتمها هنگام کلیک | ||
ul.onmousedown = function () { | ||
return false | ||
} | ||
|
||
function toggleSelect(li) { | ||
li.classList.toggle('selected') | ||
} | ||
|
||
function singleSelect(li) { | ||
let selected = ul.querySelectorAll('.selected') | ||
for (let elem of selected) { | ||
elem.classList.remove('selected') | ||
} | ||
li.classList.add('selected') | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.