Skip to content

Commit

Permalink
name createElementFromAttrs
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jun 26, 2024
1 parent d957c1c commit 7150181
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions web_src/js/features/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {clippie} from 'clippie';
import {showTemporaryTooltip} from '../modules/tippy.js';
import {GET, POST} from '../modules/fetch.js';
import {showErrorToast} from '../modules/toast.js';
import {createElementFromHTML, createElement, elemGetAttributeNumber} from '../utils/dom.js';
import {createElementFromHTML, createElementFromAttrs, elemGetAttributeNumber} from '../utils/dom.js';

const {csrfToken, i18n} = window.config;

Expand Down Expand Up @@ -69,7 +69,7 @@ export async function initDropzone(dropzoneEl) {
dzInst.on('success', (file, data) => {
file.uuid = data.uuid;
fileUuidDict[file.uuid] = {submitted: false};
const input = createElement('input', {name: 'files', type: 'hidden', id: `dropzone-file-${data.uuid}`, value: data.uuid});
const input = createElementFromAttrs('input', {name: 'files', type: 'hidden', id: `dropzone-file-${data.uuid}`, value: data.uuid});
dropzoneEl.querySelector('.files').append(input);
addCopyLink(file);
});
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function initDropzone(dropzoneEl) {
dzInst.emit('complete', attachment);
addCopyLink(attachment);
fileUuidDict[attachment.uuid] = {submitted: true};
const input = createElement('input', {name: 'files', type: 'hidden', id: `dropzone-file-${attachment.uuid}`, value: attachment.uuid});
const input = createElementFromAttrs('input', {name: 'files', type: 'hidden', id: `dropzone-file-${attachment.uuid}`, value: attachment.uuid});
dropzoneEl.querySelector('.files').append(input);
}
if (!dropzoneEl.querySelector('.dz-preview')) {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export function createElementFromHTML(htmlString) {
return div.firstChild;
}

export function createElement(tagName, attrs) {
export function createElementFromAttrs(tagName, attrs) {
const el = document.createElement(tagName);
for (const [key, value] of Object.entries(attrs)) {
if (value === undefined || value === null) continue;
Expand Down
6 changes: 3 additions & 3 deletions web_src/js/utils/dom.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {createElement, createElementFromHTML, elemGetAttributeNumber} from './dom.js';
import {createElementFromAttrs, createElementFromHTML, elemGetAttributeNumber} from './dom.js';

test('createElementFromHTML', () => {
expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>');
});

test('createElement', () => {
const el = createElement('button', {
test('createElementFromAttrs', () => {
const el = createElementFromAttrs('button', {
id: 'the-id',
class: 'cls-1 cls-2',
'data-foo': 'the-data',
Expand Down

0 comments on commit 7150181

Please sign in to comment.