(function($){function justtools(elem,options){this.elem=elem;this.set=options;} justtools.prototype={addanimation:function(){switch(this.set.animation){case 'none':break;case 'fadein':this.obj.addclass('animated fadein');break;case 'flipin':switch(this.set.gravity){case 'top':this.obj.addclass('animated flipintop');break;case 'bottom':this.obj.addclass('animated flipinbottom');break;case 'left':this.obj.addclass('animated flipinleft');break;case 'right':this.obj.addclass('animated flipinright');break;} break;case 'moveinleft':this.obj.addclass('animated moveleft');break;case 'moveintop':this.obj.addclass('animated movetop');break;case 'moveinbottom':this.obj.addclass('animated movebottom');break;case 'moveinright':this.obj.addclass('animated moveright');break;}},close:function(){this.obj.remove();},setposition:function(){var setpos={};var pos={x:this.elem.offset().left,y:this.elem.offset().top};var wh={w:this.elem.outerwidth(),h:this.elem.outerheight()};var righttmp=(pos.x+wh.w/2)+this.obj.outerwidth()/2;var lefttmp=(pos.x+wh.w/2)-this.obj.outerwidth()/2;switch(this.set.gravity){case 'top':if(righttmp>$(window).width()){setpos={x:pos.x+wh.w-this.obj.outerwidth(),y:pos.y-this.obj.outerheight()-this.set.distance};this.obj.find(".just-"+this.set.gravity).css("left",this.obj.outerwidth()-wh.w/2+"px")}else if(lefttmp<0){setpos={x:pos.x,y:pos.y-this.obj.outerheight()-this.set.distance};this.obj.find(".just-"+this.set.gravity).css("left",wh.w/2+"px")}else{setpos={x:pos.x-(this.obj.outerwidth()-wh.w)/2,y:pos.y-this.obj.outerheight()-this.set.distance};} break;case 'bottom':if(righttmp>$(window).width()){setpos={x:pos.x+wh.w-this.obj.outerwidth(),y:pos.y+wh.h+this.set.distance};this.obj.find(".just-"+this.set.gravity).css("left",this.obj.outerwidth()-wh.w/2+"px")}else if(lefttmp<0){setpos={x:pos.x,y:pos.y+wh.h+this.set.distance};this.obj.find(".just-"+this.set.gravity).css("left",wh.w/2+"px")}else{setpos={x:pos.x-(this.obj.outerwidth()-wh.w)/2,y:pos.y+wh.h+this.set.distance};} break;case 'left':setpos={x:pos.x-this.obj.outerwidth()-this.set.distance,y:pos.y-(this.obj.outerheight()-wh.h)/2};break;case 'right':setpos={x:pos.x+wh.w+this.set.distance,y:pos.y-(this.obj.outerheight()-wh.h)/2};break;} this.obj.css({"left":setpos.x+"px","top":setpos.y+"px"});},setevent:function(){var self=this;if(self.set.events=="click"||self.set.events=="onclick"){self.obj.on("click",function(e){e.stoppropagation();}) $(document).click(function(){self.obj.remove();});} if(self.set.events=="mouseover"||self.set.events=="onmouseover"||self.set.events=="mouseenter"){this.elem.on("mouseout, mouseleave",function(){self.close();});console.log(1)}},setconfirmevents:function(){var self=this;var yes=this.obj.find(".just-yes");var no=this.obj.find(".just-no");yes.click(function(){if(self.set.onyes(self)==true){self.close();};}) no.click(function(){self.close();self.set.onno(self);})},addconfirm:function(){this.obj.append("
");this.setconfirmevents();},setcontent:function(){this.obj=$("
"+this.set.contents+"
"+"
");$("body").append(this.obj);this.setevent();this.addanimation();if(this.set.confirm==true){this.addconfirm();}},init:function(){var e=arguments.callee.caller.caller.caller.caller.caller.arguments[0]||$.event.fix(event||window.event) this.set.events=e.type;var justtoolobj=$(".just-tooltip");if(justtoolobj){justtoolobj.remove();} e.stoppropagation();this.setcontent();this.setposition();var self=this;$(window).resize(function(){self.setposition();})}} $.fn.justtoolstip=function(options){var defaults={height:"auto",width:"auto",contents:'',gravity:'top',theme:'',distance:10,animation:'none',confirm:false,yes:'纭畾',no:'鍙栨秷',onyes:function(){},onno:function(){}} this.each(function(){options=$.extend(defaults,options);options.id=new date().gettime();var tooltip=new justtools($(this),options);tooltip.init();});}})(jquery);