1 |
package Frey::Web::IFrame; |
2 |
use Moose::Role; |
3 |
|
4 |
sub iframe_html { |
5 |
my ($self) = @_; |
6 |
|
7 |
$self->add_js(q` |
8 |
function ifr_close() { |
9 |
self.document.getElementById('ifr_target').style.display = 'none'; |
10 |
self.document.getElementById('ifr_close').style.display = 'none'; |
11 |
} |
12 |
function ifr_show() { |
13 |
self.document.getElementById('ifr_loading').style.display=''; |
14 |
} |
15 |
function ifr_transfer(f) { |
16 |
self.document.getElementById('ifr_loading').style.display='none'; |
17 |
self.document.getElementById('ifr_close').style.display=''; |
18 |
if ( f.contentWindow.document.body ) { |
19 |
var ifr_target = self.document.getElementById('ifr_target'); |
20 |
ifr_target.innerHTML = f.contentWindow.document.body.innerHTML; |
21 |
f.contentWindow.document.body.innerHTML = ''; // XXX we can't just undef here! |
22 |
ifr_target.style.display = ''; |
23 |
console.log( ifr_target ); |
24 |
} |
25 |
} |
26 |
`); |
27 |
|
28 |
$self->add_css(q| |
29 |
#ifr_close { |
30 |
position: absolute; |
31 |
font-size: 50%; |
32 |
right: 0.5em; |
33 |
border: 1px solid #888; |
34 |
background: #fff; |
35 |
z-index: 10; |
36 |
opacity: .2; |
37 |
filter: alpha(opacity=20); |
38 |
} |
39 |
#ifr_close:hover { |
40 |
opacity: 1; |
41 |
filter: alpha(opacity=100); |
42 |
} |
43 |
|); |
44 |
|
45 |
return qq| |
46 |
<div> |
47 |
<a href="#" id="ifr_close" style="display:none;" onclick="ifr_close();return false;" title="close iframe">X</a><span id="ifr_loading" style="display: none; background: #ff8;">Loading...</span> |
48 |
<!-- we really need src="#" here to avoid onload when page loads --> |
49 |
<iframe src="#" name="transport_iframe" id="transport_iframe" style="display: none;" frameborder=0 border=0 onload="ifr_transfer(this);"></iframe> |
50 |
<div id="ifr_target" style="display: none"></div> |
51 |
</div> |
52 |
| |
53 |
; |
54 |
} |
55 |
|
56 |
sub iframe_open { |
57 |
my ($self,$url,$text) = @_; |
58 |
|
59 |
qq| |
60 |
<a href="$url" target="transport_iframe" onclick="ifr_show(); return true;">$text</a> |
61 |
| |
62 |
} |
63 |
|
64 |
no Moose::Role; |
65 |
|
66 |
1; |