mirror of
https://github.com/marcriera/ddgo-controller-docs.git
synced 2025-05-06 08:37:04 +02:00
deploy: de39255ace
This commit is contained in:
parent
1899018f54
commit
2a009fc2a4
429 changed files with 16588 additions and 21373 deletions
|
@ -1,8 +1,19 @@
|
|||
/*
|
||||
JavaScript autoComplete v1.0.4
|
||||
#46 - positioning
|
||||
#75 - complete
|
||||
JavaScript autoComplete v1.0.4+
|
||||
McShelby/hugo-theme-relearn#155
|
||||
- PR #46, PR #75: introducing selectorToInsert and anchor to it
|
||||
- sticky dropdown on scrolling
|
||||
McShelby/hugo-theme-relearn#387
|
||||
- don't empty search input if no data-val is given
|
||||
- don't delete search term but close suggestions when suggestions are open
|
||||
- delete search term when suggestions are closed
|
||||
McShelby/hugo-theme-relearn#452
|
||||
- register focus event ignoring minChars because that doesn't make sense
|
||||
McShelby/hugo-theme-relearn#452
|
||||
- on ESC, close overlay without deleting search term if overlay is open
|
||||
- on ESC, delete search term if overlay is closed
|
||||
- on UP, preventDefault to keep cursor in position
|
||||
|
||||
Copyright (c) 2014 Simon Steinberger / Pixabay
|
||||
GitHub: https://github.com/Pixabay/JavaScript-autoComplete
|
||||
License: http://www.opensource.org/licenses/mit-license.php
|
||||
|
@ -20,7 +31,6 @@ var autoComplete = (function(){
|
|||
if (el.attachEvent) el.attachEvent('on'+type, handler); else el.addEventListener(type, handler);
|
||||
}
|
||||
function removeEvent(el, type, handler){
|
||||
// if (el.removeEventListener) not working in IE11
|
||||
if (el.detachEvent) el.detachEvent('on'+type, handler); else el.removeEventListener(type, handler);
|
||||
}
|
||||
function live(elClass, event, cb, context){
|
||||
|
@ -82,9 +92,10 @@ var autoComplete = (function(){
|
|||
pageXOffset = window.pageXOffset || document.documentElement.scrollLeft;
|
||||
pageYOffset = window.pageYOffset || document.documentElement.scrollTop;
|
||||
}
|
||||
that.sc.style.left = Math.round(rect.left + pageXOffset + o.offsetLeft - parentOffsetLeft) + 'px';
|
||||
that.sc.style.top = Math.round(rect.bottom + pageYOffset + o.offsetTop - parentOffsetTop) + 'px';
|
||||
that.sc.style.width = Math.round(rect.right - rect.left) + 'px'; // outerWidth
|
||||
// Is this really the job of the tool or should it be defered to the user?
|
||||
// that.sc.style.left = Math.round(rect.left + pageXOffset + o.offsetLeft - parentOffsetLeft) + 'px';
|
||||
// that.sc.style.top = Math.round(rect.bottom + pageYOffset + o.offsetTop - parentOffsetTop) + 'px';
|
||||
// that.sc.style.width = Math.round(rect.right - rect.left) + 'px'; // outerWidth
|
||||
if (!resize) {
|
||||
that.sc.style.display = 'block';
|
||||
if (!that.sc.maxHeight) { that.sc.maxHeight = parseInt((window.getComputedStyle ? getComputedStyle(that.sc, null) : that.sc.currentStyle).maxHeight); }
|
||||
|
@ -155,25 +166,47 @@ var autoComplete = (function(){
|
|||
var key = window.event ? e.keyCode : e.which;
|
||||
// down (40), up (38)
|
||||
if ((key == 40 || key == 38) && that.sc.innerHTML) {
|
||||
e.preventDefault();
|
||||
var next, sel = that.sc.querySelector('.autocomplete-suggestion.selected');
|
||||
if (!sel) {
|
||||
next = (key == 40) ? that.sc.querySelector('.autocomplete-suggestion') : that.sc.childNodes[that.sc.childNodes.length - 1]; // first : last
|
||||
next.className += ' selected';
|
||||
that.value = next.getAttribute('data-val');
|
||||
if (next.getAttribute('data-val')) that.value = next.getAttribute('data-val');
|
||||
} else {
|
||||
next = (key == 40) ? sel.nextSibling : sel.previousSibling;
|
||||
if (next) {
|
||||
sel.className = sel.className.replace('selected', '');
|
||||
next.className += ' selected';
|
||||
that.value = next.getAttribute('data-val');
|
||||
if (next.getAttribute('data-val')) that.value = next.getAttribute('data-val');
|
||||
}
|
||||
else {
|
||||
sel.className = sel.className.replace('selected', '');
|
||||
that.value = that.last_val;
|
||||
next = 0;
|
||||
}
|
||||
else { sel.className = sel.className.replace('selected', ''); that.value = that.last_val; next = 0; }
|
||||
}
|
||||
that.updateSC(0, next);
|
||||
return false;
|
||||
}
|
||||
// esc
|
||||
else if (key == 27) { that.value = that.last_val; that.sc.style.display = 'none'; }
|
||||
else if (key == 27) {
|
||||
if (that.sc.style.display != 'none') {
|
||||
// just close the overlay if it's open, and prevent other listeners
|
||||
// from recognizing it; this is not for you!
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
that.sc.style.display = 'none';
|
||||
var sel = that.sc.querySelector('.autocomplete-suggestion.selected');
|
||||
if (sel) {
|
||||
that.focus();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if no overlay is open, we want to remove the search term and also
|
||||
// want other listeners to recognize it
|
||||
that.value = '';
|
||||
}
|
||||
}
|
||||
// enter
|
||||
else if (key == 13 || key == 9) {
|
||||
var sel = that.sc.querySelector('.autocomplete-suggestion.selected');
|
||||
|
@ -212,7 +245,7 @@ var autoComplete = (function(){
|
|||
that.last_val = '\n';
|
||||
that.keyupHandler(e)
|
||||
};
|
||||
if (!o.minChars) addEvent(that, 'focus', that.focusHandler);
|
||||
addEvent(that, 'focus', that.focusHandler);
|
||||
}
|
||||
|
||||
// public destroy method
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue