Introduction
Introduction Statistics Contact Development Disclaimer Help
improvements - jscancer - Javascript crap (relatively small)
git clone git://git.codemadness.org/jscancer
Log
Files
Refs
README
LICENSE
---
commit d182ddbec3df3bd0bd98fa0e6ff3ae4afce761fd
parent 7f49cb4a96cdbcdd229ea47fa386c1290ef3330c
Author: Hiltjo Posthuma <[email protected]>
Date: Mon, 29 May 2017 21:30:37 +0200
improvements
- fix bug when focus on an input then unfocus and clicking it: the
list item would then be not selectable usign the mouse.
- simplify some unimportant optimization.
- kill some lines.
Diffstat:
M datalist/datalist.js | 43 +++++++++++++----------------…
1 file changed, 18 insertions(+), 25 deletions(-)
---
diff --git a/datalist/datalist.js b/datalist/datalist.js
@@ -97,7 +97,7 @@ function datalist_init(input) {
if (cursel)
input.value = cursel.textContent || cursel.inn…
if (!datalist_visible)
- return datalist_show(false);
+ return;
datalist_show(false);
e.stopPropagation();
return !!e.preventDefault();
@@ -154,30 +154,13 @@ function datalist_init(input) {
if (!hassel)
datalist_setsel(null);
}
- // show list if it has matches.
- if (m.length) {
- // only one match? select it.
- if (m.length == 1)
- datalist_setsel(m[0].el);
- datalist_render(m);
- }
+ // only one match? select it.
+ if (m.length == 1)
+ datalist_setsel(m[0].el);
+ datalist_render(m);
datalist_show(!!m.length);
};
- var focuschange = function(e) {
- datalist_setsel(null);
- if (e.target === input) {
- var m = datalist_match(input.value);
- if (m.length)
- datalist_render(m);
- datalist_show(!!m.length);
- dropdown.scrollTop = 0; // reset scroll.
- } else {
- datalist_show(false);
- }
- };
- input.addEventListener("input", function() {
- onchange();
- });
+ input.addEventListener("input", onchange);
input.addEventListener("keyup", function(e) {
mouse = true;
switch (e.which) {
@@ -192,8 +175,18 @@ function datalist_init(input) {
}
onchange();
}, false);
- input.addEventListener("focus", focuschange, false);
- document.addEventListener("click", focuschange, false);
+ input.addEventListener("focus", function() {
+ datalist_setsel(null);
+ var m = datalist_match(input.value);
+ datalist_render(m);
+ datalist_show(!!m.length);
+ dropdown.scrollTop = 0; // reset scroll.
+ }, false);
+ input.addEventListener("blur", function() {
+ mouse = true;
+ datalist_setsel(null);
+ datalist_show(false);
+ }, false);
document.body.appendChild(dropdown);
}
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.