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 |
907 |
return qq| |
29 |
dpavlin |
906 |
<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 |
dpavlin |
907 |
| |
36 |
|
|
; |
37 |
dpavlin |
905 |
} |
38 |
|
|
|
39 |
|
|
sub iframe_open { |
40 |
|
|
my ($self,$url,$text) = @_; |
41 |
|
|
|
42 |
|
|
qq| |
43 |
dpavlin |
906 |
<a href="$url" target="transport_iframe" onclick="ifr_show(); return true;">$text</a> |
44 |
dpavlin |
905 |
| |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
1; |