[pmwiki-users] Integrating JavaScript function into Custom Markup
Patrick R. Michaud
pmichaud at pobox.com
Fri Apr 7 12:49:55 CDT 2006
On Fri, Apr 07, 2006 at 06:39:58PM +0100, Hans wrote:
> Friday, April 7, 2006, 3:41:38 PM, Joshua wrote:
> > I have a custom JavaScript Function that launches a map in a new window
> > that looks like this in normal html:
> > <a href='javascript:map("map=11&1");' title="Map of Third Floor">Show
> > map of Third Floor</a>
>
> > How do I write a custom markup so that I could do this in my wiki:
>
> > (:map map=11&1 title=Map of Third Floor:) or
> > (:map map=5&1&3&5 title=Map to Central Office:)
>
> Markup('map', 'directives', "/\\(:map (.*?)?\\s*?:\\)/e", "Map('$1')");
> function Map($args) {
> $arg = PSS(ParseArgs($args));
> if (isset($arg['map'])) $map = $arg['map'];
> if (isset($arg['title'])) $maptitle = $arg['title'];
> $out = "<a href='javascript:map(\"map=$map\");' ";
> $out.= "title=\"$maptitle\">Show $maptitle</a>";
> return Keep($out);
> }
>
> Usage as (:map map=5&1&3&5 title='Map to Central Office':)
> (you need to enclose the title in hyphens)
Might want to be careful here -- the above could potentially allow
an author to inject some javascript code directly into the page
output via the map= or title arguments, since they aren't input
filtered.
However, assuming that's okay...if the arguments can contain
any quotes or backslashes, then the '$1' replacement needs a
PSS(...) around it:
Markup('map', 'directives',
"/\\(:map (.*?)?\\s*?:\\)/e",
"Map(PSS('$1'))");
You'll also want to convert any ampersands in the 'map' argument
back into ampersands (by default they're converted to '&'):
$map = str_replace('&', '&', $arg['map']);
And if the title can contain double quotes (not likely),
those need to be converted or escaped as well.
$maptitle = str_replace('"', '', $arg['maptitle']);
Pm
More information about the pmwiki-users
mailing list