mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
added .enable(..)/.disable(..) events + fixed .blur(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
270118aa80
commit
fd35af5bfc
@ -195,7 +195,7 @@ requirejs([
|
|||||||
}, {
|
}, {
|
||||||
itemButtons: [
|
itemButtons: [
|
||||||
['–'],
|
['–'],
|
||||||
['□'],
|
['□', function(){ console.log('BUTTON:', ...arguments) }],
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -2565,9 +2565,12 @@ var BaseBrowserPrototype = {
|
|||||||
getMode: 'get',
|
getMode: 'get',
|
||||||
skipDisabled: true,
|
skipDisabled: true,
|
||||||
}),
|
}),
|
||||||
blur: makeItemEventMethod('blur', function(evt, items){
|
blur: makeItemEventMethod('blur',
|
||||||
items.forEach(function(item){
|
function(evt, items){
|
||||||
delete item.focused }) }),
|
items.forEach(function(item){
|
||||||
|
delete item.focused }) },
|
||||||
|
null,
|
||||||
|
function(){ return this.focused }),
|
||||||
// NOTE: .next() / .prev() will wrap around the first/last elements...
|
// NOTE: .next() / .prev() will wrap around the first/last elements...
|
||||||
next: function(){
|
next: function(){
|
||||||
this.focus('next').focused || this.focus('first')
|
this.focus('next').focused || this.focus('first')
|
||||||
@ -2625,6 +2628,34 @@ var BaseBrowserPrototype = {
|
|||||||
function(elem){ return elem.value && elem.children },
|
function(elem){ return elem.value && elem.children },
|
||||||
{iterateCollapsed: true}),
|
{iterateCollapsed: true}),
|
||||||
|
|
||||||
|
// XXX not sure about these...
|
||||||
|
disable: makeItemEventMethod('disable',
|
||||||
|
function(evt, items){
|
||||||
|
var that = this
|
||||||
|
var change = false
|
||||||
|
items.forEach(function(item){
|
||||||
|
change = item.disabled = true
|
||||||
|
item.focused
|
||||||
|
&& that.blur(item)
|
||||||
|
})
|
||||||
|
// need to update for changes to show up...
|
||||||
|
change
|
||||||
|
&& this.update() },
|
||||||
|
null,
|
||||||
|
// XXX is this a good default???
|
||||||
|
function(){ return this.focused }),
|
||||||
|
enable: makeItemEventMethod('enable',
|
||||||
|
function(evt, items){
|
||||||
|
var change = false
|
||||||
|
items.forEach(function(item){
|
||||||
|
change = change || item.disabled
|
||||||
|
delete item.disabled })
|
||||||
|
// need to update for changes to show up...
|
||||||
|
change
|
||||||
|
&& this.update() },
|
||||||
|
null,
|
||||||
|
{ skipDisabled: false }),
|
||||||
|
|
||||||
// primary/secondary/ternary? item actions...
|
// primary/secondary/ternary? item actions...
|
||||||
// XXX revise default actions...
|
// XXX revise default actions...
|
||||||
open: makeItemEventMethod('open',
|
open: makeItemEventMethod('open',
|
||||||
@ -3108,11 +3139,8 @@ var BrowserPrototype = {
|
|||||||
// ...
|
// ...
|
||||||
// </div>
|
// </div>
|
||||||
//
|
//
|
||||||
// XXX add custom events:
|
|
||||||
// - open
|
|
||||||
// - select
|
|
||||||
// - update
|
|
||||||
// XXX should we trigger the DOM event or the browser event???
|
// XXX should we trigger the DOM event or the browser event???
|
||||||
|
// XXX should buttoms be active in disabled state???
|
||||||
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
|
||||||
@ -3210,13 +3238,30 @@ var BrowserPrototype = {
|
|||||||
var button = document.createElement('div')
|
var button = document.createElement('div')
|
||||||
button.classList.add('button')
|
button.classList.add('button')
|
||||||
button.innerHTML = html
|
button.innerHTML = html
|
||||||
|
// XXX should buttons be active in disabled state???
|
||||||
if(!item.disabled){
|
if(!item.disabled){
|
||||||
button.setAttribute('tabindex', '0')
|
button.setAttribute('tabindex', '0')
|
||||||
|
// events to keep in buttons...
|
||||||
;(options.buttonLocalEvents || options.localEvents || [])
|
;(options.buttonLocalEvents || options.localEvents || [])
|
||||||
.forEach(function(evt){
|
.forEach(function(evt){
|
||||||
button.addEventListener(evt, stopPropagation) })
|
button.addEventListener(evt, stopPropagation) })
|
||||||
handler
|
// keep focus on the item containing the button -- i.e. if
|
||||||
&& button.addEventListener('click', handler)
|
// we tab out of the item focus the item we get to...
|
||||||
|
button.addEventListener('focus', function(){
|
||||||
|
item.focused
|
||||||
|
|| that.focus(item)
|
||||||
|
&& button.focus() })
|
||||||
|
// main button action (click/enter)...
|
||||||
|
// XXX should there be a secondary action (i.e. shift-enter)???
|
||||||
|
if(handler){
|
||||||
|
button.addEventListener('click', handler)
|
||||||
|
button.addEventListener('keydown',
|
||||||
|
function(evt){
|
||||||
|
var k = keyboard.event2key(evt)
|
||||||
|
if(k.includes('Enter')){
|
||||||
|
event.stopPropagation()
|
||||||
|
handler.call(this, evt)
|
||||||
|
} }) }
|
||||||
}
|
}
|
||||||
elem.appendChild(button)
|
elem.appendChild(button)
|
||||||
})
|
})
|
||||||
@ -3256,7 +3301,17 @@ var BrowserPrototype = {
|
|||||||
this.classList.add('focused') })
|
this.classList.add('focused') })
|
||||||
// set focus...
|
// set focus...
|
||||||
.focus() },
|
.focus() },
|
||||||
// NOTE: this simply update the state...
|
__blur__: function(evt, elem){
|
||||||
|
var that = this
|
||||||
|
elem
|
||||||
|
&& getElem(elem)
|
||||||
|
.run(function(){
|
||||||
|
this.classList.remove('focused')
|
||||||
|
//this.blur()
|
||||||
|
that.dom
|
||||||
|
&& that.dom.focus() }) },
|
||||||
|
|
||||||
|
// NOTE: these simply update the state...
|
||||||
__select__: function(){
|
__select__: function(){
|
||||||
var selected = new Set(this.selected.map(getElem))
|
var selected = new Set(this.selected.map(getElem))
|
||||||
this.dom
|
this.dom
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user