Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
dokuwiki:infobox [2015-Dec-02 16:23] – ↷ Nom de la page changé de dokuwiki:alertbox à dokuwiki:infobox MOLINIER Etiennedokuwiki:infobox [2018-Sep-18 22:39] (Version actuelle) – modification externe 127.0.0.1
Ligne 2: Ligne 2:
  
 I use the bootstrap plugin along with the Bootstrap Wrapper Plugin, but I find that the syntax to add alert boxes is a hassle mainly due to the icon. I use the bootstrap plugin along with the Bootstrap Wrapper Plugin, but I find that the syntax to add alert boxes is a hassle mainly due to the icon.
-The idea is to expand the alert class to create my own infobox class that would include an icon.+The idea is to expand the alert class to create my own infobox class that would include an icon and offer the option to be centered
  
 ==== Usage ==== ==== Usage ====
  
 You can use the ''infobox'' tag in you wiki syntax as follows :  You can use the ''infobox'' tag in you wiki syntax as follows : 
-<code> +<infobox>This is the default behaviour, you can include **wiki markup** in these infoboxes.</infobox> 
-<infobox>This is the content</infobox> +<infobox type="success">You can add a type (success, info, warning or danger)</infobox> 
-<infobox type="success">Content here **with wiki markup**</infobox> +<infobox type="warning" width="80%">You can add width argument (here 80%), the box is centered by default.</infobox> 
-<infobox type="info">Content here **with wiki markup**</infobox> +<infobox type="dangerwidth="40%center="0">And you can remove the centering by adding ''center="0"''</infobox>
-<infobox type="warning">Content here **with wiki markup**</infobox> +
-<infobox type="danger">Content here **with wiki markup**</infobox> +
-</code> +
-<infobox>This is the content</infobox> +
-<infobox type="success">Content here **with wiki markup**</infobox> +
-<infobox type="info">Content here **with wiki markup**</infobox> +
-<infobox type="warning">Content here **with wiki markup**</infobox> +
-<infobox type="danger">Content here **with wiki markup**</infobox>+
  
 ==== The code ==== ==== The code ====
Ligne 29: Ligne 21:
    
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
- * @author     Etienne Molinier <webmaster@emolinier.com> + * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 
- * @copyright  (C) 2015, Giuseppe Di Terlizzi+ * @copyright  (C) 2015-2016, Giuseppe Di Terlizzi
  */  */
    
Ligne 36: Ligne 28:
 if(!defined('DOKU_INC')) die(); if(!defined('DOKU_INC')) die();
  
-require_once(dirname(__FILE__).'/alert.php');+require_once(dirname(__FILE__).'/bootstrap.php');
  
-class syntax_plugin_bootswrapper_alertbox extends syntax_plugin_bootswrapper_alert { +class syntax_plugin_bootswrapper_infobox extends syntax_plugin_bootswrapper_bootstrap {
-    protected $pattern_start  = '<(?:INFOBOX|infobox).*?>(?=.*?</(?:INFOBOX|infobox)>)'; +
-    protected $pattern_end    = '</(?:INFOBOX|infobox)>'; +
- function render($mode, Doku_Renderer $renderer, $data) {+
  
-        if ($data[2]["type"]=="success"{ +  public $pattern_start  '<(?:INFOBOX|infobox).*?>(?=.*?</(?:INFOBOX|infobox)>)'; 
-   $data[2]["icon"]= 'glyphicon glyphicon-ok'; +  public $pattern_end    = '</(?:INFOBOX|infobox)>'; 
-+  public $tag_name       = 'infobox'; 
- if ($data[2]["type"]=="info"+  public $tag_attributes array(
-   $data[2]["icon"]= 'glyphicon glyphicon-info-sign'; +
- +
- if ($data[2]["type"]=="warning") { +
-   $data[2]["icon"]= 'glyphicon glyphicon-warning-sign'; +
- +
- if ($data[2]["type"]=="danger") { +
-   $data[2]["icon"]= 'glyphicon glyphicon-minus-sign'; +
- }+
  
- parent::render($mode,$renderer,$data); +    'type'      => array('type'     => 'string', 
- }+                         'values'   => array('success', 'info', 'warning', 'danger'), 
 +                         'required' => true, 
 +                         'default'  => 'info'), 
 + 
 +    'dismiss'   => array('type'     => 'boolean', 
 +                         'values'   => array(0, 1), 
 +                         'required' => false, 
 +                         'default'  => false), 
 + 
 +    'icon'      => array('type'     => 'string', 
 +                         'values'   => null, 
 +                         'required' => false, 
 +                         'default'  => null), 
 + 
 +    'center'    => array('type'     => 'boolean', 
 +                         'values'   => array(0, 1), 
 +                         'required' => false, 
 +                         'default'  => true), 
 + 
 +      'width'      => array('type'     => 'string', 
 +                            'values'   => null, 
 +                            'required' => false, 
 +                            'default'  => null), 
 +  ); 
 + 
 +  function getPType(){ return 'block';
 + 
 +  function render($mode, Doku_Renderer $renderer, $data) 
 + 
 +    if (empty($data)) return false
 +    if ($mode !== 'xhtml') return false; 
 + 
 +    /** @var Doku_Renderer_xhtml $renderer */ 
 +    list($state, $match, $attributes) = $data; 
 + 
 +    switch($state) { 
 + 
 +      case DOKU_LEXER_ENTER: 
 + 
 +        extract($attributes); 
 + 
 +        $html_attributes = $this->mergeCoreAttributes($attributes); 
 +        $html_attributes['class'][] = 'bs-wrap alert'; 
 +        $html_attributes['class'][] = "alert-$type"; 
 +        $html_attributes['role'] = 'alert'; 
 +         
 +        $style=[]; 
 +        if ($center)          {$html_attributes['class'][] = 'center-block';}; 
 +        if (!is_null($width)) {$style["width"] = $width.';';}; 
 +        $html_attributes['style'] = $style; 
 + 
 +        if ($dismiss) $html_attributes['class'][] = 'alert-dismissible'; 
 + 
 +        $markup = sprintf('<div %s>', $this->buildAttributes($html_attributes)); 
 + 
 +        if ($dismiss) { 
 +            $markup .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'; 
 +        } 
 + 
 +        if ($icon) { 
 +          $markup .= sprintf('<i class="%s"></i> ', $icon); 
 +        } 
 + 
 +        $renderer->doc .= $markup; 
 +        return true; 
 + 
 +      case DOKU_LEXER_EXIT: 
 +        $renderer->doc .= '</div>'; 
 +        return true; 
 + 
 +    } 
 + 
 +    return true; 
 + 
 +  }
  
 } }
 </file> </file>
  • dokuwiki/infobox.1449069836.txt.gz
  • Dernière modification : 2018-Sep-18 22:38
  • (modification externe)