You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

iehacks.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Make getElementById() case-sensitive on IE7
  2. document._getElementById = document.getElementById;
  3. document.getElementById = function(id)
  4. {
  5. var i = 0, obj = document._getElementById(id);
  6. if (obj && obj.id != id)
  7. while ((obj = document.all[i]) && obj.id != id)
  8. i++;
  9. return obj;
  10. }
  11. // fix missing :last-child selectors
  12. $(document).ready(function() {
  13. if (rcmail && rcmail.env.skin != 'classic')
  14. $('ul.treelist ul').each(function(i, ul) {
  15. $('li:last-child', ul).css('border-bottom', 0);
  16. });
  17. });
  18. // gets cursor position (IE<9)
  19. rcube_webmail.prototype.get_caret_pos = function(obj)
  20. {
  21. if (document.selection && document.selection.createRange) {
  22. var range = document.selection.createRange();
  23. if (range.parentElement() != obj)
  24. return 0;
  25. var gm = range.duplicate();
  26. if (obj.tagName == 'TEXTAREA')
  27. gm.moveToElementText(obj);
  28. else
  29. gm.expand('textedit');
  30. gm.setEndPoint('EndToStart', range);
  31. var p = gm.text.length;
  32. return p <= obj.value.length ? p : -1;
  33. }
  34. return obj.value.length;
  35. };
  36. // moves cursor to specified position (IE<9)
  37. rcube_webmail.prototype.set_caret_pos = function(obj, pos)
  38. {
  39. if (obj.createTextRange) {
  40. var range = obj.createTextRange();
  41. range.collapse(true);
  42. range.moveEnd('character', pos);
  43. range.moveStart('character', pos);
  44. range.select();
  45. }
  46. };
  47. // get selected text from an input field (IE<9)
  48. // http://stackoverflow.com/questions/7186586/how-to-get-the-selected-text-in-textarea-using-jquery-in-internet-explorer-7
  49. rcube_webmail.prototype.get_input_selection = function(obj)
  50. {
  51. var start = 0, end = 0, len,
  52. normalizedValue, textInputRange, endRange,
  53. range = document.selection.createRange();
  54. if (range && range.parentElement() == obj) {
  55. len = obj.value.length;
  56. normalizedValue = obj.value; //.replace(/\r\n/g, "\n");
  57. // create a working TextRange that lives only in the input
  58. textInputRange = obj.createTextRange();
  59. textInputRange.moveToBookmark(range.getBookmark());
  60. // Check if the start and end of the selection are at the very end
  61. // of the input, since moveStart/moveEnd doesn't return what we want
  62. // in those cases
  63. endRange = obj.createTextRange();
  64. endRange.collapse(false);
  65. if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
  66. start = end = len;
  67. }
  68. else {
  69. start = -textInputRange.moveStart("character", -len);
  70. start += normalizedValue.slice(0, start).split("\n").length - 1;
  71. if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
  72. end = len;
  73. }
  74. else {
  75. end = -textInputRange.moveEnd("character", -len);
  76. end += normalizedValue.slice(0, end).split("\n").length - 1;
  77. }
  78. }
  79. }
  80. return {start: start, end: end, text: normalizedValue.substr(start, end-start)};
  81. };
  82. // For IE<9 we have to do it this way
  83. // otherwise the form will be posted to a new window
  84. rcube_webmail.prototype.async_upload_form_frame = function(name)
  85. {
  86. document.body.insertAdjacentHTML('BeforeEnd', '<iframe name="' + name + '"'
  87. + ' src="' + rcmail.assets_path('program/resources/blank.gif') + '" style="width:0; height:0; visibility:hidden"></iframe>');
  88. return $('iframe[name="' + name + '"]');
  89. };