jquery ui tooltip test

jquery ui tooltip

by Reiot

HTML

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
<button>show me the tooltip</button>
<p id="p" title="I can't see this">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<p>Hello <span title="here">Tooltip</span></p>

CSS

.ui-tooltip {
        padding:8px;
        position:absolute;
        z-index:9999;
        -o-box-shadow: 0 0 5px #aaa;
        -moz-box-shadow: 0 0 5px #aaa;
        -webkit-box-shadow: 0 0 5px #aaa;
        box-shadow: 0 0 5px #aaa;
    }
    /* Fades and background-images don't work well together in IE6, drop the image */
    * html .ui-tooltip {
        background-image: none;
    }
body .ui-tooltip { border-width:2px; }
p{padding:1em;}

JavaScript

/*global jQuery:true */
/*
 * jQuery UI Tooltip @VERSION
 *
 * Copyright 2010, AUTHORS.txt
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Tooltip
 *
 * Depends:
 *    jquery.ui.core.js
 *    jquery.ui.widget.js
 *    jquery.ui.position.js
 */
(function($) {

// role=application on body required for screenreaders to correctly interpret aria attributes
if( !$(document.body).is('[role]') ){
    $(document.body).attr('role','application');
} 

var increments = 0;

$.widget("ui.tooltip", {
    options: {
        tooltipClass: "ui-widget-content",
        content: function() {
            return $(this).attr("title");
        },
        position: {
            my: "left center",
            at: "right center",
            offset: "15 0"
        }
    },
    _init: function() {
        var self = this;
        this.tooltip = $("<div></div>")
            .attr({                
                id: "ui-tooltip-" + increments++,
                role: "tooltip",
                "aria-hidden": "true"
            })
            .addClass("ui-tooltip ui-widget ui-corner-all")
            .addClass(this.options.tooltipClass)
            .appendTo(document.body)
            .hide();
        this.tooltipContent = $("<div></div>")
            .addClass("ui-tooltip-content")
            .appendTo(this.tooltip);
        this.opacity = this.tooltip.css("opacity");
        this.element
            .hover(function(event){
                self.open(event);
            },function(event){
                self.close(event); 
            })
            .bind("focus.tooltip mouseenter.tooltip", function(event) {
                self.open( event );
            })
            .bind("blur.tooltip mouseleave.tooltip", function(event) {
                self.close( event );
            });
    },
    
    enable: function() {
        this.options.disabled = false;
    },
    
    disable: function() {
       ...