Last active
March 17, 2018 20:03
-
-
Save kselax/84a305ae2f4d5d81350ddb7a7596fed5 to your computer and use it in GitHub Desktop.
TextInserter. (javascript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TextInserter{ | |
| constructor(selector, text){ | |
| this.selector=selector | |
| this.text=text; | |
| this.field=$(selector).get(0); | |
| this.value=$(selector).val(); | |
| this.start=this.field.selectionStart; | |
| this.finish=this.field.selectionEnd; | |
| this.putText(); | |
| } | |
| putText(){ | |
| this.value=this.value.substr(0, this.start) + this.text + this.value.substr(this.finish); | |
| $(this.selector).val(this.value); | |
| } | |
| }//TextInserter | |
| var obj=new TextInserter('textarea', 'some text'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment