├── package.json ├── LICENSE ├── README ├── tooltipsy.min.js ├── tooltipsy.source.js └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tooltipsy", 3 | "version": "1.0.3", 4 | "description": "Introducing a jQuery tooltip plugin for control-obsessed designers.", 5 | "main": "./index.js", 6 | "scripts": { 7 | 8 | }, 9 | "repository": { 10 | "type": "https", 11 | "url": "https://github.com/Coding/tooltipsy" 12 | }, 13 | "author": "briancray/tooltipsy", 14 | "license": "MIT", 15 | "dependencies": { 16 | 17 | }, 18 | "devDependencies": { 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2010 Brian Cray 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | tooltipsy by Brian Cray 2 | 3 | Lincensed under MIT - http://opensource.org/licenses/MIT (Changed 12/2/14) 4 | 5 | HOW TO (THE EASY METHOD): 6 | 7 | 1. Identify the HTML element that will trigger a tooltip, such as: 8 | Foobar 9 | 2. Add a class name and title to the element 10 | Foobar 11 | 3. Link to it with jQuery 12 | $('.hastip').tooltipsy(); 13 | 4. Style it with CSS however you like, for example: 14 | .tooltipsy 15 | { 16 | padding: 10px; 17 | max-width: 200px; 18 | color: #303030; 19 | background-color: #f5f5b5; 20 | border: 1px solid #deca7e; 21 | } 22 | 5. Enjoy lovely tooltips 23 | 24 | OPTION QUICK REFERENCE: 25 | 26 | - alignTo: "element" or "cursor" (Defaults to "element") 27 | - offset: Tooltipsy distance from element or mouse cursor, dependent on alignTo setting. Set as array [x, y] (Defaults to [0, -1]) 28 | - content: HTML or text content of tooltip. Defaults to "" (empty string), which pulls content from target element's title attribute 29 | - show: function(event, tooltip) to show the tooltip. Defaults to a show(100) effect 30 | - showEvent: Set a custom event to bind the show function. Defaults to mouseenter 31 | - hide: function(event, tooltip) to hide the tooltip. Defaults to a fadeOut(100) effect 32 | - hideEvent: Set a custom event to bind the show function. Defaults to mouseleave 33 | - delay: A delay in milliseconds before showing a tooltip. Set to 0 for no delay. Defaults to 200 34 | - css: object containing CSS properties and values. Defaults to {} to use stylesheet for styles 35 | - className: DOM class for styling tooltips with CSS. Defaults to "tooltipsy" 36 | 37 | METHOD QUICK REFERENCE: 38 | 39 | - $('.hastip').data('tooltipsy').show(): Force the tooltip to show 40 | - $('.hastip').data('tooltipsy').hide(): Force the tooltip to hide 41 | - $('.hastip').data('tooltipsy').destroy(): Remove the tooltip from DOM 42 | 43 | OTHER GREAT THINGS TO KNOW: 44 | 45 | - You can use ajax, for example: 46 | $('.hastip').tooltipsy({ 47 | content: function ($el, $tip) { 48 | $.get('api.php', function (data) { 49 | $el.html(data); 50 | }); 51 | return 'Fallback content'; 52 | } 53 | }); 54 | 55 | MORE INFORMATION VISIT http://tooltipsy.com/ 56 | -------------------------------------------------------------------------------- /tooltipsy.min.js: -------------------------------------------------------------------------------- 1 | /* tooltipsy by Brian Cray 2 | * Lincensed under GPL2 - http://www.gnu.org/licenses/gpl-2.0.html 3 | * Option quick reference: 4 | * - alignTo: "element" or "cursor" (Defaults to "element") 5 | * - offset: Tooltipsy distance from element or mouse cursor, dependent on alignTo setting. Set as array [x, y] (Defaults to [0, -1]) 6 | * - content: HTML or text content of tooltip. Defaults to "" (empty string), which pulls content from target element's title attribute 7 | * - show: function(event, tooltip) to show the tooltip. Defaults to a show(100) effect 8 | * - hide: function(event, tooltip) to hide the tooltip. Defaults to a fadeOut(100) effect 9 | * - delay: A delay in milliseconds before showing a tooltip. Set to 0 for no delay. Defaults to 200 10 | * - css: object containing CSS properties and values. Defaults to {} to use stylesheet for styles 11 | * - className: DOM class for styling tooltips with CSS. Defaults to "tooltipsy" 12 | * - showEvent: Set a custom event to bind the show function. Defaults to mouseenter 13 | * - hideEvent: Set a custom event to bind the show function. Defaults to mouseleave 14 | * Method quick reference: 15 | * - $('element').data('tooltipsy').show(): Force the tooltip to show 16 | * - $('element').data('tooltipsy').hide(): Force the tooltip to hide 17 | * - $('element').data('tooltipsy').destroy(): Remove tooltip from DOM 18 | * More information visit http://tooltipsy.com/ 19 | */ 20 | ;(function(a){a.tooltipsy=function(c,b){this.options=b;this.$el=a(c);this.title=this.$el.attr("title")||"";this.$el.attr("title","");this.random=parseInt(Math.random()*10000);this.ready=false;this.shown=false;this.width=0;this.height=0;this.delaytimer=null;this.$el.data("tooltipsy",this);this.init()};a.tooltipsy.prototype={init:function(){var e=this,d,b=e.$el,c=b[0];e.settings=d=a.extend({},e.defaults,e.options);d.delay=+d.delay;if(typeof d.content==="function"){e.readify()}if(d.showEvent===d.hideEvent&&d.showEvent==="click"){b.toggle(function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}if(d.delay>0){e.delaytimer=window.setTimeout(function(){e.show(f)},d.delay)}else{e.show(f)}},function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}window.clearTimeout(e.delaytimer);e.delaytimer=null;e.hide(f)})}else{b.bind(d.showEvent,function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}e.delaytimer=window.setTimeout(function(){e.show(f)},d.delay||0)}).bind(d.hideEvent,function(f){if(d.showEvent==="click"&&c.tagName=="A"){f.preventDefault()}window.clearTimeout(e.delaytimer);e.delaytimer=null;e.hide(f)})}},show:function(i){if(this.ready===false){this.readify()}var b=this,f=b.settings,h=b.$tipsy,k=b.$el,d=k[0],g=b.offset(d);if(b.shown===false){if((function(m){var l=0,e;for(e in m){if(m.hasOwnProperty(e)){l++}}return l})(f.css)>0){b.$tip.css(f.css)}b.width=h.outerWidth();b.height=h.outerHeight()}if(f.alignTo==="cursor"&&i){var j=[i.clientX+f.offset[0],i.clientY+f.offset[1]];if(j[0]+b.width>a(window).width()){var c={top:j[1]+"px",right:j[0]+"px",left:"auto"}}else{var c={top:j[1]+"px",left:j[0]+"px",right:"auto"}}}else{var j=[(function(){if(f.offset[0]<0){return g.left-Math.abs(f.offset[0])-b.width}else{if(f.offset[0]===0){return g.left-((b.width-k.outerWidth())/2)}else{return g.left+k.outerWidth()+f.offset[0]}}})(),(function(){if(f.offset[1]<0){return g.top-Math.abs(f.offset[1])-b.height}else{if(f.offset[1]===0){return g.top-((b.height-b.$el.outerHeight())/2)}else{return g.top+b.$el.outerHeight()+f.offset[1]}}})()]}h.css({top:j[1]+"px",left:j[0]+"px"});b.settings.show(i,h.stop(true,true))},hide:function(c){var b=this;if(b.ready===false){return}if(c&&c.relatedTarget===b.$tip[0]){b.$tip.bind("mouseleave",function(d){if(d.relatedTarget===b.$el[0]){return}b.settings.hide(d,b.$tipsy.stop(true,true))});return}b.settings.hide(c,b.$tipsy.stop(true,true))},readify:function(){this.ready=true;this.$tipsy=a('