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