working on item buttons...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-06-23 00:14:45 +03:00
parent e1535bc1ba
commit c1eac80503
2 changed files with 30 additions and 19 deletions

View File

@ -260,6 +260,7 @@ requirejs([
'buttonAction: item button focused -- example button action...'], 'buttonAction: item button focused -- example button action...'],
['&square;', ['&square;',
function(){ console.log('BUTTON:', ...arguments) }], function(){ console.log('BUTTON:', ...arguments) }],
'ToggleCollapse',
'ToggleDisabled', 'ToggleDisabled',
], ],
}) })

View File

@ -165,13 +165,14 @@ Items.nest = function(item, list, options){
var buttons = Items.buttons = {} var buttons = Items.buttons = {}
// //
// Draw checked checkboz is <attr> is true...
// Checkbox('attr') // Checkbox('attr')
//
// Draw checked checkboz is <attr> is false...
// Checkbox('!attr') // Checkbox('!attr')
// //
// XXX rename -- distinguish from actual button... // XXX rename -- distinguish from actual button...
var Checkbox = buttons.Checkbox = function(attr){
buttons.Checkbox =
function(attr){
return function(item){ return function(item){
return (attr[0] == '!' return (attr[0] == '!'
&& !item[attr.slice(1)]) && !item[attr.slice(1)])
@ -180,16 +181,7 @@ function(attr){
: '&#9745;' } } : '&#9745;' } }
// XXX can we make these: // XXX can we make these not use the same icon...
// - different -- not use the same icon...
// - configurable / combinable...
// something like:
// toggleDisabled: checkbox -- need checkbox to know the state...
// toggleHidden: "&times;"
// ...
// XXX button combination/chaining would require:
// - protocol to pass data from button to button
// - protocol to fill data gradually...
buttons.ToggleDisabled = [ buttons.ToggleDisabled = [
'Checkbox: "disabled"', 'Checkbox: "disabled"',
'toggleDisabled: item', 'toggleDisabled: item',
@ -200,6 +192,19 @@ buttons.ToggleHidden = [
buttons.ToggleSelected = [ buttons.ToggleSelected = [
'Checkbox: "selected"', 'Checkbox: "selected"',
'toggleSelect: item'] 'toggleSelect: item']
// NOTE: this button is disabled for all items but the ones with .children...
buttons.ToggleCollapse = [
function(item){
return !item.children ?
// placeholder...
'&nbsp;'
: item.collapsed ?
'+'
: '-' },
'toggleCollapse: item',
// disable button for all items that do not have children...
function(item){
return 'children' in item }]
@ -3719,7 +3724,10 @@ var BrowserPrototype = {
elem.addEventListener('click', elem.addEventListener('click',
function(evt){ function(evt){
evt.stopPropagation() evt.stopPropagation()
that.open(item, text, elem) }) // XXX revise...
item.disabled ?
that.toggleCollapse(item)
: that.open(item, text, elem) })
elem.addEventListener('focus', elem.addEventListener('focus',
function(){ function(){
// NOTE: we do not retrigger focus on an item if it's // NOTE: we do not retrigger focus on an item if it's
@ -3749,15 +3757,16 @@ var BrowserPrototype = {
return button instanceof Array ? return button instanceof Array ?
button button
// XXX reference the actual make(..) and not Items... // XXX reference the actual make(..) and not Items...
: Items.buttons[button] instanceof Function ?
Items.buttons[button].call(that, item)
: Items.buttons[button] || button }) : Items.buttons[button] || button })
.slice()
// NOTE: keep the order unsurprising... // NOTE: keep the order unsurprising...
.reverse() .reverse()
var stopPropagation = function(evt){ evt.stopPropagation() } var stopPropagation = function(evt){ evt.stopPropagation() }
buttons buttons
// XXX add option to use a shortcut key... // XXX add option to use a shortcut key...
// XXX use keyword to inherit buttons... // XXX use keyword to inherit buttons...
.forEach(function([html, handler, force, keyword]){ .forEach(function([html, handler, force]){
var button = document.createElement('div') var button = document.createElement('div')
button.classList.add('button') button.classList.add('button')
@ -3770,11 +3779,12 @@ var BrowserPrototype = {
: htmlhandler && htmlhandler.action in Items.buttons ? : htmlhandler && htmlhandler.action in Items.buttons ?
Items.buttons[htmlhandler.action] Items.buttons[htmlhandler.action]
.call(that, ...htmlhandler.arguments) .call(that, ...htmlhandler.arguments)
// XXX is this the right format???
.call(that, item) .call(that, item)
: html : html
if(force || !item.disabled){ if(force instanceof Function ?
force.call(that, item)
: (force || !item.disabled) ){
button.setAttribute('tabindex', '0') button.setAttribute('tabindex', '0')
// events to keep in buttons... // events to keep in buttons...
;(options.buttonLocalEvents || options.localEvents || []) ;(options.buttonLocalEvents || options.localEvents || [])