Skip to content

Commit

Permalink
Item8655: Converted all calls to addToZone() into a call to JQueryPlu…
Browse files Browse the repository at this point in the history
…gin's own private wrapper for this method. If Foswiki::Func::addToZone() is missing, it calls addToHEAD() instead.

git-svn-id: http://svn.foswiki.org/trunk@6642 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
PaulHarvey authored and PaulHarvey committed Mar 4, 2010
1 parent 228c9bf commit f87063f
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions JQueryPlugin/data/System/JQueryPlugin.txt
Expand Up @@ -101,6 +101,7 @@ reduce bandwidth and speed up interactive performance.
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 03 Mar 2010: | made ZonePlugin an optional dependency |
| 01 Mar 2010: | improved js and css compression using yuicompressor; \
improved simplemodal integration to foswiki to create modal dialogs with less additional javascript; \
added custom events to textboxlist: <nop>AddValue, <nop>DeleteValue , Reset and Clear |
Expand Down
Expand Up @@ -12,9 +12,11 @@ sub check {
my $warnings;

if ( $Foswiki::cfg{Plugins}{JQueryPlugin}{Enabled} ) {
if ( !$Foswiki::cfg{Plugins}{ZonePlugin}{Enabled} ) {
$warnings .= $this->ERROR(<<'HERE');
JQueryPlugin depends on ZonePlugin, which is not enabled.
if ( not exists &Foswiki::Func::addToZone ) {
$warnings .= $this->NOTE(<<'HERE');
ZonePlugin is not enabled. With ZonePlugin, JQueryPlugin can optimise the
placement of <code>&lt;script&gt;</code> tags in the rendered XHTML for better
web browser page load performance.
HERE
}
}
Expand Down
23 changes: 23 additions & 0 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin.pm
Expand Up @@ -14,6 +14,7 @@
#
package Foswiki::Plugins::JQueryPlugin;
use strict;
use warnings;

=begin TML
Expand Down Expand Up @@ -415,4 +416,26 @@ sub handleJQueryPlugins {
return $theHeader.join($theSeparator, @result).$theFooter;
}

=begin TML
---++ ourAddToZone($zone, $tag, $text, $requires)
This is a simple wrapper to call Foswiki::Func::addToZone() if available, or
Foswiki::Func::addToHead() otherwise (in which case, everything is added to head)
=cut

sub ourAddToZone {
my ($zone, $tag, $text, $requires) = @_;

if (not exists &Foswiki::Func::addToZone) {
Foswiki::Func::addToHEAD($tag, $text, $requires);
} else {
Foswiki::Func::addToZone($zone, $tag, $text, $requires);
}

return;
}


1;
2 changes: 1 addition & 1 deletion JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/DEPENDENCIES
@@ -1,2 +1,2 @@
Foswiki::Plugins::ZonePlugin,>=1.0,perl,Required.
Foswiki::Plugins::ZonePlugin,>=1.0,perl,Optional

5 changes: 3 additions & 2 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
Expand Up @@ -15,6 +15,7 @@

package Foswiki::Plugins::JQueryPlugin::FOSWIKI;
use strict;
use warnings;
use Foswiki::Func;
use base 'Foswiki::Plugins::JQueryPlugin::Plugin';

Expand Down Expand Up @@ -89,8 +90,8 @@ HERE

my $footer = "<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/plugins/foswiki/$js'></script>\n";

Foswiki::Func::addToZone('head', 'JQUERYPLUGIN::FOSWIKI', $header, 'JQUERYPLUGIN');
Foswiki::Func::addToZone('body', 'JQUERYPLUGIN::FOSWIKI', $footer, 'JQUERYPLUGIN');
Foswiki::Plugins::JQueryPlugin::ourAddToZone('head', 'JQUERYPLUGIN::FOSWIKI', $header, 'JQUERYPLUGIN');
Foswiki::Plugins::JQueryPlugin::ourAddToZone('body', 'JQUERYPLUGIN::FOSWIKI', $footer, 'JQUERYPLUGIN');

}

Expand Down
5 changes: 3 additions & 2 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/GRID.pm
Expand Up @@ -15,6 +15,7 @@

package Foswiki::Plugins::JQueryPlugin::GRID;
use strict;
use warnings;

use base 'Foswiki::Plugins::JQueryPlugin::Plugin';
use Foswiki::Form ();
Expand Down Expand Up @@ -85,7 +86,7 @@ sub init {
unless -f $Foswiki::cfg{PubDir}.'/'.$localePath;

my $header .= "<script type='text/javascript' src='$Foswiki::cfg{PubUrlPath}/$localePath'></script>\n";
Foswiki::Func::addToZone('body', "JQUERYPLUGIN::GRID::LANG", $header, 'JQUERYPLUGIN::UI');
Foswiki::Plugins::JQueryPlugin::ourAddToZone('body', "JQUERYPLUGIN::GRID::LANG", $header, 'JQUERYPLUGIN::UI');
}

=begin TML
Expand Down Expand Up @@ -221,7 +222,7 @@ jQuery(document).ready(function(){
</script>
HERE

Foswiki::Func::addToZone('body', "JQUERYPLUGIN::GRID::$gridId", $jsTemplate, 'JQUERYPLUGIN::GRID');
Foswiki::Plugins::JQueryPlugin::ourAddToZone('body', "JQUERYPLUGIN::GRID::$gridId", $jsTemplate, 'JQUERYPLUGIN::GRID');

my $result = "<table id='$gridId'></table>";
$result .= "<div id='$pagerId'></div>" if $thePager eq 'on';
Expand Down
5 changes: 3 additions & 2 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm
Expand Up @@ -18,6 +18,7 @@ package Foswiki::Plugins::JQueryPlugin::Plugin;
use Foswiki::Plugins::JQueryPlugin::Plugins ();

use strict;
use warnings;

=begin TML
Expand Down Expand Up @@ -120,9 +121,9 @@ sub init {
}
}

Foswiki::Func::addToZone('head', "JQUERYPLUGIN::".uc($this->{name}), $header, join(', ', @dependencies))
Foswiki::Plugins::JQueryPlugin::ourAddToZone('head', "JQUERYPLUGIN::".uc($this->{name}), $header, join(', ', @dependencies))
if $header;
Foswiki::Func::addToZone('body', "JQUERYPLUGIN::".uc($this->{name}), $footer, join(', ', @dependencies))
Foswiki::Plugins::JQueryPlugin::ourAddToZone('body', "JQUERYPLUGIN::".uc($this->{name}), $footer, join(', ', @dependencies))
if $footer;

return 1;
Expand Down
3 changes: 2 additions & 1 deletion JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/Plugins.pm
Expand Up @@ -13,6 +13,7 @@

package Foswiki::Plugins::JQueryPlugin::Plugins;
use strict;
use warnings;

our @iconSearchPath;
our %iconCache;
Expand Down Expand Up @@ -61,7 +62,7 @@ sub init () {
$footer .= "\n<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/jquery.noconflict.js'></script>"
if $Foswiki::cfg{JQueryPlugin}{NoConflict};

Foswiki::Func::addToZone('body', 'JQUERYPLUGIN', $footer);
Foswiki::Plugins::JQueryPlugin::ourAddToZone('body', 'JQUERYPLUGIN', $footer);

# initial plugins
createPlugin('Foswiki'); # this one is needed anyway
Expand Down
3 changes: 2 additions & 1 deletion JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/TOGGLE.pm
Expand Up @@ -15,6 +15,7 @@

package Foswiki::Plugins::JQueryPlugin::TOGGLE;
use strict;
use warnings;
use base 'Foswiki::Plugins::JQueryPlugin::Plugin';

=begin TML
Expand Down Expand Up @@ -95,7 +96,7 @@ sub handleToggle {
my $cmd = "function() {\$('$theTarget').each(function() {\$(this).is(':visible')?\$(this).$showEffect:\$(this).$hideEffect;});return false;}";
my $toggleId = "jqToggle".Foswiki::Plugins::JQueryPlugin::Plugins::getRandom();

Foswiki::Func::addToZone("head", "JQUERYPLUGIN::TOGGLE::$toggleId", <<"HERE", 'JQUERYPLUGIN::TOGGLE');
Foswiki::Plugins::JQueryPlugin::ourAddToZone("head", "JQUERYPLUGIN::TOGGLE::$toggleId", <<"HERE", 'JQUERYPLUGIN::TOGGLE');
<meta name="foswiki.jquery.toggle.$toggleId" content="{id:'$toggleId', onclick:$cmd}" />
HERE

Expand Down
3 changes: 2 additions & 1 deletion JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/VALIDATE.pm
Expand Up @@ -15,6 +15,7 @@

package Foswiki::Plugins::JQueryPlugin::VALIDATE;
use strict;
use warnings;

use base 'Foswiki::Plugins::JQueryPlugin::Plugin';

Expand Down Expand Up @@ -72,7 +73,7 @@ sub init {
my $messageFile = $Foswiki::cfg{PubDir}.'/'.$messagePath;
if (-f $messageFile) {
$header .= "<script type='text/javascript' src='$Foswiki::cfg{PubUrlPath}/$messagePath'></script>\n";
Foswiki::Func::addToZone('body', "JQUERYPLUGIN::VALIDATE::LANG", $header, 'JQUERYPLUGIN::VALIDATE');
Foswiki::Plugins::JQueryPlugin::ourAddToZone('body', "JQUERYPLUGIN::VALIDATE::LANG", $header, 'JQUERYPLUGIN::VALIDATE');
}

}
Expand Down

0 comments on commit f87063f

Please sign in to comment.