Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
update: bootstrap 4.5.3, feature: add tag on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwin Heldy G committed Nov 3, 2020
1 parent ce866b9 commit 46e3f70
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dist/css/tagin.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://unpkg.com/[email protected].0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected].3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/tagin.min.css">
<title>Tagin</title>
</head>
Expand Down
31 changes: 19 additions & 12 deletions dist/js/tagin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,11 @@ function tagin(el, option = {}) {

// Adding tag
input.addEventListener('input', () => {
const value = transform(input.value.replace(new RegExp(escapeRegex(separator), 'g'), '').trim())
if (value === '') { input.value = '' }
if (input.value.includes(separator)) {
if (getTags().includes(value) && duplicate === 'false') {
alertExist(value)
} else {
input.insertAdjacentHTML('beforebegin', templateTag(value))
updateValue()
}
input.value = ''
input.removeAttribute('style')
}
addTag()
autowidth()
})
input.addEventListener('blur', () => {
addTag(true)
autowidth()
})
autowidth()
Expand All @@ -84,6 +77,20 @@ function tagin(el, option = {}) {
input.style.setProperty('width', Math.ceil(window.getComputedStyle(fakeEl).width.replace('px', '')) + 1 + 'px')
fakeEl.remove()
}
function addTag(force = false) {
const value = transform(input.value.replace(new RegExp(escapeRegex(separator), 'g'), '').trim())
if (value === '') { input.value = '' }
if (input.value.includes(separator) || (force && input.value != '')) {
if (getTags().includes(value) && duplicate === 'false') {
alertExist(value)
} else {
input.insertAdjacentHTML('beforebegin', templateTag(value))
updateValue()
}
input.value = ''
input.removeAttribute('style')
}
}
function alertExist(value) {
for (const el of wrapper.getElementsByClassName(classTag)) {
if (el.textContent === value) {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tagin.min.js

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

31 changes: 19 additions & 12 deletions js/tagin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,11 @@ function tagin(el, option = {}) {

// Adding tag
input.addEventListener('input', () => {
const value = transform(input.value.replace(new RegExp(escapeRegex(separator), 'g'), '').trim())
if (value === '') { input.value = '' }
if (input.value.includes(separator)) {
if (getTags().includes(value) && duplicate === 'false') {
alertExist(value)
} else {
input.insertAdjacentHTML('beforebegin', templateTag(value))
updateValue()
}
input.value = ''
input.removeAttribute('style')
}
addTag()
autowidth()
})
input.addEventListener('blur', () => {
addTag(true)
autowidth()
})
autowidth()
Expand All @@ -84,6 +77,20 @@ function tagin(el, option = {}) {
input.style.setProperty('width', Math.ceil(window.getComputedStyle(fakeEl).width.replace('px', '')) + 1 + 'px')
fakeEl.remove()
}
function addTag(force = false) {
const value = transform(input.value.replace(new RegExp(escapeRegex(separator), 'g'), '').trim())
if (value === '') { input.value = '' }
if (input.value.includes(separator) || (force && input.value != '')) {
if (getTags().includes(value) && duplicate === 'false') {
alertExist(value)
} else {
input.insertAdjacentHTML('beforebegin', templateTag(value))
updateValue()
}
input.value = ''
input.removeAttribute('style')
}
}
function alertExist(value) {
for (const el of wrapper.getElementsByClassName(classTag)) {
if (el.textContent === value) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "tagin",
"version": "1.1.0",
"version": "1.2.0",
"main": "index.js",
"repository": "https://github.com/erwinheldy/tagin.git",
"author": "Erwin Heldy G <[email protected]>",
"license": "MIT",
"dependencies": {
"bootstrap": "4.5.2"
"bootstrap": "4.5.3"
},
"devDependencies": {
"gulp": "4.0.2",
"gulp-autoprefixer": "7.0.1",
"gulp-clean-css": "4.3.0",
"gulp-rename": "2.0.0",
"gulp-sass": "4.1.0",
"gulp-terser": "1.4.0"
"gulp-terser": "1.4.1"
}
}

0 comments on commit 46e3f70

Please sign in to comment.