Skip to content

Commit

Permalink
Item9396: JQueryPlugins depend on id's that are never added.
Browse files Browse the repository at this point in the history
- Allow JQueryPlugins to add empty header/footer content to head/body
- Allow an add to a zone with empty text (renderZone refuses to render empty
  ids anyway)
- Fixed problem where WikiWord IDs caused spurious foswikiLink markup in HTML
- Fixed code comments
- Fixed doc a little

git-svn-id: http://svn.foswiki.org/trunk@8347 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Jul 29, 2010
1 parent 96a07e4 commit 87077d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm
Expand Up @@ -111,11 +111,11 @@ sub init {
Foswiki::Func::addToZone(
'head', "JQUERYPLUGIN::" . uc( $this->{name} ),
$header, join( ', ', @dependencies )
) if $header;
);
Foswiki::Func::addToZone(
'body', "JQUERYPLUGIN::" . uc( $this->{name} ),
$footer, join( ', ', @dependencies )
) if $footer;
);

return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions core/data/System/VarADDTOZONE.txt
Expand Up @@ -12,7 +12,7 @@

_Zones_ are specific places in the output HTML that are marked with occurances of the [[VarRENDERZONE][RENDERZONE]] macro. Zones are used to collect various content together, such as Javascript and CSS markup that must be included in the output HTML in a specific order, and in a specific place.

You can create as many zones in addition to the standard [[#HeadAndBody][ =head= and =body= ]] zones as you like. Interesting use cases in wiki applications:
You may create as many zones in addition to the standard [[#HeadAndBody][ =head= and =body= ]] zones as you like. Interesting use cases in wiki applications:
* Create a =sidebar= zone to add widgets,
* Create a =toolbar= zone to add buttons icons

Expand Down Expand Up @@ -86,7 +86,7 @@ For this reason, consideration needs to be given to the way =head= and =body= zo
jQuery('#something').shake(3, 10, 180);
</script>"
requires="JQUERYPLUGIN::SHAKE"
}%</verbatim> where "MyApp::ShakePart" is a unique =id= to identify the text added to body; and =JQUERYPLUGIN::SHAKE= signifies that the content added with this identifier should appear beforehand.
}%</verbatim> where "MyApp::ShakePart" is a unique =id= to identify the text added to body; and =JQUERYPLUGIN::SHAKE= signifies that the content added with that identifier should appear beforehand.

See also [[VarRENDERZONE][RENDERZONE]],
[[http://foswiki.org/Development/UsingADDTOZONE][Using ADDTOZONE]]
6 changes: 3 additions & 3 deletions core/data/System/VarRENDERZONE.txt
Expand Up @@ -16,14 +16,14 @@ Parameters:
zone content. =%<nop>RENDERZONE{"body"}%= will be empty.
* =header="..."= optional, prefix format string
* =format="..."= optional, format string for each item added to the zone, default:
<pre>$item &lt;!-- $id $missing--&gt;</pre>Tokens:
<verbatim class="tml">$item <!--<literal> $id $missing</literal>--></verbatim>Tokens:
* =$id= - =id= of the [[VarADDTOZONE][ADDTOZONE]] call within the =zone= currently being rendered.
* =$item= - text of the [[VarADDTOZONE][ADDTOZONE]] call within the =zone= currently being rendered.
* =$zone= - the ="zone"= currently being rendered.
* =$missing= - if the [[VarADDTOZONE][ADDTOZONE]] call being rendered required any =id= which was not found, then =$missing= is the =missingtoken= parameter; empty string otherwise.
* =$missingids= - comma separated list of ids that were required by the [[VarADDTOZONE][ADDTOZONE]] call currently being rendered but weren't found within this =zone=.
* =missingtoken="..."= optional, this will be the string assigned to the =$missing= format token for use in the =format= parameter. Default:
<pre>required id(s) that were missing from $zone zone: $missingids</pre>
<verbatim class="tml">required id(s) that were missing from $zone zone: $missingids</verbatim>
* =chomp="on"= remove leading and trailing whitespace from formatted items, can be useful for pretty-printing and compression.
* =footer="..."= optional, suffix format string
* =separator="..."= optional, put between each item of a zone
Expand All @@ -38,4 +38,4 @@ required in the templates, they will be rendered automatically.

%ICON{"info"}% Zones are flushed when rendered; they may only be rendered once

See also [[VarADDTOZONE][ADDTOZONE]] for more information on zones.
See also [[VarADDTOZONE][ADDTOZONE]] for more information on zones. %JQREQUIRE{"chili"}%
29 changes: 15 additions & 14 deletions core/lib/Foswiki.pm
Expand Up @@ -3215,14 +3215,21 @@ they are added - dependencies between =$ids= in different zones will not be
resolved, except for the special case of =head= and =body= zones when
{OptimizePageLayout} is not set.
In this case, =body= is treated as an alias to =head= so that dependencies
between these two zones may be resolved.
In this case, they are treated as separate zones when adding to them, but as
one merged zone when rendering, Ie. A call to render either =head= or =body=
zones will actually render both zones in this one call. Both zones are undef'd
afterward to avoid double rendering of content from either zone, Eg. to support
proper behaviour when =head= and =body= are rendered with separate calls even
when ={OptimizePageLayout}= is not set. See ZoneTests/Item9317
* =$zone= - name of zone to add to
This behaviour allows an addToZone('head') call to require an id that has been
added to =body= only.
* =$zone= - name of zone to add to
* =$id= - identifier for the =$data= being added
* =$data= - text to be added to the zone
* =$requires= - comma separated string of =$id= identifiers of the text
within this =$zone= that should precede this =$data=
* =$data= - text to be added to the zone
* =$requires= - comma separated string of =$id= identifiers of the text
within this =$zone= that should precede this =$data=
Implements ADDTOZONE
Expand All @@ -3231,12 +3238,7 @@ Implements ADDTOZONE
sub addToZone {
my ( $this, $zone, $id, $data, $requires ) = @_;

return unless $data; # don't add empty or even undef stuff
# When {OptimizePageLayout} is NOT set, treat all adds to body zone as adds
# to head zone instead for compatibility with ADDTOHEAD usage that has
# requirements that exist in the body zone. See ZoneTests/Item9317
$requires ||= '';
$this->{$zone} ||= {};

# get a random one
unless ($id) {
Expand Down Expand Up @@ -3308,13 +3310,13 @@ sub _renderZone {
my ( $this, $zone, $params, $topicObject ) = @_;

return '' unless $zone && $this->{_zones}{$zone};

$params->{header} ||= '';
$params->{footer} ||= '';
$params->{chomp} ||= 'off';
$params->{missingformat} =
'required id(s) that were missing from $zone zone: $missingids ';
$params->{format} = '$item <!-- $id $missing-->'

$params->{format} = '$item <!--<literal> $id $missing</literal>-->'
unless defined $params->{format};
$params->{separator} = '$n' unless defined $params->{separator};

Expand Down Expand Up @@ -3389,7 +3391,6 @@ sub _renderZone {
$line =~ s/\$missingids\b/$missingids/g;
$line =~ s/\$zone\b/$item->{zone}/g;
$line = expandStandardEscapes($line);
next unless $line;
push @result, $line if $line;
}

Expand Down

0 comments on commit 87077d6

Please sign in to comment.