Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: static/js/main.js

Issue 29587558: Issue 5868 - Allow clicking outside CustomSelect to close in help.eyeo.com (Closed) Base URL: https://hg.adblockplus.org/help.eyeo.com
Patch Set: Created Oct. 24, 2017, 8:20 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « includes/layout/footer.tmpl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: static/js/main.js
===================================================================
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -33,17 +33,42 @@
/**************************************************************************
* CustomSelect
**************************************************************************/
function CustomSelect(select)
{
this.select = select;
this.close();
- select.addEventListener("click", this._onClick.bind(this), false);
+ this.select
+ .addEventListener("click", this._onClick.bind(this), false);
+ this.select
+ .addEventListener("focusout", this._onFocusOut.bind(this), false);
+ }
+
+ CustomSelect.prototype._onFocusOut = function()
+ {
+ // setTimeout to allow document.activeElement
+ // to move to newly focused element
+ setTimeout(function()
+ {
+ var newFocus = document.activeElement;
+
+ if (newFocus
juliandoucette 2017/10/24 10:15:25 Suggest: {{{ var classList = document.activeEleme
ire 2017/10/24 14:51:09 This particular way doesn't work because I'm not o
+ .classList.contains("custom-select-selected") ||
+ newFocus
+ .parentElement
+ .classList.contains("custom-select-option"))
+ {
+ return;
+ }
+
+ this.close();
+
+ }.bind(this), 1);
}
CustomSelect.prototype._onClick = function(event)
{
if (event.target.classList.contains("custom-select-selected"))
{
var options = this.select.querySelector(".custom-select-options");
if (options.getAttribute("aria-hidden") == "true")
« no previous file with comments | « includes/layout/footer.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld