added .options.focusDisabled and most of support...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-06-25 17:41:12 +03:00
parent 3e40a31673
commit 69aafbf131

View File

@ -522,15 +522,19 @@ function(event, {handler, action, default_item, filter, options={}, getter='sear
return filter ? return filter ?
items.filter(filter) items.filter(filter)
: items } : items }
options = Object.assign( // options constructor...
{ var makeOptions = function(){
// NOTE: we need to be able to pass item objects, so we can not return Object.assign(
// use queries at the same time as there is not way to {
// distinguish one from the other... // NOTE: we need to be able to pass item objects, so we can not
noQueryCheck: true, // use queries at the same time as there is not way to
skipDisabled: true, // distinguish one from the other...
}, noQueryCheck: true,
options) skipDisabled: true,
},
options instanceof Function ?
options.call(this)
: options) }
// base event method... // base event method...
// NOTE: this is not returned directly as we need to query the items // NOTE: this is not returned directly as we need to query the items
// and pass those on to the handlers rather than the arguments // and pass those on to the handlers rather than the arguments
@ -547,10 +551,20 @@ function(event, {handler, action, default_item, filter, options={}, getter='sear
callItemEventHandlers(item, event, evt, ...args) }) }, callItemEventHandlers(item, event, evt, ...args) }) },
...(action ? [action] : []), ...(action ? [action] : []),
false) false)
// build the options statically if we can...
options = options instanceof Function ?
options
: makeOptions()
return Object.assign( return Object.assign(
// the actual method we return... // the actual method we return...
function(item, ...args){ function(item, ...args){
var that = this var that = this
// build the options dynamically if needed...
var opts = options instanceof Function ?
makeOptions.call(this)
: options
return base.call(this, return base.call(this,
// event handler... // event handler...
item instanceof Function ? item instanceof Function ?
@ -559,12 +573,12 @@ function(event, {handler, action, default_item, filter, options={}, getter='sear
: item instanceof Array ? : item instanceof Array ?
filterItems(item filterItems(item
.map(function(e){ .map(function(e){
return that.search(e, options) }) 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, options)) filterItems(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()
@ -769,6 +783,8 @@ var BaseBrowserClassPrototype = {
var BaseBrowserPrototype = { var BaseBrowserPrototype = {
// XXX should we mix item/list options or separate them into sub-objects??? // XXX should we mix item/list options or separate them into sub-objects???
options: { options: {
focusDisabled: false,
// If true item keys must be unique... // If true item keys must be unique...
uniqueKeys: false, uniqueKeys: false,
@ -2843,10 +2859,10 @@ var BaseBrowserPrototype = {
&& this.reveal(item) && this.reveal(item)
&& (item.focused = true) }, && (item.focused = true) },
default_item: function(){ return this.get(0) }, default_item: function(){ return this.get(0) },
options: { options: function(){
// XXX get this from options... return {
skipDisabled: true, skipDisabled: !(this.options || {}).focusDisabled,
}, } },
getter: 'get' }), getter: 'get' }),
blur: makeItemEventMethod('blur', { blur: makeItemEventMethod('blur', {
handler: function(evt, items){ handler: function(evt, items){
@ -2885,7 +2901,9 @@ var BaseBrowserPrototype = {
{iterateCollapsed: true}), {iterateCollapsed: true}),
// item state events... // item state events...
disable: makeItemOptionOnEventMethod('disable', 'disabled', disable: makeItemOptionOnEventMethod('disable', 'disabled',
{ handler: function(item){ this.blur(item) }, }), { handler: function(item){
(this.options || {}).focusDisabled
|| this.blur(item) }, }),
enable: makeItemOptionOffEventMethod('enable', 'disabled', enable: makeItemOptionOffEventMethod('enable', 'disabled',
{ options: {skipDisabled: false}, }), { options: {skipDisabled: false}, }),
toggleDisabled: makeItemEventToggler( toggleDisabled: makeItemEventToggler(
@ -3172,8 +3190,8 @@ var focusItem = function(direction){
var threashold = this.options.focusOffsetWhileScrolling || 0 var threashold = this.options.focusOffsetWhileScrolling || 0
var focused = this.focused var focused = this.focused
var first = this.get('first', {skipDisabled: true}) var first = this.get('first', {skipDisabled: !(this.options || {}).focusDisabled})
var last = this.get('last', {skipDisabled: true}) var last = this.get('last', {skipDisabled: !(this.options || {}).focusDisabled})
// center the first/last elements to reveal hidden items before/after... // center the first/last elements to reveal hidden items before/after...
;(focused === last || focused === first) ? ;(focused === last || focused === first) ?
@ -3208,11 +3226,12 @@ var focusPage = function(direction){
var focused = this.focused var focused = this.focused
// reveal diabled elements above the top focusable... // reveal diabled elements above the top focusable...
target === this.get(t, {skipDisabled: true}) && target === focused ? ;(target === this.get(t, {skipDisabled: !(this.options || {}).focusDisabled})
&& target === focused) ?
this.scrollTo(target, 'center') this.scrollTo(target, 'center')
// scroll one page and focus... // scroll one page and focus...
: target === focused ? : target === focused ?
this.focus(this.get(d, 1)) this.focus(this.get(d, 1, {skipDisabled: !(this.options || {}).focusDisabled}))
// focus top/bottom of current page... // focus top/bottom of current page...
: this.focus(target) : this.focus(target)
@ -3475,7 +3494,7 @@ var HTMLBrowserPrototype = {
reverse: pos == 'bottom' ? reverse: pos == 'bottom' ?
'flat' 'flat'
: false, : false,
skipDisabled: true, skipDisabled: !(this.options || {}).focusDisabled,
}) })
.run(function(){ .run(function(){
return this instanceof Array ? return this instanceof Array ?
@ -3788,6 +3807,9 @@ var HTMLBrowserPrototype = {
// ...can a disabled item be focused? // ...can a disabled item be focused?
// ...how do we collapse/expand a disabled root? // ...how do we collapse/expand a disabled root?
// ...what do we focus when toggleing disabled? // ...what do we focus when toggleing disabled?
// XXX handle .options.focusDisabled correctly...
// - tabindex
// - ...
renderItem: function(item, i, context){ renderItem: function(item, i, context){
var that = this var that = this
var options = context.options || this.options || {} var options = context.options || this.options || {}