[Demo] CheckBox Click When Disabled
[Demo] CheckBox Click When Disabled
by dying_sakura
HTML
<div onclick="showAlert();">
<input id="ckDemo" type="checkbox" disabled="disabled"/>
</div>
JavaScript
const source = [
{
entryID: 1,
entryName: "player1",
weight: 1900,
class: ['a','b'],
},
{
entryID: 2,
entryName: "player2",
weight: 1900,
class: ['a','b'],
},
{
entryID: 3,
entryName: "player3",
weight: 1900,
class: ['c','d'],
},
{
entryID: 4,
entryName: "player4",
weight: 1900,
class: ['c','d'],
},
{
entryID: 5,
entryName: "player5",
weight: 1900,
class: ['e','f'],
},
{
entryID: 6,
entryName: "player6",
weight: 1900,
class: ['e','f'],
},
];
console.log ( combine(source) )
function combine( data = [], different = 0, maxGroupSize = 2 )
{
const
groups = []
, related = []
, sortedData = [...data].sort((a, b) => a.weight - b.weight)
, alreadyInRela = (setX,eName) =>
{
let list = [...setX, eName]
return related.some(rela=>list.every(l=>rela.has(l)))
};
sortedData.forEach((el,indx)=>
{
let place = groups.findIndex( // find a place in a group forEach element, use indx as track
g => g.names.size < maxGroupSize // is the group incomplete ?
&& !g.names.has(el.entryName) // is entryName not in the group list (names Set) ?
&& (el.weight - g.weight) <= different
&& el.level == g.level // this is what i added for level.
&& !alreadyInRela(g.names, el.entryName ) // is (entryName + group list) does not already used ?
&& !el.groupNo.some(groupNo => g.indxs.map(gi => sortedData[gi].groupName).includes(groupNo))
)
if (place < 0) // not found -> create new group
{
let names = new Set().add(el.entryName) // create new group
groups.push( { names, indxs: [indx], weight: el.weight } ) // group constitutive info
related.push( names ) // keep track of group list
}
else // find a place in a group
{
groups[place].names.add(el.entryName) // related list is also updated
...