Commit 488de381 authored by Wikiki's avatar Wikiki

Merge branch 'hotfix/AutoInit-Duplicates'

parents e5d69dcc d88971a7
......@@ -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 = [];
......@@ -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');
......@@ -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.
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,14 +18,46 @@ export default class Tagify {
uppercase: false,
duplicates: true
}
this.element = element;
if( element.getAttribute("data-allow-delete") )
defaultOptions.allowDelete = element.getAttribute("data-allow-delete") == 'true';
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 = [];
......@@ -222,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');
......@@ -352,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