now all button components are extensible...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-06-22 18:24:43 +03:00
parent e278fa737c
commit e1535bc1ba

View File

@ -164,12 +164,18 @@ Items.nest = function(item, list, options){
// Buttons... // Buttons...
var buttons = Items.buttons = {} var buttons = Items.buttons = {}
// XXX make this combinable by user... //
// Checkbox('attr')
// Checkbox('!attr')
//
// XXX rename -- distinguish from actual button...
var Checkbox = var Checkbox =
buttons.Checkbox = buttons.Checkbox =
function(attr){ function(attr){
return function(item){ return function(item){
return item[attr] ? return (attr[0] == '!'
&& !item[attr.slice(1)])
|| item[attr] ?
'&#9744;' '&#9744;'
: '&#9745;' } } : '&#9745;' } }
@ -185,14 +191,14 @@ function(attr){
// - protocol to pass data from button to button // - protocol to pass data from button to button
// - protocol to fill data gradually... // - protocol to fill data gradually...
buttons.ToggleDisabled = [ buttons.ToggleDisabled = [
Checkbox('disabled'), 'Checkbox: "disabled"',
'toggleDisabled: item', 'toggleDisabled: item',
true] true]
buttons.ToggleHidden = [ buttons.ToggleHidden = [
Checkbox('hidden'), 'Checkbox: "hidden"',
'toggleHidden: item'] 'toggleHidden: item']
buttons.ToggleSelected = [ buttons.ToggleSelected = [
Checkbox('selected'), 'Checkbox: "selected"',
'toggleSelect: item'] 'toggleSelect: item']
@ -3742,6 +3748,7 @@ var BrowserPrototype = {
.map(function(button){ .map(function(button){
return button instanceof Array ? return button instanceof Array ?
button button
// XXX reference the actual make(..) and not Items...
: Items.buttons[button] || button }) : Items.buttons[button] || button })
.slice() .slice()
// NOTE: keep the order unsurprising... // NOTE: keep the order unsurprising...
@ -3754,8 +3761,17 @@ var BrowserPrototype = {
var button = document.createElement('div') var button = document.createElement('div')
button.classList.add('button') button.classList.add('button')
var htmlhandler = typeof(html) == typeof('str') ?
that.keyboard.parseStringHandler(html, {item})
: null
button.innerHTML = html instanceof Function ? button.innerHTML = html instanceof Function ?
html.call(that, item) html.call(that, item)
// XXX reference the actual make(..) and not Items...
: htmlhandler && htmlhandler.action in Items.buttons ?
Items.buttons[htmlhandler.action]
.call(that, ...htmlhandler.arguments)
// XXX is this the right format???
.call(that, item)
: html : html
if(force || !item.disabled){ if(force || !item.disabled){