diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index 0258b28154..bf4e7229fd 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -52,6 +52,8 @@ "invalid-title": "Invalid title!", "too-many-posts": "You can only post once every %1 seconds - please wait before posting again", "too-many-posts-newbie": "As a new user, you can only post once every %1 seconds until you have earned %2 reputation - please wait before posting again", + "tag-too-short": "Please enter a longer tag. Tags should contain at least %1 characters", + "tag-too-long": "Please enter a shorter tag. Tags can't be longer than %1 characters", "file-too-big": "Maximum allowed file size is %1 kbs - please upload a smaller file", "cant-vote-self-post": "You cannot vote for your own post", diff --git a/public/language/en_GB/tags.json b/public/language/en_GB/tags.json index f67b2ca7b5..a3f75bb2e6 100644 --- a/public/language/en_GB/tags.json +++ b/public/language/en_GB/tags.json @@ -1,7 +1,7 @@ { "no_tag_topics": "There are no topics with this tag.", "tags": "Tags", - "enter_tags_here": "Enter tags here. Press enter after each tag.", + "enter_tags_here": "Enter tags here. %1-%2 characters. Press enter after each tag.", "enter_tags_here_short": "Enter tags...", "no_tags": "There are no tags yet." } \ No newline at end of file diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 088cafe260..29154d1523 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -228,6 +228,8 @@ define('composer', [ var data = { allowTopicsThumbnail: allowTopicsThumbnail, showTags: isTopic || isMain, + minimumTagLength: config.minimumTagLength, + maximumTagLength: config.maximumTagLength, isTopic: isTopic, showHandleInput: (app.user.uid === 0 || (isEditing && isGuestPost && app.user.isAdmin)) && config.allowGuestHandles, handle: composer.posts[post_uuid] ? composer.posts[post_uuid].handle || '' : undefined diff --git a/public/src/modules/composer/tags.js b/public/src/modules/composer/tags.js index 93b33fbb38..f074a5abc2 100644 --- a/public/src/modules/composer/tags.js +++ b/public/src/modules/composer/tags.js @@ -14,7 +14,17 @@ define('composer/tags', function() { tagEl.tagsinput({ maxTags: config.tagsPerTopic, - confirmKeys: [13, 44] + confirmKeys: [13, 44], + trimValue: true + }); + + tagEl.on('beforeItemAdd', function(event) { + event.cancel = event.item.length < config.minimumTagLength || event.item.length > config.maximumTagLength; + if (event.item.length < config.minimumTagLength) { + app.alertError('[[error:tag-too-short, ' + config.minimumTagLength + ']]'); + } else if (event.item.length > config.maximumTagLength) { + app.alertError('[[error:tag-too-long, ' + config.maximumTagLength + ']]'); + } }); tagEl.on('itemAdded', function(event) { diff --git a/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css b/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css index 98cfa7f3c1..55f7c09df0 100644 --- a/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css +++ b/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.css @@ -10,6 +10,7 @@ border-radius: 4px; max-width: 100%; line-height: 22px; + cursor: text; } .bootstrap-tagsinput input { border: none; diff --git a/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.js b/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.js index aff7ea6cb8..16be0abb93 100644 --- a/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.js +++ b/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.js @@ -1,506 +1,7 @@ -(function ($) { - "use strict"; +/* + * bootstrap-tagsinput v0.4.2 by Tim Schlechter + * + */ - var defaultOptions = { - tagClass: function(item) { - return 'label label-info'; - }, - itemValue: function(item) { - return item ? item.toString() : item; - }, - itemText: function(item) { - return this.itemValue(item); - }, - freeInput: true, - maxTags: undefined, - confirmKeys: [13], - onTagExists: function(item, $tag) { - $tag.hide().fadeIn(); - } - }; - - /** - * Constructor function - */ - function TagsInput(element, options) { - this.itemsArray = []; - - this.$element = $(element); - this.$element.hide(); - - this.isSelect = (element.tagName === 'SELECT'); - this.multiple = (this.isSelect && element.hasAttribute('multiple')); - this.objectItems = options && options.itemValue; - this.placeholderText = element.hasAttribute('placeholder') ? this.$element.attr('placeholder') : ''; - this.inputSize = Math.max(1, this.placeholderText.length); - - this.$container = $('
'); - this.$input = $('').appendTo(this.$container); - - this.$element.after(this.$container); - - this.build(options); - } - - TagsInput.prototype = { - constructor: TagsInput, - - /** - * Adds the given item as a new tag. Pass true to dontPushVal to prevent - * updating the elements val() - */ - add: function(item, dontPushVal) { - var self = this; - - if (self.options.maxTags && self.itemsArray.length >= self.options.maxTags) - return; - - // Ignore falsey values, except false - if (item !== false && !item) - return; - - // Throw an error when trying to add an object while the itemValue option was not set - if (typeof item === "object" && !self.objectItems) - throw("Can't add objects when itemValue option is not set"); - - // Ignore strings only containg whitespace - if (item.toString().match(/^\s*$/)) - return; - - // If SELECT but not multiple, remove current tag - if (self.isSelect && !self.multiple && self.itemsArray.length > 0) - self.remove(self.itemsArray[0]); - - if (typeof item === "string" && this.$element[0].tagName === 'INPUT') { - var items = item.split(','); - if (items.length > 1) { - for (var i = 0; i < items.length; i++) { - this.add(items[i], true); - } - - if (!dontPushVal) - self.pushVal(); - return; - } - } - - var itemValue = self.options.itemValue(item), - itemText = self.options.itemText(item), - tagClass = self.options.tagClass(item); - - // Ignore items allready added - var existing = $.grep(self.itemsArray, function(item) { return self.options.itemValue(item) === itemValue; } )[0]; - if (existing) { - // Invoke onTagExists - if (self.options.onTagExists) { - var $existingTag = $(".tag", self.$container).filter(function() { return $(this).data("item") === existing; }); - self.options.onTagExists(item, $existingTag); - } - return; - } - - // register item in internal array and map - self.itemsArray.push(item); - - // add a tag element - var $tag = $('' + htmlEncode(itemText) + ''); - $tag.data('item', item); - self.findInputWrapper().before($tag); - $tag.after(' '); - - // add