[TYPO3] Multiple instances of foldoutmenu at different levels (patch)

Eduardo Trápani eduardo at esperanto.org.uy
Tue Mar 25 20:57:07 CET 2008


Hi,

I had problems with foldoutmenu when used many times at different depth levels in the same page.  All instances share the register value and the collision has side effects (like menus being always unfolded, etc.).

I patched (four lines of actual code) foldoutmenu.php and foldoutmenu.js to be able to use foldoutmenu many times.  The javascript patch skips empty uids.  When only working at level three, for example, the js function gets called with ",id" instead of "id" so the first empty field is escaped.

In order to use it many times safely (it seems to works unpatched when at the same menu level)  you have to specify .register to itemArrayProcFunc and then use the same value in the .data field of the associated TEXT object, for example:

in the menu:
       itemArrayProcFunc.register = theInstaceRegisterValue
       itemArrayProcFunc = user_foldoutMenu->getIfSubUidList

in the text object:
	data = register:theInstaceRegisterValue

That's it.  Since the default value for .register, is ifSubUidList, the patched version can be used as a drop-in replacement.

Hope it helps somebody else, it took me a long time to figure out what was wrong.

Friendly, Eduardo.

PD: I did try to contact the author, unsuccessfully.

--- foldout.js.orig     2008-03-25 15:51:38.000000000 -0300
+++ foldout.js  2008-03-25 16:13:06.000000000 -0300
@@ -114,10 +114,13 @@
                this.displayMode = (this.direction)?"inline":"block";
                var uid = uids.split(",");
                for (var i=0; i<uid.length; i++) {
+                       if (uid[i].length > 0)
+{
                        var el = this.getElById(this.prefix+"-"+uid[i]);
                        if (this.foldout_expand[uid[i]] == 1 && this.enableCookie) this.fold(el,uid[i],1);
                        else if (el.style.display!=this.displayMode) {
                                this.fold(el,uid[i],(!this.startFolded && !this.autoFold)?1:0)
+}
                        }
                }
        }
@@ -175,4 +178,4 @@
                this.setCookie(cookieName, cookieString,this.cookieLifetime,'/');
        }

-}
\ No newline at end of file
+}


--- foldoutmenu.php.orig        2008-03-25 15:51:29.000000000 -0300
+++ foldoutmenu.php     2008-03-25 16:38:24.000000000 -0300
@@ -38,18 +38,26 @@
                 */
                function getIfSubUidList($menuArr, $conf) {
                        $prefix = $conf['prefix']?$conf['prefix'].'-':'';
+                       if (isset($conf['register']))
+                       {
+                               $regname = $conf['register'];
+                       }
+                       else
+                       {
+                               $regname = 'ifSubUidList';
+                       }
                        if ($conf['parentObj']->menuNumber == 1) {
                                $GLOBALS['TSFE']->additionalHeaderData[$this->extKey] = '<script type="text/javascript" src="'.t3lib_extMgm::siteRelPath($this->extKey).'foldout.js"></script>';
                                $result = array();
                        } else {
-                               $result = explode(',', $GLOBALS['TSFE']->register['ifSubUidList']);
+                               $result = explode(',', $GLOBALS['TSFE']->register[$regname]);
                        }
                        while (list($k, $v) = each($menuArr)) {
                                if ($conf['parentObj']->isItemState('IFSUB', $k) ) {
                                        $result[]=$prefix.$v['uid'];
                                }
                        }
-                       $GLOBALS['TSFE']->register['ifSubUidList'] = implode(',', $result);
+                       $GLOBALS['TSFE']->register[$regname] = implode(',', $result);
                        return $menuArr;
                }
                /**


More information about the TYPO3-english mailing list