Guest User

Untitled

a guest
Jan 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function getSelectionCoords() {
  2. var sel = document.selection, range;
  3. var x = 0, y = 0;
  4. if (sel) {
  5. if (sel.type != "Control") {
  6. range = sel.createRange();
  7. range.collapse(true);
  8. x = range.boundingLeft;
  9. y = range.boundingTop;
  10. }
  11. } else if (window.getSelection) {
  12. sel = window.getSelection();
  13. if (sel.rangeCount) {
  14. range = sel.getRangeAt(0).cloneRange();
  15. if (range.getClientRects) {
  16. range.collapse(true);
  17. var rect = range.getClientRects()[0];
  18. x = rect.left;
  19. y = rect.top;
  20. }
  21. }
  22. }
  23. return { x: x, y: y };
  24. }
  25.  
  26. function getSelectionDimensions() {
  27. var sel = document.selection, range;
  28. var width = 0, height = 0;
  29. if (sel) {
  30. if (sel.type != "Control") {
  31. range = sel.createRange();
  32. width = range.boundingWidth;
  33. height = range.boundingHeight;
  34. }
  35. } else if (window.getSelection) {
  36. sel = window.getSelection();
  37. if (sel.rangeCount) {
  38. range = sel.getRangeAt(0).cloneRange();
  39. if (range.getBoundingClientRect) {
  40. var rect = range.getBoundingClientRect();
  41. width = rect.right - rect.left;
  42. height = rect.bottom - rect.top;
  43. }
  44. }
  45. }
  46. return { width: width , height: height };
  47. }
Add Comment
Please, Sign In to add comment