MCPcopy Create free account
hub / github.com/TruthHun/BookStack / buildElement

Function buildElement

static/bootstrap-select-1.13.18/js/bootstrap-select.js:1641–1699  ·  view source on GitHub ↗
(item)

Source from the content-addressed store, hash-verified

1639 }
1640
1641 function buildElement (item) {
1642 var liElement,
1643 combinedLength = 0;
1644
1645 switch (item.type) {
1646 case 'divider':
1647 liElement = generateOption.li(
1648 false,
1649 classNames.DIVIDER,
1650 (item.optID ? item.optID + 'div' : undefined)
1651 );
1652
1653 break;
1654
1655 case 'option':
1656 liElement = generateOption.li(
1657 generateOption.a(
1658 generateOption.text.call(that, item),
1659 item.optionClass,
1660 item.inlineStyle
1661 ),
1662 '',
1663 item.optID
1664 );
1665
1666 if (liElement.firstChild) {
1667 liElement.firstChild.id = that.selectId + '-' + item.index;
1668 }
1669
1670 break;
1671
1672 case 'optgroup-label':
1673 liElement = generateOption.li(
1674 generateOption.label.call(that, item),
1675 'dropdown-header' + item.optgroupClass,
1676 item.optID
1677 );
1678
1679 break;
1680 }
1681
1682 item.element = liElement;
1683 mainElements.push(liElement);
1684
1685 // count the number of characters in the option - not perfect, but should work in most cases
1686 if (item.display) combinedLength += item.display.length;
1687 if (item.subtext) combinedLength += item.subtext.length;
1688 // if there is an icon, ensure this option's width is checked
1689 if (item.icon) combinedLength += 1;
1690
1691 if (combinedLength > widestOptionLength) {
1692 widestOptionLength = combinedLength;
1693
1694 // guess which option is the widest
1695 // use this when calculating menu width
1696 // not perfect, but it's fast, and the width will be updating accordingly when scrolling
1697 that.selectpicker.view.widestOption = mainElements[mainElements.length - 1];
1698 }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected