-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support clicking multiple items (#970)
* First pass on multiple clicks * Stub out tests * Fix minor bug * Ensure we're testing truthiness for the multiple key * remove .only --------- Co-authored-by: Shane Osbourne <[email protected]> Co-authored-by: Shane Osbourne <[email protected]>
- Loading branch information
1 parent
f8e95c3
commit a327af5
Showing
4 changed files
with
91 additions
and
10 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
integration-test/test-pages/broker-protection/actions/click-multiple.json
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"state": { | ||
"action": { | ||
"actionType": "click", | ||
"id": "1", | ||
"elements": [ | ||
{ | ||
"type": "button", | ||
"selector": ".view-more", | ||
"multiple": true | ||
} | ||
] | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
integration-test/test-pages/broker-protection/pages/click-multiple.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Broker Protection</title> | ||
</head> | ||
<body> | ||
<div class="result"> | ||
<div class="name">John Doe</div> | ||
<div class="age">32</div> | ||
<div class="locations" data-id="1"> | ||
<span>New York, NY</span> | ||
<span>Los Angeles, CA</span> | ||
<a href="#" class="view-more">View More</a> | ||
</div> | ||
</div> | ||
<div class="result"> | ||
<div class="name">Jane Doe</div> | ||
<div class="age">32</div> | ||
<div class="locations" data-id="2"> | ||
<span>Chicago, IL</span> | ||
<span>San Francisco, CA</span> | ||
<a href="#" class="view-more">View More</a> | ||
</div> | ||
</div> | ||
<script> | ||
const locations = { | ||
1: ['Dallas, TX', 'Miami, FL'], | ||
2: ['Houston, TX', 'San Jose, CA'] | ||
}; | ||
|
||
document.querySelectorAll('.view-more').forEach(viewMore => | ||
viewMore.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
const id = this.parentNode.getAttribute('data-id'); | ||
|
||
locations[id].forEach(location => { | ||
const newLocation = document.createElement('span'); | ||
newLocation.textContent = location; | ||
this.parentNode.insertBefore(newLocation, this); | ||
}); | ||
window.location.hash ? window.location.hash += '-' + id : window.location.hash = id; | ||
this.removeEventListener('click', arguments.callee); | ||
}) | ||
); | ||
</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