/* * poshy tip jquery plugin v1.2 * http://vadikom.com/tools/poshy-tip-jquery-plugin-for-stylish-tooltips/ * copyright 2010-2013, vasil dinkov, http://vadikom.com/ */ (function(e){var a=[],d=/^url\(["']?([^"'\)]*)["']?\);?$/i,c=/\.png$/i,b=!!window.createpopup&&document.documentelement.currentstyle.minwidth=="undefined";function f(){e.each(a,function(){this.refresh(true)})}e(window).resize(f);e.poshytip=function(h,g){this.$elm=e(h);this.opts=e.extend({},e.fn.poshytip.defaults,g);this.$tip=e(['
','
','
',"
"].join("")).appendto(document.body);this.$arrow=this.$tip.find("div.tip-arrow");this.$inner=this.$tip.find("div.tip-inner");this.disabled=false;this.content=null;this.init()};e.poshytip.prototype={init:function(){a.push(this);var g=this.$elm.attr("title");this.$elm.data("title.poshytip",g!==undefined?g:null).data("poshytip",this);if(this.opts.showon!="none"){this.$elm.bind({"mouseenter.poshytip":e.proxy(this.mouseenter,this),"mouseleave.poshytip":e.proxy(this.mouseleave,this)});switch(this.opts.showon){case"hover":if(this.opts.alignto=="cursor"){this.$elm.bind("mousemove.poshytip",e.proxy(this.mousemove,this))}if(this.opts.allowtiphover){this.$tip.hover(e.proxy(this.cleartimeouts,this),e.proxy(this.mouseleave,this))}break;case"focus":this.$elm.bind({"focus.poshytip":e.proxy(this.showdelayed,this),"blur.poshytip":e.proxy(this.hidedelayed,this)});break}}},mouseenter:function(g){if(this.disabled){return true}this.$elm.attr("title","");if(this.opts.showon=="focus"){return true}this.showdelayed()},mouseleave:function(g){if(this.disabled||this.asyncanimating&&(this.$tip[0]===g.relatedtarget||jquery.contains(this.$tip[0],g.relatedtarget))){return true}if(!this.$tip.data("active")){var h=this.$elm.data("title.poshytip");if(h!==null){this.$elm.attr("title",h)}}if(this.opts.showon=="focus"){return true}this.hidedelayed()},mousemove:function(g){if(this.disabled){return true}this.eventx=g.pagex;this.eventy=g.pagey;if(this.opts.followcursor&&this.$tip.data("active")){this.calcpos();this.$tip.css({left:this.pos.l,top:this.pos.t});if(this.pos.arrow){this.$arrow[0].classname="tip-arrow tip-arrow-"+this.pos.arrow}}},show:function(){if(this.disabled||this.$tip.data("active")){return}this.reset();this.update();if(!this.content){return}this.display();if(this.opts.timeonscreen){this.hidedelayed(this.opts.timeonscreen)}},showdelayed:function(g){this.cleartimeouts();this.showtimeout=settimeout(e.proxy(this.show,this),typeof g=="number"?g:this.opts.showtimeout)},hide:function(){if(this.disabled||!this.$tip.data("active")){return}this.display(true)},hidedelayed:function(g){this.cleartimeouts();this.hidetimeout=settimeout(e.proxy(this.hide,this),typeof g=="number"?g:this.opts.hidetimeout)},reset:function(){this.$tip.queue([]).detach().css("visibility","hidden").data("active",false);this.$inner.find("*").poshytip("hide");if(this.opts.fade){this.$tip.css("opacity",this.opacity)}this.$arrow[0].classname="tip-arrow tip-arrow-top tip-arrow-right tip-arrow-bottom tip-arrow-left";this.asyncanimating=false},update:function(j,k){if(this.disabled){return}var i=j!==undefined;if(i){if(!k){this.opts.content=j}if(!this.$tip.data("active")){return}}else{j=this.opts.content}var h=this,g=typeof j=="function"?j.call(this.$elm[0],function(l){h.update(l)}):j=="[title]"?this.$elm.data("title.poshytip"):j;if(this.content!==g){this.$inner.empty().append(g);this.content=g}this.refresh(i)},refresh:function(h){if(this.disabled){return}if(h){if(!this.$tip.data("active")){return}var k={left:this.$tip.css("left"),top:this.$tip.css("top")}}this.$tip.css({left:0,top:0}).appendto(document.body);if(this.opacity===undefined){this.opacity=this.$tip.css("opacity")}var l=this.$tip.css("background-image").match(d),m=this.$arrow.css("background-image").match(d);if(l){var i=c.test(l[1]);if(b&&i){this.$tip.css("background-image","none");this.$inner.css({margin:0,border:0,padding:0});l=i=false}else{this.$tip.prepend('
').css({border:0,padding:0,"background-image":"none","background-color":"transparent"}).find(".tip-bg-image").css("background-image",'url("'+l[1]+'")').end().find("td").eq(3).append(this.$inner)}if(i&&!e.support.opacity){this.opts.fade=false}}if(m&&!e.support.opacity){if(b&&c.test(m[1])){m=false;this.$arrow.css("background-image","none")}this.opts.fade=false}var o=this.$tip.find("> table.tip-table");if(b){this.$tip[0].style.width="";o.width("auto").find("td").eq(3).width("auto");var n=this.$tip.width(),j=parseint(this.$tip.css("min-width")),g=parseint(this.$tip.css("max-width"));if(!isnan(j)&&ng){n=g}}this.$tip.add(o).width(n).eq(0).find("td").eq(3).width("100%")}else{if(o[0]){o.width("auto").find("td").eq(3).width("auto").end().end().width(document.defaultview&&document.defaultview.getcomputedstyle&&parsefloat(document.defaultview.getcomputedstyle(this.$tip[0],null).width)||this.$tip.width()).find("td").eq(3).width("100%")}}this.tipouterw=this.$tip.outerwidth();this.tipouterh=this.$tip.outerheight();this.calcpos();if(m&&this.pos.arrow){this.$arrow[0].classname="tip-arrow tip-arrow-"+this.pos.arrow;this.$arrow.css("visibility","inherit")}if(h&&this.opts.refreshaniduration){this.asyncanimating=true;var p=this;this.$tip.css(k).animate({left:this.pos.l,top:this.pos.t},this.opts.refreshaniduration,function(){p.asyncanimating=false})}else{this.$tip.css({left:this.pos.l,top:this.pos.t})}},display:function(h){var i=this.$tip.data("active");if(i&&!h||!i&&h){return}this.$tip.stop();if((this.opts.slide&&this.pos.arrow||this.opts.fade)&&(h&&this.opts.hideaniduration||!h&&this.opts.showaniduration)){var n={},m={};if(this.opts.slide&&this.pos.arrow){var l,g;if(this.pos.arrow=="bottom"||this.pos.arrow=="top"){l="top";g="bottom"}else{l="left";g="right"}var k=parseint(this.$tip.css(l));n[l]=k+(h?0:(this.pos.arrow==g?-this.opts.slideoffset:this.opts.slideoffset));m[l]=k+(h?(this.pos.arrow==g?this.opts.slideoffset:-this.opts.slideoffset):0)+"px"}if(this.opts.fade){n.opacity=h?this.$tip.css("opacity"):0;m.opacity=h?0:this.opacity}this.$tip.css(n).animate(m,this.opts[h?"hideaniduration":"showaniduration"])}h?this.$tip.queue(e.proxy(this.reset,this)):this.$tip.css("visibility","inherit");if(i){var j=this.$elm.data("title.poshytip");if(j!==null){this.$elm.attr("title",j)}}this.$tip.data("active",!i)},disable:function(){this.reset();this.disabled=true},enable:function(){this.disabled=false},destroy:function(){this.reset();this.$tip.remove();delete this.$tip;this.content=null;this.$elm.unbind(".poshytip").removedata("title.poshytip").removedata("poshytip");a.splice(e.inarray(this,a),1)},cleartimeouts:function(){if(this.showtimeout){cleartimeout(this.showtimeout);this.showtimeout=0}if(this.hidetimeout){cleartimeout(this.hidetimeout);this.hidetimeout=0}},calcpos:function(){var n={l:0,t:0,arrow:""},h=e(window),k={l:h.scrollleft(),t:h.scrolltop(),w:h.width(),h:h.height()},p,j,m,i,q,g;if(this.opts.alignto=="cursor"){p=j=m=this.eventx;i=q=g=this.eventy}else{var o=this.$elm.offset(),l={l:o.left,t:o.top,w:this.$elm.outerwidth(),h:this.$elm.outerheight()};p=l.l+(this.opts.alignx!="inner-right"?0:l.w);j=p+math.floor(l.w/2);m=p+(this.opts.alignx!="inner-left"?l.w:0);i=l.t+(this.opts.aligny!="inner-bottom"?0:l.h);q=i+math.floor(l.h/2);g=i+(this.opts.aligny!="inner-top"?l.h:0)}switch(this.opts.alignx){case"right":case"inner-left":n.l=m+this.opts.offsetx;if(this.opts.keepinviewport&&n.l+this.tipouterw>k.l+k.w){n.l=k.l+k.w-this.tipouterw}if(this.opts.alignx=="right"||this.opts.aligny=="center"){n.arrow="left"}break;case"center":n.l=j-math.floor(this.tipouterw/2);if(this.opts.keepinviewport){if(n.l+this.tipouterw>k.l+k.w){n.l=k.l+k.w-this.tipouterw}else{if(n.lk.t+k.h){n.t=i-this.tipouterh-this.opts.offsety;if(n.arrow=="top"){n.arrow="bottom"}}break;case"center":n.t=q-math.floor(this.tipouterh/2);if(this.opts.keepinviewport){if(n.t+this.tipouterh>k.t+k.h){n.t=k.t+k.h-this.tipouterh}else{if(n.t',"div.",j.classname,"{visibility:hidden;position:absolute;top:0;left:0;}","div.",j.classname," table.tip-table, div.",j.classname," table.tip-table td{margin:0;font-family:inherit;font-size:inherit;font-weight:inherit;font-style:inherit;font-variant:inherit;vertical-align:middle;}","div.",j.classname," td.tip-bg-image span{display:block;font:1px/1px sans-serif;height:",j.bgimageframesize,"px;width:",j.bgimageframesize,"px;overflow:hidden;}","div.",j.classname," td.tip-right{background-position:100% 0;}","div.",j.classname," td.tip-bottom{background-position:100% 100%;}","div.",j.classname," td.tip-left{background-position:0 100%;}","div.",j.classname," div.tip-inner{background-position:-",j.bgimageframesize,"px -",j.bgimageframesize,"px;}","div.",j.classname," div.tip-arrow{visibility:hidden;position:absolute;overflow:hidden;font:1px/1px sans-serif;}",""].join("")).appendto("head")}if(j.liveevents&&j.showon!="none"){var i,k=e.extend({},j,{liveevents:false});switch(j.showon){case"hover":i=function(){var m=e(this);if(!m.data("poshytip")){m.poshytip(k).poshytip("mouseenter")}};this.live?this.live("mouseenter.poshytip",i):e(document).delegate(this.selector,"mouseenter.poshytip",i);break;case"focus":i=function(){var m=e(this);if(!m.data("poshytip")){m.poshytip(k).poshytip("showdelayed")}};this.live?this.live("focus.poshytip",i):e(document).delegate(this.selector,"focus.poshytip",i);break}return this}return this.each(function(){new e.poshytip(this,j)})};e.fn.poshytip.defaults={content:"[title]",classname:"tip-yellow",bgimageframesize:10,showtimeout:500,hidetimeout:100,timeonscreen:0,showon:"hover",liveevents:false,alignto:"cursor",alignx:"right",aligny:"top",offsetx:-22,offsety:18,keepinviewport:true,allowtiphover:true,followcursor:false,fade:true,slide:true,slideoffset:8,showaniduration:300,hideaniduration:300,refreshaniduration:200}})(jquery);