-
Notifications
You must be signed in to change notification settings - Fork 6
/
iframe.js
45 lines (40 loc) · 1.48 KB
/
iframe.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
var debug = require('debug')('browser-monkey:angular')
var Mount = require('./lib/mount')
var createMonkey = require('./create')
var hobostyle = require('hobostyle')
var createTestDiv = require('./lib/createTestDiv')
var addressBarInterval
module.exports = function (url) {
return new Mount(url, {
stopApp: function () {},
startApp: function () {
debug('Mounting iframe: ' + url)
var div = createTestDiv()
var addressBar = document.createElement('div')
addressBar.innerText = url
addressBar.className = 'address-bar'
div.appendChild(addressBar)
var iframe = document.createElement('iframe')
iframe.src = url
iframe.onload = function () {
addressBar.innerText = iframe.contentWindow.location.href
}
iframe.height = window.innerHeight - addressBar.clientHeight - 10
div.appendChild(iframe)
if (addressBarInterval) {
clearInterval(addressBarInterval)
}
addressBarInterval = setInterval(function () {
if (iframe.contentWindow) {
addressBar.innerText = iframe.contentWindow.location.href
} else {
clearInterval(addressBarInterval)
}
}, 300)
hobostyle.style('html,body { margin: 0; height: 100%; }')
hobostyle.style('iframe { border: none; width: 100%; }')
hobostyle.style('.address-bar { padding: 5px; font-family: arial; font-size: 20px; border-bottom: 1px solid gray; }')
return createMonkey(iframe)
}
}).start()
}