added item event default getter...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-05-26 03:38:38 +03:00
parent 6f2a15fa2d
commit 9499108401

View File

@ -304,7 +304,13 @@ var callItemEventHandlers = function(item, event, evt, ...args){
// up the tree. // up the tree.
// //
// XXX need reasonable default item selections... // XXX need reasonable default item selections...
var makeItemEventMethod = function(event, handler, options){ var makeItemEventMethod = function(event, handler, default_item, options){
options = default_item instanceof Function ?
options
: default_item
default_item = default_item instanceof Function ?
default_item
: null
options = Object.assign( options = Object.assign(
// 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
@ -344,10 +350,13 @@ var makeItemEventMethod = function(event, handler, options){
// explicit item or query... // explicit item or query...
: item != null ? : item != null ?
this.search(item, options) this.search(item, options)
// item is null or undefined -- get default...
: default_item instanceof Function ?
[default_item.call(that) || []].flat()
: [], : [],
...args) }, ...args) },
// get base method attributes -- keep the event method format... // get base method attributes -- keep the event method format...
base) } base) }
@ -2019,30 +2028,47 @@ var BaseBrowserPrototype = {
// .focus(query[, ...]) // .focus(query[, ...])
// -> this // -> this
// //
// XXX need reasonable default item selections... focus: makeItemEventMethod('focus',
focus: makeItemEventMethod('focus', function(evt, items){ function(evt, items){
// blur .focused... // blur .focused...
this.focused this.focused
&& this.blur(this.focused) && this.blur(this.focused)
// NOTE: if we got multiple matches we care only about the first one... // NOTE: if we got multiple matches we care only about the first one...
var item = items.shift() var item = items.shift()
item != null item != null
&& (item.focused = true) && (item.focused = true)
}), },
// default...
function(){ return this.get(0) }),
blur: makeItemEventMethod('blur', function(evt, items){ blur: makeItemEventMethod('blur', function(evt, items){
items.forEach(function(item){ items.forEach(function(item){
delete item.focused }) }), delete item.focused }) }),
select: makeItemEventMethod('select', function(evt, items){ // XXX should we select .focused by default???
items.forEach(function(item){ select: makeItemEventMethod('select',
item.selected = true }) }), function(evt, items){
deselect: makeItemEventMethod('deselect', function(evt, items){ items.forEach(function(item){
items.forEach(function(item){ item.selected = true }) },
delete item.selected }) }), // XXX is this a good default???
open: makeItemEventMethod('open', function(evt, item){}), function(){ return this.focused }),
enter: makeItemEventMethod('enter', function(evt, item){}), // XXX should we deselect .focused by default???
deselect: makeItemEventMethod('deselect',
function(evt, items){
items.forEach(function(item){
delete item.selected }) },
function(){ return this.focused }),
open: makeItemEventMethod('open',
function(evt, item){},
function(){ return this.focused }),
enter: makeItemEventMethod('enter',
function(evt, item){},
function(){ return this.focused }),
// XXX can/should we unify these??? // XXX can/should we unify these???
collapse: makeItemEventMethod('collapse', function(evt, item){}), collapse: makeItemEventMethod('collapse',
expand: makeItemEventMethod('expand', function(evt, item){}), function(evt, item){},
function(){ return this.focused }),
expand: makeItemEventMethod('expand',
function(evt, item){},
function(){ return this.focused }),
// XXX target can be item or path... // XXX target can be item or path...
load: makeEventMethod('load', function(evt, item){}), load: makeEventMethod('load', function(evt, item){}),