[Xfce4-commits] <wiki:master> Add the cellbg plugin for dokuwiki.
Jannis Pohlmann
noreply at xfce.org
Mon Jun 6 17:12:01 CEST 2011
Updating branch refs/heads/master
to 4ae135820fc73a96313e8bb62444ea1615582f20 (commit)
from 9a2305ba2e114450e2c96ad52ed4e4867628df76 (commit)
commit 4ae135820fc73a96313e8bb62444ea1615582f20
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Mon Jun 6 17:11:04 2011 +0200
Add the cellbg plugin for dokuwiki.
lib/plugins/cellbg/images/cellbg.png | Bin 0 -> 334 bytes
lib/plugins/cellbg/plugin.info.txt | 7 ++
lib/plugins/cellbg/script.js | 112 ++++++++++++++++++++++++++++++
lib/plugins/cellbg/syntax.php | 125 ++++++++++++++++++++++++++++++++++
4 files changed, 244 insertions(+), 0 deletions(-)
diff --git a/lib/plugins/cellbg/images/cellbg.png b/lib/plugins/cellbg/images/cellbg.png
new file mode 100644
index 0000000..54c025e
Binary files /dev/null and b/lib/plugins/cellbg/images/cellbg.png differ
diff --git a/lib/plugins/cellbg/plugin.info.txt b/lib/plugins/cellbg/plugin.info.txt
new file mode 100644
index 0000000..d13127c
--- /dev/null
+++ b/lib/plugins/cellbg/plugin.info.txt
@@ -0,0 +1,7 @@
+base cellbg
+author dr4ke
+email <dr4ke at dr4ke.net>
+date 2010-03-22
+name Cell Background
+desc Allows user-defined background colored cells in tables
+url http://www.dokuwiki.org/plugin:cellbg
diff --git a/lib/plugins/cellbg/script.js b/lib/plugins/cellbg/script.js
new file mode 100644
index 0000000..e911cc2
--- /dev/null
+++ b/lib/plugins/cellbg/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 :
diff --git a/lib/plugins/cellbg/syntax.php b/lib/plugins/cellbg/syntax.php
new file mode 100644
index 0000000..2c9da44
--- /dev/null
+++ b/lib/plugins/cellbg/syntax.php
@@ -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 at 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 at 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 :
More information about the Xfce4-commits
mailing list