-
Notifications
You must be signed in to change notification settings - Fork 5
/
snapsie.js
84 lines (75 loc) · 2.69 KB
/
snapsie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* This file wraps the Snapsie ActiveX object, exposing a single saveSnapshot()
* method on a the object.
*
* See http://snapsie.sourceforge.net/
*/
function Snapsie() {
// private methods
function isQuirksMode(inDocument) {
return (inDocument.compatMode == 'BackCompat');
}
function getDrawableElement(inDocument) {
if (isQuirksMode(inDocument)) {
var body = inDocument.getElementsByTagName('body')[0];
return body;
}
else {
// standards mode
return inDocument.documentElement;
}
}
/**
* Returns the canonical Windows path for a given path. This means
* basically replacing any forwards slashes with backslashes.
*
* @param path the path whose canonical form to return
*/
function getCanonicalPath(path) {
path = path.replace(/\//g, '\\');
path = path.replace(/\\\\/g, '\\');
return path;
}
// public methods
/**
* Saves a screenshot of the current document to a file. If frameId is
* specified, a screenshot of just the frame is captured instead.
*
* @param outputFile the file to which to save the screenshot
* @param frameId the frame to capture; omit to capture entire document
*/
this.saveSnapshot = function(outputFile, frameId) {
var drawableElement = getDrawableElement(document);
var drawableInfo = {
overflow : drawableElement.style.overflow
, scrollLeft: drawableElement.scrollLeft
, scrollTop : drawableElement.scrollTop
};
var capturableDocument;
var frameBCR = { left: 0, top: 0 };
if (!frameId) {
capturableDocument = document;
}
else {
var frame = document.getElementById(frameId);
capturableDocument = frame.document;
// scroll as much of the frame into view as possible
frameBCR = frame.getBoundingClientRect();
window.scroll(frameBCR.left, frameBCR.top);
frameBCR = frame.getBoundingClientRect();
}
var nativeObj = new ActiveXObject('Snapsie.CoSnapsie');
nativeObj.saveSnapshot(
getCanonicalPath(outputFile),
frameId,
drawableElement.scrollWidth,
drawableElement.scrollHeight,
drawableElement.clientWidth,
drawableElement.clientHeight,
drawableElement.clientLeft,
drawableElement.clientTop,
frameBCR.left,
frameBCR.top
);
}
};