Solved

How to make TIPSY (jquery) work after 'clicking into' input?

Posted on 2009-04-10
2
632 Views
Last Modified: 2012-05-06
0
Comment
Question by:AndyPSV
2 Comments
 
LVL 3

Accepted Solution

by:
Ruurtjan earned 500 total points
ID: 24122498
Hi Andy,

-Replace hover by focus
-Replace "}, function() {" by "}); this.blur( function() {"

I've edited the current release for you.

Regards,
Ruurtjan
(function($) {

    $.fn.tipsy = function(opts) {
 

        opts = $.extend({fade: false, gravity: 'n'}, opts || {});

        var tip = null, cancelHide = false;
 

        this.focus(function() {

            

            $.data(this, 'cancel.tipsy', true);
 

            var tip = $.data(this, 'active.tipsy');

            if (!tip) {

                tip = $('<div class="tipsy"><div class="tipsy-inner">' + $(this).attr('title') + '</div></div>');

                tip.css({position: 'absolute', zIndex: 100000});

                $(this).attr('title', '');

                $.data(this, 'active.tipsy', tip);

            }

            

            var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});

            tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);

            var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;

            

            switch (opts.gravity.charAt(0)) {

                case 'n':

                    tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');

                    break;

                case 's':

                    tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');

                    break;

                case 'e':

                    tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tipsy-east');

                    break;

                case 'w':

                    tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tipsy-west');

                    break;

            }
 

            if (opts.fade) {

                tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 1});

            } else {

                tip.css({visibility: 'visible'});

            }
 

        });

        this.blur( function() {

            $.data(this, 'cancel.tipsy', false);

            var self = this;

            setTimeout(function() {

                if ($.data(this, 'cancel.tipsy')) return;

                var tip = $.data(self, 'active.tipsy');

                if (opts.fade) {

                    tip.stop().fadeOut(function() { $(this).remove(); });

                } else {

                    tip.remove();

                }

            }, 100);

            

        });
 

    };

})(jQuery);

Open in new window

0
 

Author Closing Comment

by:AndyPSV
ID: 31569103
works like a dream! thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now