fix keyboard throubles with ie11

This commit is contained in:
Ezequiel Bergamaschi 2015-02-06 00:54:39 -03:00
parent ba5efdeaad
commit fd07af4f5f
3 changed files with 25 additions and 4 deletions

View File

@ -88,6 +88,17 @@ mindplot.MultilineTextEditor = new Class({
me.close(true);
}
break;
case 'tab':
event.preventDefault();
var start = $(this).get(0).selectionStart;
var end = $(this).get(0).selectionEnd;
// set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start) + "\t" + $(this).val().substring(end));
// put caret at right position again
$(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 1;
break;
}
event.stopPropagation();
});
@ -248,24 +259,32 @@ mindplot.MultilineTextEditor = new Class({
_positionCursor:function (textareaElem, selectText) {
textareaElem.focus();
var lenght = textareaElem.val().length;
if (selectText) {
// Mark text as selected ...
if (textareaElem.createTextRange) {
var rang = textareaElem.createTextRange();
rang.select();
rang.move("character", textareaElem.val().length);
rang.move("character", lenght);
}
else {
textareaElem[0].setSelectionRange(0, textareaElem.val().length);
textareaElem[0].setSelectionRange(0, lenght);
}
} else {
// Move the cursor to the last character ..
if (textareaElem.createTextRange) {
var range = textareaElem.createTextRange();
range.move("character", textareaElem.val().length);
range.move("character", lenght);
} else {
textareaElem.selectionStart = textareaElem.val().length;
if (Browser.ie11) {
textareaElem[0].selectionStart = lenght;
textareaElem[0].selectionEnd = lenght;
} else {
textareaElem.selectionStart = lenght;
textareaElem.selectionEnd = lenght;
}
textareaElem.focus();
}
}

View File

@ -16,6 +16,7 @@
* limitations under the License.
*/
//FIXME: Not used!
mindplot.TextEditor = new Class({
initialize:function(topic) {
this._topic = topic;

View File

@ -31,6 +31,7 @@ Browser = {
ie6: !window.XMLHttpRequest,
ie7: document.all && window.XMLHttpRequest && !XDomainRequest && !window.opera,
ie8: document.documentMode==8,
ie11: document.documentMode==11,
opera: Boolean(window.opera),
chrome: Boolean(window.chrome),
safari: window.getComputedStyle && !window.globalStorage && !window.opera,