From c8e1657cf35dda3212794084513797ffa094942a Mon Sep 17 00:00:00 2001 From: Stefan Erichsen Date: Wed, 21 Oct 2015 17:50:44 +0200 Subject: [PATCH] added function toggleReadOnly not beautiful but works for now... --- js/tag-it.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/js/tag-it.js b/js/tag-it.js index 078c264f..311350cd 100644 --- a/js/tag-it.js +++ b/js/tag-it.js @@ -530,6 +530,39 @@ setTimeout(function () { that._showAutocomplete(); }, 0); } }, + + toggleReadOnly: function () { + var that = this; + + this.tagInput.prop("disabled", !this.options.readOnly); + + var tags = this.tagList.find(".tagit-choice"); + + if (!this.options.readOnly) { + tags.addClass('tagit-choice-read-only'); + tags.removeClass('tagit-choice-editable'); + tags.find(".tagit-close").remove(); + } else { + tags.addClass('tagit-choice-editable'); + tags.removeClass('tagit-choice-read-only'); + // Button for removing the tag. + for (i = 0; i < tags.length; i++) { + var tag = tags[i]; + var removeTagIcon = $('') + .addClass('ui-icon ui-icon-close'); + var removeTag = $('\xd7') // \xd7 is an X + .addClass('tagit-close') + .append(removeTagIcon) + .click(function(e) { + // Removes a tag when the little 'x' is clicked. + that.removeTag($(e.target).parent().parent()[0]); + }); + $(tag).append(removeTag); + } + } + + this.options.readOnly = !this.options.readOnly; + }, removeTag: function(tag, animate) { animate = typeof animate === 'undefined' ? this.options.animate : animate;