From 806683db19093af8879269c50098e33975374827 Mon Sep 17 00:00:00 2001 From: Balazs Andre and Bonaventura Fleischmann Date: Mon, 29 Oct 2018 14:54:18 +0100 Subject: [PATCH] Hide trigger char in text on page load When the page reloaded the text in the textarea contains the trigger char eg: @Will Smith I wanted to hide this @ sign in front of the mentioned person all the time. This switch keeps the original behaviour unless it is explicitly set to be true. --- jquery.mentionsInput.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/jquery.mentionsInput.js b/jquery.mentionsInput.js index e75bb0a..7e5a0ae 100644 --- a/jquery.mentionsInput.js +++ b/jquery.mentionsInput.js @@ -15,14 +15,15 @@ //Default settings var defaultSettings = { - triggerChar : '@', //Char that respond to event - onDataRequest : $.noop, //Function where we can search the data - minChars : 2, //Minimum chars to fire the event - allowRepeat : false, //Allow repeat mentions - showAvatars : true, //Show the avatars - elastic : true, //Grow the textarea automatically - defaultValue : '', - onCaret : false, + triggerChar : '@', //Char that respond to event + onDataRequest : $.noop, //Function where we can search the data + minChars : 2, //Minimum chars to fire the event + allowRepeat : false, //Allow repeat mentions + showAvatars : true, //Show the avatars + elastic : true, //Grow the textarea automatically + defaultValue : '', + onCaret : false, + hideTriggerCharOnLoad : false, classes : { autoCompleteItemActive : "active" //Classes to apply in each item }, @@ -506,7 +507,11 @@ var regex = new RegExp("(" + settings.triggerChar + ")\\[(.*?)\\]\\((.*?):(.*?)\\)", "gi"); var match, newMentionText = mentionText; while ((match = regex.exec(mentionText)) != null) { - newMentionText = newMentionText.replace(match[0], match[1] + match[2]); + if(settings.hideTriggerCharOnLoad) { + newMentionText = newMentionText.replace(match[0], match[2]); + } else { + newMentionText = newMentionText.replace(match[0], match[1] + match[2]); + } mentionsCollection.push({ 'id': match[4], 'type': match[3], 'value': match[2], 'trigger': match[1] }); } elmInputBox.val(newMentionText);