Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add get_selection_text() method

  • Loading branch information...
commit 0f77b44763991bf286c917b8ceaf11194b806a39 1 parent bc701aa
@kir authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/selection_range.js
View
12 src/selection_range.js
@@ -5,11 +5,14 @@ if (!window.maxkir) maxkir = {};
*
* Usage:
*
- * var selection = new maxkir.SelectionRange(textarea).get_selection_range()
+ * var range = new maxkir.SelectionRange(textarea);
+ * var selection = range.get_selection_range()
* var selectionStart = selection[0]
* var selectionEnd = selection[1]
+ * On a error, returns [0,0]
+ *
+ * var selection_text = range.get_selection_text();
*
- * On a error, returns [0,0]
*
* */
maxkir.SelectionRange = function(element) {
@@ -50,3 +53,8 @@ maxkir.SelectionRange.prototype.get_selection_range = function() {
return [0,0]
}
};
+
+maxkir.SelectionRange.prototype.get_selection_text = function() {
+ var r = this.get_selection_range();
+ return this.element.value.substring(r[0], r[1]);
+};
Please sign in to comment.
Something went wrong with that request. Please try again.