1 |
dpavlin |
905 |
package Frey::Web::IFrame; |
2 |
dpavlin |
907 |
use Moose::Role; |
3 |
dpavlin |
905 |
|
4 |
dpavlin |
907 |
sub iframe_html { |
5 |
dpavlin |
905 |
my ($self) = @_; |
6 |
|
|
|
7 |
dpavlin |
906 |
$self->add_js(q` |
8 |
dpavlin |
905 |
function ifr_close() { |
9 |
dpavlin |
906 |
self.document.getElementById('ifr_target').style.display = 'none'; |
10 |
|
|
self.document.getElementById('ifr_close').style.display = 'none'; |
11 |
dpavlin |
905 |
} |
12 |
|
|
function ifr_show() { |
13 |
dpavlin |
906 |
self.document.getElementById('ifr_loading').style.display=''; |
14 |
|
|
} |
15 |
|
|
function ifr_transfer(f) { |
16 |
|
|
self.document.getElementById('ifr_loading').style.display='none'; |
17 |
dpavlin |
905 |
self.document.getElementById('ifr_close').style.display=''; |
18 |
dpavlin |
906 |
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 |
dpavlin |
905 |
} |
26 |
dpavlin |
906 |
`); |
27 |
dpavlin |
905 |
|
28 |
dpavlin |
910 |
$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 |
dpavlin |
907 |
return qq| |
46 |
dpavlin |
906 |
<div> |
47 |
dpavlin |
910 |
<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 |
dpavlin |
906 |
<!-- 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 |
dpavlin |
907 |
| |
53 |
|
|
; |
54 |
dpavlin |
905 |
} |
55 |
|
|
|
56 |
|
|
sub iframe_open { |
57 |
|
|
my ($self,$url,$text) = @_; |
58 |
|
|
|
59 |
|
|
qq| |
60 |
dpavlin |
906 |
<a href="$url" target="transport_iframe" onclick="ifr_show(); return true;">$text</a> |
61 |
dpavlin |
905 |
| |
62 |
|
|
} |
63 |
|
|
|
64 |
dpavlin |
1133 |
no Moose::Role; |
65 |
|
|
|
66 |
dpavlin |
905 |
1; |