1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-23 01:39:27 +02:00

add position to frameData

This commit is contained in:
kev 2015-01-19 22:08:57 +08:00
parent e6ba069f84
commit 42de7f208c
2 changed files with 34 additions and 17 deletions

View File

@ -1,5 +1,6 @@
var webpage = require('webpage');
var frame = require('./frame');
function setCookies(page, cookies) {
@ -40,22 +41,6 @@ function execScripts(page, scripts, arr) {
}
function frameData(page, data) {
data.url = page.frameUrl;
data.name = page.frameName;
data.content = page.frameContent;
data.childCount = page.framesCount;
data.childFrames = [];
for(var i=0; i<data.childCount; i++) {
var node = {};
data.childFrames.push(node);
page.switchToFrame(i);
frameData(page, node);
page.switchToParentFrame();
}
}
function urlopen(req, callback) {
var page = webpage.create();
@ -201,7 +186,7 @@ function urlopen(req, callback) {
execScripts(page, req.execScripts.postInjected, result.execScriptsOutput.postInjected);
var fdata = {};
frameData(page, fdata);
frame.frameData(page, fdata);
fdata.content = null;
result.frameData = fdata;
page.switchToMainFrame();

32
webkit/frame.js Normal file
View File

@ -0,0 +1,32 @@
function frameData(page, data) {
data.url = page.frameUrl;
data.name = page.frameName;
data.content = page.frameContent;
data.childCount = page.framesCount;
data.childFrames = [];
var posList = page.evaluate(framePosition);
for(var i=0; i<data.childCount; i++) {
var node = {};
node.position = posList[i];
data.childFrames.push(node);
page.switchToFrame(i);
frameData(page, node);
page.switchToParentFrame();
}
}
function framePosition() {
var nodes = document.getElementsByTagName('iframe');
var results = [];
for(var i=0; i<nodes.length; i++) {
var pos = nodes[i].getBoundingClientRect();
results.push(pos);
}
return results;
}
module.exports.frameData = frameData;