Thursday, 10 December, 2009

PostHeaderIcon Sub-SubMenu for Blogger with Artisteer, part 2

The revised artDisplayTopMenu() function that we have seen in the first part of this article (see "Sub-SubMenu for Blogger with Artisteer, part 1") is interesting but it still has its flaws: firstly, it is not recursive, so it cannot give us an unlimited number of levels: if you need access to a fourth level, you'll have to modify it. Also, it doesn't include any control error; for example if you make a mistake about the order of tags "-", "-+" and "-+=". However, these are moot points in comparaison to its main problem: the difficulty that we'll have to manage the long series of options for the menu by using the standard configuration dialog of Blogger. In effect, if you need a second or a third level, for your menus, it's because you have tens or even hundreds of options to put there. For example, although the demonstration site Sub-SubMenu for Blogger with Artisteer contains only a tiny fraction of a menu that I'm building for another blog, manage it already requires a very long long series of clicks for inserting a new option or moving them around:

captured_Image.png

The final menu will be tens of times longer than that, with around one hundred options for the french version and the same for the engligh version; making its management prohibitively time consuming. In this part 2 of this article about sub-menus, Blogger and Artisteer, we will see how to solve this problem.

If we take a look at the widget's source code that will inserts the HTML items (<ul>, <li> tags, etc.) for the menu, we see that this is mainly a XML loop (the <b:loop ... in the figure below) that is running on the server; ie., before the HTML is sent back the client's browser. (Note: don't forget that you must first check the "Expand Widget Templates" option if you want to see this piece of code.)

captured_Image.png309

This loop will builds a list of items with the Javascript code necessary to store them one by one in the dynamic array menuitems; you can see part of the final result below. This list of menuitems.push(...) is part of the javascript code inside the HTML page that is sent to the browser client.  Once there, this code will be executed by the client's browser's javascript interpreter. As this part will run locally on your machine (unlike the XML loop which is executed on the server), you can see it by looking directly at the source code of the page in your browser (use the "View Source" or its equivalent on the menu of your browser):

 

The array menuitems and the first item of the menu's list (usually "Home" but "Accueil" in the example below) have already been created by the template Artisteer in a piece of javascript code just before that:

captured_Image.png[21]

Once the array menuitems has been completed, the artDisplayTopMenu() function is called, with the array passed in as parameter:

captured_Image.png[25]

To get rid of the need to use the "Configure Link List" window of Blogger, what we have to do would be simply to replace the function artDisplayTopMenu() with a new one that will have the necessary static code to build this list.  After that, a call to the original function artDisplayTopMenu() - renamed for the occasion artDisplayTopMenu2 - will build the HTML menu but now by using our own version of the menuitems array:

 

As we are now replacing the whole menuitems array, we must not forget to also include the option "Home" at its beginning; unless you don't want it there, of course!

However, if you try this code directly, it won't work at first as we have one last final adjustement to make: Blogger will not take the time to call the artDisplayTopMenu() (the original or our own version) if it doesn't see any created item in the Top Menu; so we have to create a dummy one to act as a trigger.  As this is a dummy argument that will never make it to the client's browser, you can write anything for it:

captured_Image.png[7]

You can see the an example of the result of this code on the demonstration site "Test2 - Sub-SubMenu with Artisteer".

When you have long menus or multiple blogs, it's much faster to manage them using this then by using the standard interface of Blogger (the "Configure Link List" dialog window).

However, there is one small problem remaining: this code will be erased if you refresh your Blogger template using Artisteer; so it is advisable to always make a backup copy of your code somewhere. Artisteer will also make a backup copy of your older template in the directory "C:\Documents and Settings\***YourUserName***\Application Data\Artisteer\Artisteer2\Library\BloggerBackup/" (for Windows XP); so you can always find a copy of your code there.  Notice that this an ordinary problem that you'll always have once you start customizing your templates.

This concludes Part 2 of the article on the sub-sousMenu of Artisteer for Blogger. In Part 4 we will see a new way to write our list of options for the menu without even having to go through the form "Edit HTML" each time but first, we'll see in part 3 how to adjust the width of the boxes created for the menu by Artisteer so that they will automatically adapt their size to their content instead of having all the same width.

Share/Save/Bookmark

0 comments:

Post a Comment

Welcome!

I'm in the process of launching this blog, so pardon me if a lot of features are still missing and that the articles are only partially written. In a few days, everything should be fine.
 
Thanks for your patience!
S. L.

Latest comments

Share - Bookmark - Email

Share/Bookmark

Google Friend Connect

Translate this page

      

About Me

My Photo
Consultant - Travailleur autonome pour les bases de données et l'internet.

Donate ($CAD)

 
If you have liked this site or if I've been helpful, you can support my work by making a donation. Thanks.

Advertisements

This Blogger template has been created with:
 
Artisteer - Web Design Generator

Disclaimer • Privacy policy

The information on this blog is provided for informational purposes only. The writer is not responsible for any damage caused by performing actions specified on this blog, or by relying on information published on this blog.  By using information or components provided on this blog you are accepting these terms.

This blog uses cookies.  You can find information about these and about the privacy policy of this blog by clicking here.