summaryrefslogtreecommitdiff
path: root/plugins/legacy_browser
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-05-02 11:01:18 +0200
committerAleksander Machniak <alec@alec.pl>2014-05-02 11:01:18 +0200
commit378efddbbe776cdfd9be8c5904afeb4eecf33291 (patch)
treef6a431df552857ea501212e6966327214d138d75 /plugins/legacy_browser
parent3dfb94fe45150c9c662c384b03e0866a1445a567 (diff)
MOve more IE<9 code to legacy_browser
Diffstat (limited to 'plugins/legacy_browser')
-rw-r--r--plugins/legacy_browser/js/iehacks.js80
-rw-r--r--plugins/legacy_browser/legacy_browser.php11
2 files changed, 88 insertions, 3 deletions
diff --git a/plugins/legacy_browser/js/iehacks.js b/plugins/legacy_browser/js/iehacks.js
index 129ad6003..91dc6d63a 100644
--- a/plugins/legacy_browser/js/iehacks.js
+++ b/plugins/legacy_browser/js/iehacks.js
@@ -1,7 +1,8 @@
// Make getElementById() case-sensitive on IE7
document._getElementById = document.getElementById;
-document.getElementById = function(id) {
+document.getElementById = function(id)
+{
var i = 0, obj = document._getElementById(id);
if (obj && obj.id != id)
@@ -18,3 +19,80 @@ $(document).ready(function() {
$('li:last-child', ul).css('border-bottom', 0);
});
});
+
+// gets cursor position (IE<9)
+rcube_webmail.prototype.get_caret_pos = function(obj)
+{
+ if (document.selection && document.selection.createRange) {
+ var range = document.selection.createRange();
+ if (range.parentElement() != obj)
+ return 0;
+
+ var gm = range.duplicate();
+ if (obj.tagName == 'TEXTAREA')
+ gm.moveToElementText(obj);
+ else
+ gm.expand('textedit');
+
+ gm.setEndPoint('EndToStart', range);
+ var p = gm.text.length;
+
+ return p <= obj.value.length ? p : -1;
+ }
+
+ return obj.value.length;
+};
+
+// moves cursor to specified position (IE<9)
+rcube_webmail.prototype.set_caret_pos = function(obj, pos)
+{
+ if (obj.createTextRange) {
+ var range = obj.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', pos);
+ range.moveStart('character', pos);
+ range.select();
+ }
+};
+
+// get selected text from an input field (IE<9)
+// http://stackoverflow.com/questions/7186586/how-to-get-the-selected-text-in-textarea-using-jquery-in-internet-explorer-7
+rcube_webmail.prototype.get_input_selection = function(obj)
+{
+ var start = 0, end = 0, len,
+ normalizedValue, textInputRange, endRange,
+ range = document.selection.createRange();
+
+ if (range && range.parentElement() == obj) {
+ len = obj.value.length;
+ normalizedValue = obj.value; //.replace(/\r\n/g, "\n");
+
+ // create a working TextRange that lives only in the input
+ textInputRange = obj.createTextRange();
+ textInputRange.moveToBookmark(range.getBookmark());
+
+ // Check if the start and end of the selection are at the very end
+ // of the input, since moveStart/moveEnd doesn't return what we want
+ // in those cases
+ endRange = obj.createTextRange();
+ endRange.collapse(false);
+
+ if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
+ start = end = len;
+ }
+ else {
+ start = -textInputRange.moveStart("character", -len);
+ start += normalizedValue.slice(0, start).split("\n").length - 1;
+
+ if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
+ end = len;
+ }
+ else {
+ end = -textInputRange.moveEnd("character", -len);
+ end += normalizedValue.slice(0, end).split("\n").length - 1;
+ }
+ }
+ }
+
+ return {start: start, end: end, text: normalizedValue.substr(start, end-start)};
+};
diff --git a/plugins/legacy_browser/legacy_browser.php b/plugins/legacy_browser/legacy_browser.php
index 0dc0794f3..9378cdc3e 100644
--- a/plugins/legacy_browser/legacy_browser.php
+++ b/plugins/legacy_browser/legacy_browser.php
@@ -25,10 +25,17 @@ class legacy_browser extends rcube_plugin
// replace jQuery 2.x with 1.x
$ts1 = filemtime($this->home . '/js/jquery.min.js');
$ts2 = filemtime($this->home . '/js/iehacks.js');
+
+ // put iehacks.js after app.js
+ $args['content'] = preg_replace(
+ '|(<script src="program/js/app(\.min)?\.js\?s=[0-9]+" type="text/javascript"></script>)|',
+ '\\1<script src="plugins/legacy_browser/js/iehacks.js?s=' . $ts2 . '" type="text/javascript"></script>',
+ $args['content'], 1, $count);
+
$args['content'] = preg_replace(
'|<script src="program/js/jquery\.min\.js\?s=[0-9]+" type="text/javascript"></script>|',
- '<script src="plugins/legacy_browser/js/jquery.min.js?s=' . $ts1 . '" type="text/javascript"></script>'."\n"
- .'<script src="plugins/legacy_browser/js/iehacks.js?s=' . $ts2 . '" type="text/javascript"></script>',
+ '<script src="plugins/legacy_browser/js/jquery.min.js?s=' . $ts1 . '" type="text/javascript"></script>'
+ . ($count ? '' : "\n".'<script src="plugins/legacy_browser/js/iehacks.js?s=' . $ts2 . '" type="text/javascript"></script>'),
$args['content'], 1);
return $args;