Skip to content

Commit

Permalink
commit updated build
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtobando committed Mar 18, 2021
1 parent 82b0f0e commit 5ff4a8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
5 changes: 1 addition & 4 deletions build/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
box-sizing: border-box;
margin: 1em;
padding: 0em 0.5em;
display: -webkit-box;
display: flex;
flex-wrap: wrap;
font-size: 14px;
Expand All @@ -12,7 +11,6 @@
list-style: none;
padding: 0;
margin: 0;
display: -webkit-box;
display: flex;
flex-wrap: wrap; }
.simple-tags ul li {
Expand All @@ -28,8 +26,7 @@
.simple-tags input {
padding: 0.9em 0.5em;
box-sizing: border-box;
-webkit-box-flex: 1;
flex-grow: 1;
flex-grow: 1;
border: none;
outline: none;
font-size: inherit;
Expand Down
2 changes: 1 addition & 1 deletion build/js/script-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 21 additions & 24 deletions build/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ function Tags(element) {
var arrayOfList;

function DOMCreate() {
var ul = document.createElement('ul');
var li = document.createElement('li');
var input = document.createElement('input');
var ul = document.createElement("ul");
var input = document.createElement("input");
DOMParent.appendChild(ul);
DOMParent.appendChild(input); // first child is <ul>

Expand All @@ -18,37 +17,33 @@ function Tags(element) {
}

function DOMRender() {
// clear the entire <li> inside <ul>
DOMList.innerHTML = ''; // render each <li> to <ul>
// clear the entire <li> inside <ul>
DOMList.innerHTML = ""; // render each <li> to <ul>

arrayOfList.forEach(function (currentValue, index) {
var li = document.createElement('li');
var li = document.createElement("li");
li.innerHTML = "".concat(currentValue, " <a>&times;</a>");
li.querySelector('a').addEventListener('click', function () {
if (confirm('Continue to remove tag?')) {
onDelete(index);
}

return false;
li.querySelector("a").addEventListener("click", function () {
onDelete(index);
});
DOMList.appendChild(li);
setAttribute();
});
setAttribute();
}

function onKeyUp() {
DOMInput.addEventListener('keyup', function (event) {
DOMInput.addEventListener("keyup", function (event) {
var text = this.value.trim(); // check if ',' or 'enter' key was press

if (text.includes(',') || event.keyCode == 13) {
if (text.includes(",") || event.keyCode === 13) {
// check if empty text when ',' is remove
if (text.replace(',', '') != '') {
if (text.replace(",", "") !== "") {
// push to array and remove ','
arrayOfList.push(text.replace(',', ''));
arrayOfList.push(text.replace(",", ""));
} // clear input


this.value = '';
this.value = "";
}

DOMRender();
Expand All @@ -57,7 +52,7 @@ function Tags(element) {

function onDelete(id) {
arrayOfList = arrayOfList.filter(function (currentValue, index) {
if (index == id) {
if (index === id) {
return false;
}

Expand All @@ -67,16 +62,16 @@ function Tags(element) {
}

function getAttribute() {
dataAttribute = DOMParent.getAttribute('data-simple-tags');
dataAttribute = dataAttribute.split(','); // store array of data attribute in arrayOfList
dataAttribute = DOMParent.getAttribute("data-simple-tags");
dataAttribute = dataAttribute.split(","); // store array of data attribute in arrayOfList

arrayOfList = dataAttribute.map(function (currentValue) {
return currentValue.trim();
});
}

function setAttribute() {
DOMParent.setAttribute('data-simple-tags', arrayOfList.toString());
DOMParent.setAttribute("data-simple-tags", arrayOfList.toString());
}

getAttribute();
Expand All @@ -86,10 +81,12 @@ function Tags(element) {
} // run immediately


;

(function () {
var DOMSimpleTags = document.querySelectorAll('.simple-tags');
var DOMSimpleTags = document.querySelectorAll(".simple-tags");
DOMSimpleTags = Array.from(DOMSimpleTags);
DOMSimpleTags.forEach(function (currentValue, index) {
DOMSimpleTags.forEach(function (currentValue) {
// create Tags
new Tags(currentValue);
});
Expand Down

0 comments on commit 5ff4a8d

Please sign in to comment.