Today we learned about the order of operations

This commit is contained in:
Raphael Sofaer 2011-02-09 15:51:28 -08:00
parent 7409cd8a27
commit bd38d1436e
3 changed files with 20 additions and 19 deletions

View file

@ -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>");
},

View file

@ -10,6 +10,7 @@ PAUSE : 19,
BREAK : 19,
CAPSLOCK : 20,
ESCAPE : 27,
ESC : 27,
SPACEBAR : 32,
PAGEUP : 33,
PAGEDOWN : 34,

View file

@ -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]
},