diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-04-09 13:58:03 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-04-09 13:58:03 +0000 |
commit | dcbb5fa3f4434be266793f6a610071a14c777414 (patch) | |
tree | 10a5bae9c26e0fad6a5d08eadf6fd082304354d2 /misc/drupal.js | |
parent | 15d739a5049091821c81006ad8080f0556053e16 (diff) | |
download | brdo-dcbb5fa3f4434be266793f6a610071a14c777414.tar.gz brdo-dcbb5fa3f4434be266793f6a610071a14c777414.tar.bz2 |
- Patch #107061 by Steven et al: add jQuery teaser splitter.
Diffstat (limited to 'misc/drupal.js')
-rw-r--r-- | misc/drupal.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/misc/drupal.js b/misc/drupal.js index b4130e4ad..04176089d 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -200,6 +200,26 @@ Drupal.encodeURIComponent = function (item, uri) { return uri.indexOf('?q=') ? item : item.replace('%26', '%2526').replace('%23', '%2523'); }; +/** + * Get the text selection in a textarea. + */ +Drupal.getSelection = function (element) { + if (typeof(element.selectionStart) != 'number' && document.selection) { + // The current selection + var range1 = document.selection.createRange(); + var range2 = range1.duplicate(); + // Select all text. + range2.moveToElementText(element); + // Now move 'dummy' end point to end point of original range. + range2.setEndPoint('EndToEnd', range1); + // Now we can calculate start and end points. + var start = range2.text.length - range1.text.length; + var end = start + range1.text.length; + return { 'start': start, 'end': end }; + } + return { 'start': element.selectionStart, 'end': element.selectionEnd }; +} + // Global Killswitch on the <html> element if (Drupal.jsEnabled) { document.documentElement.className = 'js'; |