new dhtmlmenu RT

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
hendrik
Posts: 66
Joined: Thu 9. Dec 2004, 21:18
Location: Berlin
Contact:

Post by hendrik »

rtilghman wrote:
What I would like to do is have the ability to have the parent item "active" when a child area is selected... which would make a lot more sense. So, for example, if you had a menu with 5 top links (visible) andthe user was in a page that resides in the pathway of "link 1" link 1 would have the ACTIVE class so you could have it highlighted.
I found something that works concerning your idea. can be improved though. I'm a php beginner. yippi.

Code: Select all

<?php

function build_dhtmlmenu2($start=0, $class='', $activeclass='', $counter=0) {
// **************************************************************************
// Paul: nice HTML source format, from class='classname' to class="classname"

   $class="class="".$class.""";
   $classactive="class="".$activeclass.""";

// Paul: nice HTML source format END   
// **************************************************************************

   $s = '';
   $g = '';
      
// **************************************************************************
// Paul: for submenu   

   $thfs = $GLOBALS["content"]["struct"];
   foreach($thfs as $key => $value)
   {
		   $x = &$GLOBALS["content"]["struct"][$value["acat_struct"]];
           if($value["acat_struct"] != 0)
                   $x["acat_has_children"] = 1;
           else
                   $x["acat_has_children"] = 0;
   }

// Paul: for submenu END
// **************************************************************************
// **************************************************************************
// Hendrik: 3 level
		 $bef0 = $GLOBALS['aktion'][0];
		 $bef1 = $GLOBALS['content']['struct'][$bef0]['acat_struct'];
		 $bef2 = $GLOBALS['content']['struct'][$bef1]['acat_struct'];
// Hendrik: 3 level END
// **************************************************************************
   foreach($GLOBALS['content']['struct'] as $key => $value) {
	
     if ($start == $GLOBALS['content']['struct'][$key]['acat_struct'] &&
         !$GLOBALS['content']['struct'][$key]['acat_hidden'] && $key)
      {
       $s .= '<li';
// **************************************************************************
// Hendrik: change and add
	     if($key == $bef0 && $activeclass) $s .= ' '.$classactive;
		 if($key == $bef1 && $activeclass) $s .= ' '.$classactive;
		 if($key == $bef2 && $activeclass) $s .= ' '.$classactive;
// Hendrik: change and add END
// **************************************************************************
       $s .= '>';

         if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
            $s .= '<a href="index.php?';
            if($GLOBALS['content']['struct'][$key]['acat_alias']) {
               $s .= $GLOBALS['content']['struct'][$key]['acat_alias'];
            } else {
               $s .= 'id='.$key.',0,0,1,0,0';
            }

// **************************************************************************
// Paul: change and add   
       
                 $s .= '"';
                 if($GLOBALS['content']['struct'][$key]['acat_has_children'])
                         $s .= ' class="submenu"';
                 $s .= '>';

// Paul: change and add END
// **************************************************************************

         } else {
            $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
            $s .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
         }

         $s .= html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);
         $s .= '</a>';

         $s .= build_dhtmlmenu2($key, $class, $activeclass,$counter+1);

         $s .= "</li>\n";
      }
   }
   if($s) {
      $g  = "\n<ul";
      if(!$counter && $class) {
		  $g .= ' '.$class;
	 }
	  $g .= ">\n".$s.'</ul>';
   }
   return $g;
}

// parse the whole webpage $content["all"] is the fully rendered webpage your site displays
$content["all"] = (myTagParser ($content["all"]));
// parse the $string and replace all possible instances of the following {RT}'s
function myTagParser($string) {
   $search[0] = '/\{DHTMLMENU:(.*?),(.*?),(.*?)\}/e';
   $replace[0] = 'build_dhtmlmenu2("$1","$2","$3");';
   $string = preg_replace($search, $replace, $string);
   $string = str_replace('\'', '\'',$string);
   $string = str_replace('&quot;', '"',$string);
   return $string;   // spit out the final webpage for display
}

?>
hendrik
Posts: 66
Joined: Thu 9. Dec 2004, 21:18
Location: Berlin
Contact:

Post by hendrik »

ok, no one is impressed so I improved the code a bit:

