- element.classList.add('selectFade');
- element.style.backgroundColor = initColor;
- }, 10);
- setTimeout(() => {
- element.classList.remove('selectFade');
- element.style.backgroundColor = '';
- }, 3000);
-}
\ No newline at end of file
+ element.style.transition = 'outline linear 3s';
+ element.style.outline = '2px dashed rgba(0, 0, 0, 0)';
+ const listener = () => {
+ element.removeEventListener('transitionend', listener);
+ element.style.transition = null;
+ element.style.outline = null;
+ element.style.outlineOffset = null;
+ };
+ element.addEventListener('transitionend', listener);
+ }, 1000);
+}
+
+/**
+ * Escape any HTML in the given 'unsafe' string.
+ * Take from https://stackoverflow.com/a/6234804.
+ * @param {String} unsafe
+ * @returns {string}
+ */
+export function escapeHtml(unsafe) {
+ return unsafe
+ .replace(/&/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''');
+}
+
+/**
+ * Generate a random unique ID.
+ *
+ * @returns {string}
+ */
+export function uniqueId() {
+ // eslint-disable-next-line no-bitwise
+ const S4 = () => (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
+ return (`${S4() + S4()}-${S4()}-${S4()}-${S4()}-${S4()}${S4()}${S4()}`);
+}
+
+/**
+ * Create a promise that resolves after the given time.
+ * @param {int} timeMs
+ * @returns {Promise}
+ */
+export function wait(timeMs) {
+ return new Promise(res => {
+ setTimeout(res, timeMs);
+ });
+}