Gebruikershulpmiddelen

Site-hulpmiddelen


bridge:trumpsuits-dokuwiki-plugin

Verschillen

Dit geeft de verschillen weer tussen de geselecteerde revisie en de huidige revisie van de pagina.

Link naar deze vergelijking

Beide kanten vorige revisieVorige revisie
Volgende revisie
Vorige revisie
bridge:trumpsuits-dokuwiki-plugin [2020/12/19 16:39] – oude revisie hersteld (2020/08/26 22:09) 5.183.253.38bridge:trumpsuits-dokuwiki-plugin [2024/03/08 19:45] (huidige) – [Notes] Pieter van der Meulen
Regel 1: Regel 1:
 ====== Trump suits plugin for DokuWiki ====== ====== Trump suits plugin for DokuWiki ======
  
-This may not be the most spectacular DokuWiki plugin available, but it suits my own needs just fine. The plugin renders the diamond and heart card suit symbols in red (♦/♥), and the clubs and spade card suit symbols in black (♣/♠). It also adds four buttons to the editor toolbar for quick access to the trump suit symbols.+This may not be the most spectacular DokuWiki plugin available, but it suits my own needs just fine. The plugin renders (FIXME will render in the near future) the diamond and heart card suit symbols in red, and the clubs and spade card suit symbols in black. It also adds four buttons to the editor toolbar for quick access to the trump suit symbols.
  
-Due to my very limited knowledge of PHP and javascript I can't guarantee this won't set fire to your DokuWiki server. Mine seems to have survived thus far, so there is hope yet. Suggestions for improvement are very welcome.+Due to my very limited knowledge of PHP and javascript I can't guarantee this won't set fire to your DokuWiki server. Mine seems to have survived this far though, so there is hope yet. Suggestions for improvement are very welcome.
  
 ===== Syntax ===== ===== Syntax =====
  
 No special syntax. Just use standard UTF card suit symbols (optionally inserted by using the toolbar buttons). No special syntax. Just use standard UTF card suit symbols (optionally inserted by using the toolbar buttons).
- 
-===== Versions ===== 
- 
-  ;2010-09-03 
-  :Fixed javascript that was broken in DokuWiki version 2009-12-25, “Lemming”. 
-  ;2009-11-05 
-  :Initial version 
-   
- 
- 
  
 ===== Installation ===== ===== Installation =====
- 
  
  
Regel 26: Regel 15:
  
  
-Point your plug-in manager at [[/downloads/trumpsuits-dokuwiki-plugin.tar.gz]] or [[/downloads/trumpsuits-dokuwiki-plugin.zip]]. +Point your plug-in manager at [[/downloads/trumpsuits-dokuwiki-plugin.tar.gz]] or [[/downloads/trumpsuits-dokuwiki-plugin.zip]]. FIXME
  
 ==== Manual ==== ==== Manual ====
Regel 33: Regel 21:
 Create the folder ''lib/plugins/trumpsuits'' in your DokuWiki folder. Create ''syntax.php'' and ''scrips.js'' as given below. Create the folder lib/plugins/trumpsuits/images and place the images in this table in there. Create the folder ''lib/plugins/trumpsuits'' in your DokuWiki folder. Create ''syntax.php'' and ''scrips.js'' as given below. Create the folder lib/plugins/trumpsuits/images and place the images in this table in there.
  
