[pmwiki-devel] How to create a GUIEdit button using Javascript

Peter Bowers pbowers at pobox.com
Fri Sep 19 04:37:13 CDT 2014


On Fri, Sep 19, 2014 at 8:31 AM, Randy Brown <randy at brownragfilms.com>
wrote:

> $num = rand ( 1, 1000 );
> SDVA($GUIButtons, array(
>   'mybutton'       => array(8000, "{(mymarkupexpression ".$num." "",
> "")}\\nThe above number is ".$num."\\n", '$[Default text if none
> selected]',
>                   '$GUIButtonDirUrlFmt/mybuttonicon.png"$[DoXYZ]"','')
> ));
> $HTMLHeaderFmt['DoXYZ']= <<<EOF
> <script type='text/javascript'><!--
> function DoXYZ() {
>
> I IMAGINE THERE IS A WAY TO DO THIS IN JAVASCRIPT
>
>   return;
> }
> //--></script>
>
> EOF;
>

I don't think there's an easily configurable way to do this (i.e., nothing
as simple as adding something to $GUIButtons - insButton() doesn't support
executable javascript code due to quoting).  However, in the spirit of
fairly messy code that seems to work, try this in config.php:

===(snip)===
Markup('e_guibuttons', 'directives',
  '/\\(:e_guibuttons:\\)/e',
  "Keep(FmtPageName(GUIButtonCode(\$pagename), \$pagename).'<script
type=\'text/javascript\'><!--\nInsertSpecialBtn();//--></script>')");
SDVA($HTMLHeaderFmt, array('guiedit2' => "<script type='text/javascript'>
    function DoSpecialBtn()
    {
        var num = Math.floor(Math.random()*10)+1;
        insMarkup('{(mymarkupexpression '+num+ ' \"', '\")}\\nThe above
number is '+num, 'My text');
    }
    function InsertSpecialBtn()
    {
        document.write('<a tabindex=\"-1\" r
onclick=\"DoSpecialBtn()\">asdf</a>');
    }
</script>\n"));
===(snip)===

It basically overrides the e_guibuttons markup so it will add your special
button immediately after the rest of the GUI buttons.  Then it defines a
short javascript with a function to insert the button and another function
to calculate the random number and construct your text.

Note that I've hardcoded the random number to be between 1 and 10,
hardcoded the access key to r, hardcoded the button to the imaginative text
of "asdf", etc - it's messy but should get you 90% of the way there.

-Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-devel/attachments/20140919/77580e88/attachment.html>


More information about the pmwiki-devel mailing list