Skip to content

Commit

Permalink
- Show dropdown on arrow down #333
Browse files Browse the repository at this point in the history
- fixed #267 - Pasted text separated with new line symbol doesn't process correctly
- fixed #356 - addTags not working on mix-mode
  • Loading branch information
yairEO committed Nov 28, 2019
1 parent 52d92e3 commit 6de7300
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 86 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ dropdown:select | Suggestions dropdown item selected (by mouse/keyboard/touch)
Name | Type | Default | Info
----------------------- | ---------- | -------------------------------- | --------------------------------------------------------------------------
placeholder | String | | Placeholder text. If this attribute is set on an input/textarea element it will override this setting
delimiters | String | `,` | [regex] split tags by any of these delimiters. Example: `",|` |."`
delimiters | String | `,` | [regex string] split tags by any of these delimiters. Example: `",|` |."`
pattern | String | null | Validate input by REGEX pattern (can also be applied on the input itself as an attribute) Ex: `/[1-9]/`
mode | String | null | Use `select` for single-value dropdown-like select box. Sse `mix` as value to allow mixed-content. The 'pattern' setting must be set to some character.
mixTagsInterpolator | Array | `['[[', ']]']` | Interpolation for mix mode. Everything between these will become a tag
mixTagsAllowedAfter | Regex | `/,|\.|\:|\s/` | Define conditions in which typed mix-tags content is allowing a tag to be created after.
duplicates | Boolean | false | Should duplicate tags be allowed or not
enforceWhitelist | Boolean | false | Should ONLY use tags allowed in whitelist
autocomplete | Boolean | true | Tries to autocomplete the input's value while typing (match from whitelist)
Expand Down
2 changes: 1 addition & 1 deletion dist/jQuery.tagify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tagify.css

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

48 changes: 21 additions & 27 deletions dist/tagify.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ Tagify.prototype = {

case 'Down':
case 'ArrowDown':
if (this.settings.mode == 'select') this.dropdown.show.call(this);
// if( this.settings.mode == 'select' ) // #333
this.dropdown.show.call(this);
break;

case 'ArrowRight':
Expand Down Expand Up @@ -492,7 +493,7 @@ Tagify.prototype = {
// this.setRangeAtStartEnd(); // fix caret position

if (value.search(this.settings.delimiters) != -1) {
if (this.addTags(value).length) {
if (this.addTags(value)) {
this.input.set.call(this); // clear the input field's value
}
} else if (this.settings.dropdown.enabled >= 0) {
Expand All @@ -502,12 +503,7 @@ Tagify.prototype = {
this.trigger("input", data);
},
onMixTagsInput: function onMixTagsInput(e) {
var sel,
range,
split,
tag,
showSuggestions,
eventData = {};
var sel, range, split, tag, showSuggestions;
if (this.maxTagsReached()) return true;

if (window.getSelection) {
Expand Down Expand Up @@ -769,8 +765,7 @@ Tagify.prototype = {
var clone = node,
//.cloneNode(true),
v = clone.innerText;
if ("settings" in this && this.settings.delimiters) v = v.replace(/(?:\r\n|\r|\n)/g, this.settings.delimiters.source.charAt(1));
v = v.replace(/\s/g, ' ') // replace NBSPs with spaces characters
v = v.replace(/(?:\r\n|\r|\n)/g, this.settings.delimiters.source.charAt(1)).replace(/\s/g, ' ') // replace NBSPs with spaces characters
.replace(/^\s+/, ""); // trimLeft

return v;
Expand Down Expand Up @@ -804,10 +799,7 @@ Tagify.prototype = {
return true;
}

return false; // if( suggestion && this.addTags(this.input.value + suggestion).length ){
// this.input.set.call(this);
// this.dropdown.hide.call(this);
// }
return false;
}
}
},
Expand Down Expand Up @@ -1017,10 +1009,10 @@ Tagify.prototype = {
* For mixed-mode: replaces a text starting with a prefix with a wrapper element (tag or something)
* First there *has* to be a "this.state.tag" which is a string that was just typed and is staring with a prefix
*/
replaceTaggedText: function replaceTaggedText(wrapperElm) {
if (!this.state.tag) return;
var tag = this.state.tag.prefix + this.state.tag.value,
iter = document.createNodeIterator(this.DOM.input, NodeFilter.SHOW_TEXT, null, false),
replaceTaggedText: function replaceTaggedText(wrapperElm, tagString) {
if (!this.state.tag && !tagString) return;
tagString = tagString || this.state.tag.prefix + this.state.tag.value;
var iter = document.createNodeIterator(this.DOM.input, NodeFilter.SHOW_TEXT, null, false),
textnode,
idx,
maxLoops = 100,
Expand All @@ -1031,11 +1023,11 @@ Tagify.prototype = {

if (textnode.nodeType === Node.TEXT_NODE) {
// get the index of which the tag (string) is within the textNode (if at all)
idx = textnode.nodeValue.indexOf(tag);
idx = textnode.nodeValue.indexOf(tagString);
if (idx == -1) continue;
replacedNode = textnode.splitText(idx); // clean up the tag's string and put tag element instead

replacedNode.nodeValue = replacedNode.nodeValue.replace(tag, '');
replacedNode.nodeValue = replacedNode.nodeValue.replace(tagString, '');
textnode.parentNode.insertBefore(wrapperElm, replacedNode);
}
}
Expand Down Expand Up @@ -1091,15 +1083,17 @@ Tagify.prototype = {
this.settings.transformTag.call(this, tagsItems[0]);
tagElm = this.createTagElem(tagsItems[0]);

if (this.replaceTaggedText(tagElm)) {
this.value.push(tagsItems[0]);
this.update();
this.trigger('add', this.extend({}, {
index: this.value.length,
tag: tagElm
}, tagsItems[0]));
if (!this.replaceTaggedText(tagElm)) {
this.DOM.input.appendChild(tagElm);
}

this.value.push(tagsItems[0]);
this.update();
this.trigger('add', this.extend({}, {
tag: tagElm
}, {
data: tagsItems[0]
}));
return tagElm;
}

Expand Down
2 changes: 1 addition & 1 deletion dist/tagify.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 6de7300

Please sign in to comment.