]> git.mjollnir.org Git - moodle.git/commitdiff
Added javascript function insertAtCursor()
authorvyshane <vyshane>
Tue, 14 Mar 2006 05:26:40 +0000 (05:26 +0000)
committervyshane <vyshane>
Tue, 14 Mar 2006 05:26:40 +0000 (05:26 +0000)
lib/javascript-static.js

index 6f720404a28a0864c5e1a86304133666a04dc12c..3fe0dda3759ec8786bdbb5441195dfec110415b5 100644 (file)
@@ -219,3 +219,25 @@ function fix_column_width(colName) {
         }
     }
 }
+
+
+/*
+       Insert myValue at current cursor position
+*/
+function insertAtCursor(myField, myValue) {
+       // IE support
+       if (document.selection) {
+               myField.focus();
+               sel = document.selection.createRange();
+               sel.text = myValue;
+       }
+       // Mozilla/Netscape support
+       else if (myField.selectionStart || myField.selectionStart == '0') {
+               var startPos = myField.selectionStart;
+               var endPos = myField.selectionEnd;
+               myField.value = myField.value.substring(0, startPos)
+                       + myValue + myField.value.substring(endPos, myField.value.length);
+       } else {
+               myField.value += myValue;
+       }
+}