Commit 49aa552e authored by Wikiki's avatar Wikiki

Merge branch 'master' into develop

# Conflicts:
#	CHANGELOG.md
#	bower.json
#	package.json
parents e7c92665 488de381
<a name="1.0.8"></a>
## [1.0.8](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.7...1.0.8) (2018-05-12)
### Bug Fixes
* [#20](https://github.com/Wikiki/bulma-tagsinput/issues/20) Deleted tags result in leading commas ([25349a1](https://github.com/Wikiki/bulma-tagsinput/commit/25349a1))
<a name="1.0.7"></a>
## [1.0.7](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.6...1.0.7) (2018-03-29)
<a name="1.0.6"></a>
## [1.0.6](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.1...1.0.6) (2018-02-21)
<a name="1.0.5"></a>
## [1.0.5](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.4...1.0.5) (2018-02-21)
## [1.0.5](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.1...1.0.5) (2018-02-21)
......@@ -9,12 +29,12 @@
<a name="1.0.3"></a>
## [1.0.3](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.1...1.0.3) (2018-02-21)
## [1.0.3](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.2...1.0.3) (2018-02-21)
<a name="1.0.2"></a>
## [1.0.2](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.1...1.0.2) (2018-02-21)
## [1.0.2](https://github.com/Wikiki/bulma-tagsinput/compare/1.0.1...1.0.2) (2018-02-20)
......
......@@ -2,7 +2,7 @@
"name": "bulma-tagsinput",
"description": "Bulma.io extension to add interaction on input tags",
"main": "tagsinput.sass",
"version": "1.0.5",
"version": "1.0.8",
"authors": [
"Wikiki <wikiki@protonmail.com> (https://wikiki.github.io)"
],
......
......@@ -4,36 +4,6 @@
(global.bulmaTagsinput = factory());
}(this, (function () { 'use strict';
if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
const MOUSE_EVENTS = ['click', 'touchstart'];
const KEY_BACKSPACE = 8;
......@@ -45,7 +15,7 @@ const KEY_DELETE = 46;
const KEY_COMMA = 188;
class Tagify {
constructor(element, options = {}) {
constructor(selector, options = {}) {
let defaultOptions = {
disabled: false,
delimiter: ',',
......@@ -54,12 +24,46 @@ class Tagify {
uppercase: false,
duplicates: true
};
this.element = element;
this.element = typeof selector === 'string'
? document.querySelector(selector)
: selector;
// An invalid selector or non-DOM node has been provided.
if (!this.element) {
throw new Error('An invalid selector or non-DOM node has been provided.');
}
this.options = Object.assign({}, defaultOptions, options);
if (this.element.dataset.hasOwnProperty('lowercase')) {
this.options.lowercase = this.element.dataset('lowercase');
}
if (this.element.dataset.hasOwnProperty('uppercase')) {
this.options.lowercase = this.element.dataset('uppercase');
}
if (this.element.dataset.hasOwnProperty('duplicates')) {
this.options.lowercase = this.element.dataset('duplicates');
}
this.init();
}
/**
* Initiate all DOM element containing tagsinput class
* @method
* @return {Array} Array of all TagsInput instances
*/
static attach(selector = 'input[type="tags"]') {
let tagsinputlInstances = new Array();
const tagsinputs = document.querySelectorAll(selector);
[].forEach.call(tagsinputs, tagsinput => {
setTimeout(() => {
tagsinputlInstances.push(new Tagify(tagsinput));
}, 100);
});
return tagsinputlInstances;
}
init() {
if (!this.options.disabled) {
this.tags = [];
......@@ -135,7 +139,7 @@ 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) {
......@@ -146,7 +150,7 @@ 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) {
......@@ -226,13 +230,13 @@ class Tagify {
return false;
}
if (this.element.getAttribute('lowercase') || this.options['lowercase'] == 'true') {
if (this.options['lowercase'] == 'true') {
tag = tag.toLowerCase();
}
if (this.element.getAttribute('uppercase') || this.options['uppercase'] == 'true') {
if (this.options['uppercase'] == 'true') {
tag = tag.toUpperCase();
}
if (this.element.getAttribute('duplicates') == 'true' || this.options['duplicates'] || this.tags.indexOf(tag) === -1) {
if (this.options['duplicates'] || this.tags.indexOf(tag) === -1) {
this.tags.push(tag);
let newTagWrapper = document.createElement('div');
......@@ -268,7 +272,7 @@ 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();
}
......@@ -294,7 +298,7 @@ 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);
......@@ -357,13 +361,6 @@ class Tagify {
}
}
document.addEventListener( 'DOMContentLoaded', function () {
let tagInputs = document.querySelectorAll('input[type="tags"]');
[].forEach.call(tagInputs, function(tagInput) {
new Tagify(tagInput);
});
});
return Tagify;
})));
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();
});
/**
......
{
"name": "bulma-tagsinput",
"version": "1.0.5",
"version": "1.0.8",
"description": "Bulma.io extension to add interaction on input tags",
"main": "dist/bulma-tagsinput.sass",
"scripts": {
......
if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
const MOUSE_EVENTS = ['click', 'touchstart'];
const KEY_BACKSPACE = 8,
......@@ -39,7 +9,7 @@ const KEY_BACKSPACE = 8,
KEY_COMMA = 188;
export default class Tagify {
constructor(element, options = {}) {
constructor(selector, options = {}) {
let defaultOptions = {
disabled: false,
delimiter: ',',
......@@ -48,12 +18,46 @@ export default class Tagify {
uppercase: false,
duplicates: true
}
this.element = element;
this.element = typeof selector === 'string'
? document.querySelector(selector)
: selector;
// An invalid selector or non-DOM node has been provided.
if (!this.element) {
throw new Error('An invalid selector or non-DOM node has been provided.');
}
this.options = Object.assign({}, defaultOptions, options);
if (this.element.dataset.hasOwnProperty('lowercase')) {
this.options.lowercase = this.element.dataset('lowercase')
}
if (this.element.dataset.hasOwnProperty('uppercase')) {
this.options.lowercase = this.element.dataset('uppercase')
}
if (this.element.dataset.hasOwnProperty('duplicates')) {
this.options.lowercase = this.element.dataset('duplicates')
}
this.init();
}
/**
* Initiate all DOM element containing tagsinput class
* @method
* @return {Array} Array of all TagsInput instances
*/
static attach(selector = 'input[type="tags"]') {
let tagsinputlInstances = new Array();
const tagsinputs = document.querySelectorAll(selector);
[].forEach.call(tagsinputs, tagsinput => {
setTimeout(() => {
tagsinputlInstances.push(new Tagify(tagsinput));
}, 100);
});
return tagsinputlInstances;
}
init() {
if (!this.options.disabled) {
this.tags = [];
......@@ -129,7 +133,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 +144,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) {
......@@ -220,13 +224,13 @@ export default class Tagify {
return false;
}
if (this.element.getAttribute('lowercase') || this.options['lowercase'] == 'true') {
if (this.options['lowercase'] == 'true') {
tag = tag.toLowerCase();
}
if (this.element.getAttribute('uppercase') || this.options['uppercase'] == 'true') {
if (this.options['uppercase'] == 'true') {
tag = tag.toUpperCase();
}
if (this.element.getAttribute('duplicates') == 'true' || this.options['duplicates'] || this.tags.indexOf(tag) === -1) {
if (this.options['duplicates'] || this.tags.indexOf(tag) === -1) {
this.tags.push(tag);
let newTagWrapper = document.createElement('div');
......@@ -262,7 +266,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 +292,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);
......@@ -350,10 +354,3 @@ export default class Tagify {
this.element = null;
}
}
document.addEventListener( 'DOMContentLoaded', function () {
let tagInputs = document.querySelectorAll('input[type="tags"]');
[].forEach.call(tagInputs, function(tagInput) {
new Tagify(tagInput);
});
});
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