User Tools

Site Tools


Action disabled: source
docs:development:dokuwiki:jslink:index.html

Dokuwiki Javascript Plugin

This is a rather dump plugin for DokuWiki to allow for HREF=“javascript:…” links.

<?php
/**
 * Javascript link plugin. Lets you use action links in your wiki syntax.
 * Based on plugin syntax:actionlink.
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author Andreas Gohr <andi@splitbrain.org>
 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
 * @author nowotny <nowotnypl@gmail.com>
 * @author Peter J. Weyers
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
class syntax_plugin_jslink extends DokuWiki_Syntax_Plugin {
 
    function getInfo(){
        return array(
            'author' => 'Peter J. Weyers',
            'email'  => '',
            'date'   => '2012-03-14',
            'name'   => 'JSlink plugin',
            'desc'   => 'JSlink plugin lets you use javascript in your wiki syntax.
                              Basic syntax: {{js>code|title}}',
            'url'    => 'http://www.usr-local.org/wiki/doku.php/docs/development/dokuwiki_jslink/index.html',
        );
    }
 
    function getType(){
        return 'substition';
    }
 
    function getSort(){
        return 306;
    }
 
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern('\{\{js>.+?\}\}',$mode,'plugin_jslink');
    }

    function handle($match, $state, $pos, &$handler){
              $match = substr($match,5, -2);
              $matches=explode('|', $match, 2);
              return array('payload'=>hsc($matches[0]),'title'=>hsc($matches[1]));
    }
 
    function render($mode, &$renderer, $data){
      if($mode == 'xhtml'){

              if(!empty($data['payload'])) $payload=$data['payload'];
              else $payload='void();';
              if(!empty($data['title'])) $title=$data['title'];

              $renderer->doc .= '<A HREF="javascript:'.$data['payload'].'">'.$title.'(4)</A>';
        }
        return false;
    }
}
docs/development/dokuwiki/jslink/index.html.txt · Last modified: 22.03.2012 13:13 CET by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki