From 23eff70f777965212b171291d721fa20002895fa Mon Sep 17 00:00:00 2001 From: Rolux Date: Wed, 30 Jun 2010 11:27:02 +0200 Subject: [PATCH] make list focus on click --- build/css/ox.ui.modern.css | 6 +++--- build/js/ox.ui.js | 36 +++++++++++++++++++++--------------- demos/test/list.js | 1 + 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/build/css/ox.ui.modern.css b/build/css/ox.ui.modern.css index b8511b5..f776875 100644 --- a/build/css/ox.ui.modern.css +++ b/build/css/ox.ui.modern.css @@ -119,10 +119,10 @@ Lists .OxThemeModern .OxTextList .OxItem.OxSelected:nth-child(even) { 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); } -.OxThemeModern .OxTextList.OxFocus .OxItem.OxSelected:nth-child(even) { +.OxThemeModern .OxTextList .OxFocus .OxItem.OxSelected:nth-child(even) { background: rgb(66, 66, 66); } .OxThemeModern .OxTextList .OxBar .OxSelected { @@ -142,7 +142,7 @@ Lists .OxThemeModern .OxTextList .OxItem.OxSelected .OxCell { 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); color: rgb(255, 255, 255); } diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 812689b..ea9bf58 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -45,7 +45,7 @@ requires }(), path: $("script[src*=ox.ui.js]").attr("src") .replace("js/ox.ui.js", ""), - symbols: { // fixme: make lowercase + symbols: { alt: "\u2325", apple: "\uF8FF", arrow_down: "\u2193", @@ -105,7 +105,8 @@ requires $(function() { $window = $(window), $document = $(document), - $body = $("body"); + $body = $("body"), + $elements = {}; Ox.theme(oxui.defaultTheme); }); @@ -286,6 +287,15 @@ requires Ox.Focus = function() { var stack = []; 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) { var index = stack.indexOf(id); if (stack.length) { @@ -295,19 +305,12 @@ requires stack.splice(index, 1); } stack.push(id); + $elements[Ox.Focus.focused()].addClass("OxFocus"); Ox.Event.bindKeyboard(id); Ox.print("focus", stack); }, focused: function() { 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() { - var elements = {}; + var elements = {}; // fixme: unused, we need this outside Element (for Focus) return function(options, self) { @@ -782,7 +785,7 @@ requires ox: that.id } }); - elements[that.id] = that; + $elements[that.id] = that; wrapjQuery(); })(); @@ -836,8 +839,8 @@ requires // if the $element of an ox object was returned // then return the ox object instead // so we can do oxObj.jqFn().oxFn() - return ret.jquery && elements[id = ret.data("ox")] ? - elements[id] : ret; + return ret.jquery && $elements[id = ret.data("ox")] ? + $elements[id] : ret; } }); } @@ -933,7 +936,7 @@ requires }; that.remove = function() { that.$element.remove(); - delete elements[that.ox]; + delete $elements[that.ox]; return that; }; that.triggerEvent = function() { @@ -2462,6 +2465,7 @@ requires function click(e) { var $element = $(e.target), pos; + that.gainFocus(); while (!$element.hasClass("OxItem") && !$element.hasClass("OxPage")) { $element = $element.parent(); } @@ -2760,6 +2764,7 @@ requires .defaults({ columns: [], columnWidth: [40, 800], + id: "", request: function() {}, // {sort, range, keys, callback} sort: [] }) @@ -2858,6 +2863,7 @@ requires that.$body = new Ox.List({ construct: constructItem, + id: self.options.id, itemHeight: 16, itemWidth: getItemWidth(), keys: $.map(self.visibleColumns, function(v, i) { diff --git a/demos/test/list.js b/demos/test/list.js index c764f1a..8a3af26 100644 --- a/demos/test/list.js +++ b/demos/test/list.js @@ -115,6 +115,7 @@ $(function() { width: 80 } ], + id: "list", request: function(options) { app.request("find", $.extend(options, { query: {