-^ Suit      ^  Unicode, hexadecimal  ^^ Filename      ^  Image                                                 ^ +^ Suit      ^  Filename      ^  Image                                                 ^ 
-| Clubs     |  2663  |  2667  |  clubs.png      {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/clubs.png}}     | +| Clubs      clubs.png      {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/clubs.png}}     | 
-| Diamonds   2666  |  2662   diamonds.png  |  {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/diamonds.png}} +| Diamonds  |  diamonds.png  |  {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/diamonds.png}} 
-| Hearts    |  2665  |  2661  |  hearts.png    |  {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/hearts.png}}    | +| Hearts    |  hearts.png    |  {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/hearts.png}}    | 
-| Spades    |  2660  |  2664  |  spades.png    |  {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/spades.png}}    |+| Spades    |  spades.png    |  {{http://www.vdmeulen.net/wiki/lib/plugins/trumpsuits/images/spades.png}}    | 
  
 === syntax.php === === syntax.php ===
  
 Take care not to include whitespace in front of the first php tag or after the last php tag. This leads to strange behaviour by DokuWiki. Take care not to include whitespace in front of the first php tag or after the last php tag. This leads to strange behaviour by DokuWiki.
- 
 <code php> <code php>
 <?php <?php
 /** /**
- * Plugin Trumpsuitscontrols display of trump suit card symbols with CSS style attributes+ * Plugin base linksCreates links relative to site root for all links beginning with "/"
  *  *
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
Regel 52: Regel 40:
  */  */
  
-if(!defined('DOKU_INC')) die();+if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 require_once(DOKU_PLUGIN.'syntax.php'); require_once(DOKU_PLUGIN.'syntax.php');
Regel 61: Regel 49:
  */  */
 class syntax_plugin_trumpsuits extends DokuWiki_Syntax_Plugin { class syntax_plugin_trumpsuits extends DokuWiki_Syntax_Plugin {
- 
-    public static $SPADES='â™ '; 
-    public static $HEARTS='♥'; 
-    public static $DIAMONDS='♦'; 
-    public static $CLUBS='♣'; 
  
     /**     /**
      * return some info      * return some info
      */      */
-    function getInfo() {+    function getInfo(){
         return array(         return array(
             'author' => 'Pieter van der Meulen',             'author' => 'Pieter van der Meulen',
             'email'  => 'pieter@vdmeulen.net',             'email'  => 'pieter@vdmeulen.net',
-            'date'   => '2010-09-03',+            'date'   => '2007-08-09',
             'name'   => 'trumpsuits',             'name'   => 'trumpsuits',
-            'desc'   => 'Adds toolbar buttons in editor for trump suits. Displays red suits red, black suits black (configurable).',+            'desc'   => 'Adds toolbar buttons in editor for trump suits. Displays red suits red, black suits black.',
             'url'    => 'http://www.vdmeulen.net/wiki/bridge/trumpsuits-dokuwiki-plugin',             'url'    => 'http://www.vdmeulen.net/wiki/bridge/trumpsuits-dokuwiki-plugin',
         );         );
Regel 84: Regel 67:
      * What kind of syntax are we?      * What kind of syntax are we?
      */      */
-    function getType() {+    function getType(){
         return 'substition';         return 'substition';
     }     }
  
     //This must be implemented     //This must be implemented
-    function getSort() { +    function getSort(){ return 123; }
-        return 123; +
-    }+
  
 +
 +}
 +?>
 +</code>
 +
 +Hieruit eventueel nog stukje gebruiken:
 +
 +<code php>
 +<?php
 +/**
 + * Plugin Trumpsigns: Inserts <font size="+1" color="..."> tags into the document when trumpsigns are encountered
 + 
 + * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 + * @author     Pieter van der Meulen <dev@vdmeulen.net>
 + */
 + 
 +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_tab extends DokuWiki_Syntax_Plugin {
 + 
     /**     /**
-     Set "normal" inline substitution+     return some info
      */      */
-    function getPType() { +    function getInfo(){ 
-        return 'normal';+        return array( 
 +            'author=> 'Pieter van der Meulen', 
 +            'email'  => 'dev@vdmeulen.net', 
 +            'date'   => '2006-11-20', 
 +            'name'   => 'Trumpsigns Plugin', 
 +            'desc'   => 'Inserts <font size="+1" color="..."> tags into the html around trump signs', 
 +            'url'    => 'http://www.vdmeulen.net/wiki/bridge/troeftekens_in_dokuwiki#vergroot_in_rood_en_wart_weergeven', 
 +        );
     }     }
 +  
 +    /** 
 +     * What kind of syntax are we? 
 +     */ 
 +    function getType(){ 
 +        return 'substition'; 
 +    } 
 +    
 +  
 +    /** 
 +     * Where to sort in? 
 +     */  
 +    function getSort(){ 
 +        return 789; 
 +    } 
 +  
 + 
     /**     /**
      * Connect pattern to lexer      * Connect pattern to lexer
      */      */
     function connectTo($mode) {     function connectTo($mode) {
-        $this->Lexer->addSpecialPattern($this->nt_symbol_regex(), $mode, 'plugin_trumpsuits'); +      $this->Lexer->addSpecialPattern('♣',$mode,'plugin_trumpsigns'); 
-        $this->Lexer->addSpecialPattern(self::$CLUBS, $mode,'plugin_trumpsuits'); +      $this->Lexer->addSpecialPattern('♦',$mode,'plugin_trumpsigns'); 
-        $this->Lexer->addSpecialPattern(self::$DIAMONDS,$mode,'plugin_trumpsuits'); +      $this->Lexer->addSpecialPattern('♥',$mode,'plugin_trumpsigns'); 
-        $this->Lexer->addSpecialPattern(self::$HEARTS,$mode,'plugin_trumpsuits'); +      $this->Lexer->addSpecialPattern('',$mode,'plugin_trumpsigns');
-        $this->Lexer->addSpecialPattern(self::$SPADES,$mode,'plugin_trumpsuits');+
     }     }
 +  
     /**     /**
      * Handle the match      * Handle the match
      */      */
-    function handle($match, $state, $pos, &$handler) { +    function handle($match, $state, $pos, &$handler){ 
-        $repl = $match; +        switch ($state) { 
-        switch ($match) { +          case DOKU_LEXER_ENTER :  
-            case self::$CLUBS+            break; 
-                $repl = $this->render_style($match, $this->getConf('clubs_css')); +          case DOKU_LEXER_MATCHED 
-                break; +            break; 
-            case self::$DIAMONDS+          case DOKU_LEXER_UNMATCHED 
-                $repl = $this->render_style($match, $this->getConf('diamonds_css')); +            break; 
-                break; +          case DOKU_LEXER_EXIT 
-            case self::$HEARTS+            break; 
-                $repl = $this->render_style($match, $this->getConf('hearts_css')); +          case DOKU_LEXER_SPECIAL 
-                break; +            break;
-            case self::$SPADES+
-                $repl = $this->render_style($match, $this->getConf('spades_css')); +
-                break; +
-            default+
-                $regex = '/'.$this->nt_symbol_regex().'/'; +
-                if (preg_match($regex, $match)==1) { +
-                    $repl = substr($match, 0, 1); +
-                    $repl .= $this->render_style($this->getConf('notrump_symbol'), $this->getConf('notrump_css')); +
-                    $repl .= substr($match, -1, 1); +
-                } +
-                else { +
-                    $repl = $match; +
-                }+
         }         }
-        return array($match, $repl);+        return array();
     }     }
 + 
     /**     /**
-     * Create output. On non-xhtml formasts leave symbols unaffected +     * Create output
-     * +
-     * @param <type> $format +
-     * @param <type> $renderer +
-     * @param <type> $data +
-     * @return <type> +
      */      */
-    function render($format, &$renderer, $data) { +    function render($mode, &$renderer, $data) { 
-        if($format == 'xhtml') { +        if($mode == 'xhtml'){ 
-            $renderer->doc .= $data[1]; +            $renderer->doc .= "<FONT SIZE=\"+1\" COLOR=\"RED\">XXX+"
-        } else { +            $renderer->doc .= $data
-            $renderer->doc .= $data[0];+            $renderer->doc .= "-XXX</FONT>"; 
 +            return true;
         }         }
-        return true;+        return false;
     }     }
 +}
 + 
 +//Setup VIM: ex: et ts=4 enc=utf-8 :
  
-    function render_style($s, $style) { 
-        return '<span style="'.$style.'">'.$s.'</span>'; 
-    } 
  
-    function nt_symbol_regex() { 
-        return '[^A-Za-z]'.$this->getConf('notrump_symbol').'[^\w]'; 
-    } 
- 
-} 
-?> 
 </code> </code>
 +
 +
 +
  
 === script.js === === script.js ===
  
 <code javascript> <code javascript>
-if(window.toolbar!=undefined){ +//create a single toolbutton with desired properties 
-    var icobase = DOKU_BASE + "lib/plugins/trumpsuits/images/"; +function plugin_trumpsuits_createToolbutton (id, tooltipText, imgFile, insText, accKey) { 
-    toolbar[toolbar.length] = { +    var ico = document.createElement("img"); 
-        "type": "insert", +    ico.src = DOKU_BASE + "lib/plugins/trumpsuits/images/" + imgFile
-        "title": "Spades", +    var btn = document.createElement("button"); 
-        "icon": "spades.png"+    btn.id = "syntax__plugin_trumpsuits_+ id
-        "insert": "♠", +    btn.className = "toolbutton"; 
-        "icobase": icobase}+    btn.appendChild(ico)
-    toolbar[toolbar.length] +    btn.title tooltipText;     
-        "type": "insert", +    btn.accessKey = accKey
-        "title": "Hearts", +    eval('btn.onclick function(){insertAtCarret("wiki__text", "' + insText + '"); return false;}'); 
-        "icon": "hearts.png", +    return(btn);
-        "insert":  "♥", +
-        "icobase": icobase}+
-    toolbar[toolbar.length] { +
-        "type": "insert", +
-        "title": "Diamonds", +
-        "icon": "diamonds.png", +
-        "insert": "♦", +
-        "icobase": icobase}+
-    toolbar[toolbar.length] = { +
-        "type": "insert", +
-        "title": "Clubs", +
-        "icon": "clubs.png", +
-        "insert": "♣", +
-        "icobase": icobase};+
 } }
-</code> 
- 
- 
- 
  
 +//if this is an "edit" page, add toolbuttons
 +function plugin_trumpsuits_toolbar_additions() {
 +    var toolbar = $("tool__bar");
 +    if(!toolbar) {return;}
 +    if(!$("edbtn__save")) {return; //We must be able to save the page
 +    var tbtn = plugin_trumpsuits_createToolbutton("spades", "Spades", "spades.png", "â™ ", 'S');
 +    if (tbtn) {toolbar.appendChild(tbtn);}
 +    tbtn = plugin_trumpsigns_createToolbutton("hearts", "Hearts", "hearts.png", "♥", 'H');
 +    if (tbtn) {toolbar.appendChild(tbtn);}
 +    tbtn = plugin_trumpsigns_createToolbutton("diamonds", "Diamonds", "diamonds.png", "♦", 'D');
 +    if (tbtn) {toolbar.appendChild(tbtn);}
 +    tbtn = plugin_trumpsigns_createToolbutton("clubs", "Clubs", "clubs.png", "♣", 'C');
 +    if (tbtn) {toolbar.appendChild(tbtn);}
 +}
  
 +addInitEvent(plugin_trumpsuits_toolbar_additions);
 +</code>
 +===== Notes =====
  
 +Notes on javasript in plugins: http://wiki.splitbrain.org/wiki:devel:javascript. For debugging, first turn CSS en javascript compression off in your DokuWiki config. Then debug path/to/wiki/lib/exe/js.php. I use the Firefox javascript debugger plugin. User manual: http://devedge-temp.mozilla.org/viewsource/2002/venkman/01/index_en.html.
  
-===== Wishlist =====+Browser an OS dependent CSS selectors: https://rafael.adm.br/css_browser_selector/
  
-  *Configuration options for trump suit symbol replacement 
-  *Language options. Can one use language conf in javascript? 
  
bridge/trumpsuits-dokuwiki-plugin.1608392349.txt.gz · Laatst gewijzigd: (Externe bewerking)