| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * |
| 22 | 23 | * @param {?string} icon |
| 23 | 24 | * @param {?boolean} showLabel |
| 24 | 25 | * @param {string} label |
| 26 | + * @param {?string} title Tooltip |
| 25 | 27 | * @param {object} value |
| 28 | + * @param {boolean} isHidden QR is Invisible (auto-execute only) |
| 26 | 29 | * @param {function} callback |
| 27 | 30 | * @param {MenuItem[]} children |
| 28 | 31 | */ |
| 29 | 32 | constructor(icon, showLabel, label, title, value, isHidden, callback, children = []) { |
| 30 | 33 | this.icon = icon; |
| 31 | 34 | this.showLabel = showLabel; |
| 32 | 35 | this.label = label; |
| 36 | + this.title = title; |
| 33 | 37 | this.value = value; |
| 38 | + this.isHidden = isHidden; |
| 34 | 39 | this.callback = callback; |
| 35 | 40 | this.childList = children; |
| 36 | 41 | } |
| 37 | 42 | |
| 38 | 43 | |
| 44 | + /** |
| 45 | + * Renders the MenuItem |
| 46 | + * |
| 47 | + * A .qr--hidden class is added to: |
| 48 | + * - the item if it is "Invisible (auto-execute only)" |
| 49 | + * - the icon if no icon is set |
| 50 | + * - the label if an icon is set and showLabel is false |
| 51 | + * |
| 52 | + * There is no .qr--hidden class defined in default CSS, since having items |
| 53 | + * that are invisible on the QR bar but visible in the context menu, |
| 54 | + * or icon-only on the QR bar but labelled in the context menu, is a valid use case. |
| 55 | + * |
| 56 | + * To hide optional labels when icons are present, add this user CSS: |
| 57 | + * .ctx-menu .ctx-item .qr--button-label.qr--hidden {display: none;} |
| 58 | + * To hide icons when no icon is present (removes unwanted padding): |
| 59 | + * .ctx-menu .ctx-item .qr--button-icon.qr--hidden {display: none;} |
| 60 | + * To hide items that are set "invisible": |
| 61 | + * .ctx-menu .ctx-item.qr--hidden {display: none;} |
| 62 | + * To target submenus only, use .ctx-menu .ctx-sub-menu .qr--hidden {display: none;} |
| 63 | + * |
| 64 | + * @returns {HTMLElement} |
| 65 | + */ |
| 39 | 66 | render() { |
| 40 | 67 | if (!this.root) { |
| 41 | 68 | const item = document.createElement('li'); { |
| 42 | 69 | this.root = item; |
| 43 | 70 | item.classList.add('list-group-item'); |
| 44 | 71 | item.classList.add('ctx-item'); |
| 45 | | - item.title = this.value; |
| 72 | + |
| 73 | + // if this item is Invisible, add the hidden class |
| 74 | + if (this.isHidden) item.classList.add('qr--hidden'); |
| 75 | + |
| 76 | + // if a title/tooltip is set, add it, otherwise use the QR content |
| 77 | + // same as for the main QR list |
| 78 | + item.title = this.title || this.value; |
| 79 | + |
| 46 | 80 | if (this.callback) { |
| 47 | 81 | item.addEventListener('click', (evt) => this.callback(evt, this)); |
| 48 | 82 | } |
| 49 | 83 | const icon = document.createElement('div'); { |
| 50 | | - this.domIcon = icon; |
| 51 | 84 | icon.classList.add('qr--button-icon'); |
| 52 | 85 | icon.classList.add('fa-solid'); |
| 53 | 86 | if (!this.icon) icon.classList.add('qr--hidden'); |