diff --git a/public/javascripts/jquery.autocomplete-custom.js b/public/javascripts/jquery.autocomplete-custom.js index b9171888acb0e0e7b24e2b01b840b0fff33efde7..e10b9de6d49a4275a4b75c6ec6042c7bf15719d3 100644 --- a/public/javascripts/jquery.autocomplete-custom.js +++ b/public/javascripts/jquery.autocomplete-custom.js @@ -52,18 +52,7 @@ $.fn.extend({ $.Autocompleter = function(input, options) { - var KEY = { - UP: 38, - DOWN: 40, - DEL: 46, - TAB: 9, - RETURN: 13, - ESC: 27, - COMMA: 188, - PAGEUP: 33, - PAGEDOWN: 34, - BACKSPACE: 8 - }; + var KEY = KEYCODES; // Create $ object for input element var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass); @@ -94,6 +83,12 @@ $.Autocompleter = function(input, options) { lastKeyPressCode = event.keyCode; switch(event.keyCode) { + case KEY.LEFT: + case KEY.RIGHT: + if( options.disableRightAndLeft && select.visible()){ + event.preventDefault(); + } + break; case KEY.UP: if ( select.visible() ) { event.preventDefault(); @@ -408,6 +403,7 @@ $.Autocompleter.defaults = { width: 0, multiple: false, multipleSeparator: ", ", + disableRightAndLeft: false, highlight: function(value, term) { return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"); }, diff --git a/public/javascripts/keycodes.js b/public/javascripts/keycodes.js index 6138b08acd51d6eee3c630fd95d93dd9958a25f9..ca275d1ce598224a8ed9b3be075ee4d7cb0c7ab0 100644 --- a/public/javascripts/keycodes.js +++ b/public/javascripts/keycodes.js @@ -10,6 +10,7 @@ PAUSE : 19, BREAK : 19, CAPSLOCK : 20, ESCAPE : 27, +ESC : 27, SPACEBAR : 32, PAGEUP : 33, PAGEDOWN : 34, diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index 1b3f30a044974119dd8699f7569f3da53246d8bf..ac5bd9c6d40f995039ca84e262defbb62f7bbf4f 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -53,7 +53,8 @@ var Publisher = { }, formatResult: function(row) { return row.name; - } + }, + disableRightAndLeft : true };}, hiddenMentionFromPerson : function(personData){ return "@{" + personData.name + "; " + personData.handle + "}"; @@ -104,7 +105,9 @@ var Publisher = { }, insertionAt : function(insertionStartIndex, selectionEnd, keyCode){ - this.selectionDeleted(insertionStartIndex, selectionEnd); + if(insertionStartIndex != selectionEnd){ + this.selectionDeleted(insertionStartIndex, selectionEnd); + } this.updateMentionLocations(insertionStartIndex, 1); this.destroyMentionAt(insertionStartIndex); }, @@ -188,26 +191,27 @@ var Publisher = { keyDownHandler : function(event){ var input = Publisher.input(); var selectionStart = input[0].selectionStart; - var isDeletion = (event.keyCode == KEYCODES.DEL && selectionStart < input.val().length) || (event.keyCode == KEYCODES.BACKSPACE && selectionStart > 0) + var selectionEnd = input[0].selectionEnd; + var isDeletion = (event.keyCode == KEYCODES.DEL && selectionStart < input.val().length) || (event.keyCode == KEYCODES.BACKSPACE && (selectionStart > 0 || selectionStart != selectionEnd)) var isInsertion = (KEYCODES.isInsertion(event.keyCode) && event.keyCode != KEYCODES.RETURN ) if(isDeletion){ - Publisher.autocompletion.mentionList.deletionAt(selectionStart, input[0].selectionEnd, event.keyCode); + Publisher.autocompletion.mentionList.deletionAt(selectionStart, selectionEnd, event.keyCode); }else if(isInsertion){ - Publisher.autocompletion.mentionList.insertionAt(selectionStart, input[0].selectionEnd, event.keyCode); + Publisher.autocompletion.mentionList.insertionAt(selectionStart, selectionEnd, event.keyCode); } }, addMentionToInput: function(input, cursorIndex, formatted){ var inputContent = input.val(); - var stringLoc = Publisher.autocompletion.findStringToReplace(input.val(), cursorIndex); + var stringLoc = Publisher.autocompletion.findStringToReplace(inputContent, cursorIndex); var stringStart = inputContent.slice(0, stringLoc[0]); var stringEnd = inputContent.slice(stringLoc[1]); input.val(stringStart + formatted + stringEnd); - var offset = formatted.length - stringLoc[1] - stringLoc[0] + var offset = formatted.length - (stringLoc[1] - stringLoc[0]) Publisher.autocompletion.mentionList.updateMentionLocations(stringStart.length, offset); return [stringStart.length, stringStart.length + formatted.length] },