fixing placement of head tags in widgets
This commit is contained in:
parent
a8dab0ac03
commit
fd48c81e76
3 changed files with 50 additions and 5 deletions
|
|
@ -1948,13 +1948,12 @@ sub outputWidgetMarkup {
|
|||
# we'll be serializing the content of the asset which is being widgetized.
|
||||
my $storage = WebGUI::Storage->get($session, $assetId);
|
||||
my $content = $self->view;
|
||||
if($styleTemplateId eq '' or $styleTemplateId eq 'none'){
|
||||
$content = $self->session->style->userStyle($content);
|
||||
}else{
|
||||
if($styleTemplateId ne '' && $styleTemplateId ne 'none'){
|
||||
$content = $self->session->style->process($content,$styleTemplateId);
|
||||
}
|
||||
WebGUI::Macro::process($session, \$content);
|
||||
my $jsonContent = to_json( { "asset$assetId" => { content => $content } } );
|
||||
my ($headTags, $body) = WebGUI::HTML::splitHeadBody($content);
|
||||
my $jsonContent = to_json( { "asset$assetId" => { content => $body } } );
|
||||
$storage->addFileFromScalar("$assetId.js", "data = $jsonContent");
|
||||
my $jsonUrl = $storage->getUrl("$assetId.js");
|
||||
|
||||
|
|
@ -1985,6 +1984,7 @@ sub outputWidgetMarkup {
|
|||
}
|
||||
YAHOO.util.Event.addListener(window, 'load', setupPage);
|
||||
</script>
|
||||
$headTags
|
||||
</head>
|
||||
<body id="widget$assetId">
|
||||
\${asset$assetId.content}
|
||||
|
|
|
|||
|
|
@ -443,5 +443,44 @@ sub splitTag {
|
|||
return $result[0];
|
||||
}
|
||||
|
||||
sub splitHeadBody {
|
||||
my $html = shift;
|
||||
|
||||
my $parser = HTML::Parser->new(api_version => 3);
|
||||
|
||||
my $head = '';
|
||||
my $body = '';
|
||||
my $accum;
|
||||
$parser->handler(start => sub {
|
||||
my ($tag, $text) = @_;
|
||||
if ($tag eq 'head') {
|
||||
$accum = \$head;
|
||||
}
|
||||
elsif ($tag eq 'body') {
|
||||
$accum = \$body;
|
||||
}
|
||||
elsif ($accum) {
|
||||
$$accum .= $text;
|
||||
}
|
||||
}, 'tagname, text');
|
||||
$parser->handler(end => sub {
|
||||
my ($tag, $text) = @_;
|
||||
if ($tag eq 'head' || $tag eq 'body') {
|
||||
$accum = undef;
|
||||
}
|
||||
elsif ($accum) {
|
||||
$$accum .= $text;
|
||||
}
|
||||
}, 'tagname, text');
|
||||
$parser->handler(default => sub {
|
||||
my ($tag, $text) = @_;
|
||||
if ($accum) {
|
||||
$$accum .= $text;
|
||||
}
|
||||
}, 'tagname, text');
|
||||
$parser->parse($html);
|
||||
return ($head, $body);
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,11 @@ sub process {
|
|||
$wgWidgetPath = $exportUrl . $extras . '/wgwidget.js';
|
||||
$scratch->delete('exportUrl');
|
||||
my $viewContent = $asset->view;
|
||||
if ($styleTemplateId ne '' && $styleTemplateId ne 'none') {
|
||||
$viewContent = $session->style->process($viewContent,$styleTemplateId);
|
||||
}
|
||||
my ($headTags, $bodyContent) = WebGUI::HTML::splitHeadBody($viewContent);
|
||||
|
||||
WebGUI::Macro::process($session, \$viewContent);
|
||||
my $containerCss = $extras . '/yui/build/container/assets/container.css';
|
||||
my $containerJs = $extras . '/yui/build/container/container-min.js';
|
||||
|
|
@ -95,9 +100,10 @@ sub process {
|
|||
}
|
||||
YAHOO.util.Event.addListener(window, 'load', setupPage);
|
||||
</script>
|
||||
$headTags
|
||||
</head>
|
||||
<body id="widget$assetId">
|
||||
$viewContent
|
||||
$bodyContent
|
||||
</body>
|
||||
</html>
|
||||
OUTPUT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue