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 17:07] MOLINIER Etiennedokuwiki:infobox [2018-Sep-18 22:39] (Version actuelle) – modification externe 127.0.0.1
Ligne 10: Ligne 10:
 <infobox type="success">You can add a type (success, info, warning or danger)</infobox> <infobox type="success">You can add a type (success, info, warning or danger)</infobox>
 <infobox type="warning" width="80%">You can add width argument (here 80%), the box is centered by default.</infobox> <infobox type="warning" width="80%">You can add width argument (here 80%), the box is centered by default.</infobox>
-<infobox type="danger" width="40%" center="false">And you can remove the centering by adding ''center="false"''</infobox>+<infobox type="danger" width="40%" center="0">And you can remove the centering by adding ''center="0"''</infobox>
  
 ==== The code ==== ==== The code ====
Ligne 21: 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 based on work from Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> + * @author     Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 
- * @copyright  (C) 2015, Giuseppe Di Terlizzi+ * @copyright  (C) 2015-2016, Giuseppe Di Terlizzi
  */  */
    
Ligne 32: Ligne 32:
 class syntax_plugin_bootswrapper_infobox extends syntax_plugin_bootswrapper_bootstrap { class syntax_plugin_bootswrapper_infobox extends syntax_plugin_bootswrapper_bootstrap {
  
-    protected $pattern_start  = '<(?:INFOBOX|infobox).*?>(?=.*?</(?:INFOBOX|infobox)>)'; +  public $pattern_start  = '<(?:INFOBOX|infobox).*?>(?=.*?</(?:INFOBOX|infobox)>)'; 
-    protected $pattern_end    = '</(?:INFOBOX|infobox)>'; +  public $pattern_end    = '</(?:INFOBOX|infobox)>'; 
-    protected $tag_attributes = array(+  public $tag_name       = 'infobox'; 
 +  public $tag_attributes = array(
  
-      'type'      => array('type'     => 'string', +    'type'      => array('type'     => 'string', 
-                           'values'   => array('success', 'info', 'warning', 'danger'), +                         'values'   => array('success', 'info', 'warning', 'danger'), 
-                           'required' => true, +                         'required' => true, 
-                           'default'  => 'info'),+                         'default'  => 'info'),
  
-      'dismiss'   => array('type'     => 'boolean', +    'dismiss'   => array('type'     => 'boolean', 
-                           'values'   => array(0, 1), +                         'values'   => array(0, 1), 
-                           'required' => false, +                         'required' => false, 
-                           'default'  => false),+                         'default'  => false),
  
-      'icon'      => array('type'     => 'string', +    'icon'      => array('type'     => 'string', 
-                           'values'   => null, +                         'values'   => null, 
-                           'required' => false, +                         'required' => false, 
-                           'default'  => null),+                         'default'  => null),
  
-      'center'    => array('type'     => 'string', +    'center'    => array('type'     => 'boolean', 
-                           'values'   => array('true''false'), +                         'values'   => array(01), 
-                           'required' => false, +                         'required' => false, 
-                           'default'  => 'true'),+                         'default'  => true),
  
       'width'      => array('type'     => 'string',       'width'      => array('type'     => 'string',
-                           'values'   => null, +                            'values'   => null, 
-                           'required' => false, +                            'required' => false, 
-                           'default'  => null), +                            'default'  => null), 
-    );+  );
  
-    function getPType(){ return 'block'; }+  function getPType(){ return 'block'; }
  
-    function render($mode, Doku_Renderer $renderer, $data) {+  function render($mode, Doku_Renderer $renderer, $data) {
  
-        if (empty($data)) return false;+    if (empty($data)) return false; 
 +    if ($mode !== 'xhtml') return false;
  
-        if ($mode == 'xhtml'{+    /** @var Doku_Renderer_xhtml $renderer */ 
 +    list($state, $match, $attributes= $data;
  
-            /** @var Doku_Renderer_xhtml $renderer */ +    switch($state) {
-            list($state, $match, $attributes= $data;+
  
-            switch($state) {+      case DOKU_LEXER_ENTER:
  
-                case DOKU_LEXER_ENTER:+        extract($attributes);
  
-                    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;
  
- $markup=""; +        if ($dismiss) $html_attributes['class'][] = 'alert-dismissible';
- if ($center!="false" || !is_null($width)) { +
- $markup.=sprintf('<div style="%s%s">',(($center=="false")?"":"margin:auto;"),((is_null($width))?"":"width:$width;")); +
- }+
  
-                    $markup .= sprintf('<div class="bs-wrap alert alert-%s %s" role="alert">', +        $markup = sprintf('<div %s>', $this->buildAttributes($html_attributes));
-                                      $type, (($dismiss) ? 'alert-dismissible' : ''));+
  
-                    if ($dismiss) { +        if ($dismiss) { 
-                        $markup .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'; +            $markup .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'; 
-                    }+        }
  
-                    if ($icon) { +        if ($icon) { 
-                      $markup .= sprintf('<i class="%s"></i> ', $icon); +          $markup .= sprintf('<i class="%s"></i> ', $icon); 
-                    } else { +        }
-                 if ($type=="success") { +
-                   $icon = 'glyphicon glyphicon-ok'; +
-                 } +
-                 if ($type=="info") { +
-                   $icon = 'glyphicon glyphicon-info-sign'; +
-                 } +
-                 if ($type=="warning") { +
-                   $icon = 'glyphicon glyphicon-warning-sign'; +
-                 } +
-                 if ($type=="danger") { +
-                   $icon = 'glyphicon glyphicon-minus-sign'; +
-                 } +
- $markup .= sprintf('<i class="%s"></i> ', $icon); +
- }+
  
-                    $renderer->doc .= $markup; +        $renderer->doc .= $markup; 
-                    return true;+        return true;
  
-                case DOKU_LEXER_EXIT: +      case DOKU_LEXER_EXIT: 
- if ($center!="false" || !is_null($width)) { +        $renderer->doc .= '</div>'; 
-                     $renderer->doc .= '</div></div>'; +        return true;
- } else { +
-                     $renderer->doc .= '</div>'; +
-+
-                    return true;+
  
-            }+    }
  
-            return true;+    return true;
  
-        } +  }
- +
-        return false; +
- +
-    }+
  
 } }
 </file> </file>
  • dokuwiki/infobox.1449072427.txt.gz
  • Dernière modification : 2018-Sep-18 22:38
  • (modification externe)