you can have a look at http://www.hendrikschirmann.de/cms
well, site is under construction

the code gives a css class to the item you clicked on and the 'itemOn'-class to
the parents and it checks all levels of parents automaticly.

Code: Select all

<?php

function build_dhtmlmenu2($start=0, $class='', $activeclass='', $counter=0) {
// **************************************************************************
// Paul: nice HTML source format, from class='classname' to class="classname"

   $class="class=\"".$class."\"";
   $classactive="class=\"".$activeclass."\"";

// Paul: nice HTML source format END   
// **************************************************************************

   $s = '';
   $g = '';
      
// **************************************************************************
// Paul: for submenu   

   $thfs = $GLOBALS["content"]["struct"];
   foreach($thfs as $key => $value)
   {
		   $x = &$GLOBALS["content"]["struct"][$value["acat_struct"]];
           if($value["acat_struct"] != 0)
                   $x["acat_has_children"] = 1;
           else
                   $x["acat_has_children"] = 0;
   }

// Paul: for submenu END
// **************************************************************************
// Hendrik: add
		$bef[0] = $GLOBALS['aktion'][0];// the ID of the item you clicked is stored
		$se = 0;
		while ($bef[$se])//if there are parents, this is > 0
		{
			$se++;
			$bef[$se] = $GLOBALS['content']['struct'][$bef[$se-1]]['acat_struct'];// store parents ID's
		}
// Hendrik: add END
// **************************************************************************
   foreach($GLOBALS['content']['struct'] as $key => $value) {
	
     if ($start == $GLOBALS['content']['struct'][$key]['acat_struct'] &&
         !$GLOBALS['content']['struct'][$key]['acat_hidden'] && $key)
      {
       $s .= '<li';
// **************************************************************************
// Hendrik: change and add
	  if ($activeclass)
	  {
	     for ($i = 0 ; $i <= $se ; $i++)
		 {
			 if($key == $bef[$i])
			 {
				 if (!$i) $s .= ' class="itemChoosen"'; //the choosen item can get an extra css-class
					 else $s .= ' '.$classactive; //parents
			 }
		 }
	   }
// Hendrik: change and add END
// **************************************************************************
       $s .= '>';

         if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
            $s .= '<a href="index.php?';
            if($GLOBALS['content']['struct'][$key]['acat_alias']) {
               $s .= $GLOBALS['content']['struct'][$key]['acat_alias'];
            } else {
               $s .= 'id='.$key.',0,0,1,0,0';
            }

// **************************************************************************
// Paul: change and add   
       
                 $s .= '"';
                 if($GLOBALS['content']['struct'][$key]['acat_has_children'])
                         $s .= ' class="submenu"';
                 $s .= '>';

// Paul: change and add END
// **************************************************************************

         } else {
            $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
            $s .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
         }

         $s .= html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);
         $s .= '</a>';

         $s .= build_dhtmlmenu2($key, $class, $activeclass,$counter+1);

         $s .= "</li>\n";
      }
   }
   if($s) {
      $g  = "\n<ul";
      if(!$counter && $class) $g .= ' '.$class;
	  $g .= ">\n".$s.'</ul>';
   }
   return $g;
}
// parse the whole webpage $content["all"] is the fully rendered webpage your site displays
$content["all"] = (myTagParser ($content["all"]));
// parse the $string and replace all possible instances of the following {RT}'s
function myTagParser($string) {
   $search[0] = '/\{DHTMLMENU:(.*?),(.*?),(.*?)\}/e';
   $replace[0] = 'build_dhtmlmenu2("$1","$2","$3");';
   $string = preg_replace($search, $replace, $string);
   $string = str_replace('\'', '\'',$string);
   $string = str_replace('&quot;', '"',$string);
   return $string;   // spit out the final webpage for display
}

?>
hendrik
User avatar
Kosse
Posts: 1066
Joined: Thu 9. Sep 2004, 12:08
Location: Brussels, Belgium
Contact:

Post by Kosse »

hendrik wrote:ok, no one is impressed so I improved the code a bit:

you can have a look at http://www.hendrikschirmann.de/cms
well, site is under construction

the code gives a css class to the item you clicked on and the 'itemOn'-class to
the parents and it checks all levels of parents automaticly.

