Results 1 to 3 of 3

Thread: Fixed Tooltip script: this Object is not getting passed or What ? Problem in Mozilla!

  1. #1
    Join Date
    Jun 2012
    Location
    New Delhi, India
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Fixed Tooltip script: this Object is not getting passed or What ? Problem in Mozilla!

    1) Script Title: Fixed Tooltip script

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...xedtooltip.htm

    3) Describe problem:

    I have copied the JS Code to and external .js file and it is working fine when using normally, in Chrome, Mozilla and IE.

    Now, I am trying to implement in one of my application in which I want to call the main function for tooltip, i.e, fixedtooltip() using another custom function showtip().
    Simply, I will call showtip() which in turn will call fixedtooltip().

    What I've done is this :

    1. Added a small custom function in the end of the JS file :
    Code:
    function showtip(mytext,obj)
    {
    fixedtooltip(mytext, obj, event, '150px')
    }
    2. Then using it in HTML as :
    HTML Code:
    <a href="http://www.javascriptkit.com" onMouseover="showtip('Testing !',this)" onMouseout="delayhidetip()">JavaScript Kit</a>
    See, I have passed the this object into the function.

    The problem is that this is working Good in IE, Google Chrome but not in Mozilla...

    Please Help !

    Thank You

    Regards,
    Ankur
    Last edited by AnkurThakur; 06-20-2012 at 12:50 PM. Reason: Resolved !

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    
    #fixedtipdiv{
    position:absolute;
    padding: 2px;
    border:1px solid black;
    font:normal 12px Verdana;
    line-height:18px;
    z-index:100;
    }
    
    </style>
    
    
    </head>
    
    <body>
    <script type="text/javascript">
    
    /***********************************************
    * Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var tipwidth='150px' //default tooltip width
    var tipbgcolor='lightyellow'  //tooltip bgcolor
    var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
    var vertical_offset="0px" //horizontal offset of tooltip from anchor link
    var horizontal_offset="-3px" //horizontal offset of tooltip from anchor link
    
    /////No further editting needed
    
    var ie4=document.all
    var ns6=document.getElementById&&!document.all
    
    if (ie4||ns6)
    document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')
    
    function getposOffset(what, offsettype){
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
    }
    return totaloffset;
    }
    
    
    function showhide(obj, e, visible, hidden, tipwidth){
    if (ie4||ns6)
    dropmenuobj.style.left=dropmenuobj.style.top=-500
    if (tipwidth!=""){
    dropmenuobj.widthobj=dropmenuobj.style
    dropmenuobj.widthobj.width=tipwidth
    }
    if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
    obj.visibility=visible
    else if (e.type=="click")
    obj.visibility=hidden
    }
    
    function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }
    
    function clearbrowseredge(obj, whichedge){
    var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
    if (whichedge=="rightedge"){
    var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
    dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
    if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
    edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
    }
    else{
    var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
    dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
    if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
    edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
    }
    return edgeoffset
    }
    
    function fixedtooltip(menucontents, obj, e, tipwidth){
    if (window.event) event.cancelBubble=true
    else if (e.stopPropagation) e.stopPropagation()
    clearhidetip()
    dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
    dropmenuobj.innerHTML=menucontents
    
    if (ie4||ns6){
    showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
    dropmenuobj.x=getposOffset(obj, "left")
    dropmenuobj.y=getposOffset(obj, "top")
    dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
    dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
    }
    }
    
    function hidetip(e){
    if (typeof dropmenuobj!="undefined"){
    if (ie4||ns6)
    dropmenuobj.style.visibility="hidden"
    }
    }
    
    function delayhidetip(){
    if (ie4||ns6)
    delayhide=setTimeout("hidetip()",disappeardelay)
    }
    
    function clearhidetip(){
    if (typeof delayhide!="undefined")
    clearTimeout(delayhide)
    }
    
    </script>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function showtip(mytext,obj,e)
    {
    fixedtooltip(mytext, obj, e, '150px')
    }/*]]>*/
    </script>
    <a href="http://www.javascriptkit.com" onMouseover="showtip('Testing !',this,event)" onMouseout="delayhidetip()">JavaScript Kit</a><br />
    <br />
    <a href="http://www.javascriptkit.com" onMouseover="fixedtooltip('Comprehensive JavaScript tutorials and over 400+ <b>free</b> scripts.', this, event, '150px')" onMouseout="delayhidetip()">JavaScript Kit</a> |
    
    <a href="http://www.codingforums.com" onMouseover="fixedtooltip('Web coding and development forums. This tooltip has an apostrophe- I\'m here.', this, event, '200px')" onMouseout="delayhidetip()">CodingForums.com</a>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    AnkurThakur (06-20-2012)

  4. #3
    Join Date
    Jun 2012
    Location
    New Delhi, India
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks !!!

    Very Nice Solution !!! Thanks a Lot my Friend

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •