Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getSelectionCoords() {
- var sel = document.selection, range;
- var x = 0, y = 0;
- if (sel) {
- if (sel.type != "Control") {
- range = sel.createRange();
- range.collapse(true);
- x = range.boundingLeft;
- y = range.boundingTop;
- }
- } else if (window.getSelection) {
- sel = window.getSelection();
- if (sel.rangeCount) {
- range = sel.getRangeAt(0).cloneRange();
- if (range.getClientRects) {
- range.collapse(true);
- var rect = range.getClientRects()[0];
- x = rect.left;
- y = rect.top;
- }
- }
- }
- return { x: x, y: y };
- }
- function getSelectionDimensions() {
- var sel = document.selection, range;
- var width = 0, height = 0;
- if (sel) {
- if (sel.type != "Control") {
- range = sel.createRange();
- width = range.boundingWidth;
- height = range.boundingHeight;
- }
- } else if (window.getSelection) {
- sel = window.getSelection();
- if (sel.rangeCount) {
- range = sel.getRangeAt(0).cloneRange();
- if (range.getBoundingClientRect) {
- var rect = range.getBoundingClientRect();
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- }
- }
- }
- return { width: width , height: height };
- }
Add Comment
Please, Sign In to add comment