Node.js based forum software built for the modern web
possible fix to #1660
barisusaklib9c30aa42d83
diff --git a/public/src/modules/composer/tags.js b/public/src/modules/composer/tags.jsindex 7383844eea..2b50560d0c 100644--- a/public/src/modules/composer/tags.js+++ b/public/src/modules/composer/tags.js@@ -14,7 +14,7 @@ define('composer/tags', function() {tagEl.tagsinput({maxTags: config.tagsPerTopic,- confirmKeys: [13, 188]+ confirmKeys: [13, 44]});addTags(postData.tags, tagEl);@@ -46,7 +46,7 @@ define('composer/tags', function() {function triggerEnter(input) {// http://stackoverflow.com/a/3276819/583363- var e = jQuery.Event('keydown');+ var e = jQuery.Event('keypress');e.which = 13;e.keyCode = 13;setTimeout(function() {diff --git a/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.js b/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.jsindex 6e5dc24e61..aff7ea6cb8 100644--- a/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.js+++ b/public/vendor/jquery/bootstrap-tagsinput/bootstrap-tagsinput.min.js@@ -1,7 +1,506 @@-/*- * bootstrap-tagsinput v0.3.9 by Tim Schlechter- *- */-!function(a){"use strict";function b(b,c){this.itemsArray=[],this.$element=a(b),this.$element.hide(),this.isSelect="SELECT"===b.tagName,this.multiple=this.isSelect&&b.hasAttribute("multiple"),this.objectItems=c&&c.itemValue,this.placeholderText=b.hasAttribute("placeholder")?this.$element.attr("placeholder"):"",this.inputSize=Math.max(1,this.placeholderText.length),this.$container=a('<div class="bootstrap-tagsinput"></div>'),this.$input=a('<input size="'+this.inputSize+'" type="text" placeholder="'+this.placeholderText+'"/>').appendTo(this.$container),this.$element.after(this.$container),this.build(c)}function c(a,b){if("function"!=typeof a[b]){var c=a[b];a[b]=function(a){return a[c]}}}function d(a,b){if("function"!=typeof a[b]){var c=a[b];a[b]=function(){return c}}}function e(a){return a?h.text(a).html():""}function f(a){var b=0;if(document.selection){a.focus();var c=document.selection.createRange();c.moveStart("character",-a.value.length),b=c.text.length}else(a.selectionStart||"0"==a.selectionStart)&&(b=a.selectionStart);return b}var g={tagClass:function(){return"label label-info"},itemValue:function(a){return a?a.toString():a},itemText:function(a){return this.itemValue(a)},freeInput:!0,maxTags:void 0,confirmKeys:[13],onTagExists:function(a,b){b.hide().fadeIn()}};b.prototype={constructor:b,add:function(b,c){var d=this;if(!(d.options.maxTags&&d.itemsArray.length>=d.options.maxTags||b!==!1&&!b)){if("object"==typeof b&&!d.objectItems)throw"Can't add objects when itemValue option is not set";if(!b.toString().match(/^\s*$/)){if(d.isSelect&&!d.multiple&&d.itemsArray.length>0&&d.remove(d.itemsArray[0]),"string"==typeof b&&"INPUT"===this.$element[0].tagName){var f=b.split(",");if(f.length>1){for(var g=0;g<f.length;g++)this.add(f[g],!0);return c||d.pushVal(),void 0}}var h=d.options.itemValue(b),i=d.options.itemText(b),j=d.options.tagClass(b),k=a.grep(d.itemsArray,function(a){return d.options.itemValue(a)===h})[0];if(k){if(d.options.onTagExists){var l=a(".tag",d.$container).filter(function(){return a(this).data("item")===k});d.options.onTagExists(b,l)}}else{d.itemsArray.push(b);var m=a('<span class="tag '+e(j)+'">'+e(i)+'<span data-role="remove"></span></span>');if(m.data("item",b),d.findInputWrapper().before(m),m.after(" "),d.isSelect&&!a('option[value="'+escape(h)+'"]',d.$element)[0]){var n=a("<option selected>"+e(i)+"</option>");n.data("item",b),n.attr("value",h),d.$element.append(n)}c||d.pushVal(),d.options.maxTags===d.itemsArray.length&&d.$container.addClass("bootstrap-tagsinput-max"),d.$element.trigger(a.Event("itemAdded",{item:b}))}}}},remove:function(b,c){var d=this;d.objectItems&&(b="object"==typeof b?a.grep(d.itemsArray,function(a){return d.options.itemValue(a)==d.options.itemValue(b)})[0]:a.grep(d.itemsArray,function(a){return d.options.itemValue(a)==b})[0]),b&&(a(".tag",d.$container).filter(function(){return a(this).data("item")===b}).remove(),a("option",d.$element).filter(function(){return a(this).data("item")===b}).remove(),d.itemsArray.splice(a.inArray(b,d.itemsArray),1)),c||d.pushVal(),d.options.maxTags>d.itemsArray.length&&d.$container.removeClass("bootstrap-tagsinput-max"),d.$element.trigger(a.Event("itemRemoved",{item:b}))},removeAll:function(){var b=this;for(a(".tag",b.$container).remove(),a("option",b.$element).remove();b.itemsArray.length>0;)b.itemsArray.pop();b.pushVal(),b.options.maxTags&&!this.isEnabled()&&this.enable()},refresh:function(){var b=this;a(".tag",b.$container).each(function(){var c=a(this),d=c.data("item"),f=b.options.itemValue(d),g=b.options.itemText(d),h=b.options.tagClass(d);if(c.attr("class",null),c.addClass("tag "+e(h)),c.contents().filter(function(){return 3==this.nodeType})[0].nodeValue=e(g),b.isSelect){var i=a("option",b.$element).filter(function(){return a(this).data("item")===d});i.attr("value",f)}})},items:function(){return this.itemsArray},pushVal:function(){var b=this,c=a.map(b.items(),function(a){return b.options.itemValue(a).toString()});b.$element.val(c,!0).trigger("change")},build:function(b){var e=this;e.options=a.extend({},g,b);var h=e.options.typeahead||{};e.objectItems&&(e.options.freeInput=!1),c(e.options,"itemValue"),c(e.options,"itemText"),c(e.options,"tagClass"),e.options.source&&(h.source=e.options.source),h.source&&a.fn.typeahead&&(d(h,"source"),e.$input.typeahead({source:function(b,c){function d(a){for(var b=[],d=0;d<a.length;d++){var g=e.options.itemText(a[d]);f[g]=a[d],b.push(g)}c(b)}this.map={};var f=this.map,g=h.source(b);a.isFunction(g.success)?g.success(d):a.when(g).then(d)},updater:function(a){e.add(this.map[a])},matcher:function(a){return-1!==a.toLowerCase().indexOf(this.query.trim().toLowerCase())},sorter:function(a){return a.sort()},highlighter:function(a){var b=new RegExp("("+this.query+")","gi");return a.replace(b,"<strong>$1</strong>")}})),e.$container.on("click",a.proxy(function(){e.$input.focus()},e)),e.$container.on("keydown","input",a.proxy(function(b){var c=a(b.target),d=e.findInputWrapper();switch(b.which){case 8:if(0===f(c[0])){var g=d.prev();g&&e.remove(g.data("item"))}break;case 46:if(0===f(c[0])){var h=d.next();h&&e.remove(h.data("item"))}break;case 37:var i=d.prev();0===c.val().length&&i[0]&&(i.before(d),c.focus());break;case 39:var j=d.next();0===c.val().length&&j[0]&&(j.after(d),c.focus());break;default:e.options.freeInput&&a.inArray(b.which,e.options.confirmKeys)>=0&&(e.add(c.val()),c.val(""),b.preventDefault())}c.attr("size",Math.max(this.inputSize,c.val().length))},e)),e.$container.on("click","[data-role=remove]",a.proxy(function(b){e.remove(a(b.target).closest(".tag").data("item"))},e)),e.options.itemValue===g.itemValue&&("INPUT"===e.$element[0].tagName?e.add(e.$element.val()):a("option",e.$element).each(function(){e.add(a(this).attr("value"),!0)}))},destroy:function(){var a=this;a.$container.off("keypress","input"),a.$container.off("click","[role=remove]"),a.$container.remove(),a.$element.removeData("tagsinput"),a.$element.show()},focus:function(){this.$input.focus()},input:function(){return this.$input},findInputWrapper:function(){for(var b=this.$input[0],c=this.$container[0];b&&b.parentNode!==c;)b=b.parentNode;return a(b)}},a.fn.tagsinput=function(c,d){var e=[];return this.each(function(){var f=a(this).data("tagsinput");if(f){var g=f[c](d);void 0!==g&&e.push(g)}else f=new b(this,c),a(this).data("tagsinput",f),e.push(f),"SELECT"===this.tagName&&a("option",a(this)).attr("selected","selected"),a(this).val(a(this).val())}),"string"==typeof c?e.length>1?e:e[0]:e},a.fn.tagsinput.Constructor=b;var h=a("<div />");a(function(){a("input[data-role=tagsinput], select[multiple][data-role=tagsinput]").tagsinput()})}(window.jQuery);-/*-*/\ No newline at end of file+(function ($) {+ "use strict";++ 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 = $('<div class="bootstrap-tagsinput"></div>');+ this.$input = $('<input size="' + this.inputSize + '" type="text" placeholder="' + this.placeholderText + '"/>').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 = $('<span class="tag ' + htmlEncode(tagClass) + '">' + htmlEncode(itemText) + '<span data-role="remove"></span></span>');+ $tag.data('item', item);+ self.findInputWrapper().before($tag);+ $tag.after(' ');++ // add <option /> if item represents a value not present in one of the <select />'s options+ if (self.isSelect && !$('option[value="' + escape(itemValue) + '"]',self.$element)[0]) {+ var $option = $('<option selected>' + htmlEncode(itemText) + '</option>');+ $option.data('item', item);+ $option.attr('value', itemValue);+ self.$element.append($option);+ }++ if (!dontPushVal)+ self.pushVal();++ // Add class when reached maxTags+ if (self.options.maxTags === self.itemsArray.length)+ self.$container.addClass('bootstrap-tagsinput-max');++ self.$element.trigger($.Event('itemAdded', { item: item }));+ },++ /**+ * Removes the given item. Pass true to dontPushVal to prevent updating the+ * elements val()+ */+ remove: function(item, dontPushVal) {+ var self = this;++ if (self.objectItems) {+ if (typeof item === "object")+ item = $.grep(self.itemsArray, function(other) { return self.options.itemValue(other) == self.options.itemValue(item); } )[0];+ else+ item = $.grep(self.itemsArray, function(other) { return self.options.itemValue(other) == item; } )[0];+ }++ if (item) {+ $('.tag', self.$container).filter(function() { return $(this).data('item') === item; }).remove();+ $('option', self.$element).filter(function() { return $(this).data('item') === item; }).remove();+ self.itemsArray.splice($.inArray(item, self.itemsArray), 1);+ }++ if (!dontPushVal)+ self.pushVal();++ // Remove class when reached maxTags+ if (self.options.maxTags > self.itemsArray.length)+ self.$container.removeClass('bootstrap-tagsinput-max');++ self.$element.trigger($.Event('itemRemoved', { item: item }));+ },++ /**+ * Removes all items+ */+ removeAll: function() {+ var self = this;++ $('.tag', self.$container).remove();+ $('option', self.$element).remove();++ while(self.itemsArray.length > 0)+ self.itemsArray.pop();++ self.pushVal();++ if (self.options.maxTags && !this.isEnabled())+ this.enable();+ },++ /**+ * Refreshes the tags so they match the text/value of their corresponding+ * item.+ */+ refresh: function() {+ var self = this;+ $('.tag', self.$container).each(function() {+ var $tag = $(this),+ item = $tag.data('item'),+ itemValue = self.options.itemValue(item),+ itemText = self.options.itemText(item),+ tagClass = self.options.tagClass(item);++ // Update tag's class and inner text+ $tag.attr('class', null);+ $tag.addClass('tag ' + htmlEncode(tagClass));+ $tag.contents().filter(function() {+ return this.nodeType == 3;+ })[0].nodeValue = htmlEncode(itemText);++ if (self.isSelect) {+ var option = $('option', self.$element).filter(function() { return $(this).data('item') === item; });+ option.attr('value', itemValue);+ }+ });+ },++ /**+ * Returns the items added as tags+ */+ items: function() {+ return this.itemsArray;+ },++ /**+ * Assembly value by retrieving the value of each item, and set it on the+ * element.+ */+ pushVal: function() {+ var self = this,+ val = $.map(self.items(), function(item) {+ return self.options.itemValue(item).toString();+ });++ self.$element.val(val, true).trigger('change');+ },++ /**+ * Initializes the tags input behaviour on the element+ */+ build: function(options) {+ var self = this;++ self.options = $.extend({}, defaultOptions, options);+ var typeahead = self.options.typeahead || {};++ // When itemValue is set, freeInput should always be false+ if (self.objectItems)+ self.options.freeInput = false;++ makeOptionItemFunction(self.options, 'itemValue');+ makeOptionItemFunction(self.options, 'itemText');+ makeOptionItemFunction(self.options, 'tagClass');++ // for backwards compatibility, self.options.source is deprecated+ if (self.options.source)+ typeahead.source = self.options.source;++ if (typeahead.source && $.fn.typeahead) {+ makeOptionFunction(typeahead, 'source');++ self.$input.typeahead({+ source: function (query, process) {+ function processItems(items) {+ var texts = [];++ for (var i = 0; i < items.length; i++) {+ var text = self.options.itemText(items[i]);+ map[text] = items[i];+ texts.push(text);+ }+ process(texts);+ }++ this.map = {};+ var map = this.map,+ data = typeahead.source(query);++ if ($.isFunction(data.success)) {+ // support for Angular promises+ data.success(processItems);+ } else {+ // support for functions and jquery promises+ $.when(data)+ .then(processItems);+ }+ },+ updater: function (text) {+ self.add(this.map[text]);+ },+ matcher: function (text) {+ return (text.toLowerCase().indexOf(this.query.trim().toLowerCase()) !== -1);+ },+ sorter: function (texts) {+ return texts.sort();+ },+ highlighter: function (text) {+ var regex = new RegExp( '(' + this.query + ')', 'gi' );+ return text.replace( regex, "<strong>$1</strong>" );+ }+ });+ }++ self.$container.on('click', $.proxy(function(event) {+ self.$input.focus();+ }, self));++ self.$container.on('keypress', 'input', $.proxy(function(event) {+ var $input = $(event.target);+ if (self.options.freeInput && $.inArray(event.which, self.options.confirmKeys) >= 0) {+ self.add($input.val());+ $input.val('');+ event.preventDefault();+ }+ }));++ self.$container.on('keydown', 'input', $.proxy(function(event) {+ var $input = $(event.target),+ $inputWrapper = self.findInputWrapper();++ switch (event.which) {+ // BACKSPACE+ case 8:+ if (doGetCaretPosition($input[0]) === 0) {+ var prev = $inputWrapper.prev();+ if (prev) {+ self.remove(prev.data('item'));+ }+ }+ break;++ // DELETE+ case 46:+ if (doGetCaretPosition($input[0]) === 0) {+ var next = $inputWrapper.next();+ if (next) {+ self.remove(next.data('item'));+ }+ }+ break;++ // LEFT ARROW+ case 37:+ // Try to move the input before the previous tag+ var $prevTag = $inputWrapper.prev();+ if ($input.val().length === 0 && $prevTag[0]) {+ $prevTag.before($inputWrapper);+ $input.focus();+ }+ break;+ // RIGHT ARROW+ case 39:+ // Try to move the input after the next tag+ var $nextTag = $inputWrapper.next();+ if ($input.val().length === 0 && $nextTag[0]) {+ $nextTag.after($inputWrapper);+ $input.focus();+ }+ break;+ default:+ break+ }++ // Reset internal input's size+ $input.attr('size', Math.max(this.inputSize, $input.val().length));+ }, self));++ // Remove icon clicked+ self.$container.on('click', '[data-role=remove]', $.proxy(function(event) {+ self.remove($(event.target).closest('.tag').data('item'));+ }, self));++ // Only add existing value as tags when using strings as tags+ if (self.options.itemValue === defaultOptions.itemValue) {+ if (self.$element[0].tagName === 'INPUT') {+ self.add(self.$element.val());+ } else {+ $('option', self.$element).each(function() {+ self.add($(this).attr('value'), true);+ });+ }+ }+ },++ /**+ * Removes all tagsinput behaviour and unregsiter all event handlers+ */+ destroy: function() {+ var self = this;++ // Unbind events+ self.$container.off('keypress', 'input');+ self.$container.off('click', '[role=remove]');++ self.$container.remove();+ self.$element.removeData('tagsinput');+ self.$element.show();+ },++ /**+ * Sets focus on the tagsinput+ */+ focus: function() {+ this.$input.focus();+ },++ /**+ * Returns the internal input element+ */+ input: function() {+ return this.$input;+ },++ /**+ * Returns the element which is wrapped around the internal input. This+ * is normally the $container, but typeahead.js moves the $input element.+ */+ findInputWrapper: function() {+ var elt = this.$input[0],+ container = this.$container[0];+ while(elt && elt.parentNode !== container)+ elt = elt.parentNode;++ return $(elt);+ }+ };++ /**+ * Register JQuery plugin+ */+ $.fn.tagsinput = function(arg1, arg2) {+ var results = [];++ this.each(function() {+ var tagsinput = $(this).data('tagsinput');++ // Initialize a new tags input+ if (!tagsinput) {+ tagsinput = new TagsInput(this, arg1);+ $(this).data('tagsinput', tagsinput);+ results.push(tagsinput);++ if (this.tagName === 'SELECT') {+ $('option', $(this)).attr('selected', 'selected');+ }++ // Init tags from $(this).val()+ $(this).val($(this).val());+ } else {+ // Invoke function on existing tags input+ var retVal = tagsinput[arg1](arg2);+ if (retVal !== undefined)+ results.push(retVal);+ }+ });++ if ( typeof arg1 == 'string') {+ // Return the results from the invoked function calls+ return results.length > 1 ? results : results[0];+ } else {+ return results;+ }+ };++ $.fn.tagsinput.Constructor = TagsInput;++ /**+ * Most options support both a string or number as well as a function as+ * option value. This function makes sure that the option with the given+ * key in the given options is wrapped in a function+ */+ function makeOptionItemFunction(options, key) {+ if (typeof options[key] !== 'function') {+ var propertyName = options[key];+ options[key] = function(item) { return item[propertyName]; };+ }+ }+ function makeOptionFunction(options, key) {+ if (typeof options[key] !== 'function') {+ var value = options[key];+ options[key] = function() { return value; };+ }+ }+ /**+ * HtmlEncodes the given value+ */+ var htmlEncodeContainer = $('<div />');+ function htmlEncode(value) {+ if (value) {+ return htmlEncodeContainer.text(value).html();+ } else {+ return '';+ }+ }++ /**+ * Returns the position of the caret in the given input field+ * http://flightschool.acylt.com/devnotes/caret-position-woes/+ */+ function doGetCaretPosition(oField) {+ var iCaretPos = 0;+ if (document.selection) {+ oField.focus ();+ var oSel = document.selection.createRange();+ oSel.moveStart ('character', -oField.value.length);+ iCaretPos = oSel.text.length;+ } else if (oField.selectionStart || oField.selectionStart == '0') {+ iCaretPos = oField.selectionStart;+ }+ return (iCaretPos);+ }++ /**+ * Initialize tagsinput behaviour on inputs and selects which have+ * data-role=tagsinput+ */+ $(function() {+ $("input[data-role=tagsinput], select[multiple][data-role=tagsinput]").tagsinput();+ });+})(window.jQuery);