aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--finder_menu.js45
1 files changed, 24 insertions, 21 deletions
diff --git a/finder_menu.js b/finder_menu.js
index 2b20d68..1a56a51 100644
--- a/finder_menu.js
+++ b/finder_menu.js
@@ -58,14 +58,8 @@ function ul2finder()
ul = this.parentNode.getElementsByTagName('ul')[0];
for(var i=0;i<uls.length;i++)
{
- // check if it's connected to this link
- var found=false;
- if (isparent(ul, uls[i]) || isparent(uls[i],ul)) {
- found=true;
- }
-
- // hide elements
- if(!found || window.finderOpened[this.id] == true)
+ // hide unconnected or closing elements
+ if (!connected(ul, uls[i]) || window.finderOpened[this.id] == true)
{
ref = uls[i].parentNode.getElementsByTagName('a')[0];
if (ref != this && !isparent(uls[i],ul)) {
@@ -98,13 +92,14 @@ function ul2finder()
}
}
- // hide the previously opened element
- if (window.finderPrevious != this.id && window.finderPrevious != null) {
+ // hide the previously opened element if not connected
+ if (window.finderPrevious != null && window.finderPrevious != this.id) {
+
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');
+
+ if (!connected(uls[0],current)) {
window.finderOpened[previous.id] = false;
// change the current link from open to parent
// and hide the current nested list
@@ -123,25 +118,33 @@ function ul2finder()
return false;
}
}
+
+ /*
+ * isparent
+ * written by Silvio - s1lv10 at uol.com.br
+ * checks if an element is parent of another via DOM
+ * inspired by http://stackoverflow.com/questions/245241/jquery-ancestors-using-jquery-objects
+ */
function isparent(par, child) {
if ($(child).parents().index(par) >= 0) {
return true;
}
return false;
}
- function isparent_std(par, child) {
- if (par == child) {
+
+ /*
+ * connected
+ * written by Silvio - s1lv10 at uol.com.br
+ * checks if two elements are connect via DOM, either by one being
+ * child of parent of the another.
+ */
+ function connected(a, b) {
+ if (isparent(a, b) || isparent(b, a)) {
return true;
- } else if (par.hasChildNodes()) {
- children = par.childNodes;
- for (var i=0;i<children.length;i++) {
- if (children[i] == child || isparent(children[i], child)) {
- return true;
- }
- }
}
return false;
}
+
/*
* cssjs
* written by Christian Heilmann (http://icant.co.uk)