diff --git a/.gitignore b/.gitignore
index 496ee2c..cfca405 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-.DS_Store
\ No newline at end of file
+.DS_Store
+/node_modules/
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..796910a
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,20 @@
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ uglify: {
+ build: {
+ src: 'src/<%= pkg.name %>.js',
+ dest: '<%= pkg.name %>.min.js'
+ }
+ }
+ });
+
+ // Load the plugin that provides the "uglify" task.
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+
+ // Default task(s).
+ grunt.registerTask('default', ['uglify']);
+
+};
\ No newline at end of file
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..69b0876
--- /dev/null
+++ b/bower.json
@@ -0,0 +1,16 @@
+{
+ "name": "jquery.miniTip",
+ "version": "1.5.3",
+ "homepage": "https://github.com/jmmerino/miniTip",
+ "authors": [
+ "James Simpson"
+ ],
+ "description": "Ultra lightweight jQuery tooltip plugin",
+ "main": "src/jquery.miniTip.js",
+ "keywords": [
+ "jquery",
+ "minitip",
+ "tooltip"
+ ],
+ "license": "MIT and GPL"
+}
diff --git a/jquery.miniTip.min.js b/jquery.miniTip.min.js
index c8ba007..fccd7d6 100644
--- a/jquery.miniTip.min.js
+++ b/jquery.miniTip.min.js
@@ -1,15 +1 @@
-/*!
- * miniTip v1.5.3
- *
- * Updated: July 15, 2012
- * Requires: jQuery v1.3+
- *
- * (c) 2011, James Simpson
- * http://goldfirestudios.com
- *
- * Dual licensed under the MIT and GPL
- *
- * Documentation found at:
- * http://goldfirestudios.com/blog/81/miniTip-jQuery-Plugin
-*/
-(function(e){e.fn.miniTip=function(t){var n={title:"",content:!1,delay:300,anchor:"n",event:"hover",fadeIn:200,fadeOut:200,aHide:!0,maxW:"250px",offset:5,stemOff:0,doHide:!1},r=e.extend(n,t);e("#miniTip")[0]||e("body").append('
');var i=e("#miniTip"),s=e("#miniTip_t"),o=e("#miniTip_c"),u=e("#miniTip_a");return r.doHide?(i.stop(!0,!0).fadeOut(r.fadeOut),!1):this.each(function(){var t=e(this),n=r.content?r.content:t.attr("title");if(n!=""&&typeof n!="undefined"){window.delay=!1;var a=!1,f=!0;r.content||t.removeAttr("title"),r.event=="hover"?(t.hover(function(){i.removeAttr("click"),f=!0,l.call(this)},function(){f=!1,c()}),r.aHide||i.hover(function(){a=!0},function(){a=!1,setTimeout(function(){!f&&!i.attr("click")&&c()},20)})):r.event=="click"&&(r.aHide=!0,t.click(function(){return i.attr("click","t"),i.data("last_target")!==t?l.call(this):i.css("display")=="none"?l.call(this):c(),i.data("last_target",t),e("html").unbind("click").click(function(t){i.css("display")=="block"&&!e(t.target).closest("#miniTip").length&&(e("html").unbind("click"),c())}),!1}));var l=function(){r.show&&r.show.call(this,r),r.content&&r.content!=""&&(n=r.content),o.html(n),r.title!=""?s.html(r.title).show():s.hide(),r.render&&r.render(i),u.removeAttr("class"),i.hide().width("").width(i.width()).css("max-width",r.maxW);var a=t.is("area");if(a){var f,l=[],c=[],h=t.attr("coords").split(",");function p(e,t){return e-t}for(f=0;fparseInt(e(window).width(),10),k=w+r.offset+8>m,L=E+r.offset+8>g-e(window).scrollTop(),A=g+b+E+r.offset+8>parseInt(e(window).height()+e(window).scrollTop(),10),O=r.anchor;if(k||r.anchor=="e"&&!C){if(r.anchor=="w"||r.anchor=="e")O="e",N=Math.round(E/2-8-parseInt(i.css("borderRightWidth"),10)),T=-8-parseInt(i.css("borderRightWidth"),10),S=m+y+r.offset+8,x=Math.round(g+b/2-E/2)}else if(C||r.anchor=="w"&&!k)if(r.anchor=="w"||r.anchor=="e")O="w",N=Math.round(E/2-8-parseInt(i.css("borderLeftWidth"),10)),T=w-parseInt(i.css("borderLeftWidth"),10),S=m-w-r.offset-8,x=Math.round(g+b/2-E/2);if(A||r.anchor=="n"&&!L){if(r.anchor=="n"||r.anchor=="s")O="n",N=E-parseInt(i.css("borderTopWidth"),10),x=g-(E+r.offset+8)}else if(L||r.anchor=="s"&&!A)if(r.anchor=="n"||r.anchor=="s")O="s",N=-8-parseInt(i.css("borderBottomWidth"),10),x=g+b+r.offset+8;r.anchor=="n"||r.anchor=="s"?w/2>m?(S=S<0?T+S:T,T=0):m+w/2>parseInt(e(window).width(),10)&&(S-=T,T*=2):L?(x+=N,N=0):A&&(x-=N,N*=2),u.css({"margin-left":(T>0?T:T+parseInt(r.stemOff,10)/2)+"px","margin-top":N+"px"}).attr("class",O),delay&&clearTimeout(delay),delay=setTimeout(function(){i.css({"margin-left":S+"px","margin-top":x+"px"}).stop(!0,!0).fadeIn(r.fadeIn)},r.delay)},c=function(){if(!r.aHide&&!a||r.aHide)delay&&clearTimeout(delay),delay=setTimeout(function(){h()},r.delay)},h=function(){!r.aHide&&!a||r.aHide?(i.stop(!0,!0).fadeOut(r.fadeOut),r.hide&&r.hide.call(this)):setTimeout(function(){c()},200)}}})}})(jQuery)
\ No newline at end of file
+!function(a){a.fn.miniTip=function(b){var c={title:"",content:!1,delay:300,anchor:"n",event:"hover",fadeIn:200,fadeOut:200,aHide:!0,maxW:"250px",offset:5,stemOff:0,doHide:!1,className:""},d=a.extend(c,b);a("#miniTip"+(d.className?"."+d.className:""))[0]||a("body").append('');var e=a("#miniTip"),f=a("#miniTip_t"),g=a("#miniTip_c"),h=a("#miniTip_a");return d.doHide?(e.stop(!0,!0).fadeOut(d.fadeOut),!1):this.each(function(){var b=a(this),c=d.content?d.content:b.attr("title");if(""!=c&&"undefined"!=typeof c){window.delay=!1;var i=!1,j=!0;d.content||b.removeAttr("title"),"hover"==d.event?(b.hover(function(){e.removeAttr("click"),j=!0,k.call(this)},function(){j=!1,l()}),d.aHide||e.hover(function(){i=!0},function(){i=!1,setTimeout(function(){j||e.attr("click")||l()},20)})):"click"==d.event&&(d.aHide=!0,b.click(function(){return e.attr("click","t"),e.data("last_target")!==b?k.call(this):"none"==e.css("display")?k.call(this):l(),e.data("last_target",b),a("html").unbind("click").click(function(b){"block"!=e.css("display")||a(b.target).closest("#miniTip").length||(a("html").unbind("click"),l())}),!1}));var k=function(){function i(a,b){return a-b}d.show&&d.show.call(this,d),d.content&&""!=d.content&&(c=d.content),g.html(c),""!=d.title?f.html(d.title).show():f.hide(),d.render&&d.render(e),h.removeAttr("class"),e.hide().width("").width(e.width()).css("max-width",d.maxW);var j=b.is("area");if(j){var k,l=[],m=[],n=b.attr("coords").split(",");for(k=0;kparseInt(a(window).width(),10),B=u+d.offset+8>q,C=v+d.offset+8>r-a(window).scrollTop(),D=r+t+v+d.offset+8>parseInt(a(window).height()+a(window).scrollTop(),10),E=d.anchor;B||"e"==d.anchor&&!A?("w"==d.anchor||"e"==d.anchor)&&(E="e",z=Math.round(v/2-8-parseInt(e.css("borderRightWidth"),10)),y=-8-parseInt(e.css("borderRightWidth"),10),w=q+s+d.offset+8,x=Math.round(r+t/2-v/2)):(A||"w"==d.anchor&&!B)&&("w"==d.anchor||"e"==d.anchor)&&(E="w",z=Math.round(v/2-8-parseInt(e.css("borderLeftWidth"),10)),y=u-parseInt(e.css("borderLeftWidth"),10),w=q-u-d.offset-8,x=Math.round(r+t/2-v/2)),D||"n"==d.anchor&&!C?("n"==d.anchor||"s"==d.anchor)&&(E="n",z=v-parseInt(e.css("borderTopWidth"),10),x=r-(v+d.offset+8)):(C||"s"==d.anchor&&!D)&&("n"==d.anchor||"s"==d.anchor)&&(E="s",z=-8-parseInt(e.css("borderBottomWidth"),10),x=r+t+d.offset+8),"n"==d.anchor||"s"==d.anchor?u/2>q?(w=0>w?y+w:y,y=0):q+u/2>parseInt(a(window).width(),10)&&(w-=y,y*=2):C?(x+=z,z=0):D&&(x-=z,z*=2),h.css({"margin-left":(y>0?y:y+parseInt(d.stemOff,10)/2)+"px","margin-top":z+"px"}).attr("class",E),delay&&clearTimeout(delay),delay=setTimeout(function(){e.css({"margin-left":w+"px","margin-top":x+"px"}).stop(!0,!0).fadeIn(d.fadeIn)},d.delay)},l=function(){(!d.aHide&&!i||d.aHide)&&(delay&&clearTimeout(delay),delay=setTimeout(function(){m()},d.delay))},m=function(){!d.aHide&&!i||d.aHide?(e.stop(!0,!0).fadeOut(d.fadeOut),d.hide&&d.hide.call(this)):setTimeout(function(){l()},200)}}})}}(jQuery);
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..77c501a
--- /dev/null
+++ b/package.json
@@ -0,0 +1,10 @@
+{
+ "name": "jquery.miniTip",
+ "version": "1.5.3",
+ "devDependencies": {
+ "grunt": "~0.4.2",
+ "grunt-contrib-jshint": "~0.6.3",
+ "grunt-contrib-nodeunit": "~0.2.0",
+ "grunt-contrib-uglify": "~0.2.2"
+ }
+}
\ No newline at end of file
diff --git a/src/jquery.miniTip.js b/src/jquery.miniTip.js
index 5c0219a..1d2ecce 100644
--- a/src/jquery.miniTip.js
+++ b/src/jquery.miniTip.js
@@ -1,7 +1,7 @@
/*!
- * miniTip v1.5.3
+ * miniTip v1.5.0
*
- * Updated: July 15, 2012
+ * Updated: December 9, 2011
* Requires: jQuery v1.3+
*
* (c) 2011, James Simpson
@@ -11,298 +11,354 @@
*
* Documentation found at:
* http://goldfirestudios.com/blog/81/miniTip-jQuery-Plugin
-*/
-
-(function($){
- $.fn.miniTip = function(opts) {
- // declare the default option values
- var d = {
- title: '', // if left blank, no title bar will show
- content: false, // the content of the tooltip
- delay: 300, // how long to wait before showing and hiding the tooltip (ms)
- anchor: 'n', // n (top), s (bottom), e (right), w (left)
- event: 'hover', // can be 'hover' or 'click'
- fadeIn: 200, // speed of fade in animation (ms)
- fadeOut: 200, // speed of fade out animation (ms)
- aHide: true, // set to false to only hide when the mouse moves away from the anchor and tooltip
- maxW: '250px', // max width of tooltip
- offset: 5, // offset in pixels of stem from anchor
- stemOff: 0, // x-axis offset of stem, set to value of border-radius to adjust for viewport correction
- doHide: false // call $('#id').miniTip({hide: true}); to manually hide the tooltip
- },
-
- // merge the defaults with the user declared options
- o = $.extend(d, opts);
-
- // add the tip elements to the DOM
- if (!$('#miniTip')[0])
- $('body').append('');
-
- // declare the containers
- var tt_w = $('#miniTip'),
- tt_t = $('#miniTip_t'),
- tt_c = $('#miniTip_c'),
- tt_a = $('#miniTip_a');
-
- // manually hide the tooltip if $('#id').miniTip({hide: true}); is called
- if (o.doHide) {
- tt_w.stop(true,true).fadeOut(o.fadeOut);
- return false;
- }
-
- // initialize the tooltip
- return this.each(function(){
- // make sure the anchor element can be referred to below
- var el = $(this);
-
- // if content is set to false, use the title attribute
- var cont = o.content ? o.content : el.attr('title');
-
- // if the tooltip isn't empty
- if (cont != '' && typeof cont != 'undefined') {
- // declare the delay variable and make sure it is global
- window.delay = false;
-
- // declare the variables that check if the mouse is still on the tooltip
- var tHov = false,
- aHov = true;
-
- // if you are using the title attribute, remove it from the anchor
- if (!o.content)
- el.removeAttr('title');
-
- if (o.event == 'hover') {
- // add the hover event
- el.hover(
- function(){
- // make sure we know this wasn't activated by click
- tt_w.removeAttr('click');
-
- // show the tooltip
- aHov = true;
- show.call(this);
- },
- function(){
- aHov = false;
- hide();
- }
- );
-
- // add a hover event for the tooltip if aHide is false
- if (!o.aHide) {
- tt_w.hover(
- function() {
- tHov = true;
- },
- function() {
- tHov = false;
- setTimeout(function(){if (!aHov && !tt_w.attr('click')) hide()}, 20);
- }
- );
- }
- } else if (o.event == 'click') {
- // make sure auto hide is set to false automatically
- o.aHide = true;
-
- // add the click event to the anchor
- el.click(function(){
- // make sure we know this was activated by click
- tt_w.attr('click', 't');
-
- if (tt_w.data('last_target') !== el) {
- // rerender the tooltip if the target changed
- show.call(this);
- } else {
- // show the tooltip, unless it is already showing, then close it
- if (tt_w.css('display') == 'none') show.call(this); else hide();
- }
-
- tt_w.data('last_target', el);
-
- // clear the tooltip if anywhere but the tooltip itself is clicked
- $('html').unbind('click').click(function(e){
- if (tt_w.css('display') == 'block' && !$(e.target).closest('#miniTip').length) {
- $('html').unbind('click');
- hide();
- }
- });
-
- return false;
- });
- }
-
- // show the tooltip
- var show = function() {
- // call the show callback function
- if (o.show) o.show.call(this, o);
-
- // use content set by callback, if any
- if (o.content && o.content != '') {
- cont = o.content;
- }
-
- // add in the content
- tt_c.html(cont);
-
- // insert the title (or hide if none is set)
- if (o.title != '')
- tt_t.html(o.title).show();
- else
- tt_t.hide();
-
- // call the render callback function
- if (o.render) o.render(tt_w);
-
- // reset arrow position
- tt_a.removeAttr('class');
-
- // make sure the tooltip is the right width even if the anchor is flush to the right of the screen
- // set the max width
- tt_w.hide().width('').width(tt_w.width()).css('max-width', o.maxW);
-
- // add support for image maps
- var isArea = el.is('area');
- if (isArea) {
- // declare variables to determine coordinates
- var i,
- x = [],
- y = [],
- c = el.attr('coords').split(',');
-
- // sortin funciton for coordinates
- function num (a, b) {
- return a - b;
- }
-
- // loop through the coordinates and populate x & y arrays
- for (i=0; i < c.length; i++){
- x.push(c[i++]);
- y.push(c[i]);
- }
-
- // get the center coordinates of the area
- var mapImg = el.parent().attr('name'),
- mapOff = $('img[usemap=\\#' + mapImg + ']').offset(),
- left = parseInt(mapOff.left, 10) + parseInt((parseInt(x.sort(num)[0], 10) + parseInt(x.sort(num)[x.length-1], 10)) / 2, 10),
- top = parseInt(mapOff.top, 10) + parseInt((parseInt(y.sort(num)[0], 10) + parseInt(y.sort(num)[y.length-1], 10)) / 2, 10);
- } else {
- // get the coordinates of the element
- var top = parseInt(el.offset().top, 10),
- left = parseInt(el.offset().left, 10);
- }
-
- // get width and height of the anchor element
- var elW = isArea ? 0 : parseInt(el.outerWidth(), 10),
- elH = isArea ? 0 : parseInt(el.outerHeight(), 10),
-
- // get width and height of the tooltip
- tipW = tt_w.outerWidth(),
- tipH = tt_w.outerHeight(),
-
- // calculate position for tooltip
- mLeft = Math.round(left + Math.round((elW - tipW) / 2)),
- mTop = Math.round(top + elH + o.offset + 8),
-
- // position of the arrow
- aLeft = (Math.round(tipW - 16) / 2) - parseInt(tt_w.css('borderLeftWidth'), 10),
- aTop = 0,
-
- // figure out if the tooltip will go off of the screen
- eOut = (left + elW + tipW + o.offset + 8) > parseInt($(window).width(), 10),
- wOut = (tipW + o.offset + 8) > left,
- nOut = (tipH + o.offset + 8) > top - $(window).scrollTop(),
- sOut = (top + elH + tipH + o.offset + 8) > parseInt($(window).height() + $(window).scrollTop(), 10),
-
- // default anchor position
- elPos = o.anchor;
-
- // calculate where the anchor should be (east & west)
- if (wOut || o.anchor == 'e' && !eOut) {
- if (o.anchor == 'w' || o.anchor == 'e') {
- elPos = 'e';
- aTop = Math.round((tipH / 2) - 8 - parseInt(tt_w.css('borderRightWidth'), 10));
- aLeft = -8 - parseInt(tt_w.css('borderRightWidth'), 10);
- mLeft = left + elW + o.offset + 8;
- mTop = Math.round((top + elH / 2) - (tipH / 2));
- }
- } else if (eOut || o.anchor == 'w' && !wOut) {
- if (o.anchor == 'w' || o.anchor == 'e') {
- elPos = 'w';
- aTop = Math.round((tipH / 2) - 8 - parseInt(tt_w.css('borderLeftWidth'), 10));
- aLeft = tipW - parseInt(tt_w.css('borderLeftWidth'), 10);
- mLeft = left - tipW - o.offset - 8;
- mTop = Math.round((top + elH / 2) - (tipH / 2));
- }
- }
-
- // calculate where the anchor should be (north & south)
- if (sOut || o.anchor == 'n' && !nOut) {
- if (o.anchor == 'n' || o.anchor == 's') {
- elPos = 'n';
- aTop = tipH - parseInt(tt_w.css('borderTopWidth'), 10);
- mTop = top - (tipH + o.offset + 8);
- }
- } else if (nOut || o.anchor == 's' && !sOut) {
- if (o.anchor == 'n' || o.anchor == 's') {
- elPos = 's';
- aTop = -8 - parseInt(tt_w.css('borderBottomWidth'), 10);
- mTop = top + elH + o.offset + 8;
- }
- }
-
- // if it is going to go off on the sides, use corner
- if (o.anchor == 'n' || o.anchor == 's') {
- if ((tipW / 2) > left) {
- mLeft = mLeft < 0 ? aLeft + mLeft : aLeft;
- aLeft = 0;
- } else if ((left + tipW / 2) > parseInt($(window).width(), 10)) {
- mLeft -= aLeft;
- aLeft *= 2;
- }
- } else {
- if (nOut) {
- mTop = mTop + aTop
- aTop = 0;
- } else if (sOut) {
- mTop -= aTop;
- aTop *= 2;
- }
- }
-
- // position the arrow
- tt_a.css({'margin-left': (aLeft > 0 ? aLeft : aLeft + parseInt(o.stemOff, 10) / 2) + 'px', 'margin-top': aTop + 'px'}).attr('class', elPos);
-
- // clear delay timer if exists
- if (delay) clearTimeout(delay);
-
- // position the tooltip and show it
- delay = setTimeout(function(){ tt_w.css({"margin-left": mLeft+"px", "margin-top": mTop + 'px'}).stop(true,true).fadeIn(o.fadeIn); }, o.delay);
- }
-
- // hide the tooltip
- var hide = function() {
- if (!o.aHide && !tHov || o.aHide) {
- // clear delay timer if exists
- if (delay) clearTimeout(delay);
-
- // fade out the tooltip
- delay = setTimeout(function(){hide2()}, o.delay);
- }
- }
-
- // make a second hide function if the tooltip is set to not auto hide
- var hide2 = function() {
- // if the mouse isn't on the tooltip or the anchor, hide it, otherwise loop back through
- if (!o.aHide && !tHov || o.aHide) {
- // fade out the tooltip
- tt_w.stop(true,true).fadeOut(o.fadeOut);
-
- // call the show callback function
- if (o.hide) o.hide.call(this);
- } else
- setTimeout(function(){hide()}, 200);
- }
- }
- });
- }
+ *
+ * Modified by jesus@touristeye.com
+ * - Added class name for the tooltip to personalize appearance
+ */
+
+// Example of use
+//
+// $('#idelement').miniTip({
+// content: 'Ejemplo de tooltip',
+// anchor: 'n',
+// className: 'red'
+// });
+
+
+;(function($){
+ $.fn.miniTip = function(opts) {
+ // declare the default option values
+ var d = {
+ title :'', // if left blank, no title bar will show
+ content :false, // the content of the tooltip
+ delay :100, // how long to wait before showing and hiding the tooltip (ms)
+ anchor :'n', // n (top), s (bottom), e (right), w (left)
+ event :'hover', // can be 'hover' or 'click'
+ fadeIn :100, // speed of fade in animation (ms)
+ fadeOut :100, // speed of fade out animation (ms)
+ aHide :true, // set to false to only hide when the mouse moves away from the anchor and tooltip
+ maxW :'300px', // max width of tooltip
+ offset :5, // offset in pixels of stem from anchor
+ doHide :false, // call $('#id').miniTip({hide: true}); to manually hide the tooltip
+ className:'', //Class name to personalize the tooltip colors,
+ autoShow :false //Tooltip is showed when it is created,
+ },
+
+ // merge the defaults with the user declared options
+ o = $.extend(d, opts);
+
+ // add the tip elements to the DOM
+ if (!$('#miniTip' + (o.className?'.' + o.className:''))[0]){
+ $('body').append('');
+ }
+
+ // declare the containers
+ var tt_w = $('#miniTip' + (o.className?'.' + o.className.replace(/\s/g, '.'):'') ),
+ tt_t = tt_w.find('#miniTip_t'),
+ tt_c = tt_w.find('#miniTip_c'),
+ tt_a = tt_w.find('#miniTip_a');
+
+ // manually hide the tooltip if $('#id').miniTip({hide: true}); is called
+ if (o.doHide) {
+ tt_w.stop(true,true).fadeOut(o.fadeOut);
+ return false;
+ }
+
+ var returnObject = {};
+
+ // initialize the tooltip
+ this.each(function(){
+ // make sure the anchor element can be referred to below
+ var el = $(this);
+
+ // if content is set to false, use the title attribute
+ var cont = o.content ? o.content : (el.attr('data-title') ? el.attr('data-title') : el.attr('title') );
+
+ // if the tooltip isn't empty
+ if (cont != '' && typeof cont != 'undefined') {
+ // declare the delay variable and make sure it is global
+ window.delay = false;
+
+ // declare the variables that check if the mouse is still on the tooltip
+ var tHov = false,
+ aHov = true;
+
+ // if you are using the title attribute, remove it from the anchor
+ if (!o.content)
+ el.removeAttr('title');
+
+ if (o.event == 'hover') {
+ // add the hover event
+ el.hover(
+ function(){
+ // make sure we know this wasn't activated by click
+ tt_w.removeAttr('click');
+
+ // show the tooltip
+ aHov = true;
+ show.call(this);
+ },
+ function(){
+ aHov = false;
+ hide();
+ }
+ );
+
+ // add a hover event for the tooltip if aHide is false
+ if (!o.aHide) {
+ tt_w.hover(
+ function() {
+ tHov = true;
+ },
+ function() {
+ tHov = false;
+ setTimeout(function(){if (!aHov && !tt_w.attr('click')) hide()}, 20);
+ }
+ );
+ }
+ } else if (o.event == 'click') {
+ // make sure auto hide is set to false automatically
+ o.aHide = true;
+
+ // add the click event to the anchor
+ el.click(function(){
+ // make sure we know this was activated by click
+ tt_w.attr('click', 't');
+
+ if (tt_w.data('last_target') !== el) {
+ // rerender the tooltip if the target changed
+ show.call(this);
+ } else {
+ // show the tooltip, unless it is already showing, then close it
+ if (tt_w.css('display') == 'none') show.call(this); else hide();
+ }
+
+ tt_w.data('last_target', el);
+
+ //return false;
+ });
+
+ }
+
+
+ // show the tooltip
+ var show = function() {
+
+ $('.minitip-item').hide();
+
+ // call the show callback function
+ if (o.show) o.show.call(this, o);
+
+ // use content set by callback, if any
+ if (o.content && o.content != '') {
+ cont = o.content;
+ }
+
+ // add in the content
+ tt_c.html(cont);
+
+ // insert the title (or hide if none is set)
+ if (o.title != '')
+ tt_t.html(o.title).show();
+ else
+ tt_t.hide();
+
+ // call the render callback function
+ if (o.render) o.render(tt_w);
+
+ // reset arrow position
+ tt_a.removeAttr('class');
+
+ // make sure the tooltip is the right width even if the anchor is flush to the right of the screen
+ // set the max width
+ // tt_w.hide().width('').width(tt_w.width()).css('max-width', o.maxW);
+
+ // add support for image maps
+ var isArea = el.is('area');
+ if (isArea) {
+ // declare variables to determine coordinates
+ var i,
+ x = [],
+ y = [],
+ c = el.attr('coords').split(',');
+
+ // sortin funciton for coordinates
+ function num (a, b) {
+ return a - b;
+ }
+
+ // loop through the coordinates and populate x & y arrays
+ for (i=0; i < c.length; i++){
+ x.push(c[i++]);
+ y.push(c[i]);
+ }
+
+ // get the center coordinates of the area
+ var mapImg = el.parent().attr('name'),
+ mapOff = $('img[usemap=\\#' + mapImg + ']').offset(),
+ left = parseInt(mapOff.left, 10) + parseInt((parseInt(x.sort(num)[0], 10) + parseInt(x.sort(num)[x.length-1], 10)) / 2, 10),
+ top = parseInt(mapOff.top, 10) + parseInt((parseInt(y.sort(num)[0], 10) + parseInt(y.sort(num)[y.length-1], 10)) / 2, 10);
+ } else {
+ // get the coordinates of the element
+ var top,left;
+ if (tt_w.parent()[0].tagName === 'BODY'){
+ top = parseInt(el.offset().top, 10);
+ left = parseInt(el.offset().left, 10);
+ }else{
+ top = left = 0;
+ }
+
+
+ }
+
+ // get width and height of the anchor element
+ var elW = isArea ? 0 : parseInt(el.outerWidth(), 10),
+ elH = isArea ? 0 : parseInt(el.outerHeight(), 10),
+
+ // get width and height of the tooltip
+ tipW = tt_w.outerWidth(),
+ tipH = tt_w.outerHeight(),
+
+ // calculate position for tooltip
+ mLeft = Math.round(left + Math.round((elW - tipW) / 2)),
+ mTop = Math.round(top + elH + o.offset + 4),
+
+ // position of the arrow
+ aLeft = (Math.round(tipW - 16) / 2) - parseInt(tt_w.css('borderLeftWidth'), 10),
+ aTop = 0,
+
+ // figure out if the tooltip will go off of the screen
+ eOut = (left + elW + tipW + o.offset + 4) > parseInt($(window).width(), 10),
+ wOut = (tipW + o.offset + 4) > left,
+ nOut = (tipH + o.offset + 4) > top - $(window).scrollTop(),
+ sOut = (top + elH + tipH + o.offset + 4) > parseInt($(window).height() + $(window).scrollTop(), 10),
+
+ // default anchor position
+ elPos = o.anchor;
+
+ // calculate where the anchor should be (east & west)
+ if (wOut || o.anchor == 'e' && !eOut) {
+ if (o.anchor == 'w' || o.anchor == 'e') {
+ elPos = 'e';
+ aTop = Math.round((tipH / 2) - 4 - parseInt(tt_w.css('borderRightWidth'), 10));
+ aLeft = - 11 - parseInt(tt_w.css('borderRightWidth'), 10);
+ mLeft = left + elW + o.offset + 4;
+ mTop = Math.round((top + elH / 2) - (tipH / 2));
+ }
+ } else if (eOut || o.anchor == 'w' && !wOut) {
+ if (o.anchor == 'w' || o.anchor == 'e') {
+ elPos = 'w';
+ aTop = Math.round((tipH / 2) - 4 - parseInt(tt_w.css('borderLeftWidth'), 10));
+ aLeft = tipW - parseInt(tt_w.css('borderLeftWidth'), 10);
+ mLeft = left - tipW - o.offset - 8;
+ mTop = Math.round((top + elH / 2) - (tipH / 2));
+ }
+ }
+
+ // calculate where the anchor should be (north & south)
+ if (sOut || o.anchor == 'n' && !nOut) {
+ if (o.anchor == 'n' || o.anchor == 's') {
+ elPos = 'n';
+ aTop = tipH - parseInt(tt_w.css('borderTopWidth'), 10);
+ mTop = top - (tipH + o.offset + 4) - 4;
+ }
+ } else if (nOut || o.anchor == 's' && !sOut) {
+ if (o.anchor == 'n' || o.anchor == 's') {
+ elPos = 's';
+ aTop = - 11 - parseInt(tt_w.css('borderBottomWidth'), 10);
+ mTop = top + elH + o.offset + 8;
+ }
+ }
+
+ // if it is going to go off on the sides, use corner
+ // if (o.anchor == 'n' || o.anchor == 's') {
+ // if ((tipW / 2) > left) {
+ // mLeft = mLeft < 0 ? aLeft + mLeft : aLeft;
+ // aLeft = 0;
+ // } else if ((left + tipW / 2) > parseInt($(window).width(), 10)) {
+ // mLeft -= aLeft;
+ // aLeft *= 2;
+ // }
+ // } else {
+ // if (nOut) {
+ // mTop = mTop + aTop
+ // aTop = 0;
+ // } else if (sOut) {
+ // mTop -= aTop;
+ // aTop *= 2;
+ // }
+ // }
+
+ // position the arrow
+ tt_a.css({'margin-left': aLeft + 'px', 'margin-top': aTop + 'px'}).attr('class', elPos);
+ tt_w.addClass(elPos);
+
+ // clear delay timer if exists
+ if (delay) clearTimeout(delay);
+
+ // position the tooltip and show it
+ delay = setTimeout(function(){ tt_w.css({"margin-left": mLeft+"px", "margin-top": mTop + 'px'}).stop(true,true).fadeIn(o.fadeIn); }, o.delay);
+
+ if (o.event === 'click'){
+ // clear the tooltip if anywhere but the tooltip itself is clicked
+ $('html').on('click.miniTip', hideHTML);
+ }
+ }
+
+ var hideHTML = function(e){
+ if (tt_w.css('display') == 'block' && !$(e.target).closest('#miniTip').length){
+ hide();
+ }
+ }
+
+ // hide the tooltip
+ var hide = function() {
+ if (!o.aHide && !tHov || o.aHide) {
+ // clear delay timer if exists
+ if (delay) clearTimeout(delay);
+
+ // fade out the tooltip
+ delay = setTimeout(function(){hide2()}, o.delay);
+ }
+
+ $('html').off('click.miniTip');
+ }
+
+ // make a second hide function if the tooltip is set to not auto hide
+ var hide2 = function() {
+ // if the mouse isn't on the tooltip or the anchor, hide it, otherwise loop back through
+ if (!o.aHide && !tHov || o.aHide) {
+ // fade out the tooltip
+ tt_w.stop(true,true).fadeOut(o.fadeOut);
+
+ // call the show callback function
+ if (o.hide) o.hide.call(this);
+ } else
+ setTimeout(function(){hide()}, 200);
+ }
+
+ if (o.autoShow){
+ show.call(this);
+ }
+
+ //public functions
+ returnObject.updateContent = function( content ){
+ o.content = content;
+ // add in the content
+ tt_c.html(o.content);
+ }
+
+ returnObject.showTooltip = function( ){
+ show();
+ }
+
+ returnObject.destroy = function( ){
+ el.unbind(o.event);
+ tt_w.remove();
+ }
+ }
+ });
+
+ return returnObject;
+}
})(jQuery);
\ No newline at end of file