Support new "persist" parameter
parent
1022acc34f
commit
b70150f3db
47
hinter.js
47
hinter.js
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
Homepage: http://yourcmc.ru/wiki/SimpleAutocomplete
|
Homepage: http://yourcmc.ru/wiki/SimpleAutocomplete
|
||||||
License: MPL 2.0+ (http://www.mozilla.org/MPL/2.0/)
|
License: MPL 2.0+ (http://www.mozilla.org/MPL/2.0/)
|
||||||
Version: 2013-11-13
|
Version: 2014-09-04
|
||||||
(c) Vitaliy Filippov 2011-2013
|
(c) Vitaliy Filippov 2011-2014
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
Include hinter.css, hinter.js on your page. Then write:
|
Include hinter.css, hinter.js on your page. Then write:
|
||||||
|
@ -61,6 +61,11 @@
|
||||||
of the list, and SimpleAutocomplete will issue another request to
|
of the list, and SimpleAutocomplete will issue another request to
|
||||||
dataLoader with incremented 'more' parameter when it will be clicked.
|
dataLoader with incremented 'more' parameter when it will be clicked.
|
||||||
You can also set moreMarker to false to disable this feature.
|
You can also set moreMarker to false to disable this feature.
|
||||||
|
persist
|
||||||
|
If true, the hint layer will never be hidden. You can use it to create
|
||||||
|
multiselect-like controls (see example at the homepage).
|
||||||
|
className
|
||||||
|
CSS class name for the hint layer. Default is 'hintLayer'.
|
||||||
|
|
||||||
Destroy instance:
|
Destroy instance:
|
||||||
hint.remove(); hint = null;
|
hint.remove(); hint = null;
|
||||||
|
@ -85,6 +90,8 @@ var SimpleAutocomplete = function(input, dataLoader, params)
|
||||||
this.prompt = params.prompt;
|
this.prompt = params.prompt;
|
||||||
this.delay = params.delay;
|
this.delay = params.delay;
|
||||||
this.moreMarker = params.moreMarker;
|
this.moreMarker = params.moreMarker;
|
||||||
|
this.persist = params.persist;
|
||||||
|
this.className = params.className || 'hintLayer';
|
||||||
|
|
||||||
// Default values
|
// Default values
|
||||||
if (this.moreMarker === undefined)
|
if (this.moreMarker === undefined)
|
||||||
|
@ -119,13 +126,20 @@ SimpleAutocomplete.prototype.init = function()
|
||||||
|
|
||||||
// Create hint layer
|
// Create hint layer
|
||||||
var t = this.hintLayer = document.createElement('div');
|
var t = this.hintLayer = document.createElement('div');
|
||||||
t.className = 'hintLayer';
|
t.className = this.className;
|
||||||
t.style.display = 'none';
|
if (!this.persist)
|
||||||
t.style.position = 'absolute';
|
{
|
||||||
t.style.top = (p.top+e.offsetHeight) + 'px';
|
t.style.display = 'none';
|
||||||
t.style.zIndex = 1000;
|
t.style.position = 'absolute';
|
||||||
t.style.left = p.left + 'px';
|
t.style.top = (p.top+e.offsetHeight) + 'px';
|
||||||
document.body.appendChild(t);
|
t.style.zIndex = 1000;
|
||||||
|
t.style.left = p.left + 'px';
|
||||||
|
document.body.appendChild(t);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
e.nextSibling ? e.parentNode.insertBefore(t, e.nextSibling) : e.parentNode.appendChild(t);
|
||||||
|
}
|
||||||
|
|
||||||
// Remember instance
|
// Remember instance
|
||||||
e.SimpleAutocomplete_input = this;
|
e.SimpleAutocomplete_input = this;
|
||||||
|
@ -146,7 +160,7 @@ SimpleAutocomplete.prototype.init = function()
|
||||||
this.addRmListener('focus', function() { return self.onInputFocus(); });
|
this.addRmListener('focus', function() { return self.onInputFocus(); });
|
||||||
this.addRmListener('blur', function() { return self.onInputBlur(); });
|
this.addRmListener('blur', function() { return self.onInputBlur(); });
|
||||||
addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); });
|
addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); });
|
||||||
this.onChange();
|
this.onChange(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
// items = [ [ name, value ], [ name, value ], ... ]
|
// items = [ [ name, value ], [ name, value ], ... ]
|
||||||
|
@ -360,16 +374,19 @@ SimpleAutocomplete.prototype.toggleValue = function(index)
|
||||||
// Hide hinter
|
// Hide hinter
|
||||||
SimpleAutocomplete.prototype.hide = function()
|
SimpleAutocomplete.prototype.hide = function()
|
||||||
{
|
{
|
||||||
if (!this.skipHideCounter)
|
if (!this.persist)
|
||||||
this.hintLayer.style.display = 'none';
|
{
|
||||||
else
|
if (!this.skipHideCounter)
|
||||||
this.skipHideCounter = 0;
|
this.hintLayer.style.display = 'none';
|
||||||
|
else
|
||||||
|
this.skipHideCounter = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Show hinter
|
// Show hinter
|
||||||
SimpleAutocomplete.prototype.show = function()
|
SimpleAutocomplete.prototype.show = function()
|
||||||
{
|
{
|
||||||
if (!this.disabled)
|
if (!this.disabled && !this.persist)
|
||||||
{
|
{
|
||||||
var p = getOffset(this.input);
|
var p = getOffset(this.input);
|
||||||
this.hintLayer.style.top = (p.top+this.input.offsetHeight) + 'px';
|
this.hintLayer.style.top = (p.top+this.input.offsetHeight) + 'px';
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue