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 |
return qq| |
29 |
<div> |
30 |
<a href="#" id="ifr_close" style="display:none;" onclick="ifr_close();return false;">close</a><span id="ifr_loading" style="display: none; background: #ff8;">Loading...</span> |
31 |
<!-- we really need src="#" here to avoid onload when page loads --> |
32 |
<iframe src="#" name="transport_iframe" id="transport_iframe" style="display: none;" frameborder=0 border=0 onload="ifr_transfer(this);"></iframe> |
33 |
<div id="ifr_target" style="display: none"></div> |
34 |
</div> |
35 |
| |
36 |
; |
37 |
} |
38 |
|
39 |
sub iframe_open { |
40 |
my ($self,$url,$text) = @_; |
41 |
|
42 |
qq| |
43 |
<a href="$url" target="transport_iframe" onclick="ifr_show(); return true;">$text</a> |
44 |
| |
45 |
} |
46 |
|
47 |
1; |