From 79b376f9912891a8748fcbb4580969e4dbf7fc75 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 17 Oct 2008 20:28:18 -0400 Subject: Add an underlay for javascript, and add ikiwiki.js containing some utility code. * Add an underlay for javascript, and add ikiwiki.js containing some utility code. * toggle: Stop embedding the full toggle code on each page using it, and move it to toggle.js in the javascript underlay. --- IkiWiki/Plugin/attachment.pm | 7 +++-- IkiWiki/Plugin/toggle.pm | 69 ++++++++--------------------------------- debian/changelog | 9 ++++++ doc/plugins/write.mdwn | 29 +++++++++++++++++ po/ikiwiki.pot | 16 +++++----- underlays/javascript/ikiwiki.js | 37 ++++++++++++++++++++++ underlays/javascript/toggle.js | 29 +++++++++++++++++ 7 files changed, 129 insertions(+), 67 deletions(-) create mode 100644 underlays/javascript/ikiwiki.js create mode 100644 underlays/javascript/toggle.js diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index dcac3e820..6c1df488a 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -6,6 +6,7 @@ use strict; use IkiWiki 2.00; sub import { #{{{ + add_underlay("javascript"); hook(type => "getsetup", id => "attachment", call => \&getsetup); hook(type => "checkconfig", id => "attachment", call => \&checkconfig); hook(type => "formbuilder_setup", id => "attachment", call => \&formbuilder_setup); @@ -104,10 +105,10 @@ sub formbuilder_setup (@) { #{{{ $form->tmpl_param("field-upload" => ''); $form->tmpl_param("field-link" => ''); - # Add the javascript from the toggle plugin; - # the attachments interface uses it to toggle visibility. + # Add the toggle javascript; the attachments interface uses + # it to toggle visibility. require IkiWiki::Plugin::toggle; - $form->tmpl_param("javascript" => $IkiWiki::Plugin::toggle::javascript); + $form->tmpl_param("javascript" => IkiWiki::Plugin::toggle::include_javascript($params{page}, 1)); # Start with the attachments interface toggled invisible, # but if it was used, keep it open. if ($form->submitted ne "Upload Attachment" && diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index 610d38e3a..657d8d3c2 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -5,61 +5,8 @@ use warnings; use strict; use IkiWiki 2.00; -# Here's the javascript that makes this possible. A key feature is the use -# of css to hide toggleables, to avoid any flashing on page load. The css -# is only emitted after the javascript tests that it's going to be able to -# show the toggleables. -our $javascript=<<'EOF'; - -EOF - sub import { #{{{ + add_underlay("javascript"); hook(type => "getsetup", id => "toggle", call => \&getsetup); hook(type => "preprocess", id => "toggle", call => \&preprocess_toggle); @@ -121,12 +68,22 @@ sub format (@) { #{{{ if ($params{content}=~s!(
\s*)
!$1!g) { $params{content}=~s/
//g; - if (! ($params{content}=~s!^!$javascript!m)) { + if (! ($params{content}=~s!^()!$1.include_javascript($params{page})!em)) { # no tag, probably in preview mode - $params{content}=$javascript.$params{content}; + $params{content}=include_javascript($params{page}, 1).$params{content}; } } return $params{content}; } # }}} +sub include_javascript ($;$) { #{{{ + my $page=shift; + my $absolute=shift; + + return ''."\n". + ''; +} #}}} + 1 diff --git a/debian/changelog b/debian/changelog index b93da0aae..66d108e9e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +ikiwiki (2.68) UNRELEASED; urgency=low + + * Add an underlay for javascript, and add ikiwiki.js containing some utility + code. + * toggle: Stop embedding the full toggle code on each page using it, and + move it to toggle.js in the javascript underlay. + + -- Joey Hess Fri, 17 Oct 2008 20:11:02 -0400 + ikiwiki (2.67) unstable; urgency=low * remove: Avoid $_ breakage. (Stupid, stupid perl.) diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 1b78f5900..daf70c8e2 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -847,3 +847,32 @@ to a hash containing all the config items. They should also implement a By the way, to parse a ikiwiki setup file and populate `%config`, a program just needs to do something like: `use IkiWiki::Setup; IkiWiki::Setup::load($filename)` + +### Javascript + +Some plugins use javascript to make ikiwiki look a bit more web-2.0-ish. + +All javascript code should be put in `.js` files in the `javascript` +underlay, and plugins using those files can enable use of the underlay by +calling `add_underlay("javascript");` in their `import` function. + +You'll have to arrange for `