From 22ca916daf2f34bc2958f8da0e0c95d82e479812 Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Wed, 25 Aug 2021 20:02:05 -0400 Subject: [PATCH] I dont know --- composer.json | 6 +++--- js/dom.js | 27 +++++++++++++++++++++++++++ js/main.js | 25 +++++++++++-------------- js/tag_input.js | 32 ++++++++++++-------------------- theme/bulma/main.php | 15 +-------------- 5 files changed, 54 insertions(+), 51 deletions(-) create mode 100644 js/dom.js diff --git a/composer.json b/composer.json index 961e059..8daf308 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,11 @@ } ], "require": { - "scrivo/highlight.php": "v9.18.1.7", "ext-pdo": "*", "ext-openssl": "*", - "erusev/parsedown": "^1.7", "ext-gd": "*", - "ext-mbstring": "*" + "ext-mbstring": "*", + "scrivo/highlight.php": "v9.18.1.7", + "erusev/parsedown": "^1.7" } } diff --git a/js/dom.js b/js/dom.js new file mode 100644 index 0000000..8107a30 --- /dev/null +++ b/js/dom.js @@ -0,0 +1,27 @@ +const $ = function(selector) { + return document.querySelector(selector); +}; + +const $$ = function(selector) { + return document.querySelectorAll(selector) || []; +}; + +const makeEl = function(html) { + const template = document.createElement('template'); + + template.innerHTML = html.trim(); + + return template.content.firstChild; +}; + +const escape = function(unsafe) { + return unsafe + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + + +export { $, $$, makeEl, escape }; \ No newline at end of file diff --git a/js/main.js b/js/main.js index aa4202e..6553f91 100644 --- a/js/main.js +++ b/js/main.js @@ -1,17 +1,14 @@ -import { TagsInput } from './tag_input'; +import { $$ } from './dom'; +import { TagsInput } from "./tag_input"; -class Meme { - constructor() { - alert('xss'); - } +const setupSite = function() { + Array.prototype.forEach.call($$('.js-tag-input'), (el) => { + new TagsInput(el).attach(); + }); +}; - meme() { - console.log('meme'); - } +if (document.readyState !== 'loading') { + setupSite(); +} else { + document.addEventListener('DOMContentLoaded', setupSite); } - -const meme = new Meme(); - -meme.meme(); - -new TagsInput(null); \ No newline at end of file diff --git a/js/tag_input.js b/js/tag_input.js index 364851b..1aeca0e 100644 --- a/js/tag_input.js +++ b/js/tag_input.js @@ -1,19 +1,4 @@ -function htmlToElement(html) { - const template = document.createElement('template'); - - template.innerHTML = html.trim(); - - return template.content.firstChild; -} - -function escapeHtml(unsafe) { - return unsafe - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); -} +import { makeEl, escape } from "./dom"; class TagsInput { constructor(element, options = {}) { @@ -29,12 +14,19 @@ class TagsInput { attach() { this.element.style.display = 'none'; - this.containerNode = htmlToElement('
'); - this.inputNode = htmlToElement(''); + this.containerNode = makeEl('
'); + this.inputNode = makeEl(''); this.containerNode.appendChild(this.inputNode); this.element.parentNode.insertBefore(this.containerNode, this.element.nextSibling); + /* Load existing tags from input */ + if (this.element.value) { + for (const tag of this.element.value.split(',')) { + this.addTag(tag); + } + } + /* Handle addition and removal of tags via key-presses */ this.containerNode.addEventListener('keydown', this._handleInputKeyUp.bind(this)); @@ -70,7 +62,7 @@ class TagsInput { this.tags.push(tagValue.toLowerCase()); this.inputNode.parentNode.insertBefore( - htmlToElement('' + escapeHtml(tagValue) + ''), + makeEl('' + escape(tagValue) + ''), this.inputNode ); @@ -109,4 +101,4 @@ class TagsInput { } } -export { TagsInput }; \ No newline at end of file +export { TagsInput }; diff --git a/theme/bulma/main.php b/theme/bulma/main.php index 5d860d4..78645a6 100644 --- a/theme/bulma/main.php +++ b/theme/bulma/main.php @@ -1,16 +1,4 @@ - -
@@ -202,7 +190,7 @@
- ">
@@ -213,7 +201,6 @@
-