Skip to content

Commit

Permalink
Item2297: this started with trying to get the latest TMCE working wit…
Browse files Browse the repository at this point in the history
…h 1.0.9. First, there's no need for a required dependency on ZonePlugin, as long as the reporting of *why* JQueryPlugins don't work is clear. Second, the checking for zone capability is *not* dependent on the plugin, but the availability of the addToZone function. Third, the JQueryPlugin doc needed some work, and still needs more to clarify the role of the macros it registers (why are these not registered as and when plugins are enabled?) Fourth, TMCE now requires jQuery, which requires addToZone, so it can safely add itself to the body. Finally, a minor improvement to the reporting of initPlugin failures. The upshot of this all is that TinyMCE + jQuery + ZonePlugin, latest trunk versions, works with 1.0.9 and 1.1.

git-svn-id: http://svn.foswiki.org/trunk@7692 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jun 8, 2010
1 parent ff1dc5e commit d50bf42
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
35 changes: 26 additions & 9 deletions JQueryPlugin/data/System/JQueryPlugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ HTML documents, handle events, perform animations, and add Ajax interactions to
your web pages."
</blockquote>

---++ Macros
Depending on what jQuery plugins are enabled, the following Foswiki macros are available. See the documentation for the individual plugins for more information.
* Enabled by the 'foswiki' jQuery plugin
* [[VarJQTHEME][%<nop>JQTHEME%]]
* [[VarJQREQUIRE][%<nop>JQREQUIRE%]]
* [[VarJQICON][%<nop>JQICON%]]
* [[VarJQICONPATH][%<nop>JQICONPATH%]]
* [[VarJQPLUGINS][%<nop>JQPLUGINS%]]
* Enabled by the 'tabpane' jQuery plugin
* [[VarTABPANE][%<nop>TABPANE%]]
* [[VarENDTABPANE][%<nop>ENDTABPANE%]]
* [[VarTAB][%<nop>TAB%]]
* [[VarENDTAB][%<nop>ENDTAB%]]
* Enabled by the 'button' jQuery plugin
* [[VarBUTTON][%<nop>BUTTON%]]
* [[VarCLEAR][%<nop>CLEAR%]]

---++ Coding Standards

