1<?php
2/**
3 * SearchTablejs: Javascript for Searchable table
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Robert Henjes
7 * version 0.1 Initial version copied from sortablejs plugin
8 */
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'syntax.php');
13
14class syntax_plugin_searchtablejs extends DokuWiki_Syntax_Plugin {
15
16  function getInfo(){
17    return array(
18      'author' => 'Robert Henjes',
19      'email'  => 'dokuwiki@rhenjes.de',
20      'date'   => '2010-10-22',
21      'name'   => 'Searchable javascript',
22      'desc'   => 'Add <searchtable>  and </searchtable> around your table.',
23      'url'    => 'http://github.com/xdreamer/searchtablejs/',
24    );
25  }
26  function getType() { return 'container';}
27  function getPType(){ return 'normal';}
28  function getSort() { return 999; }
29
30  //Fix compatibility with edittable
31  function getAllowedTypes() {return array('container','formatting','substition');}
32
33  function connectTo($mode) {
34    $this->Lexer->addEntryPattern('<searchtable[^>]*>(?=.*?\x3C/searchtable\x3E)',$mode,'plugin_searchtablejs');
35  }
36  function postConnect() {
37    $this->Lexer->addExitPattern('</searchtable>','plugin_searchtablejs');
38  }
39  function handle($match, $state, $pos, Doku_Handler $handler){
40
41    switch ($state) {
42      case DOKU_LEXER_ENTER :
43        $match = substr($match,12,-1);
44        $match=trim($match);
45        $scl="";
46        if (strlen($match)>0) {
47          $scl=" search$match";
48        }
49        return array($state, $scl);
50        break;
51      case DOKU_LEXER_UNMATCHED :
52        return array($state, $match);
53        break;
54      case DOKU_LEXER_EXIT :
55        return array($state, "");
56        break;
57    }
58    return array();
59  }
60
61  function render($mode, Doku_Renderer $renderer, $data) {
62    list($state,$match) = $data;
63    if ($mode == 'xhtml'){
64      switch ($state) {
65        case DOKU_LEXER_ENTER :
66          $id = mt_rand();
67          $renderer->doc .= '<div class="searchtable'.$match.'" id="'.$id.'">';
68          $renderer->doc .= 'Filter: <form class="searchtable" onsubmit="return false;"><input class="searchtable" name="filtertable" onkeyup="searchtable.filterall(this, \''.$id.'\')" type="text"></form>';
69          break;
70        case DOKU_LEXER_UNMATCHED :
71          $renderer->doc .= p_render('xhtml',p_get_instructions($match),$info);
72          break;
73        case DOKU_LEXER_EXIT :
74          $renderer->doc .=  '</div>';
75          break;
76      }
77      return true;
78    }
79    return false;
80  }
81}
82?>
83