aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <s1lv10@uol.com.br>2009-10-03 16:34:28 -0300
committerSilvio <s1lv10@uol.com.br>2009-10-03 16:34:28 -0300
commitac3d9e1062ebdd1addd7e68ed45674832709ce38 (patch)
treeef3aede63d35063d91daf32b3062b6e3c24a9ddc
parent13f0d19c42dc38b35c4ab334c6c9e1f0355ae0cc (diff)
downloadfinder_menu-ac3d9e1062ebdd1addd7e68ed45674832709ce38.tar.gz
finder_menu-ac3d9e1062ebdd1addd7e68ed45674832709ce38.tar.bz2
Almost working version with new isparent() function
-rw-r--r--finder_menu.js44
-rw-r--r--finder_menu.module12
2 files changed, 44 insertions, 12 deletions
diff --git a/finder_menu.js b/finder_menu.js
index b6b25db..ca40c91 100644
--- a/finder_menu.js
+++ b/finder_menu.js
@@ -13,6 +13,7 @@ function ul2finder()
var hideClass='hidden';
var openClass='open';
window.finderOpened = new Object();
+ window.finderPrevious = null;
// check if our finder list exists, if not, stop all activities
finder=document.getElementById('finder');
@@ -58,6 +59,10 @@ function ul2finder()
{
// check if it's connected to this link
var found=false;
+ /*if (isparent(this.parentNode.getElementsByTagName('ul')[0], uls[i]) ||
+ isparent(uls[i],this.parentNode.getElementsByTagName('ul')[0])) {
+ found=true;
+ }*/
for(j=0;j<uls[i].getElementsByTagName('ul').length;j++)
{
if(uls[i].getElementsByTagName('ul')[j] ==
@@ -97,24 +102,49 @@ function ul2finder()
// and hide the current nested list
cssjs('add',this,parentClass);
cssjs('remove',this,openClass);
- // TODO: check why it's not iterating
- for(i=0;i<uls.lenght;i++) {
- cssjs('remove',uls[i],showClass);
+ for(var u=0;u<uls.length;u++) {
+ cssjs('remove',uls[u],showClass);
}
}
+ // hide the previously opened element
+ if (window.finderPrevious != this.id && window.finderPrevious != null) {
+ previous = document.getElementById(window.finderPrevious);
+ uls = previous.parentNode.getElementsByTagName('ul');
+ current = this.parentNode.getElementsByTagName('ul')[0];
+ if (!isparent(uls[0],current) && !isparent(current,uls[0])) {
+ uls = previous.parentNode.getElementsByTagName('ul');
+ window.finderOpened[previous.id] = false;
+ // change the current link from open to parent
+ // and hide the current nested list
+ cssjs('add',previous,parentClass);
+ cssjs('remove',previous,openClass);
+ for(var t=0;t<uls.length;t++) {
+ cssjs('remove',uls[t],showClass);
+ }
+ previous.innerHTML = window.finderOpened[previous.id];
+ }
+ }
+
+ window.finderPrevious = this.id;
this.innerHTML = window.finderOpened[this.id];
// don't follow the real HREF of the link
return false;
}
}
function isparent(par, child) {
- if (par.hasChildNodes()) {
+ if ($(child).parents().index(par) >= 0) {
+ return true;
+ }
+ return false;
+ }
+ function isparent_std(par, child) {
+ if (par == child) {
+ return true;
+ } else if (par.hasChildNodes()) {
children = par.childNodes;
for (var i=0;i<children.length;i++) {
- if (children[i] == child) {
- return true;
- } else if (isparent(children[i], child)) {
+ if (children[i] == child || isparent(children[i], child)) {
return true;
}
}
diff --git a/finder_menu.module b/finder_menu.module
index 6b757b3..6857987 100644
--- a/finder_menu.module
+++ b/finder_menu.module
@@ -110,7 +110,7 @@ function theme_finder_menu($menu_name, $mlid) {
// Build the menus
$output = '<div id="finderparent">';
- $output .= finder_menu_build($menu, TRUE);
+ $output .= finder_menu_build($menu, "finder");
$output .= '</div>';
drupal_add_js(drupal_get_path('module', 'finder_menu') .'/finder_menu.js');
@@ -122,12 +122,14 @@ function theme_finder_menu($menu_name, $mlid) {
*
* @ingroup themeable
*/
-function finder_menu_build($menu, $first = FALSE) {
+function finder_menu_build($menu, $id = null) {
- if ($first === TRUE) {
+ if ($id == "finder") {
$output = '<ul id="finder">';
+ $id = 0;
} else {
- $output = '<ul>';
+ $id = ($id == null) ? 0: $id;
+ $output = '<ul id="finder[ul][' . $id . ']">';
}
foreach ($menu as $menu_item) {
@@ -135,7 +137,7 @@ function finder_menu_build($menu, $first = FALSE) {
$output .= '<li>';
if ($menu_item['below'] !== FALSE && finder_menu_has_unhidden_submenu($menu_item['below'])) {
$output .= $menu_item['link']['title'];
- $output .= finder_menu_build($menu_item['below']);
+ $output .= finder_menu_build($menu_item['below'], ++$id);
} else {
$output .= theme('menu_item_link', $menu_item['link']);
}