Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var m = require( 'mithril' )
var isSelected = require( '../functions/isSelected' )
function action(option, selection, e){
if (isSelected(ctrl.option, ctrl.selection)) {
var i = ctrl.selection.indexOf(ctrl.option)
ctrl.selection.splice(i, 1)
} else {
if (Array.isArray(ctrl.selection)) {
ctrl.selection.push(ctrl.option)
} else {
ctrl.selection(ctrl.option)
}
}
e.stopPropagation()
m.redraw()
}
function setClasses(option, selection, highlighted, index){
var selected = isSelected(option, selection);
if (selected && highlighted() === index){
return "selected highlighted";
} else if (selected && highlighted() !== index){
return "selected";
} else if (!selected && highlighted() === index){
return 'highlighted';
} else {
return '';
}
}
var selectOption = {};
selectOption.view = function( vnode ){
return m('.item[tabindex=0]', {
class: setClasses(option, selection, highlighted, index),
style: {
display: search() && option.toLowerCase().indexOf(search().toLowerCase()) === -1 ? 'none' : 'block'
},
onclick: function( e ){} action(option, selection, e) },
onfocus: function(){ ctrl.highlighted(index) },
onmouseover: function(){ ctrl.highlighted(index) }
}, option )
}
module.exports = selectOption
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.