fixed auto complete for insertion in the middle, 6am commits FTW

This commit is contained in:
Baris Soner Usakli
2014-01-08 06:15:48 -05:00
parent 0d26b21a2c
commit d2c0aa9949
2 changed files with 54 additions and 12 deletions

View File

@@ -187,6 +187,40 @@
if ('undefined' !== typeof window) {
window.utils = module.exports;
(function ($, undefined) {
$.fn.getCursorPosition = function() {
var el = $(this).get(0);
var pos = 0;
if('selectionStart' in el) {
pos = el.selectionStart;
} else if('selection' in document) {
el.focus();
var Sel = document.selection.createRange();
var SelLength = document.selection.createRange().text.length;
Sel.moveStart('character', -el.value.length);
pos = Sel.text.length - SelLength;
}
return pos;
}
$.fn.selectRange = function(start, end) {
if(!end) end = start;
return this.each(function() {
if (this.setSelectionRange) {
this.focus();
this.setSelectionRange(start, end);
} else if (this.createTextRange) {
var range = this.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
}
});
};
})(jQuery);
}
})('undefined' === typeof module ? {