forked from 0x2620/oxjs
some autocomplete
This commit is contained in:
parent
a62a18cb58
commit
3b7b3d8e64
2 changed files with 155 additions and 115 deletions
|
|
@ -485,7 +485,6 @@ requires
|
|||
//ret = true,
|
||||
time;
|
||||
$.each(modifierNames, function(k, v) {
|
||||
Ox.print(k, event[k])
|
||||
if (event[k]) {
|
||||
keys.push(v);
|
||||
}
|
||||
|
|
@ -715,6 +714,7 @@ requires
|
|||
type: options.type,
|
||||
url: options.url
|
||||
});
|
||||
Ox.print("request", options.data);
|
||||
Ox.length(requests) == 1 && Ox.Event.trigger("requestStart");
|
||||
}
|
||||
}
|
||||
|
|
@ -1759,11 +1759,11 @@ requires
|
|||
})
|
||||
.options(options || {})
|
||||
.addClass("OxInput Ox" + Ox.toTitleCase(self.options.size)),
|
||||
autocomplete;
|
||||
autocomplete; // fixme: should be self.autocomplete
|
||||
|
||||
if (self.options.label) {
|
||||
self.options.label = Ox.makeArray(self.options.label);
|
||||
self.option = self.options.label[self.options.selected];
|
||||
self.option = self.options.label[self.options.selected]; // fixme: id or title? or not use this at all?
|
||||
self.items = self.options.label;
|
||||
} else if (self.options.placeholder) {
|
||||
self.options.placeholder = Ox.makeArray(self.options.placeholder);
|
||||
|
|
@ -1780,7 +1780,7 @@ requires
|
|||
that.$label = new Ox.Element()
|
||||
.addClass("OxInputLabel")
|
||||
.width(self.options.labelWidth)
|
||||
.html(self.options.label[0])
|
||||
.html(self.options.label[0].title)
|
||||
.appendTo(that);
|
||||
}
|
||||
if (self.options.label.length > 1 || self.options.placeholder.length > 1) {
|
||||
|
|
@ -1797,12 +1797,12 @@ requires
|
|||
self.selectMenu = new Ox.Menu({
|
||||
element: that,
|
||||
id: self.selectId,
|
||||
items: $.map(self.items, function(title, position) {
|
||||
items: $.map(self.items, function(item, position) {
|
||||
return {
|
||||
checked: position == self.options.selected,
|
||||
id: title.toLowerCase(),
|
||||
id: item.id,
|
||||
group: self.selectId, // fixme: same id, works here, but should be different
|
||||
title: title
|
||||
title: item.title
|
||||
};
|
||||
}),
|
||||
offset: {
|
||||
|
|
@ -1895,17 +1895,24 @@ requires
|
|||
|
||||
function call() {
|
||||
var value = that.$input.val();
|
||||
Ox.print("autocomplete call", self.option, value)
|
||||
if (self.options.autocomplete) {
|
||||
Ox.isFunction(self.options.autocomplete) ? (
|
||||
self.option ?
|
||||
self.options.autocomplete(self.option, value, callback) :
|
||||
self.options.autocomplete(value, callback)
|
||||
) : autocomplete(value, callback);
|
||||
if (value !== "") {
|
||||
Ox.isFunction(self.options.autocomplete) ? (
|
||||
self.option ?
|
||||
self.options.autocomplete(self.option.id, value, callback) :
|
||||
self.options.autocomplete(value, callback)
|
||||
) : autocomplete(value, callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function callback(items) {
|
||||
var selected = items.length == 1 ? 0 : -1,
|
||||
Ox.print("autocomplete callback", items)
|
||||
var items = items || [],
|
||||
selected = items.length == 1 ? 0 : -1,
|
||||
value = that.$input.val().toLowerCase();
|
||||
if (items.length) {
|
||||
items = $.map(items, function(title, position) {
|
||||
|
|
@ -1935,9 +1942,15 @@ requires
|
|||
}
|
||||
|
||||
function change(event, data) {
|
||||
self.option = data.value; // fixme: could be "title" as well
|
||||
Ox.print("input change", event, data)
|
||||
if (data) {
|
||||
self.option = {
|
||||
id: data.id,
|
||||
title: data.value // fixme: should be data.title
|
||||
};
|
||||
}
|
||||
if (self.options.label) {
|
||||
that.$label.html(self.option);
|
||||
that.$label.html(self.option.title);
|
||||
that.$input.focus();
|
||||
call();
|
||||
} else {
|
||||
|
|
@ -1957,17 +1970,19 @@ requires
|
|||
}
|
||||
|
||||
function focus() {
|
||||
var value;
|
||||
that.gainFocus();
|
||||
if (that.$input.is(".OxPlaceholder")) {
|
||||
that.$input.val("").removeClass("OxPlaceholder");
|
||||
}
|
||||
value = that.$input.val();
|
||||
if (self.options.autocomplete) {
|
||||
// fixme: different in webkit and firefox (?), see keyboard handler, need generic function
|
||||
$document.bind("keydown", keypress);
|
||||
$document.bind("keypress", keypress);
|
||||
Ox.isFunction(self.options.autocomplete) ?
|
||||
self.options.autocomplete(that.$input.val(), callback) :
|
||||
autocomplete(that.$input.val(), callback);
|
||||
value !== "" && Ox.isFunction(self.options.autocomplete) ?
|
||||
self.options.autocomplete(self.option.id, value, callback) :
|
||||
autocomplete(value, callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2006,6 +2021,7 @@ requires
|
|||
}
|
||||
|
||||
function submit() {
|
||||
Ox.print("input submit", that.$input.val())
|
||||
that.$input.trigger("blur");
|
||||
that.triggerEvent("submit", that.$input.val());
|
||||
}
|
||||
|
|
@ -2318,7 +2334,7 @@ requires
|
|||
that.$button = new Ox.Button($.extend(self.options, {
|
||||
id: self.buttonId,
|
||||
type: "text", // fixme: this shouldn't be necessary
|
||||
value: self.options.items[self.selected].title
|
||||
value: self.options.items[self.selected].title // fixme: title instead of value?
|
||||
}), {})
|
||||
.click(clickButton)
|
||||
.appendTo(that);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue