Support new "persist" parameter
parent
1022acc34f
commit
b70150f3db
27
hinter.js
27
hinter.js
|
@ -2,8 +2,8 @@
|
|||
|
||||
Homepage: http://yourcmc.ru/wiki/SimpleAutocomplete
|
||||
License: MPL 2.0+ (http://www.mozilla.org/MPL/2.0/)
|
||||
Version: 2013-11-13
|
||||
(c) Vitaliy Filippov 2011-2013
|
||||
Version: 2014-09-04
|
||||
(c) Vitaliy Filippov 2011-2014
|
||||
|
||||
Usage:
|
||||
Include hinter.css, hinter.js on your page. Then write:
|
||||
|
@ -61,6 +61,11 @@
|
|||
of the list, and SimpleAutocomplete will issue another request to
|
||||
dataLoader with incremented 'more' parameter when it will be clicked.
|
||||
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:
|
||||
hint.remove(); hint = null;
|
||||
|
@ -85,6 +90,8 @@ var SimpleAutocomplete = function(input, dataLoader, params)
|
|||
this.prompt = params.prompt;
|
||||
this.delay = params.delay;
|
||||
this.moreMarker = params.moreMarker;
|
||||
this.persist = params.persist;
|
||||
this.className = params.className || 'hintLayer';
|
||||
|
||||
// Default values
|
||||
if (this.moreMarker === undefined)
|
||||
|
@ -119,13 +126,20 @@ SimpleAutocomplete.prototype.init = function()
|
|||
|
||||
// Create hint layer
|
||||
var t = this.hintLayer = document.createElement('div');
|
||||
t.className = 'hintLayer';
|
||||
t.className = this.className;
|
||||
if (!this.persist)
|
||||
{
|
||||
t.style.display = 'none';
|
||||
t.style.position = 'absolute';
|
||||
t.style.top = (p.top+e.offsetHeight) + 'px';
|
||||
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
|
||||
e.SimpleAutocomplete_input = this;
|
||||
|
@ -146,7 +160,7 @@ SimpleAutocomplete.prototype.init = function()
|
|||
this.addRmListener('focus', function() { return self.onInputFocus(); });
|
||||
this.addRmListener('blur', function() { return self.onInputBlur(); });
|
||||
addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); });
|
||||
this.onChange();
|
||||
this.onChange(true);
|
||||
};
|
||||
|
||||
// items = [ [ name, value ], [ name, value ], ... ]
|
||||
|
@ -359,17 +373,20 @@ SimpleAutocomplete.prototype.toggleValue = function(index)
|
|||
|
||||
// Hide hinter
|
||||
SimpleAutocomplete.prototype.hide = function()
|
||||
{
|
||||
if (!this.persist)
|
||||
{
|
||||
if (!this.skipHideCounter)
|
||||
this.hintLayer.style.display = 'none';
|
||||
else
|
||||
this.skipHideCounter = 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Show hinter
|
||||
SimpleAutocomplete.prototype.show = function()
|
||||
{
|
||||
if (!this.disabled)
|
||||
if (!this.disabled && !this.persist)
|
||||
{
|
||||
var p = getOffset(this.input);
|
||||
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