mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
added item event default getter...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6f2a15fa2d
commit
9499108401
@ -304,7 +304,13 @@ var callItemEventHandlers = function(item, event, evt, ...args){
|
||||
// up the tree.
|
||||
//
|
||||
// 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(
|
||||
// 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
|
||||
@ -344,6 +350,9 @@ var makeItemEventMethod = function(event, handler, options){
|
||||
// explicit item or query...
|
||||
: item != null ?
|
||||
this.search(item, options)
|
||||
// item is null or undefined -- get default...
|
||||
: default_item instanceof Function ?
|
||||
[default_item.call(that) || []].flat()
|
||||
: [],
|
||||
...args) },
|
||||
// get base method attributes -- keep the event method format...
|
||||
@ -2019,8 +2028,8 @@ var BaseBrowserPrototype = {
|
||||
// .focus(query[, ...])
|
||||
// -> this
|
||||
//
|
||||
// XXX need reasonable default item selections...
|
||||
focus: makeItemEventMethod('focus', function(evt, items){
|
||||
focus: makeItemEventMethod('focus',
|
||||
function(evt, items){
|
||||
// blur .focused...
|
||||
this.focused
|
||||
&& this.blur(this.focused)
|
||||
@ -2028,21 +2037,38 @@ var BaseBrowserPrototype = {
|
||||
var item = items.shift()
|
||||
item != null
|
||||
&& (item.focused = true)
|
||||
}),
|
||||
},
|
||||
// default...
|
||||
function(){ return this.get(0) }),
|
||||
blur: makeItemEventMethod('blur', function(evt, items){
|
||||
items.forEach(function(item){
|
||||
delete item.focused }) }),
|
||||
select: makeItemEventMethod('select', function(evt, items){
|
||||
// XXX should we select .focused by default???
|
||||
select: makeItemEventMethod('select',
|
||||
function(evt, items){
|
||||
items.forEach(function(item){
|
||||
item.selected = true }) }),
|
||||
deselect: makeItemEventMethod('deselect', function(evt, items){
|
||||
item.selected = true }) },
|
||||
// XXX is this a good default???
|
||||
function(){ return this.focused }),
|
||||
// XXX should we deselect .focused by default???
|
||||
deselect: makeItemEventMethod('deselect',
|
||||
function(evt, items){
|
||||
items.forEach(function(item){
|
||||
delete item.selected }) }),
|
||||
open: makeItemEventMethod('open', function(evt, item){}),
|
||||
enter: makeItemEventMethod('enter', function(evt, 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???
|
||||
collapse: makeItemEventMethod('collapse', function(evt, item){}),
|
||||
expand: makeItemEventMethod('expand', function(evt, item){}),
|
||||
collapse: makeItemEventMethod('collapse',
|
||||
function(evt, item){},
|
||||
function(){ return this.focused }),
|
||||
expand: makeItemEventMethod('expand',
|
||||
function(evt, item){},
|
||||
function(){ return this.focused }),
|
||||
|
||||
// XXX target can be item or path...
|
||||
load: makeEventMethod('load', function(evt, item){}),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user