Commit 25349a1f authored by Wikiki's avatar Wikiki

fix: #20 Deleted tags result in leading commas

parent f37dbb3e
......@@ -135,7 +135,8 @@ class Tagify {
this.select(selectedTag.previousSibling.querySelector('.tag'));
}
this.container.removeChild(selectedTag);
delete this.tags[this.tags.indexOf(selectedTag.getAttribute('data-tag'))];
this.tags.splice(this.tags.indexOf(selectedTag.getAttribute('data-tag')), 1);
console.log(this.tags);
this.setInputWidth();
this.save();
} else if (key === KEY_BACKSPACE) {
......@@ -146,7 +147,8 @@ class Tagify {
this.select(selectedTag.nextSibling.querySelector('.tag'));
}
this.container.removeChild(selectedTag);
delete this.tags[this.tags.indexOf(selectedTag.getAttribute('data-tag'))];
this.tags.splice(this.tags.indexOf(selectedTag.getAttribute('data-tag')), 1);
console.log(this.tags);
this.setInputWidth();
this.save();
} else if (last && atStart) {
......@@ -233,7 +235,9 @@ class Tagify {
tag = tag.toUpperCase();
}
if (this.element.getAttribute('duplicates') == 'true' || this.options['duplicates'] || this.tags.indexOf(tag) === -1) {
console.log(this.tags);
this.tags.push(tag);
console.log(this.tags);
let newTagWrapper = document.createElement('div');
newTagWrapper.className = 'control';
......@@ -268,7 +272,8 @@ class Tagify {
if (selectedTag) {
this.select(selectedTag.previousSibling);
this.container.removeChild(selectedTag);
delete this.tags[this.tags.indexOf(selectedTag.getAttribute('data-tag'))];
this.tags.splice(this.tags.indexOf(selectedTag.getAttribute('data-tag')), 1);
console.log(this.tags);
this.setInputWidth();
this.save();
}
......@@ -294,7 +299,8 @@ class Tagify {
setValue(value) {
(Array.prototype.slice.call(this.container.querySelectorAll('.tag'))).forEach((tag) => {
delete this.tags[this.tags.indexOf(tag.innerHTML)];
this.tags.splice(this.tags.indexOf(tag.innerHTML), 1);
console.log(this.tags);
this.container.removeChild(tag);
});
this.savePartial(value);
......
This diff is collapsed.
......@@ -18,7 +18,6 @@ var postcss = require('gulp-postcss');
var rollup = require('gulp-better-rollup');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var spawn = require('child_process').spawn;
var minify = require('gulp-babel-minify');
......@@ -49,17 +48,19 @@ var distJsFile = package.name + '.min.js';
// Uses Sass compiler to process styles, adds vendor prefixes, minifies, then
// outputs file to the appropriate location.
gulp.task('build:styles', ['build:styles:copy'], function() {
return gulp.src([paths.bulma + bulmaSassFile, paths.src + mainSassFile])
.pipe(concat(globalSassFile))
.pipe(sass({
style: 'compressed',
includePaths: [paths.bulma]
}))
.pipe(concat(distCssFile))
.pipe(postcss([autoprefixer({browsers: ['last 2 versions']})]))
.pipe(cleancss())
.pipe(gulp.dest(paths.dest));
gulp.task('build:styles', function() {
runSequence('build:styles:copy',function() {
return gulp.src([paths.bulma + bulmaSassFile, paths.src + mainSassFile])
.pipe(concat(globalSassFile))
.pipe(sass({
style: 'compressed',
includePaths: [paths.bulma]
}))
.pipe(postcss([autoprefixer({browsers: ['last 2 versions']})]))
.pipe(cleancss())
.pipe(concat(distCssFile))
.pipe(gulp.dest(paths.dest));
});
});
// Copy original sass file to dist
......@@ -69,12 +70,11 @@ var distJsFile = package.name + '.min.js';
.pipe(gulp.dest(paths.dest));
});
gulp.task('clean:styles', function(callback) {
gulp.task('clean:styles', function() {
del([
paths.dest + mainSassFile,
paths.dest + distCssFile
]);
callback();
});
/**
......@@ -87,51 +87,47 @@ gulp.task('clean:styles', function(callback) {
// appropriate location.
gulp.task('build:scripts', function() {
return gulp
.src([paths.src + paths.jsPattern])
.pipe(sourcemaps.init({
loadMaps: true
}))
.src([paths.src + mainJsFile])
.pipe(rollup({
plugins: [babel({
babelrc: false,
sourceMaps: true,
sourceMaps: false,
exclude: 'node_modules/**',
presets: [
["@babel/preset-env", {
"modules": false,
"targets": {
"browsers": gutil.env.babelTarget ? gutil.env.babelTarget : ["last 2 versions"]
"browsers": gutil.env.babelTarget ? gutil.env.babelTarget : ['last 2 versions']
}
}]
]
})]
}, {
format: gutil.env.jsFormat ? gutil.env.jsFormat : 'umd',
format: 'umd',
name: camelCase(package.name)
}
))
).on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString())
}))
.pipe(concat(globalJsFile))
.pipe(gulp.dest(paths.dest))
.pipe(concat(distJsFile))
.pipe(minify().on('error', function(err) {
gutil.log(gutil.colors.red('[Error]'), err.toString())
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.dest));
});
gulp.task('clean:scripts', function(callback) {
gulp.task('clean:scripts', function() {
del([
paths.dest + mainJsFile,
paths.dest + distJsFile
]);
callback();
});
// Deletes the entire dist directory.
gulp.task('clean', ['clean:scripts', 'clean:styles'], function(callback) {
gulp.task('clean', function() {
del(paths.dest);
callback();
});
/**
......
......@@ -129,7 +129,7 @@ export default class Tagify {
this.select(selectedTag.previousSibling.querySelector('.tag'));
}
this.container.removeChild(selectedTag);
delete this.tags[this.tags.indexOf(selectedTag.getAttribute('data-tag'))];
this.tags.splice(this.tags.indexOf(selectedTag.getAttribute('data-tag')), 1);
this.setInputWidth();
this.save();
} else if (key === KEY_BACKSPACE) {
......@@ -140,7 +140,7 @@ export default class Tagify {
this.select(selectedTag.nextSibling.querySelector('.tag'));
}
this.container.removeChild(selectedTag);
delete this.tags[this.tags.indexOf(selectedTag.getAttribute('data-tag'))];
this.tags.splice(this.tags.indexOf(selectedTag.getAttribute('data-tag')), 1);
this.setInputWidth();
this.save();
} else if (last && atStart) {
......@@ -262,7 +262,7 @@ export default class Tagify {
if (selectedTag) {
this.select(selectedTag.previousSibling);
this.container.removeChild(selectedTag);
delete this.tags[this.tags.indexOf(selectedTag.getAttribute('data-tag'))];
this.tags.splice(this.tags.indexOf(selectedTag.getAttribute('data-tag')), 1);
this.setInputWidth();
this.save();
}
......@@ -288,7 +288,7 @@ export default class Tagify {
setValue(value) {
(Array.prototype.slice.call(this.container.querySelectorAll('.tag'))).forEach((tag) => {
delete this.tags[this.tags.indexOf(tag.innerHTML)];
this.tags.splice(this.tags.indexOf(tag.innerHTML), 1);
this.container.removeChild(tag);
});
this.savePartial(value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment