focus issues mostly worked out but not quite fully...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-06-30 01:42:41 +03:00
parent e3e3c175cb
commit 91e6e497d8

View File

@ -609,15 +609,12 @@ function(event, {handler, action, default_item, filter, options={}, getter='sear
[] []
: [items] : [items]
return filter ? return filter ?
items.filter(filter) items.filter(filter.bind(this))
: items } : items }
// options constructor... // options constructor...
var makeOptions = function(){ var makeOptions = function(){
return Object.assign( return Object.assign(
{ {
// get items from all sections...
// XXX SECTION_FOCUS
//section: '*',
// NOTE: we need to be able to pass item objects, so we can not // NOTE: we need to be able to pass item objects, so we can not
// use queries at the same time as there is not way to // use queries at the same time as there is not way to
// distinguish one from the other... // distinguish one from the other...
@ -663,14 +660,14 @@ function(event, {handler, action, default_item, filter, options={}, getter='sear
item item
// array of queries... // array of queries...
: item instanceof Array ? : item instanceof Array ?
filterItems(item filterItems.call(this, item
.map(function(e){ .map(function(e){
return that.search(e, opts) }) return that.search(e, opts) })
.flat() .flat()
.unique()) .unique())
// explicit item or query... // explicit item or query...
: item != null ? : item != null ?
filterItems(this[getter](item, opts)) filterItems.call(this, this[getter](item, opts))
// item is undefined -- get default... // item is undefined -- get default...
: item !== null && default_item instanceof Function ? : item !== null && default_item instanceof Function ?
[default_item.call(that) || []].flat() [default_item.call(that) || []].flat()
@ -749,7 +746,7 @@ function(get_state, set_state, unset_state, default_item, multi, options){
&& multi && multi
var filterItems = function(items){ var filterItems = function(items){
return filter ? return filter ?
items.filter(filter) items.filter(filter.bind(this))
: items } : items }
multi = multi !== false multi = multi !== false
var getter = multi ? 'search' : 'get' var getter = multi ? 'search' : 'get'
@ -796,7 +793,7 @@ function(get_state, set_state, unset_state, default_item, multi, options){
: item == null ? : item == null ?
false false
: state == '?' ? : state == '?' ?
filterItems( filterItems.call(this,
[this[getter](item, options)] [this[getter](item, options)]
.flat()) .flat())
.map(_get_state) .map(_get_state)
@ -806,7 +803,7 @@ function(get_state, set_state, unset_state, default_item, multi, options){
_unset_state.call(this, item) _unset_state.call(this, item)
// 'next' or '!'... // 'next' or '!'...
// NOTE: 'next' and '!' are opposites of each other... // NOTE: 'next' and '!' are opposites of each other...
: filterItems( : filterItems.call(this,
[this[getter](item, options)] [this[getter](item, options)]
.flat()) .flat())
.map(function(e){ .map(function(e){
@ -3064,17 +3061,16 @@ var BaseBrowserPrototype = {
var item = items.shift() var item = items.shift()
// do not change focus if item is not in the main section... // do not change focus if item is not in the main section...
// NOTE: we will still trigger item focus handlers... // NOTE: we will still trigger item focus handlers...
/*/ XXX SECTION_FOCUS
if(item != null if(item != null
&& this.get(item) == null && this.get(item) == null
&& !(this.options || {}).allowSecondaySectionFocus){ && !(this.options || {}).allowSecondaySectionFocus){
// XXX SECTION_FOCUS
// XXX this fixes the .__focus__(..) falling into recursion // XXX this fixes the .__focus__(..) falling into recursion
// problem but prevent non-main-section item handlers // problem but prevent non-main-section item handlers
// from triggering... // from triggering...
evt.stopPropagation() evt.stopPropagation()
return return
} }
//*/
// blur .focused... // blur .focused...
this.focused this.focused
&& this.blur(this.focused) && this.blur(this.focused)
@ -3085,15 +3081,7 @@ var BaseBrowserPrototype = {
default_item: function(){ return this.get(0) }, default_item: function(){ return this.get(0) },
options: function(){ options: function(){
return { return {
/*/ XXX SECTION_FOCUS this set to '*' will enable non-main-section
// to be passed to .focus(..) handlers, otherwise they will
// get undefined (i.e. blur the .focused item)...
// ...setting this to '*' will also make next/prev keywords get
// other section items...
// ...in turn this will break .__focus__(..) when
// on footer/header...
section: '*', section: '*',
//*/
skipDisabled: !(this.options || {}).focusDisabledItems, skipDisabled: !(this.options || {}).focusDisabledItems,
} }, } },
getter: 'get' }), getter: 'get' }),
@ -3102,19 +3090,21 @@ var BaseBrowserPrototype = {
items.forEach(function(item){ items.forEach(function(item){
delete item.focused }) }, delete item.focused }) },
default_item: function(){ return this.focused } }), default_item: function(){ return this.focused } }),
// NOTE: .next() / .prev() will wrap around the first/last elements,
// this is different from .focus('next') / .focus('prev')...
next: function(){
this.focus('next').focused || this.focus('first')
return this },
prev: function(){
this.focus('prev').focused || this.focus('last')
return this },
toggleFocus: makeItemEventToggler( toggleFocus: makeItemEventToggler(
'focused', 'focused',
'focus', 'blur', 'focus', 'blur',
function(){ return this.focused || 0 }, function(){ return this.focused || 0 },
false), false),
// NOTE: .next() / .prev() will wrap around the first/last elements,
// this is different from .focus('next') / .focus('prev')...
// NOTE: these also differ from focus in that they will only go
// through the main section...
next: function(){
this.focus(this.get('next') || this.get('first'))
return this },
prev: function(){
this.focus(this.get('prev') || this.get('last'))
return this },
// selection... // selection...
select: makeItemOptionOnEventMethod('select', 'selected', { select: makeItemOptionOnEventMethod('select', 'selected', {
options: function(){ options: function(){
@ -4480,6 +4470,7 @@ var HTMLBrowserPrototype = {
}) })
}) })
// set focus... // set focus...
// XXX SECTION_FOCUS breaks int recursion on non main section items...
.focus() }, .focus() },
__blur__: function(evt, elem){ __blur__: function(evt, elem){
var that = this var that = this