Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file block.jstabs.php

Documentation is available at block.jstabs.php

  1. <?php 
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * Smarty {jstabs} block plugin
  10.  *
  11.  * Type:        block
  12.  * Name:        jstabs
  13.  * Input:        you can use {jstab tab=<tab number>} (staring with 0) to select a given tab
  14.  *              or you can use the url to do so: page.php?jstab=<tab number>
  15.  * Abstract:    Used to enclose a set of tabs
  16.  */
  17. function smarty_block_jstabs( $pParams, $pContent, &$gBitSmarty, $pRepeat ) {
  18.     global $gBitSystem, $jsTabLinks;
  19.     if( $pRepeat ){
  20.         $jsTabLinks = array();
  21.     } else {
  22.         extract( $pParams );
  23.  
  24.         $tabId = !empty( $pParams['id'] ) ? $pParams['id'] : substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
  25.  
  26.         if( isset( $_REQUEST['jstab'] ) ) {
  27.             // make sure we aren't passed any evil shit
  28.             if( !isset( $tab ) && isset( $_REQUEST['jstab'] ) && preg_match( "!^\d+$!", $_REQUEST['jstab'] ) ) {
  29.                 $tab = $_REQUEST['jstab'];
  30.             }
  31.             $setupJs = '$(\'#'.$tabId.' a[href="#profile"]\').tab(\'show\');';
  32.         } else {
  33.             $setupJs = "$('#$tabId a:first').tab('show');";
  34.         }
  35.         
  36.  
  37.         $ret = '<ul class="nav nav-tabs" data-tabs="tabs" id="'.$tabId.'">';
  38.         foreach( $jsTabLinks as $tabLink ) {
  39.             $ret .= $tabLink;
  40.         }
  41.         $ret .= '</ul><div class="tab-content">'.$pContent.'</div>';
  42.         $ret .= '<script type="text/javascript">/*<![CDATA[*/ $(\'#'.$tabId.' a\').click(function (e) { e.preventDefault(); $(this).tab(\'show\'); }); '.$setupJs .'/*]]>*/</script> ';
  43.  
  44.  
  45.         $jsTabLinks = NULL;
  46.  
  47.         return $ret;
  48.     }
  49. }
  50. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:11 +0000 by phpDocumentor 1.5.0-lsces