Search code examples
ajaxmootoolstooltip

How to create a mootool tooltip with Ajax response


How to create a mootool tooltip with Ajax response.Anybody can please suggest me a tutorial for the same.


Solution

  • What have you tried so far?

    You could do this way btw:

    Set inside your parent tippable elements a data-attribute to store the url (needed to retrieve the tooltip by ajax) i.e.:

    <div class="tippable" data-tipurl="/some/url/">
      when I mouseover here, a tip appears
    </div>
    

    Then, by js, create and cache the tips i.e.:

    $$('div.tippable').each(function(tippable){
    
        tippable.addEvents({
    
            'mouseenter' : function(){
    
                if(!this.retrieve('tip')){ //first time, build tip!
    
                    var tip = new Element('div.tip');
    
                    tip.set('load',{/* options */});
    
                    tip.load(this.get('data-tipurl')); //get through ajax 
    
                    tip.inject(this, 'top').setStyles({ //set tip style
                        position : 'absolute'
                        /* etc... */
                    });
    
                    this.store('tip', tip); //store it inside the parent
    
                }else{ // already built, just show it
    
                    this.retrieve('tip').setStyle('display', 'block');
                }
            },
    
            'mouseleave' : function(){
                var tip = this.retrieve('tip'); //retrieve the tip
    
                if(tip){ //if it's already built, hide it
                   tip.setStyle('display','none'); 
                }
    
                //otherwise, do nothing
            }
    
        });
    });