From 56d5414e272b5bb07ff05ddae0e3471e587c1965 Mon Sep 17 00:00:00 2001 From: kochi Date: Sun, 20 Sep 2015 10:31:16 +0200 Subject: [PATCH 1/3] Use CSS style for background color instead of attribut bgcolor. --- syntax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax.php b/syntax.php index 7cfd30d..e6c51ad 100644 --- a/syntax.php +++ b/syntax.php @@ -92,7 +92,7 @@ function render($mode, &$renderer, $data) { break; case DOKU_LEXER_SPECIAL : if (preg_match('/(]*)>[[:space:]]*$/', $renderer->doc) != 0) { - $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 bgcolor='.$color.'>', $renderer->doc); + $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 style="background-color:'.$color.'">', $renderer->doc); } else { $renderer->doc .= $text; } From 718c4f6583fe92351d8f03efb165973a148b46e7 Mon Sep 17 00:00:00 2001 From: kochi Date: Mon, 21 Sep 2015 16:52:38 +0200 Subject: [PATCH 2/3] Toolbar icon for cellbg plugin --- action/toolbar.php | 67 +++++++++++++++ conf/default.php | 6 ++ conf/metadata.php | 10 +++ images/cellbg-toolbar.png | Bin 0 -> 1053 bytes images/cellbg.png | Bin 334 -> 0 bytes images/gradient.png | Bin 0 -> 209 bytes lang/cs/lang.php | 12 +++ lang/cs/settings.php | 11 +++ lang/en/lang.php | 10 +++ lang/en/settings.php | 11 +++ script.js | 173 +++++++++++++++----------------------- style.css | 23 +++++ syntax.php | 19 +++-- 13 files changed, 230 insertions(+), 112 deletions(-) create mode 100644 action/toolbar.php create mode 100644 conf/default.php create mode 100644 conf/metadata.php create mode 100644 images/cellbg-toolbar.png delete mode 100644 images/cellbg.png create mode 100644 images/gradient.png create mode 100644 lang/cs/lang.php create mode 100644 lang/cs/settings.php create mode 100644 lang/en/lang.php create mode 100644 lang/en/settings.php create mode 100644 style.css diff --git a/action/toolbar.php b/action/toolbar.php new file mode 100644 index 0000000..0e93657 --- /dev/null +++ b/action/toolbar.php @@ -0,0 +1,67 @@ + + */ +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +/** + * Class action_plugin_cellbg_toolbar + */ +class action_plugin_cellbg_toolbar extends DokuWiki_Action_Plugin { + + /** + * Register event handlers. + * + * @param Doku_Event_Handler $controller The plugin controller + */ + public function register(Doku_Event_Handler $controller) { + if($this->getConf('toolbar_icon')) $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insert_toolbar_button', array ()); + } + + /** + * Inserts the cellbg toolbar button + */ + function insert_toolbar_button(Doku_Event &$event, $param) { + $defaultColors = array( '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' + ); + $custom_colors = array(); + if($this->getConf('custom_colors')) + { + $custom_colors_lines = explode(DOKU_LF, $this->getConf('custom_colors')); + foreach ($custom_colors_lines as $line) { + list($colerName, $color) = explode('=', $line); + $custom_colors[$colerName] = $color; + } + } + $event->data[] = array ( + 'type' => 'CellbgPicker', + 'title' => $this->getLang('toolbar_icon'), + 'icon' => '../../plugins/cellbg/images/cellbg-toolbar.png', + 'open' => '@#', + 'colorlist' => array_merge($defaultColors, $custom_colors), + 'sample' => 'RRGGBB', + 'close' => ':' + ); + } +} \ No newline at end of file diff --git a/conf/default.php b/conf/default.php new file mode 100644 index 0000000..ffa6d73 --- /dev/null +++ b/conf/default.php @@ -0,0 +1,6 @@ + + */ + +$meta['toolbar_icon'] = array('onoff'); +$meta['custom_colors'] = array(''); diff --git a/images/cellbg-toolbar.png b/images/cellbg-toolbar.png new file mode 100644 index 0000000000000000000000000000000000000000..1cb073052c8d3177a19cf7012488578512d0ea22 GIT binary patch literal 1053 zcmV+&1mgRNP)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ<08mU+MF9Ui095}(L`45{0 zD=aK5EiElBE-o)GFEB7LF)=YRGBPtWGc+_bH8nLhHa0gmH#j&rIXO8xIyyT$J3Kr* zJv}`>K0ZG`KR`f0K|w)6LPA4BLqtSGMMXtMMn*?RM@UFWNl8gcN=i#hOH52mO-)Ts zPEJoxPf$=$QBhG+Qc_b>Q&dz`RaI41R#sP6S6EnBSy@?HT3TCMTU=aRU0q#XUS3~c zUtnNhVPRonVq#-sV`OAxWo2b%W@cw+XJ}|>X=!O{YHDk1Yiw+6ZEbCCZf7mzbECnVFfInwp!No1C1Sot>SYo}QndpP-Ll?si~=|s;aB2tE{Z7t*x!DuCA}IuduMNv9YnTva++Yv$V9dwY9aj zwzjvox45{txw*Nzy1Ki&yS%)-y}iA@zP`V|zreu2!NI}8!otJD!^FhI#l^+O#>U6T z$H>UY$;rve%F4^j%goHo&CSiu&d$%z&(P4&(b3V;($dq@)6~?|)z#J3*4Ee8*Vx$D z+1c6J+S=RO+uYpT-QC^Z-rnEe-{9cj;o;%p;^O1ulq(=H}<;=jiC@>FMd} z>gwz3>+J08?d|RE?(XmJ@9^;O@$vEU^78ZZ^Yrxe_4W1k_V)Mp_xSku`T62p}{8CMJLYVnE|F0R$KT XR$Bx}ahD-f00000NkvXXu0mjf(w@r$ literal 0 HcmV?d00001 diff --git a/images/cellbg.png b/images/cellbg.png deleted file mode 100644 index 54c025efa94b8b1a81274ba3f2741d0f7e74c76c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 334 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgga9u6KYHQ&3FKtks{T^vI!PA{Eo z%XP>>pmqP$4AD!`9jz?qlhYr^7V%jN=CE>03-0L`zo1knwmRd&kI6hX(}5D_YHMc^KK7&pa(!6x6-DPL%2BrXzRxHuuDH$~C4p z+4TR*YR&B0d{cS(v@op$Td0Ai>ljm;eJH!7z-D91ISDEAL{M0 zQ*esalC)&BIHvSO#xey`T(*nsZ>F%MxQvY)b_hEvKbC#mN4~3zu?{(Gk@s%7n@EEB zSf+gYnC))gtHD%~tb00000 LNkvXXu0mjf(p*!Y literal 0 HcmV?d00001 diff --git a/lang/cs/lang.php b/lang/cs/lang.php new file mode 100644 index 0000000..e12493b --- /dev/null +++ b/lang/cs/lang.php @@ -0,0 +1,12 @@ + + */ + +// custom language strings for the plugin +$lang['toolbar_icon'] = 'Vložit Cellbg-Syntaxi'; + +//Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/lang/cs/settings.php b/lang/cs/settings.php new file mode 100644 index 0000000..d4da796 --- /dev/null +++ b/lang/cs/settings.php @@ -0,0 +1,11 @@ + + */ + +// for the configuration manager +$lang['toolbar_icon'] = 'Zobrazit toolbar ikonku (pokud se nezobrazuje, smažte data/cache/* a cache prohlížeče)'; +$lang['custom_colors'] = 'Uživatelsky definované barvy.
Název barvy následován znakem = a textem barvy či kódu barvy.

Příklad:
Barva 1=green
Barva 2=#002244
'; diff --git a/lang/en/lang.php b/lang/en/lang.php new file mode 100644 index 0000000..76b3f3f --- /dev/null +++ b/lang/en/lang.php @@ -0,0 +1,10 @@ + + */ + +// custom language strings for the plugin +$lang['toolbar_icon'] = 'Insert Cellbg-Syntax'; diff --git a/lang/en/settings.php b/lang/en/settings.php new file mode 100644 index 0000000..3012d0d --- /dev/null +++ b/lang/en/settings.php @@ -0,0 +1,11 @@ + + */ + +// for the configuration manager +$lang['toolbar_icon'] = 'Show toolbar icon (clear data/cache/* and browser cache if it\'s not displayed)'; +$lang['custom_colors'] = 'Custom colors definitions.
The color name, followed by a an equals sign and a text color name or color code.

Example:
Color 1=green
Color 2=#002244
Color 2=#ABC
'; diff --git a/script.js b/script.js index adfed10..aef3068 100644 --- a/script.js +++ b/script.js @@ -1,112 +1,71 @@ /* 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; +/* see https://www.dokuwiki.org/devel:toolbar for more info */ + +function createCellbgPicker(id, props, edid) { + // create the wrapping div + var $picker = jQuery(document.createElement('div')); + + $picker.addClass('picker a11y'); - 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
- 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
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); + $picker.attr('id', id).css('position', 'absolute'); + + function $makebutton(title, colorValue) { + var $btn = jQuery(document.createElement('button')) + .addClass('pickerbutton cellbg').attr('title', title) + .attr('aria-controls', edid); + + if (colorValue == 'RGB') + { + $btn.text(colorValue) + .addClass('custom') + .bind('click', bind(tb_format, $btn[0], props, edid)); + } + else + { + var insertColorValue = "@" + colorValue + ":"; + $btn.css('backgroundColor', colorValue) + .bind('click', bind(pickerInsert, insertColorValue, edid)); + } + $btn.appendTo($picker); + return $btn; } - } - - var body = document.getElementsByTagName('body')[0]; - body.appendChild(picker); // attach the picker
to the page body - toolbar.appendChild(p_btn); // attach the picker button to the toolbar + + $makebutton('custom', 'RGB'); + jQuery.each(props.colorlist, function (key, item) { + if (!props.colorlist.hasOwnProperty(key)) { + return; + } + $makebutton(key, item); + }); + jQuery('body').append($picker); + + // we have to return a DOM object (for compatibility reasons) + return $picker[0]; +} + +/** + * Add button action for color picker buttons and create color picker element + * + * @param jQuery btn Button element to add the action to + * @param array props Associative array of button properties + * @param string edid ID of the editor textarea + * @return boolean If button should be appended + * @author Pavel Kochman + */ +function addBtnActionCellbgPicker($btn, props, edid) { + var pickerid = 'picker_plugin_cellbg'; // picker id that we're creating + var picker = createCellbgPicker(pickerid, props, edid); + + $btn.click( + function(e) { + pickerToggle(pickerid, $btn); + e.preventDefault(); + return ''; + } + ); + $btn.attr('aria-haspopup', 'true'); + + return pickerid; } -jQuery(plugin_cellbg_toolbar_picker); - + //Setup VIM: ex: et ts=2 sw=2 enc=utf-8 : diff --git a/style.css b/style.css new file mode 100644 index 0000000..f6fafe2 --- /dev/null +++ b/style.css @@ -0,0 +1,23 @@ +div.picker button.pickerbutton.cellbg +{ + height: 2em; + width: 2em; + line-height: 2em; + padding: 1em; + background-image: none; + background-image: url("images/gradient.png"); +} +div.picker button.pickerbutton.cellbg:first-child +{ + width: 4em; + display: inline-block; + padding: 0; +} +div.picker button.pickerbutton.cellbg:hover +{ + background-image: none; +} +#picker_plugin_cellbg +{ + width: 10em; +} \ No newline at end of file diff --git a/syntax.php b/syntax.php index e6c51ad..a654971 100644 --- a/syntax.php +++ b/syntax.php @@ -37,7 +37,7 @@ function getType(){ return 'formatting'; } // What kind of syntax do we allow (optional) function getAllowedTypes() { - return array('formatting', 'substition', 'disabled'); + return array('formatting', /*'substition', 'disabled'*/); } // What about paragraphs? (optional) @@ -49,7 +49,10 @@ function getSort(){ return 200; } // Connect pattern to lexer function connectTo($mode) { - $this->Lexer->addSpecialPattern('^@#?[0-9a-zA-Z]*:(?=[^\n]*\|[[:space:]]*\n)',$mode,'plugin_cellbg'); + if ($mode == "table") + { + $this->Lexer->addSpecialPattern('^@#?[0-9a-zA-Z]*:', $mode, 'plugin_cellbg'); + } } function postConnect() { //$this->Lexer->addExitPattern(':','plugin_cellbg'); @@ -57,7 +60,7 @@ function postConnect() { // Handle the match - function handle($match, $state, $pos, &$handler){ + function handle($match, $state, $pos, &$handler) { switch ($state) { case DOKU_LEXER_ENTER : break; @@ -79,6 +82,9 @@ function handle($match, $state, $pos, &$handler){ // Create output function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ +// echo '
';
+//         echo htmlspecialchars($renderer->doc);
+//         echo '
'; list($state, $color, $text) = $data; switch ($state) { case DOKU_LEXER_ENTER : @@ -91,13 +97,16 @@ function render($mode, &$renderer, $data) { case DOKU_LEXER_EXIT : break; case DOKU_LEXER_SPECIAL : - if (preg_match('/(]*)>[[:space:]]*$/', $renderer->doc) != 0) { - $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 style="background-color:'.$color.'">', $renderer->doc); + if (preg_match('/(]*)>[[:space:]]*$/', $renderer->doc) != 0) { + $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 style="background-color:'.$color.'">111', $renderer->doc); } else { $renderer->doc .= $text; } break; } +// echo htmlspecialchars($renderer->doc); +// echo '
'; +// echo '
'; return true; } return false; From b12695aa9d6645c7fe7785807ba763bffd2fd635 Mon Sep 17 00:00:00 2001 From: kochi Date: Mon, 21 Sep 2015 22:26:17 +0200 Subject: [PATCH 3/3] Small fixes. --- conf/default.php | 2 +- syntax.php | 46 +++++++++++++++++++--------------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/conf/default.php b/conf/default.php index ffa6d73..9733720 100644 --- a/conf/default.php +++ b/conf/default.php @@ -3,4 +3,4 @@ * Options for the Cellbg Plugin */ $conf['toolbar_icon'] = 0; // enables/disables the toolbar icon -$meta['custom_colors'] = array(''); // Custom colors to show in toolbar +$conf['custom_colors'] = array(''); // Custom colors to show in toolbar diff --git a/syntax.php b/syntax.php index a654971..2a9a7cf 100644 --- a/syntax.php +++ b/syntax.php @@ -4,23 +4,23 @@ * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author dr4Ke - * @link http://git.dr4ke.net/?p=dr4Ke/forks/dokuwiki-cells-bg.git + * @link https://github.com/dr4Ke/cellbg * @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', @@ -31,7 +31,7 @@ function getInfo(){ // return some info 'url' => 'http://www.dokuwiki.org/plugin:cellbg', ); } - + // What kind of syntax are we? function getType(){ return 'formatting'; } @@ -39,14 +39,13 @@ function getType(){ return 'formatting'; } function getAllowedTypes() { return array('formatting', /*'substition', 'disabled'*/); } - - // What about paragraphs? (optional) - function getPType(){ return 'normal'; } - + + // What about paragraphs? (optional) + function getPType(){ return 'normal'; } + // Where to sort in? function getSort(){ return 200; } - - + // Connect pattern to lexer function connectTo($mode) { if ($mode == "table") @@ -57,8 +56,7 @@ function connectTo($mode) { function postConnect() { //$this->Lexer->addExitPattern(':','plugin_cellbg'); } - - + // Handle the match function handle($match, $state, $pos, &$handler) { switch ($state) { @@ -78,13 +76,10 @@ function handle($match, $state, $pos, &$handler) { } return array($state, "yellow", $match); } - + // Create output function render($mode, &$renderer, $data) { if($mode == 'xhtml'){ -// echo '
';
-//         echo htmlspecialchars($renderer->doc);
-//         echo '
'; list($state, $color, $text) = $data; switch ($state) { case DOKU_LEXER_ENTER : @@ -98,37 +93,34 @@ function render($mode, &$renderer, $data) { break; case DOKU_LEXER_SPECIAL : if (preg_match('/(]*)>[[:space:]]*$/', $renderer->doc) != 0) { - $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 style="background-color:'.$color.'">111', $renderer->doc); + $renderer->doc = preg_replace('/(]*)>[[:space:]]*$/', '\1 style="background-color:'.$color.'">', $renderer->doc); } else { $renderer->doc .= $text; } break; } -// echo htmlspecialchars($renderer->doc); -// echo '
'; -// echo '
'; 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 :