Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions documentUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Checks the item is not missed or messed
* @param {object|string[]|Element[]|HTMLElement|string} elem - element
* @returns {boolean} true if element is correct
* @private
*/
function _isNotMissed(elem) {
return (!(elem === undefined || elem === null));
}

/**
* Create DOM element with set parameters
* @param {string} tagName - Html tag of the element to be created
* @param {string[]} cssClasses - Css classes that must be applied to an element
* @param {object} attrs - Attributes that must be applied to the element
* @param {Element[]} children - child elements of creating element
* @returns {HTMLElement} the new element
*/
export function create(tagName, cssClasses = null, attrs = null, children = null) {
const elem = document.createElement(tagName);

if (_isNotMissed(cssClasses)) {
for (let i = 0; i < cssClasses.length; i++) {
if (_isNotMissed(cssClasses[i])) {
elem.classList.add(cssClasses[i]);
}
}
}
if (_isNotMissed(attrs)) {
for (let key in attrs) {
elem.setAttribute(key, attrs[key]);
}
}
if (_isNotMissed(children)) {
for (let i = 0; i < children.length; i++) {
if (_isNotMissed(children[i])) {
elem.appendChild(children[i]);
}
}
}
return elem;
}
1 change: 1 addition & 0 deletions img/deleteColIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/deleteRowIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/indertColAfterIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/insertColBeforeIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/insertRowAfter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/insertRowBeforeIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/mergeCellIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions img/toolboxIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions img/unmergeCellIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading