Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Szymon Olewniczak
committed
Jun 17, 2013
0 parents
commit 3dc05c2
Showing
3 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
base tablefilterjs | ||
author Szymon Olewniczak | ||
email szymon.olewniczak@rid.pl | ||
date 2011-05-10 | ||
name Table Filter JavaScript | ||
desc Filter dokuwiki tables using regexs | ||
url http://www.dokuwiki.org/plugin:tablefilterjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
tablefilterjs = {}; | ||
tablefilterjs.decodeHTML = function(text) | ||
{ | ||
return jQuery('<div/>').html(text).text(); | ||
}; | ||
tablefilterjs.find_th_eq = function( col, $table ) | ||
{ | ||
var eq = -1; | ||
$table.find('th').each(function() { | ||
if( jQuery(this).text() == col ) | ||
eq = jQuery(this).index(); | ||
}); | ||
return eq; | ||
} | ||
jQuery(document).ready(function () | ||
{ | ||
jQuery(".tablefilterjs").each(function() { | ||
$table = jQuery(this).find("table"); | ||
|
||
var filters = jQuery.parseJSON( tablefilterjs.decodeHTML(jQuery(this).data("filters")) ); | ||
|
||
for( col in filters ) | ||
{ | ||
if( isNaN( col ) ) | ||
{ | ||
var eq = tablefilterjs.find_th_eq( col, $table ); | ||
if( eq == -1) | ||
continue; | ||
} else | ||
{ | ||
var eq = parseInt( col ) - 1; | ||
} | ||
var regex = new RegExp( filters[col][0], filters[col][1] ); | ||
$table.find("tr:has(td)").each(function() { | ||
if( ! jQuery(this).find("td").eq(eq).text().match( regex ) ) | ||
jQuery(this).hide(); | ||
}); | ||
} | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?php | ||
/** | ||
* | ||
* @license GPL 3 (http://www.gnu.org/licenses/gpl.html) | ||
* @author Szymon Olewniczak | ||
*/ | ||
// must be run within Dokuwiki | ||
if (!defined('DOKU_INC')) die(); | ||
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); | ||
require_once(DOKU_PLUGIN.'syntax.php'); | ||
|
||
class syntax_plugin_tablefilterjs extends DokuWiki_Syntax_Plugin { | ||
|
||
function getType() { return 'container';} | ||
function getPType(){ return 'block';} | ||
function getSort() { return 500; } | ||
function getAllowedTypes() {return array('container','formatting','substition');} | ||
function connectTo($mode) { | ||
$this->Lexer->addEntryPattern('<filter[^>]*>(?=.*?</filter>)',$mode,'plugin_tablefilterjs'); | ||
} | ||
function postConnect() { | ||
$this->Lexer->addExitPattern('</filter>','plugin_tablefilterjs'); | ||
} | ||
function __filter_data($str) | ||
{ | ||
$filter_data = array(); | ||
|
||
$key = ''; | ||
|
||
//0 no 1 | ||
$in_str = 0; | ||
//0 header 1 regex | ||
$state = 0; | ||
for( $i = 0; $i < strlen( $str ); $i++ ) | ||
{ | ||
if($state == 0) | ||
{ | ||
if( $str[$i] == '=' ) | ||
{ | ||
$state = 1; | ||
|
||
while( $str[$i] != '/' ) | ||
{ | ||
$i++; | ||
if( $i == strlen( $str ) ) | ||
{ | ||
return $filter_data; | ||
} | ||
} | ||
|
||
//$filter_data[ trim($key) ] .= $str[ $i ]; | ||
|
||
} else | ||
{ | ||
|
||
if( $in_str == 1 && $str[$i] == '\\' ) | ||
{ | ||
$i++; | ||
$key .= $str[ $i ]; | ||
continue; | ||
} | ||
|
||
if( $str[$i] == '"' || $str[$i] == "'") | ||
{ | ||
if( $in_str == 1 ) | ||
$in_str = 0; | ||
else | ||
$in_str = 1; | ||
continue; | ||
} | ||
|
||
$key .= $str[ $i ]; | ||
} | ||
|
||
} else | ||
{ | ||
if( $str[$i] == '/' ) | ||
{ | ||
$i++; | ||
$state = 0; | ||
while( $str[$i] != ' ' && $i < strlen( $str ) ) | ||
{ | ||
$filter_data[ trim($key) ][1] .= $str[ $i ]; | ||
$i++; | ||
if( $i == strlen( $str ) ) | ||
{ | ||
return $filter_data; | ||
} | ||
} | ||
$key = ''; | ||
continue; | ||
} | ||
$filter_data[ trim($key) ][0] .= $str[ $i ]; | ||
} | ||
} | ||
return $filter_data; | ||
} | ||
function __encodeHTML($str) | ||
{ | ||
return str_replace(array('"', '\'', '&', '<'), array('"', ''', '&', '<'), $str); | ||
} | ||
function handle($match, $state, $pos, &$handler){ | ||
|
||
switch ($state) { | ||
case DOKU_LEXER_ENTER : | ||
$match = substr($match,8,-1); | ||
|
||
return array($state, $this->__filter_data($match)); | ||
break; | ||
case DOKU_LEXER_UNMATCHED : | ||
return array($state, $match); | ||
break; | ||
case DOKU_LEXER_EXIT : | ||
return array($state, ""); | ||
break; | ||
} | ||
return array(); | ||
} | ||
|
||
function render($mode, &$renderer, $data) { | ||
list($state,$match) = $data; | ||
if ($mode == 'xhtml'){ | ||
switch ($state) { | ||
case DOKU_LEXER_ENTER : | ||
$json = new JSON(); | ||
$renderer->doc .= '<div class="tablefilterjs" data-filters="'.$this->__encodeHTML($json->encode($match)).'">'; | ||
break; | ||
case DOKU_LEXER_UNMATCHED : | ||
$instructions = p_get_instructions($match); | ||
foreach ($instructions as $instruction) { | ||
call_user_func_array(array(&$renderer, $instruction[0]),$instruction[1]); | ||
} | ||
break; | ||
case DOKU_LEXER_EXIT : | ||
$renderer->doc .= "</div>"; | ||
break; | ||
} | ||
return true; | ||
} | ||
} | ||
} |