Permalink
Browse files

first version

  • Loading branch information...
dr4Ke
dr4Ke committed Mar 15, 2010
1 parent 17bdb20 commit f60a093d1c6ec14d1bf0ff4870f8070a5251666c
Showing with 239 additions and 0 deletions.
  1. +2 −0 README
  2. BIN images/cellbg.png
  3. +112 −0 script.js
  4. +125 −0 syntax.php
2 README
@@ -0,0 +1,2 @@
This is a plugin for dokuwiki.
It will enable syntax to set cell background in tables.
BIN +334 Bytes images/cellbg.png
Binary file not shown.
112 script.js
@@ -0,0 +1,112 @@
/* JavaScript function to create cellbg toolbar in DokuwKki */
/* see http:// for more info */
var plugin_cellbg_colors = {
"Yellow": "yellow",
"Red": "red",
"Orange": "orange",
"Salmon": "salmon",
"Pink": "pink",
"Plum": "plum",
"Purple": "purple",
"Fuchsia": "fuchsia",
"Silver": "silver",
"Aqua": "aqua",
"Teal": "teal",
"Cornflower": "#6495ed",
"Sky Blue": "skyblue",
"Aquamarine": "aquamarine",
"Pale Green": "palegreen",
"Lime": "lime",
"Green": "green",
"Olive": "olive"
//"Yellow": "#ffff00",
//"Red": "#ff0000",
//"Orange": "#ffa500",
//"Salmon": "#fa8072",
//"Pink": "#ffc0cb",
//"Plum": "#dda0dd",
//"Purple": "#800080",
//"Fuchsia": "#ff00ff",
//"Silver": "#c0c0c0",
//"Aqua": "#00ffff",
//"Teal": "#008080",
//"Cornflower": "#6495ed",
//"Sky Blue": "#87ceeb",
//"Aquamarine": "#7fffd4",
//"Pale Green": "#98fb98",
//"Lime": "#00ff00",
//"Green": "#008000",
//"Olive": "#808000"
};
function plugin_cellbg_make_color_button(name, value) {
var btn = document.createElement('button');
btn.className = 'pickerbutton';
btn.value = '';
btn.title = name;
btn.style.height = '2em';
btn.style.padding = '1em';
btn.style.backgroundColor = value;
var open = "@" + value + ":";
eval("btn.onclick = function(){ insertAtCarret( '"
+ jsEscape('wiki__text') + "','"
+ jsEscape(open) + "','"
+ "'); return false; } "
);
return(btn);
}
function plugin_cellbg_toolbar_picker() {
if (!document.getElementById('spell__action')) return;
var toolbar = document.getElementById('tool__bar');
if (!toolbar) return;
// Create the picker button
var p_id = 'picker_plugin_cellbg'; // picker id that we're creating
var p_ico = document.createElement('img');
p_ico.src = DOKU_BASE + 'lib/plugins/cellbg/images/cellbg.png';
var p_btn = document.createElement('button');
p_btn.className = 'toolbutton';
p_btn.title = 'Cell background';
p_btn.appendChild(p_ico);
eval("p_btn.onclick = function() { showPicker('"
+ p_id + "',this); return false; }");
// Create the picker <div>
var picker = document.createElement('div');
picker.className = 'picker';
picker.id = p_id;
picker.style.position = 'absolute';
picker.style.display = 'none';
// Add a button to the picker <div> for each of the colors
for( var color in plugin_cellbg_colors ) {
var btn = plugin_cellbg_make_color_button(color,
plugin_cellbg_colors[color]);
picker.appendChild(btn);
}
if (typeof user_cellbg_colors != 'undefined') {
for( var color in user_cellbg_colors ) {
var btn = plugin_cellbg_make_color_button(color,
user_cellbg_colors[color]);
picker.appendChild(btn);
}
}
var body = document.getElementsByTagName('body')[0];
body.appendChild(picker); // attach the picker <div> to the page body
toolbar.appendChild(p_btn); // attach the picker button to the toolbar
}
addInitEvent(plugin_cellbg_toolbar_picker);
//Setup VIM: ex: et ts=2 sw=2 enc=utf-8 :
@@ -0,0 +1,125 @@
<?php
/**
* cellbg Plugin: Allows user-defined colored cells in tables
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author dr4Ke <dr4ke@dr4ke.net>
* @link http://git.dr4ke.net/?p=dr4Ke/forks/dokuwiki-cells-bg.git
* @version 1.0
*
* Derived from the highlight plugin from : http://www.dokuwiki.org/plugin:highlight
* and : http://www.staddle.net/wiki/plugins/highlight
*/
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');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_cellbg extends DokuWiki_Syntax_Plugin {
function getInfo(){ // return some info
return array(
'author' => 'dr4Ke',
'email' => 'dr4ke@dr4ke.net',
'date' => '2009-12-08',
'name' => 'Cells background color plugin',
'desc' => 'Sets background of a cell with a specific color',
'url' => 'http://git.dr4ke.net/?p=dr4Ke/dokuwiki-cellbg.git',
);
}
// What kind of syntax are we?
function getType(){ return 'formatting'; }
// What kind of syntax do we allow (optional)
function getAllowedTypes() {
return array('formatting', 'substition', 'disabled');
}
// What about paragraphs? (optional)
function getPType(){ return 'normal'; }
// Where to sort in?
function getSort(){ return 200; }
// Connect pattern to lexer
function connectTo($mode) {
$this->Lexer->addSpecialPattern('^@#?[0-9a-zA-Z]*:(?=[^\n]*\|[[:space:]]*\n)',$mode,'plugin_cellbg');
}
function postConnect() {
//$this->Lexer->addExitPattern(':','plugin_cellbg');
}
// Handle the match
function handle($match, $state, $pos, &$handler){
switch ($state) {
case DOKU_LEXER_ENTER :
break;
case DOKU_LEXER_MATCHED :
break;
case DOKU_LEXER_UNMATCHED :
//return array($state, $match);
break;
case DOKU_LEXER_EXIT :
break;
case DOKU_LEXER_SPECIAL :
preg_match("/@([^:]*)/", $match, $color); // get the color
if ( $this->_isValid($color[1]) ) return array($state, $color[1], $match);
break;
}
return array($state, "yellow", $match);
}
// Create output
function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
list($state, $color, $text) = $data;
switch ($state) {
case DOKU_LEXER_ENTER :
break;
case DOKU_LEXER_MATCHED :
break;
case DOKU_LEXER_UNMATCHED :
//$renderer->doc .= $renderer->_xmlEntities($color);
break;
case DOKU_LEXER_EXIT :
break;
case DOKU_LEXER_SPECIAL :
if (preg_match('/(<td[^<>]*)>[[:space:]]*$/', $renderer->doc) != 0) {
$renderer->doc = preg_replace('/(<td[^<>]*)>[[:space:]]*$/', '\1 bgcolor='.$color.'>', $renderer->doc);
} else {
$renderer->doc .= $text;
}
break;
}
return true;
}
return false;
}
// validate color value $c
// this is cut price validation - only to ensure the basic format is
// correct and there is nothing harmful
// three basic formats "colorname", "#fff[fff]", "rgb(255[%],255[%],255[%])"
function _isValid($c) {
$c = trim($c);
$pattern = "/
(^[a-zA-Z]+$)| #colorname - not verified
(^\#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$)| #colorvalue
(^rgb\(([0-9]{1,3}%?,){2}[0-9]{1,3}%?\)$) #rgb triplet
/x";
return (preg_match($pattern, $c));
}
}
//Setup VIM: ex: et ts=4 sw=4 enc=utf-8 :

0 comments on commit f60a093

Please sign in to comment.