Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Plugin for tafelTree (Very good JavaScript TreeView)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
Abalam
Smarty Rookie


Joined: 14 Jul 2003
Posts: 12

PostPosted: Thu Dec 28, 2006 2:28 pm    Post subject: Plugin for tafelTree (Very good JavaScript TreeView) Reply with quote

Just to add my smarty plug-in for tafelTree :

Code:

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {tafelTree} function plugin
 *
 * Type:     function
 * Name:     tafelTree
 * Purpose:  make a tafelTree from PHP array structure
 * Version:     0.1
 * @link http://tafel.developpez.com/
 * @author Yann-Gaël GAUTHERON <abalam -at- aewd -dot- net>
 * Example:
 
       Note that values are javascript code or strings, if it's strings you must add a JS quote inside de PHP quote like
      $struct = array(
         array(
            "id" => "'root0'"
            ,"txt" => "'root 0'"
         )
         ,array(
            'id' => "'root1'"
            ,'txt' => "'TafelTree JS'"
            ,'img' => "'base.gif'"
            ,'items' => array(
               array(
                  'id' => "'child1'"
                  ,'txt' => "'L\'objet en question'"
                  ,'items' => array(
                     array(
                        'id' => "'child2'"
                        ,'txt' => "'<span>Ses méthodes</span>'"
                     )
                     ,array(
                        'id' => "'3'"
                        ,'txt' => "'Ses propriétés'"
                     )
                     ,array(
                        'id' => "'child4'"
                        ,'txt' => "'Ses functions utilisateur (genre onclick)'"
                        ,'onclick' => 'function(branch){alert("le texte de ce noeud est le suivant  =>  \n" + branch.struct.txt);}'
                        ,'items'  =>  array(
                           array(
                              'id'  =>  "'blu'"
                              ,'txt'  =>  "'hop'"
                              ,'check' => 1
                              ,'tooltip'  =>  "'Mon joli tooltip'"
                           )
                        )
                     )
                  )
               )
            )
         )
      );

 * @param array
 * @param Smarty
 * @return string
 */
function smarty_function_tafelTree($params, &$smarty)
{
   /* Initialize */
      $attributes = array(
      'generate'=>"true",
      'imgBase' => "'js/tafelTree/imgs/'",
      'openAtLoad'=>"true",
      'cookies'=>"true",
      'multiline'=>"true",
      'defaultImg'=>"'page.gif'",
      'defaultImgSelected'=>"'globe.gif'",
      'defaultImgOpen'=>"'folderopen.gif'",
      'defaultImgClose'=>"'folder.gif'",
      'defaultImgCloseSelected'=>"'unlock.gif'",
      'defaultImgOpenSelected'=>"'imgfolder.gif'",
      'rtlMode'=>"false",
      'dropALT'=>"false",
      'checkboxesThreeState'=>"true",
      'behaviourDrop'=>"'sibling'",
   );

    foreach ($params as $_key=>$_value) {
        switch ($_key) {            
            case 'struct':
         case 'id':
         case 'phpAjaxEditorFilename':
            $$_key = $_value;
                break;
            
         case 'generate':
         case 'imgBase':
         case 'openAtLoad':
         case 'cookies':
         case 'ondrop':
         case 'multiline':
         case 'defaultImg':
         case 'defaultImgSelected':
         case 'defaultImgOpen':
         case 'defaultImgClose':
         case 'defaultImgCloseSelected':
         case 'defaultImgOpenSelected':
         case 'rtlMode':
         case 'dropALT':
         case 'checkboxesThreeState':
         case 'behaviourDrop':
         case 'onclick':
            $attributes[$_key] = (string)$_value;
                break;
            
            default:
                $smarty->trigger_error("[tafelTree] parametre inconnu $_key", E_USER_WARNING);
        }
    }

    if (empty($id) || empty($struct)) {
        $smarty->trigger_error("[tafelTree] attribut 'id' et 'struct' requis");
        return false;
    }

   $html .= '<div id="'.$id.'"></div>';
   $html .= '<script type="text/javascript">/*<![CDATA[*/';
   
   function to_json($array) {
      foreach ($array as $k => $i) {
         if (is_array($i)) {
            $i = to_json($i);
         }
         if ($array[0]) { /* Index numériques */
            $data[] = $i;
         } else { /* Index associatifs */
            $data[] = "'".$k."':".$i;
         }
      }
      $s = implode(",",$data);
      if ($array[0]) { /* Index numériques */
         return "[".$s."]";
      } else { /* Index associatifs */
         return "{".$s."}";
      }
   }

   $html .= 'new TafelTree("'.$id.'", '.to_json($struct).', '.to_json($attributes).");";   
   $html .= '/*]]>*/</script>';
   
   return $html;
}
?>
Back to top
View user's profile Send private message
rekam
Smarty n00b


Joined: 03 Jan 2007
Posts: 1

PostPosted: Wed Jan 03, 2007 3:49 pm    Post subject: Reply with quote

Hi, and just for info :

http://tafel.developpez.com/site/lang/en/index.php
http://sourceforge.net/projects/tafeltree

Good coding and viva Smarty!
Rekam
Back to top
View user's profile Send private message
vain
Smarty Rookie


Joined: 20 May 2006
Posts: 23
Location: Berlin / Germany

PostPosted: Fri Aug 24, 2007 1:37 pm    Post subject: Reply with quote

nice work! thanks a lot!
regards vain
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP