/****** * Tipped: A tooltip plugin for jQuery * http://code.google.com/p/tipped/ * * Copyright 2010, University of Alberta * * Tipped is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Tipped is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License v2 * along with Tipped. If not, see */ (function(b){var g={ajaxType:"POST",cache:false,cached:{},closer:"Close",delay:0,hideDelay:0,marginX:10,marginY:10,mode:"hover",oversizeStick:true,params:{},position:"element",posX:0,posY:0,source:"title",themeroller:false,throbber:false,url:""};window.Tip={$tip:{},$content:{},timer:undefined,settings:{},$target:{},evt:false,init:function(){this.$tip=b("#tipped").length==0?b('
").appendTo(document.body).data("showing",false):b("#tipped");this.$content=b("#tipped-content")},setup:function(a,c,d){this.settings=c;this.$target=a;this.evt=d;this.hide(true);this._setupCloser();this._setupThemeRollerCompat();this._removeTitle();clearTimeout(this.timer)},show:function(){if(this.settings.source==="url")this._showURL();else if(this.settings.source==="title")this._display(this.$target.data("tipped").title);else if(typeof this.settings.source=="string")this._display(this.settings.source); else if(typeof this.settings.source=="function")this._display(this.settings.source(this.$target));else typeof settings.source=="object"&&this._display(this.settings.source.html())},hide:function(a){if(arguments.length==0)a=false;if(a){this.$tip.data("showing",false).data("original","").hide();this.$content.html("")}else{this.$tip.hover(function(){clearTimeout(Tip.timer)},function(){Tip.hide(true)});this.timer=setTimeout(function(){Tip.hide(true)},Tip.settings.hideDelay)}},_setupCloser:function(a){if(arguments.length== 0)a=false;b("#tipped-closer").html(this.settings.closer).click(function(){Tip.hide(true)});this.settings.mode!="click"&&!a?b("#tipped-closer-wrapper").hide():b("#tipped-closer-wrapper").show()},_setupThemeRollerCompat:function(){if(this.settings.themeroller){this.$tip.addClass("ui-helper-hidden ui-widget ui-dialog ui-corner-all");b("#tipped-closer").addClass("ui-button ui-state-hover ui-state-default").hover(function(){b(this).addClass("ui-state-hover")},function(){b(this).removeClass("ui-state-hover")}).mousedown(function(){b(this).addClass("ui-state-active")}).mouseup(function(){b(this).removeClass("ui-state-active")})}else{this.$tip.removeClass("ui-helper-hidden ui-widget ui-dialog ui-corner-all"); b("#tipped-closer").removeClass("ui-button ui-state-hover ui-state-default")}},_removeTitle:function(){var a=this.$target.data("tipped");if(a.title===undefined){a.title=this.$target.attr("title");this.$target.data("tipped",a)}this.$target.removeAttr("title").attr("title","")},_showURL:function(){var a=this.$tip.data("cache");if(!this.settings.cache||a===undefined||a[this.settings.url]===undefined){var c={};if(typeof this.settings.params=="function")c=this.settings.params(this.$target);else if(typeof this.settings.params== "object")c=this.settings.params;$this=this;b.ajax({data:c,type:$this.settings.ajaxType,url:$this.settings.url,beforeSend:function(){$this.settings.throbber&&$this._display("')},error:function(){$this._display("Unable to retrieve contents")},success:function(d){$this._display(d);if($this.settings.cache){var e={};e[$this.settings.url]=d;a=b.extend(a,e);$this.$tip.data("cache",a)}}})}else this._display(a[this.settings.url])},_display:function(a){this.$content.html(a); this._setSize();this._setPosition();this.$tip.data("showing",true).data("original",this.$target).show();this._resizeAfterShow()},_setSize:function(){this.$content.css({height:"auto",width:"auto"});this.$tip.css({height:"auto",width:"auto"});if(this.$tip.outerHeight()>b(window).height()){if(this.settings.oversizeStick){this._setupCloser(true);this.$target.unbind("mouseout")}var a=this.$tip.outerHeight()-this.$tip.height();this.$tip.css("height",b(window).height()-a-10);this.$content.css({height:b(window).height()- a-10,width:this.$tip.outerWidth()+20,overflow:"auto"})}this.$tip.outerWidth()+10>=b(window).width()&&this.$tip.css({height:this.$tip.outerHeight(),width:b(window).width()-20,overflow:"auto"})},_resizeAfterShow:function(){var a=b("#tipped-closer-wrapper");if(a.is(":visible")){a=a.outerHeight();this.$content.height(this.$tip.height()-a)}},_setPosition:function(){this.$tip.css({left:0,top:0});var a={x:0,y:0};a=this._calcInitialPosition(a);a=this._adjustPositionForWindow(a);a=this._adjustPositionForMouse(a); this.$tip.css({left:a.x,top:a.y})},_calcInitialPosition:function(a){switch(this.settings.position){case "mouse":a.x=this.evt.pageX+this.settings.marginX;a.y=this.evt.pageY+this.settings.marginY;break;case "absolute":a.x=typeof this.settings.posX=="function"?this.settings.posX($target):this.settings.posX;a.y=typeof this.settings.posY=="function"?this.settings.posY($target):this.settings.posY;break;default:var c=this.$target.offset();a.x=c.left+this.$target.outerWidth()+this.settings.marginX;a.y=c.top+ this.$target.outerHeight()+this.settings.marginY}return a},_adjustPositionForWindow:function(a){var c=a.x+this.$tip.outerWidth(),d=a.y+this.$tip.outerHeight(),e=b(window).width()+b(window).scrollLeft()-5,f=b(window).height()+b(window).scrollTop()-5;a.x=c>e?a.x-(c-e):a.x;a.y=d>f?a.y-(d-f):a.y;return a},_adjustPositionForMouse:function(a){if(this.settings.position!="absolute"){var c=this.evt.pageX,d=this.evt.pageY,e=this.$tip.outerWidth(),f=this.$tip.outerHeight();if(a.xc)if(a.y d)a.x=this.settings.position=="mouse"?c-e-this.settings.marginX:this.$target.offset().left-e-this.settings.marginX}return a}};b(document).ready(function(){Tip.init()});b.fn.tipped=function(a){this.each(function(){$target=b(this);a=b.extend({},g,a);$target.data("tipped",a);if(a.mode=="hover")$target.mouseover(function(c){if(Tip.timer){clearTimeout(Tip.timer);}Tip.setup(b(this),a,c);Tip.timer = setTimeout(function(){Tip.show();},a.delay);}).mouseout(function(){if(Tip.timer){clearTimeout(Tip.timer);}Tip.hide()});else a.mode=="click"&&$target.click(function(c){clickedSettings=b(this).data("tipped");Tip.setup(b(this),clickedSettings, c);Tip.show()})});return this};b.extend({getTrigger:function(){return $tip.data("original")}})})(jQuery);