hendrik
It looks very cool hendrik, thx for sharing!
Cheers
hendrik
Posts: 66
Joined: Thu 9. Dec 2004, 21:18
Location: Berlin
Contact:

Post by hendrik »

thank you Kosse! :D
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Post by Paal »

Kosse wrote:
hendrik wrote:ok, no one is impressed so I improved the code a bit:

you can have a look at http://www.hendrikschirmann.de/cms
well, site is under construction

the code gives a css class to the item you clicked on and the 'itemOn'-class to
the parents and it checks all levels of parents automaticly.

hendrik
It looks very cool hendrik, thx for sharing!
Cheers
Great job!

Paul
hendrik
Posts: 66
Joined: Thu 9. Dec 2004, 21:18
Location: Berlin
Contact:

Post by hendrik »

thanx Paal, nice to hear!
hendrik
Posts: 66
Joined: Thu 9. Dec 2004, 21:18
Location: Berlin
Contact:

Post by hendrik »

want some more classes (and work and confusion :wink: )?
then exchange

Code: Select all

// Hendrik: change and add
     if ($activeclass)
     {
        for ($i = 0 ; $i <= $se ; $i++)
       {
          if($key == $bef[$i])
          {
             if (!$i) $s .= ' class="itemChoosen"'; //the choosen item can get an extra css-class
                else $s .= ' '.$classactive; //parents
          }
       }
      }
// Hendrik: change and add END 
by

Code: Select all

// Hendrik: change and add
	  if ($activeclass)
	  {
	     for ($i = 0 ; $i <= $se ; $i++)
		 {
			 if($key == $bef[$i])
			 {
				 if (!$i) 
				 {
				   if ($se == 1) $s .= ' class="itemChoosenFirst"';//item choosen no parents (is upmost level)
				   else $s .= ' class="itemChoosen"'; //item choosen has parents
				}
				 else 
				 {
					 if ($se == $i +1) $s .= ' class="itemOnFirst"'; //upmost level leading to item choosen
					 else $s .= ' '.$classactive; //class="itemOn" leading to item choosen
				  }
			 }
		 }
	   }
// Hendrik: change and add END
could look like:
Image
Image

hendrik
User avatar
Heiko H.
Posts: 868
Joined: Thu 27. Oct 2005, 11:41
Location: Dresden
Contact:

Post by Heiko H. »

Hallo,

super RT !!!

Does anybody have an idea how to delay the menu collapse 1-2 seconds?
Once the mouse is outside the menu, the menu collapse immediately, so the user has to start the navigation again. :cry:


THX!
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Post by Stim »

Hi

Is it more then one menu in this topic?

Can someone please post all file I for this menu somewhere because I don’t really understand how to fix this stuff :lol:

There are lots off cod in this topic and don’t really know if all cod is for different menu or just for one menu. :lol:
ssyfrig
Posts: 364
Joined: Tue 2. Mar 2004, 17:01
Location: Zürich / Switzerland
Contact:

Post by ssyfrig »

Hi Stim

check http://www.swisscopter.net/index.php?cms

I create a zip file for you, with all files (code) where I running on swisscopter.net

greez Sven
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Post by Stim »

Hi

Thanks for zip file

Is this menu based on the category structure in admin or can I add and remove link in the menu?

I need menu that lets my choose my one category, subcategory or link to other pages in the menu etc. Can I do that whiteout "hide and sows category" in admin?
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Post by Stim »

Hi again

There is one file ”DHTMLMENU2.php” in that zip file. which folder do I insert the file in phpwcms?

Someone?
ssyfrig
Posts: 364
Joined: Tue 2. Mar 2004, 17:01
Location: Zürich / Switzerland
Contact:

Post by ssyfrig »

/phpwcms_template/inc_script/frontend_render/

greez Sven
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Post by Stim »

I need menu that lets my choose my one category, subcategory or link to other pages in the menu etc. Can I do that whiteout "hide and sows category" in admin?[/quote]


Bump!!
pepe
Posts: 3954
Joined: Mon 19. Jan 2004, 13:46

Post by pepe »

Look into ADMIN... there you can make a redirection to another page of your site... or to a page of another site :idea:
Post Reply