Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

Commit

Permalink
Initial commit for github repo. License, readme, example and source i…
Browse files Browse the repository at this point in the history
…ncluded.
  • Loading branch information
arnklint committed Jul 19, 2009
1 parent 9b33aaa commit e5cb2d2
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 Jonas Arnklint ( http://arnklint.com )

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 changes: 37 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Simple Tooltip for jQuery
====================================

Simple Tooltip is a tiny plugin for making simple tooltips, when hovering over an element. It is written by Jonas Arnklint ( http://arnklint.com ). The goal is to keep it simple, tiny and agile as I'm a fan of KISS. Its functionality includes displaying generic tooltip messages as well as individual messages based on the title attribute of an element. The source was originally extracted from our easy to use CMS Venio at http://venio.se

Usage
====================================
1. Include it along with jQuery (i'm including jQuery from G All Mighty in this example):
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="path/to/jquery.simple-tooltip.js" type="text/javascript" charset="utf-8"></script>

2. Declare an element that you want to display a tooltip when hovering over:
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function(){
$('#my-link, p span').simpleTooltip({
title: 'me is a tooltip'
});
});
</script>
Look at $.fn.simpleTooltip.defaults in source for more options.

3. Style it! The tooltip gets the "v-tooltip" id so that you can style it however you want with CSS.
<style type="text/css" media="screen">
#v-tooltip {
position:absolute;
background:#000;
padding:3px 5px;
color:#fff;
font-size: 11px;
font-family: Arial, Verdana, sans-serif;
display:none;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
</style>

4. Done!
41 changes: 41 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Simple Tooltip for jQuery</title>
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="../jquery.simple-tooltip.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
jQuery(document).ready(function(){
$('#my-link, p span').simpleTooltip({
title: 'me is a tooltip'
});
});
</script>
<style type="text/css" media="screen">
#v-tooltip {
position:absolute;
background:#000;
padding:3px 5px;
color:#fff;
font-size: 11px;
font-family: Arial, Verdana, sans-serif;
display:none;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
}
p span {
font-style: italic;
}
</style>
</head>
<body>
<h1>Simple tooltip for jQuery</h1>
<p>
This example shows how you can use the Simple Tooltip plugin for jQuery to display tooltips when <span>hovering over</span> elements in DOM. Simple, tiny and agile!
</p>
<p>
This plugin is made by <a href="http://arnklint.com" id="my-link" title="Web developer from Umeå in Sweden">Jonas Arnklint</a>
</p>
</body>
</html>
36 changes: 36 additions & 0 deletions jquery.simple-tooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Made by web ninja Jonas Arnklint. Use it, modify it and...
An MIT license is distributed with this plugins original source.
Originally extracted from the easy to use CMS Venio at http://venio.se.
*/
(function($) {
$.fn.simpleTooltip = function(options){
var opts = $.extend({}, $.fn.simpleTooltip.defaults, options);

return this.each(function(){
var me = $(this);
me.hover(function(e){
var title = me.attr('title') && !opts.overrideElementTitle ? me.attr('title') : opts.title;
$("body").append("<p id='v-tooltip'>"+title+"</p>");
$("#v-tooltip")
.css("top",(e.pageY - opts.xOffset) + "px")
.css("left",(e.pageX + opts.yOffset) + "px")
.fadeIn("fast");
},function(){
$("#v-tooltip").remove();
});
me.mousemove(function(e){
$("#v-tooltip")
.css("top",(e.pageY - opts.xOffset) + "px")
.css("left",(e.pageX + opts.yOffset) + "px");
});
});
}

$.fn.simpleTooltip.defaults = {
title: null,
xOffset: 10,
yOffset: 20,
overrideElementTitle: false
}
})(jQuery);

0 comments on commit e5cb2d2

Please sign in to comment.