javascript function acting weirdly
hey guys i cant get a function working properly, the point is to climb over the pareents till i get the one to trigger the toggle action. But the function acting weirdly and when the validated tag is found it seems to doesnt returning true and complete the recursive way.
unction dock(e){
if(e.get(0).tagName != "BODY"){
alert("current : "+e.get(0).tagName)
e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName)
if($(this).length > 0){
e.parent().trigger('toggleDock')
alert("triggered parent : "+e.parent().get(0).tagName)
return true
}
})
if ( dock(e.parent()) ){
alert("validated parent : "+e.parent().get(0).tagName)
return true
}
alert("end dock(), current : "+e.get(0).tagName)
}
return false
}
$(".dockme").live('click', function(event) {
a = dock($(this))
alert("dock returned :"+a)
});
the whole code :
/* when the page is loaded */
$(document).ready(function(){
$("body").splitter({
splitVertical: true,
outline: true,
sizeLeft: 30, minLeft: 0, maxLeft: 100,
resizeToWidth: true,
anchorToWindow: true,
dock: "left",
dockSpeed: 200,
cookie: "docksplitter"
});
$("#a").splitter({
splitHorizontal: true,
outline: true,
sizeBottom: 30, minBottom: 0, maxBottom: 30,
dock: "bottom",
dockSpeed: 200,
cookie: "docksplitter"
});
$("#b").splitter({
splitVertical: true,
sizeRight: 320, minRight: 0, maxRight: 320,
dock: "right",
dockSpeed: 200,
cookie: "docksplitter"
});
function dock(e){
if(e.get(0).tagName != "BODY"){
alert("current : "+e.get(0).tagName)
开发者_如何学Go e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName)
if($(this).length > 0){
e.parent().trigger('toggleDock')
alert("triggered parent : "+e.parent().get(0).tagName)
return true
}
})
if ( dock(e.parent()) ){
alert("validated parent : "+e.parent().get(0).tagName)
return true
}
alert("end dock(), current : "+e.get(0).tagName)
}
return false
}
$(".dockme").live('click', function(event) {
a = dock($(this))
alert("dock returned :"+a)
});
});html : http://pastie.org/1329885
The function inside e.siblings(...).each
is not returning true
from dock
.
So instead of
e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName)
if($(this).length > 0){
e.parent().trigger('toggleDock')
alert("triggered parent : "+e.parent().get(0).tagName)
return true
}
})
I think you need to say something like:
var triggeredInSplitterBar = false; // ADDED
e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName);
if($(this).length > 0){
e.parent().trigger('toggleDock');
alert("triggered parent : "+e.parent().get(0).tagName);
triggeredInSplitterBar = true; // CHANGED
}
});
if (triggeredInSplitterBar) { return true; } // ADDED
精彩评论