View Full Version : Help with this code...

04-16-2009, 09:16 PM
I am using a code on my MyBB forums, and what the code does, is when I click on a link, Search, for example, it pops open a search box, like vBulletin does, when you click Search.

But what Iam trying to figure out, if how to make it so when I click elsewhere, the box closes.

On my forums, I have to click the link to get it to close back up.

If you go to vBulletin's website (vbulletin.com), and click Community, click either Blogs, or Search, in the navigation.

See how a box pops open?
Now, click somewhere else, it doesnt even have to be a link.

The box should close.
That is what I am trying to accomplish with mine.

Here is the Javascript code I am using.

<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
return totaloffset;

function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)?

-(subobj.offsetWidth-curobj.offsetWidth) : 0)
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)?

curobj.offsetHeight : 0)
return false
return true

function overlayclose(subobj){

// ]]></script>

And in the code for the link, I have to put this.

onclick="return overlay(this, 'search','bottom')"

If you need to know anything else, please let me know.