See [[JQuery Coding Standards]]
Expand All @@ -38,22 +55,21 @@ using jQuery with Foswiki.
* [[http://docs.jquery.com/Using_jQuery_with_Other_Libraries][Using jQuery with other libraries]]
* [[http://docs.jquery.com/Plugins][Plugin repository]]


---++ Using compressed javascript and css files
All jQuery plugins are shipped with uncompressed js and css files, as well as minified and gzip compressed.
For instance the jquery.autocomplete comes with the following set:
1 %PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/plugins/autocomplete/jquery.autocomplete.uncompressed.js
1 %PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/plugins/autocomplete/jquery.autocomplete.js
1 %PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin/plugins/autocomplete/jquery.autocomplete.js.gz

There is a Makefile in the =%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin= root directory that grants all these
files are up to date. By default all files in the !JQueryPlugin package are up to date. So you only have to
There is a Makefile in the =%PUBURLPATH%/%SYSTEMWEB%/JQueryPlugin= root directory that ensures all these
files are up to date. By default all files in the !JQueryPlugin package are up to date, so you only have to
issue a =make= in the root directory if you wish to
modify one of the files underneath. This will update
all minified and gzipped files as needed. Enable the ={JQueryPlugin}{Debug}= flag in =configure=,
to use the uncompressed files right away to omit the =make= step during development of further javascript components.
all minified and gzipped files as required. Enable the ={JQueryPlugin}{Debug}= flag in =configure=,
to use the uncompressed files right away to omit the =make= step during development of new javascript components.

Apache can be configured to automatically use the =.gz= files if present using mod_rewrite as follows:
Apache can be configured to automatically use the =.gz= files if present using =mod_rewrite= as follows:
<verbatim>
<FilesMatch ".*\.(js|css)$">
RewriteEngine On
Expand All @@ -73,9 +89,9 @@ Apache can be configured to automatically use the =.gz= files if present using m
</Files>
</verbatim>

So whenever the browser accepts encoding the file as gzip _and_ the file with the =.gz= does exist
in the filesystem, then trigger an internal redirect while still enforcing the original mine-type.
The browser on the other side will unzip the css and js files automatically. This will drastically
So whenever the browser accepts encoding the file as gzip _and_ the file with the =.gz= exists
in the filesystem, then there will be an internal redirect in the server while still enforcing the original mime-type.
The browser on the client side will unzip the css and js files automatically. This will drastically
reduce bandwidth and speed up interactive performance.

---++ Available jQuery plugins
Expand All @@ -93,6 +109,7 @@ reduce bandwidth and speed up interactive performance.
---++ Installation Instructions
%$INSTALL_INSTRUCTIONS%

* %X% For Foswiki versions before 1.1, this plugin requires the Foswiki:Extensions.ZonePlugin to be installed. The !ZonePlugin is *not* required for Foswiki 1.1 or later.

---++ Plugin Info
| Author(s): | Michael Daum |
Expand Down
4 changes: 1 addition & 3 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ sub initPlugin {
my ( $topic, $web, $user ) = @_;

# check for prerequisites
if ( !$Foswiki::cfg{Plugins}{ZonePlugin}{Enabled}
&& $Foswiki::Plugins::VERSION < 2.1 )
{
unless (defined(&Foswiki::Func::addToZone)) {
Foswiki::Func::writeWarning(
"ZonePlugin not installed/enabled...disabling JQueryPlugin");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Foswiki::Plugins::ZonePlugin,>=2.1,perl,Required
Foswiki::Plugins::ZonePlugin,>=2.1,perl,Optional, required for Foswiki < 1.1
34 changes: 21 additions & 13 deletions TinyMCEPlugin/lib/Foswiki/Plugins/TinyMCEPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ sub _notAvailable {
return 'Unsupported browser: ' . $query->user_agent()
if $ua && $query->user_agent() && $query->user_agent() =~ /$ua/;

# This should only ever happen on Foswiki 1.0.9 and earlier
return 'TinyMCEPlugin requires ZonePlugin to be installed and enabled'
unless (defined &Foswiki::Func::addToZone);

return 0;
}

Expand Down Expand Up @@ -219,11 +223,10 @@ sub beforeEditHandler {
# URL-encode the init string
$metainit =~ s/([^0-9a-zA-Z-_.:~!*'\/%])/'%'.sprintf('%02x',ord($1))/ge;

# SMELL: meta tag now in a separate addToHEAD for Item8566, due to
# addToZONE shenanigans. <meta> tags really do have to be in the head!
Foswiki::Func::addToZone( 'head', 'tinyMCE::Meta', <<"SCRIPT");
# <meta> tags really do have to be in the head!
Foswiki::Func::addToHEAD( 'tinyMCE::Meta', <<META );
<meta name="foswiki.TINYMCEPLUGIN_INIT_ENCODED" content="$metainit" />
SCRIPT
META

my $behaving;
eval {
Expand All @@ -234,27 +237,32 @@ SCRIPT
}
};
unless ($behaving) {
Foswiki::Func::addToHEAD( 'BEHAVIOURCONTRIB',
'<script type="text/javascript" src="%PUBURLPATH%/%SYSTEMWEB%/BehaviourContrib/behaviour.js"></script>'
);
Foswiki::Func::addToHEAD( 'BEHAVIOURCONTRIB', <<SCRIPT );
<script type="text/javascript" src="%PUBURLPATH%/%SYSTEMWEB%/BehaviourContrib/behaviour.js">
</script>
SCRIPT
}

# URL-encode the version number to include in the .js URLs, so that the browser re-fetches the .js
# when this plugin is upgraded.
# URL-encode the version number to include in the .js URLs, so that
# the browser re-fetches the .js when this plugin is upgraded.
my $encodedVersion = $VERSION;

# SMELL: This regex (and the one applied to $metainit, above) duplicates Foswiki::urlEncode(),
# but Foswiki::Func.pm does not expose that function, so plugins may not use it
# SMELL: This regex (and the one applied to $metainit, above)
# duplicates Foswiki::urlEncode(), but Foswiki::Func.pm does not
# expose that function, so plugins may not use it
$encodedVersion =~
s/([^0-9a-zA-Z-_.:~!*'\/%])/'%'.sprintf('%02x',ord($1))/ge;

Foswiki::Func::addToZone( 'body', 'tinyMCE',
<<"SCRIPT", 'tinyMCE::Meta, JQUERYPLUGIN::FOSWIKI' );
my $scripts = <<SCRIPT;
<script language="javascript" type="text/javascript" src="$tmceURL/tiny_mce_jquery$USE_SRC.js?v=$encodedVersion"></script>
<script language="javascript" type="text/javascript" src="$pluginURL/foswiki_tiny$USE_SRC.js?v=$encodedVersion"></script>
<script language="javascript" type="text/javascript" src="$pluginURL/foswiki$USE_SRC.js?v=$encodedVersion"></script>
SCRIPT

Foswiki::Func::addToZone(
'body', 'tinyMCE', $scripts,
'tinyMCE::Meta, JQUERYPLUGIN::FOSWIKI' );

# See %SYSTEMWEB%.IfStatements for a description of this context id.
Foswiki::Func::getContext()->{textareas_hijacked} = 1;
}
Expand Down
5 changes: 4 additions & 1 deletion core/lib/Foswiki/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ sub registerHandlers {

unless ($status) {
if ( !$exception ) {
$exception = $sub . ' did not return true';
$exception = <<MESSAGE;
$sub did not return true.
Check your Foswiki warning and error logs for more information.
MESSAGE
}
push( @{ $this->{errors} }, $exception );
$this->{disabled} = 1;
Expand Down

0 comments on commit d50bf42

Please sign in to comment.