Skip to content

Commit dffa9c3

Browse files
committed
rename generateUniqueId to generateElemId because it isn't really unique
1 parent 60cbc3d commit dffa9c3

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

web_src/js/components/DiffCommitSelector.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {defineComponent} from 'vue';
33
import {SvgIcon} from '../svg.ts';
44
import {GET} from '../modules/fetch.ts';
5-
import {generateUniqueId} from '../utils/dom.ts';
5+
import {generateElemId} from '../utils/dom.ts';
66
77
type Commit = {
88
id: string,
@@ -35,8 +35,8 @@ export default defineComponent({
3535
commits: [] as Array<Commit>,
3636
hoverActivated: false,
3737
lastReviewCommitSha: '',
38-
uniqueIdMenu: generateUniqueId('diff-commit-selector-menu-'),
39-
uniqueIdShowAll: generateUniqueId('diff-commit-selector-show-all-'),
38+
uniqueIdMenu: generateElemId('diff-commit-selector-menu-'),
39+
uniqueIdShowAll: generateElemId('diff-commit-selector-show-all-'),
4040
};
4141
},
4242
computed: {

web_src/js/features/comp/ComboMarkdownEditor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '@github/markdown-toolbar-element';
22
import '@github/text-expander-element';
33
import {attachTribute} from '../tribute.ts';
4-
import {hideElem, showElem, autosize, isElemVisible, generateUniqueId} from '../../utils/dom.ts';
4+
import {hideElem, showElem, autosize, isElemVisible, generateElemId} from '../../utils/dom.ts';
55
import {
66
EventUploadStateChanged,
77
initEasyMDEPaste,
@@ -123,7 +123,7 @@ export class ComboMarkdownEditor {
123123
setupTextarea() {
124124
this.textarea = this.container.querySelector('.markdown-text-editor');
125125
this.textarea._giteaComboMarkdownEditor = this;
126-
this.textarea.id = generateUniqueId(`_combo_markdown_editor_`);
126+
this.textarea.id = generateElemId(`_combo_markdown_editor_`);
127127
this.textarea.addEventListener('input', () => triggerEditorContentChanged(this.container));
128128
this.applyEditorHeights(this.textarea, this.options.editorHeights);
129129

@@ -211,7 +211,7 @@ export class ComboMarkdownEditor {
211211

212212
// Fomantic Tab requires the "data-tab" to be globally unique.
213213
// So here it uses our defined "data-tab-for" and "data-tab-panel" to generate the "data-tab" attribute for Fomantic.
214-
const uniqueIdSuffix = generateUniqueId();
214+
const uniqueIdSuffix = generateElemId();
215215
this.tabEditor = Array.from(tabs).find((tab) => tab.getAttribute('data-tab-for') === 'markdown-writer');
216216
this.tabPreviewer = Array.from(tabs).find((tab) => tab.getAttribute('data-tab-for') === 'markdown-previewer');
217217
this.tabEditor.setAttribute('data-tab', `markdown-writer-${uniqueIdSuffix}`);

web_src/js/modules/fomantic/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import $ from 'jquery';
2-
import {generateUniqueId} from '../../utils/dom.ts';
2+
import {generateElemId} from '../../utils/dom.ts';
33

44
export function linkLabelAndInput(label: Element, input: Element) {
55
const labelFor = label.getAttribute('for');
@@ -8,7 +8,7 @@ export function linkLabelAndInput(label: Element, input: Element) {
88
if (inputId && !labelFor) { // missing "for"
99
label.setAttribute('for', inputId);
1010
} else if (!inputId && !labelFor) { // missing both "id" and "for"
11-
const id = generateUniqueId('_aria_label_input_');
11+
const id = generateElemId('_aria_label_input_');
1212
input.setAttribute('id', id);
1313
label.setAttribute('for', id);
1414
}

web_src/js/modules/fomantic/dropdown.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22
import type {FomanticInitFunction} from '../../types.ts';
3-
import {generateUniqueId, queryElems} from '../../utils/dom.ts';
3+
import {generateElemId, queryElems} from '../../utils/dom.ts';
44

55
const ariaPatchKey = '_giteaAriaPatchDropdown';
66
const fomanticDropdownFn = $.fn.dropdown;
@@ -46,7 +46,7 @@ function ariaDropdownFn(this: any, ...args: Parameters<FomanticInitFunction>) {
4646
// make the item has role=option/menuitem, add an id if there wasn't one yet, make items as non-focusable
4747
// the elements inside the dropdown menu item should not be focusable, the focus should always be on the dropdown primary element.
4848
function updateMenuItem(dropdown: HTMLElement, item: HTMLElement) {
49-
if (!item.id) item.id = generateUniqueId('_aria_dropdown_item_');
49+
if (!item.id) item.id = generateElemId('_aria_dropdown_item_');
5050
item.setAttribute('role', (dropdown as any)[ariaPatchKey].listItemRole);
5151
item.setAttribute('tabindex', '-1');
5252
for (const el of item.querySelectorAll('a, input, button')) el.setAttribute('tabindex', '-1');
@@ -58,7 +58,7 @@ function updateMenuItem(dropdown: HTMLElement, item: HTMLElement) {
5858
function updateSelectionLabel(label: HTMLElement) {
5959
// the "label" is like this: "<a|div class="ui label" data-value="1">the-label-name <i|svg class="delete icon"/></a>"
6060
if (!label.id) {
61-
label.id = generateUniqueId('_aria_dropdown_label_');
61+
label.id = generateElemId('_aria_dropdown_label_');
6262
}
6363
label.tabIndex = -1;
6464

@@ -126,7 +126,7 @@ function delegateDropdownModule($dropdown: any) {
126126
function attachStaticElements(dropdown: HTMLElement, focusable: HTMLElement, menu: HTMLElement) {
127127
// prepare static dropdown menu list popup
128128
if (!menu.id) {
129-
menu.id = generateUniqueId('_aria_dropdown_menu_');
129+
menu.id = generateElemId('_aria_dropdown_menu_');
130130
}
131131

132132
$(menu).find('> .item').each((_, item) => updateMenuItem(dropdown, item));

web_src/js/utils/dom.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export function isPlainClick(e: MouseEvent) {
373373
return e.button === 0 && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
374374
}
375375

376-
let uniqueIdCounter = 0;
377-
export function generateUniqueId(prefix: string = ''): string {
378-
return `${prefix}${uniqueIdCounter++}`;
376+
let elemIdCounter = 0;
377+
export function generateElemId(prefix: string = ''): string {
378+
return `${prefix}${elemIdCounter++}`;
379379
}

0 commit comments

Comments
 (0)