make list focus on click

This commit is contained in:
Rolux 2010-06-30 11:27:02 +02:00
parent 084d05d108
commit de422b8faa
3 changed files with 25 additions and 18 deletions

View file

@ -119,10 +119,10 @@ Lists
.OxThemeModern .OxTextList .OxItem.OxSelected:nth-child(even) { .OxThemeModern .OxTextList .OxItem.OxSelected:nth-child(even) {
background: rgb(34, 34, 34); background: rgb(34, 34, 34);
} }
.OxThemeModern .OxTextList.OxFocus .OxItem.OxSelected:nth-child(odd) { .OxThemeModern .OxTextList .OxFocus .OxItem.OxSelected:nth-child(odd) {
background: rgb(62, 62, 62); background: rgb(62, 62, 62);
} }
.OxThemeModern .OxTextList.OxFocus .OxItem.OxSelected:nth-child(even) { .OxThemeModern .OxTextList .OxFocus .OxItem.OxSelected:nth-child(even) {
background: rgb(66, 66, 66); background: rgb(66, 66, 66);
} }
.OxThemeModern .OxTextList .OxBar .OxSelected { .OxThemeModern .OxTextList .OxBar .OxSelected {
@ -142,7 +142,7 @@ Lists
.OxThemeModern .OxTextList .OxItem.OxSelected .OxCell { .OxThemeModern .OxTextList .OxItem.OxSelected .OxCell {
border-right: 1px solid rgb(40, 40, 40); border-right: 1px solid rgb(40, 40, 40);
} }
.OxThemeModern .OxTextList.OxFocus .OxItem.OxSelected .OxCell { .OxThemeModern .OxTextList .OxFocus .OxItem.OxSelected .OxCell {
border-right: 1px solid rgb(72, 72, 72); border-right: 1px solid rgb(72, 72, 72);
color: rgb(255, 255, 255); color: rgb(255, 255, 255);
} }

View file

@ -45,7 +45,7 @@ requires
}(), }(),
path: $("script[src*=ox.ui.js]").attr("src") path: $("script[src*=ox.ui.js]").attr("src")
.replace("js/ox.ui.js", ""), .replace("js/ox.ui.js", ""),
symbols: { // fixme: make lowercase symbols: {
alt: "\u2325", alt: "\u2325",
apple: "\uF8FF", apple: "\uF8FF",
arrow_down: "\u2193", arrow_down: "\u2193",
@ -105,7 +105,8 @@ requires
$(function() { $(function() {
$window = $(window), $window = $(window),
$document = $(document), $document = $(document),
$body = $("body"); $body = $("body"),
$elements = {};
Ox.theme(oxui.defaultTheme); Ox.theme(oxui.defaultTheme);
}); });
@ -286,6 +287,15 @@ requires
Ox.Focus = function() { Ox.Focus = function() {
var stack = []; var stack = [];
return { return {
blur: function(id) {
if (stack.indexOf(id) > -1) {
$elements[Ox.Focus.focused()].removeClass("OxFocus");
stack.splice(stack.length - 2, 0, stack.pop());
Ox.Event.unbindKeyboard(id);
Ox.Event.bindKeyboard(stack[stack.length - 1]);
Ox.print("blur", stack);
}
},
focus: function(id) { focus: function(id) {
var index = stack.indexOf(id); var index = stack.indexOf(id);
if (stack.length) { if (stack.length) {
@ -295,19 +305,12 @@ requires
stack.splice(index, 1); stack.splice(index, 1);
} }
stack.push(id); stack.push(id);
$elements[Ox.Focus.focused()].addClass("OxFocus");
Ox.Event.bindKeyboard(id); Ox.Event.bindKeyboard(id);
Ox.print("focus", stack); Ox.print("focus", stack);
}, },
focused: function() { focused: function() {
return stack[stack.length - 1]; return stack[stack.length - 1];
},
blur: function(id) {
if (stack.indexOf(id) > -1) {
stack.splice(stack.length - 2, 0, stack.pop());
}
Ox.Event.unbindKeyboard(id);
Ox.Event.bindKeyboard(stack[stack.length - 1]);
Ox.print("blur", stack);
} }
}; };
}(); }();
@ -758,7 +761,7 @@ requires
Ox.Element = function() { Ox.Element = function() {
var elements = {}; var elements = {}; // fixme: unused, we need this outside Element (for Focus)
return function(options, self) { return function(options, self) {
@ -782,7 +785,7 @@ requires
ox: that.id ox: that.id
} }
}); });
elements[that.id] = that; $elements[that.id] = that;
wrapjQuery(); wrapjQuery();
})(); })();
@ -836,8 +839,8 @@ requires
// if the $element of an ox object was returned // if the $element of an ox object was returned
// then return the ox object instead // then return the ox object instead
// so we can do oxObj.jqFn().oxFn() // so we can do oxObj.jqFn().oxFn()
return ret.jquery && elements[id = ret.data("ox")] ? return ret.jquery && $elements[id = ret.data("ox")] ?
elements[id] : ret; $elements[id] : ret;
} }
}); });
} }
@ -933,7 +936,7 @@ requires
}; };
that.remove = function() { that.remove = function() {
that.$element.remove(); that.$element.remove();
delete elements[that.ox]; delete $elements[that.ox];
return that; return that;
}; };
that.triggerEvent = function() { that.triggerEvent = function() {
@ -2462,6 +2465,7 @@ requires
function click(e) { function click(e) {
var $element = $(e.target), pos; var $element = $(e.target), pos;
that.gainFocus();
while (!$element.hasClass("OxItem") && !$element.hasClass("OxPage")) { while (!$element.hasClass("OxItem") && !$element.hasClass("OxPage")) {
$element = $element.parent(); $element = $element.parent();
} }
@ -2760,6 +2764,7 @@ requires
.defaults({ .defaults({
columns: [], columns: [],
columnWidth: [40, 800], columnWidth: [40, 800],
id: "",
request: function() {}, // {sort, range, keys, callback} request: function() {}, // {sort, range, keys, callback}
sort: [] sort: []
}) })
@ -2858,6 +2863,7 @@ requires
that.$body = new Ox.List({ that.$body = new Ox.List({
construct: constructItem, construct: constructItem,
id: self.options.id,
itemHeight: 16, itemHeight: 16,
itemWidth: getItemWidth(), itemWidth: getItemWidth(),
keys: $.map(self.visibleColumns, function(v, i) { keys: $.map(self.visibleColumns, function(v, i) {

View file

@ -115,6 +115,7 @@ $(function() {
width: 80 width: 80
} }
], ],
id: "list",
request: function(options) { request: function(options) {
app.request("find", $.extend(options, { app.request("find", $.extend(options, {
query: { query: {