Fix scroll style, make <label> elements in multi-select mode

master
Vitaliy Filippov 2013-04-10 20:19:21 +00:00
parent 7b47d7a939
commit a0366d6169
3 changed files with 16 additions and 20 deletions

View File

@ -4,8 +4,8 @@
background-color: white; background-color: white;
font-size: 80%; font-size: 80%;
max-height: 300pt; max-height: 300pt;
overflow-y: scroll; overflow-y: auto;
overflow: -moz-scrollbars-vertical; -ms-overflow-y: auto;
z-index: 1000; z-index: 1000;
} }
.hintEmptyText { .hintEmptyText {

View File

@ -77,7 +77,7 @@ var SimpleAutocomplete = function(input, dataLoader, params)
// Parameters // Parameters
this.input = input; this.input = input;
this.dataLoader = dataLoader; this.dataLoader = dataLoader;
this.multipleDelimiter = params.multipleDelimiter || params.multipleListener; this.multipleDelimiter = params.multipleDelimiter;
this.multipleListener = params.multipleListener; this.multipleListener = params.multipleListener;
this.onChangeListener = params.onChangeListener; this.onChangeListener = params.onChangeListener;
this.emptyText = params.emptyText; this.emptyText = params.emptyText;
@ -138,8 +138,7 @@ SimpleAutocomplete.prototype.init = function()
this.addRmListener('change', function() { return self.onChange(); }); this.addRmListener('change', function() { return self.onChange(); });
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(); });
// Set autocomplete=on to prevent FF and Chrome from clearing inputs on Back click addListener(window, 'beforeunload', function() { e.autocomplete = 'on'; });
addListener(window, 'beforeunload', this.closure['beforeunload'] = function() { e.autocomplete = 'on'; });
addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); }); addListener(t, 'mousedown', function(ev) { return self.cancelBubbleOnHint(ev); });
this.onChange(); this.onChange();
}; };
@ -166,7 +165,7 @@ SimpleAutocomplete.prototype.replaceItems = function(items, append)
if (!this.multipleListener) if (!this.multipleListener)
for (var i in items) for (var i in items)
items[i][2] = 0; items[i][2] = 0;
if (this.multipleDelimiter && !this.multipleListener) if (this.multipleDelimiter)
{ {
var h = {}; var h = {};
var old = this.input.value.split(this.multipleDelimiter); var old = this.input.value.split(this.multipleDelimiter);
@ -195,8 +194,6 @@ SimpleAutocomplete.prototype.remove = function()
if (!this.hintLayer) if (!this.hintLayer)
return; return;
this.hintLayer.parentNode.removeChild(this.hintLayer); this.hintLayer.parentNode.removeChild(this.hintLayer);
removeListener(window, 'beforeunload', this.closure['beforeunload']);
delete this.closure['beforeunload'];
for (var i in this.closure) for (var i in this.closure)
{ {
removeListener(this.input, i, this.closure[i]); removeListener(this.input, i, this.closure[i]);
@ -222,8 +219,7 @@ SimpleAutocomplete.prototype.makeItem = function(index, item)
d.id = this.id+'_item_'+index; d.id = this.id+'_item_'+index;
d.className = item[2] ? 'hintDisabledItem' : (this.selectedIndex == index ? 'hintActiveItem' : 'hintItem'); d.className = item[2] ? 'hintDisabledItem' : (this.selectedIndex == index ? 'hintActiveItem' : 'hintItem');
d.title = item[1]; d.title = item[1];
d.innerHTML = item[0]; if (this.multipleDelimiter || this.multipleListener)
if (this.multipleDelimiter)
{ {
var c = document.createElement('input'); var c = document.createElement('input');
c.type = 'checkbox'; c.type = 'checkbox';
@ -231,12 +227,15 @@ SimpleAutocomplete.prototype.makeItem = function(index, item)
c.checked = item[3] && true; c.checked = item[3] && true;
c.disabled = item[2] && true; c.disabled = item[2] && true;
c.value = item[1]; c.value = item[1];
if (d.childNodes.length) d.appendChild(c);
d.insertBefore(c, d.firstChild); var l = document.createElement('label');
else l.htmlFor = c.id;
d.appendChild(c); l.innerHTML = item[0];
d.appendChild(l);
addListener(c, 'click', this.preventCheck); addListener(c, 'click', this.preventCheck);
} }
else
d.innerHTML = item[0];
var self = this; var self = this;
addListener(d, 'mouseover', function() { return self.onItemMouseOver(this); }); addListener(d, 'mouseover', function() { return self.onItemMouseOver(this); });
addListener(d, 'mousedown', function(ev) { return self.onItemClick(ev, this); }); addListener(d, 'mousedown', function(ev) { return self.onItemClick(ev, this); });
@ -285,7 +284,7 @@ SimpleAutocomplete.prototype.getItem = function(index)
// Select index'th item - change the input value and hide the hint if not a multi-select // Select index'th item - change the input value and hide the hint if not a multi-select
SimpleAutocomplete.prototype.selectItem = function(index) SimpleAutocomplete.prototype.selectItem = function(index)
{ {
if (!this.multipleDelimiter) if (!this.multipleDelimiter && !this.multipleListener)
{ {
this.input.value = this.items[index][1]; this.input.value = this.items[index][1];
this.hide(); this.hide();
@ -293,11 +292,8 @@ SimpleAutocomplete.prototype.selectItem = function(index)
else else
{ {
document.getElementById(this.id+'_check_'+index).checked = this.items[index][3] = !this.items[index][3]; document.getElementById(this.id+'_check_'+index).checked = this.items[index][3] = !this.items[index][3];
if (this.multipleListener) if (this.multipleListener && !this.multipleListener(this, index, this.items[index]))
{
this.multipleListener(this, index, this.items[index]);
return; return;
}
this.toggleValue(index); this.toggleValue(index);
} }
this.curValue = this.input.value; this.curValue = this.input.value;

2
hinter.min.js vendored

File diff suppressed because one or more lines are too long