1 |
package Frey::Web::IFrame; |
2 |
use Moose; |
3 |
|
4 |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
6 |
#with 'Frey::Storage'; |
7 |
|
8 |
has skeleton => ( |
9 |
is => 'rw', |
10 |
isa => 'Str', |
11 |
required => 1, |
12 |
default => 'skeleton', |
13 |
); |
14 |
|
15 |
sub as_markup { |
16 |
my ($self) = @_; |
17 |
|
18 |
$self->add_js(q` |
19 |
function ifr_close() { |
20 |
self.document.getElementById('ifr_target').style.display = 'none'; |
21 |
self.document.getElementById('ifr_close').style.display = 'none'; |
22 |
} |
23 |
function ifr_show() { |
24 |
self.document.getElementById('ifr_loading').style.display=''; |
25 |
} |
26 |
function ifr_transfer(f) { |
27 |
self.document.getElementById('ifr_loading').style.display='none'; |
28 |
self.document.getElementById('ifr_close').style.display=''; |
29 |
if ( f.contentWindow.document.body ) { |
30 |
var ifr_target = self.document.getElementById('ifr_target'); |
31 |
ifr_target.innerHTML = f.contentWindow.document.body.innerHTML; |
32 |
f.contentWindow.document.body.innerHTML = ''; // XXX we can't just undef here! |
33 |
ifr_target.style.display = ''; |
34 |
console.log( ifr_target ); |
35 |
} |
36 |
} |
37 |
`); |
38 |
|
39 |
my $html = qq| |
40 |
<div> |
41 |
<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> |
42 |
<!-- we really need src="#" here to avoid onload when page loads --> |
43 |
<iframe src="#" name="transport_iframe" id="transport_iframe" style="display: none;" frameborder=0 border=0 onload="ifr_transfer(this);"></iframe> |
44 |
<div id="ifr_target" style="display: none"></div> |
45 |
</div> |
46 |
|; |
47 |
|
48 |
$html .= $self->iframe_open('/Frey::Web::IFrame','introspect in iframe'); |
49 |
|
50 |
return $html; |
51 |
} |
52 |
|
53 |
sub iframe_open { |
54 |
my ($self,$url,$text) = @_; |
55 |
|
56 |
qq| |
57 |
<a href="$url" target="transport_iframe" onclick="ifr_show(); return true;">$text</a> |
58 |
| |
59 |
} |
60 |
|
61 |
1; |