From 3c9d2b31d0ccd984f85cd240f4a8eeb9a35acd81 Mon Sep 17 00:00:00 2001 From: urin Date: Sun, 9 Feb 2014 16:39:00 +0530 Subject: [PATCH] Bug fix. --- balloon.jquery.json | 32 ++++++++++++++++---------------- jquery.balloon.js | 9 ++++++--- jquery.balloon.min.js | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/balloon.jquery.json b/balloon.jquery.json index e6a9bee..8eccde8 100644 --- a/balloon.jquery.json +++ b/balloon.jquery.json @@ -4,21 +4,21 @@ "description": "A jQuery plugin to add balloon tips to elements. User-friendly, fine-tunable and without css and images.", "keywords": [ "balloon", - "tip" - ], - "version": "0.4.0", + "tip" + ], + "version": "0.4.1", "author": { "name": "urin", "url": "https://github.com/urin" }, "maintainers": [ - { - "name": "urin", - "email": "urinkun@gmail.com", - "url": "https://github.com/urin" - } + { + "name": "urin", + "email": "urinkun@gmail.com", + "url": "https://github.com/urin" + } ], - "licenses": [ + "licenses": [ { "type": "MIT", "url": "http://www.opensource.org/licenses/mit-license.php" @@ -28,11 +28,11 @@ "url": "http://www.gnu.org/licenses/gpl.html" } ], - "bugs": "https://github.com/urin/jquery.balloon.js/issues", - "homepage": "https://github.com/urin/jquery.balloon.js", - "docs": "http://urin.github.com/jquery.balloon.js", - "download": "https://raw.github.com/urin/jquery.balloon.js/master/jquery.balloon.js", - "dependencies": { - "jquery": ">=1.4.2" - } + "bugs": "https://github.com/urin/jquery.balloon.js/issues", + "homepage": "https://github.com/urin/jquery.balloon.js", + "docs": "http://urin.github.com/jquery.balloon.js", + "download": "https://raw.github.com/urin/jquery.balloon.js/master/jquery.balloon.js", + "dependencies": { + "jquery": ">=1.4.2" + } } diff --git a/jquery.balloon.js b/jquery.balloon.js index 9247d87..2c7d2f0 100644 --- a/jquery.balloon.js +++ b/jquery.balloon.js @@ -6,7 +6,7 @@ * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * @author: Hayato Takenaka (http://urin.github.com) - * @version: 0.4.0 - 2014/02/09 + * @version: 0.4.1 - 2014/02/09 **/ (function($) { //----------------------------------------------------------------------------- @@ -177,6 +177,9 @@ $balloon.mouseleave(function(e) { if(t === e.relatedTarget || $.contains(t, e.relatedTarget)) return; $target.hideBalloon(); + }).mouseenter(function(e) { + $balloon.stop(true, true); + $target.showBalloon(); }); } }).mouseleave(function(e) { @@ -188,7 +191,7 @@ $.fn.showBalloon = function(options) { var $target, $balloon, offTimer; if(options || !this.data("options")) { - if($.balloon.defaults.css == null) $.balloon.defaults.css = {}; + if($.balloon.defaults.css === null) $.balloon.defaults.css = {}; this.data("options", $.extend(true, {}, $.balloon.defaults, options || {})); } options = this.data("options"); @@ -212,7 +215,7 @@ if(isNew) { $balloon .addClass(options.classname) - .css(options.css) + .css(options.css || {}) .css({visibility: "hidden", position: "absolute"}) .appendTo("body"); $target.data("balloon", $balloon); diff --git a/jquery.balloon.min.js b/jquery.balloon.min.js index 83e0431..633f2d1 100644 --- a/jquery.balloon.min.js +++ b/jquery.balloon.min.js @@ -1 +1 @@ -(function(e){function n(){this.initialize.apply(this,arguments)}function r(r,i,s){function p(e,t,n,r,i){var s=Math.round(r/1.7320508);t.inactive()["setBorder"+n.camel.pos.f](r)["setBorder"+n.camel.pos.c1](s)["setBorder"+n.camel.pos.c2](s)["set"+n.camel.pos.p1](n.isTopLeft?-r:e.inner[n.size.p])["set"+n.camel.pos.c1](e.inner[n.size.c]/2-s).active().$.css("border-"+n.pos.f+"-color",i)}i.stop(true,true);var o,u,a={position:"absolute",height:"0",width:"0",border:"solid 0 transparent"},f=new n(r),l=new n(i);l.setTop(-s.offsetY+(s.position&&s.position.indexOf("top")>=0?f.top-l.height:s.position&&s.position.indexOf("bottom")>=0?f.bottom:f.center.top-l.height/2));l.setLeft(s.offsetX+(s.position&&s.position.indexOf("left")>=0?f.left-l.width:s.position&&s.position.indexOf("right")>=0?f.right:f.center.left-l.width/2));if(s.tipSize>0){if(i.data("outerTip")){i.data("outerTip").remove();i.removeData("outerTip")}if(i.data("innerTip")){i.data("innerTip").remove();i.removeData("innerTip")}o=new n(e("
").css(a).appendTo(i));u=new n(e("
").css(a).appendTo(i));var c;for(var h=0;h=f[c.pos.c1]&&l.center[c.pos.c1]<=f[c.pos.c2]){if(h%2==0){if(l[c.pos.o]>=f[c.pos.o]&&l[c.pos.f]>=f[c.pos.f])break}else{if(l[c.pos.o]<=f[c.pos.o]&&l[c.pos.f]<=f[c.pos.f])break}}c=null}if(c){l["set"+c.camel.pos.p1](l[c.pos.p1]+(c.isTopLeft?1:-1)*(s.tipSize-l["border"+c.camel.pos.o]));p(l,o,c,s.tipSize,i.css("border-"+c.pos.o+"-color"));p(l,u,c,s.tipSize-2*l["border"+c.camel.pos.o],i.css("background-color"));i.data("outerTip",o.$).data("innerTip",u.$)}else{e.each([o.$,u.$],function(){this.remove()})}}}function i(t,n){var r=t.data("balloon")&&t.data("balloon").get(0);return!(r&&(r===n.relatedTarget||e.contains(r,n.relatedTarget)))}var t={};t.pos=e.extend(["top","bottom","left","right"],{camel:["Top","Bottom","Left","Right"]});t.size=e.extend(["height","width"],{camel:["Height","Width"]});t.getRelativeNames=function(e){var n={pos:{o:e,f:e%2==0?e+1:e-1,p1:e%2==0?e:e-1,p2:e%2==0?e+1:e,c1:e<2?2:0,c2:e<2?3:1},size:{p:e<2?0:1,c:e<2?1:0}};var r={};for(var i in n){if(!r[i])r[i]={};for(var s in n[i]){r[i][s]=t[i][n[i][s]];if(!r.camel)r.camel={};if(!r.camel[i])r.camel[i]={};r.camel[i][s]=t[i].camel[n[i][s]]}}r.isTopLeft=r.pos.o==r.pos.p1;return r};(function(){function s(e,n){if(n==undefined){s(e,true);return s(e,false)}var r=t.getRelativeNames(n?0:2);e[r.size.p]=e.$["outer"+r.camel.size.p]();e[r.pos.f]=e[r.pos.o]+e[r.size.p];e.center[r.pos.o]=e[r.pos.o]+e[r.size.p]/2;e.inner[r.pos.o]=e[r.pos.o]+e["border"+r.camel.pos.o];e.inner[r.size.p]=e.$["inner"+r.camel.size.p]();e.inner[r.pos.f]=e.inner[r.pos.o]+e.inner[r.size.p];e.inner.center[r.pos.o]=e.inner[r.pos.f]+e.inner[r.size.p]/2;return e}var r={setBorder:function(e,t){return function(n){this.$.css("border-"+e.toLowerCase()+"-width",n+"px");this["border"+e]=n;return this.isActive?s(this,t):this}},setPosition:function(e,t){return function(n){this.$.css(e.toLowerCase(),n+"px");this[e.toLowerCase()]=n;return this.isActive?s(this,t):this}}};n.prototype={initialize:function(n){this.$=n;e.extend(true,this,this.$.offset(),{center:{},inner:{center:{}}});for(var r=0;r").append(o);if(!t.url&&(!i||i.html()==""))return;if(!u&&o&&o!=i.html())i.empty().append(o);n.removeAttr("title");if(t.url){i.load(e.isFunction(t.url)?t.url(this):t.url,function(e,s,o){if(t.ajaxComplete)t.ajaxComplete(e,s,o);r(n,i,t)})}if(u){i.addClass(t.classname).css(t.css).css({visibility:"hidden",position:"absolute"}).appendTo("body");n.data("balloon",i);r(n,i,t);i.hide().css("visibility","visible")}else{r(n,i,t)}n.data("onTimer",setTimeout(function(){if(t.showAnimation){t.showAnimation.apply(i.stop(true,true),[t.showDuration,t.showComplete])}else{i.show(t.showDuration,function(){if(this.style.removeAttribute){this.style.removeAttribute("filter")}t.showComplete&&t.showComplete.apply(i)})}},t.delay))})};e.fn.hideBalloon=function(){var t=this.data("options"),n,r;if(!this.data("balloon"))return this;return this.each(function(){var i=e(this);(n=i.data("onTimer"))&&clearTimeout(n);(r=i.data("offTimer"))&&clearTimeout(r);i.data("offTimer",setTimeout(function(){var e=i.data("balloon");if(t.hideAnimation){e&&t.hideAnimation.apply(e.stop(true,true),[t.hideDuration,t.hideComplete])}else{e&&e.stop(true,true).hide(t.hideDuration,t.hideComplete)}},t.minLifetime))})};e.balloon={defaults:{contents:null,url:null,ajaxComplete:null,classname:null,position:"top",offsetX:0,offsetY:0,tipSize:12,delay:0,minLifetime:200,showDuration:100,showAnimation:null,hideDuration:80,hideAnimation:function(e){this.fadeOut(e)},showComplete:null,hideComplete:null,css:{minWidth:"20px",padding:"5px",borderRadius:"6px",border:"solid 1px #777",boxShadow:"4px 4px 4px #555",color:"#666",backgroundColor:"#efefef",opacity:e.support.opacity?"0.85":null,zIndex:"32767",textAlign:"left"}}}})(jQuery) +(function(e){function n(){this.initialize.apply(this,arguments)}function r(r,i,s){function p(e,t,n,r,i){var s=Math.round(r/1.7320508);t.inactive()["setBorder"+n.camel.pos.f](r)["setBorder"+n.camel.pos.c1](s)["setBorder"+n.camel.pos.c2](s)["set"+n.camel.pos.p1](n.isTopLeft?-r:e.inner[n.size.p])["set"+n.camel.pos.c1](e.inner[n.size.c]/2-s).active().$.css("border-"+n.pos.f+"-color",i)}i.stop(true,true);var o,u,a={position:"absolute",height:"0",width:"0",border:"solid 0 transparent"},f=new n(r),l=new n(i);l.setTop(-s.offsetY+(s.position&&s.position.indexOf("top")>=0?f.top-l.height:s.position&&s.position.indexOf("bottom")>=0?f.bottom:f.center.top-l.height/2));l.setLeft(s.offsetX+(s.position&&s.position.indexOf("left")>=0?f.left-l.width:s.position&&s.position.indexOf("right")>=0?f.right:f.center.left-l.width/2));if(s.tipSize>0){if(i.data("outerTip")){i.data("outerTip").remove();i.removeData("outerTip")}if(i.data("innerTip")){i.data("innerTip").remove();i.removeData("innerTip")}o=new n(e("
").css(a).appendTo(i));u=new n(e("
").css(a).appendTo(i));var c;for(var h=0;h=f[c.pos.c1]&&l.center[c.pos.c1]<=f[c.pos.c2]){if(h%2==0){if(l[c.pos.o]>=f[c.pos.o]&&l[c.pos.f]>=f[c.pos.f])break}else{if(l[c.pos.o]<=f[c.pos.o]&&l[c.pos.f]<=f[c.pos.f])break}}c=null}if(c){l["set"+c.camel.pos.p1](l[c.pos.p1]+(c.isTopLeft?1:-1)*(s.tipSize-l["border"+c.camel.pos.o]));p(l,o,c,s.tipSize,i.css("border-"+c.pos.o+"-color"));p(l,u,c,s.tipSize-2*l["border"+c.camel.pos.o],i.css("background-color"));i.data("outerTip",o.$).data("innerTip",u.$)}else{e.each([o.$,u.$],function(){this.remove()})}}}function i(t,n){var r=t.data("balloon")&&t.data("balloon").get(0);return!(r&&(r===n.relatedTarget||e.contains(r,n.relatedTarget)))}var t={};t.pos=e.extend(["top","bottom","left","right"],{camel:["Top","Bottom","Left","Right"]});t.size=e.extend(["height","width"],{camel:["Height","Width"]});t.getRelativeNames=function(e){var n={pos:{o:e,f:e%2==0?e+1:e-1,p1:e%2==0?e:e-1,p2:e%2==0?e+1:e,c1:e<2?2:0,c2:e<2?3:1},size:{p:e<2?0:1,c:e<2?1:0}};var r={};for(var i in n){if(!r[i])r[i]={};for(var s in n[i]){r[i][s]=t[i][n[i][s]];if(!r.camel)r.camel={};if(!r.camel[i])r.camel[i]={};r.camel[i][s]=t[i].camel[n[i][s]]}}r.isTopLeft=r.pos.o==r.pos.p1;return r};(function(){function s(e,n){if(n==undefined){s(e,true);return s(e,false)}var r=t.getRelativeNames(n?0:2);e[r.size.p]=e.$["outer"+r.camel.size.p]();e[r.pos.f]=e[r.pos.o]+e[r.size.p];e.center[r.pos.o]=e[r.pos.o]+e[r.size.p]/2;e.inner[r.pos.o]=e[r.pos.o]+e["border"+r.camel.pos.o];e.inner[r.size.p]=e.$["inner"+r.camel.size.p]();e.inner[r.pos.f]=e.inner[r.pos.o]+e.inner[r.size.p];e.inner.center[r.pos.o]=e.inner[r.pos.f]+e.inner[r.size.p]/2;return e}var r={setBorder:function(e,t){return function(n){this.$.css("border-"+e.toLowerCase()+"-width",n+"px");this["border"+e]=n;return this.isActive?s(this,t):this}},setPosition:function(e,t){return function(n){this.$.css(e.toLowerCase(),n+"px");this[e.toLowerCase()]=n;return this.isActive?s(this,t):this}}};n.prototype={initialize:function(n){this.$=n;e.extend(true,this,this.$.offset(),{center:{},inner:{center:{}}});for(var r=0;r").append(o);if(!t.url&&(!i||i.html()==""))return;if(!u&&o&&o!=i.html())i.empty().append(o);n.removeAttr("title");if(t.url){i.load(e.isFunction(t.url)?t.url(this):t.url,function(e,s,o){if(t.ajaxComplete)t.ajaxComplete(e,s,o);r(n,i,t)})}if(u){i.addClass(t.classname).css(t.css||{}).css({visibility:"hidden",position:"absolute"}).appendTo("body");n.data("balloon",i);r(n,i,t);i.hide().css("visibility","visible")}else{r(n,i,t)}n.data("onTimer",setTimeout(function(){if(t.showAnimation){t.showAnimation.apply(i.stop(true,true),[t.showDuration,t.showComplete])}else{i.show(t.showDuration,function(){if(this.style.removeAttribute){this.style.removeAttribute("filter")}t.showComplete&&t.showComplete.apply(i)})}},t.delay))})};e.fn.hideBalloon=function(){var t=this.data("options"),n,r;if(!this.data("balloon"))return this;return this.each(function(){var i=e(this);(n=i.data("onTimer"))&&clearTimeout(n);(r=i.data("offTimer"))&&clearTimeout(r);i.data("offTimer",setTimeout(function(){var e=i.data("balloon");if(t.hideAnimation){e&&t.hideAnimation.apply(e.stop(true,true),[t.hideDuration,t.hideComplete])}else{e&&e.stop(true,true).hide(t.hideDuration,t.hideComplete)}},t.minLifetime))})};e.balloon={defaults:{contents:null,url:null,ajaxComplete:null,classname:null,position:"top",offsetX:0,offsetY:0,tipSize:12,delay:0,minLifetime:200,showDuration:100,showAnimation:null,hideDuration:80,hideAnimation:function(e){this.fadeOut(e)},showComplete:null,hideComplete:null,css:{minWidth:"20px",padding:"5px",borderRadius:"6px",border:"solid 1px #777",boxShadow:"4px 4px 4px #555",color:"#666",backgroundColor:"#efefef",opacity:e.support.opacity?"0.85":null,zIndex:"32767",textAlign:"left"}}}})(jQuery)