/* ======================================================================== * Frosty.js v1.03 * https://owensbla.github.com/frosty/ * * Plugin boilerplate provied by: http://jqueryboilerplate.com/ * ======================================================================== * Copyright 2013 Blake Owens (http://blakeowens.com/) * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ======================================================================== */ (function(e,t,n,r){function o(t,n){this.anchor=t,this.$anchor=e(t),this.options=e.extend({},s,n,this.$anchor.data()),this._defaults=s,this._name=i,this.init()}var i="frosty",s={attribute:"title",classes:"tip",content:"",delay:0,hasArrow:!0,html:!1,offset:10,position:"top",removeTitle:!0,selector:!1,trigger:"hover",onHidden:function(){},onShown:function(){}};o.prototype={init:function(){this._createTip(),this._bindEvents()},_createTip:function(){this.options.html?this.tipContent=this.options.content:this.options.selector?this.tipContent=e(this.options.selector).html():(this.tipContent=this.$anchor.attr(this.options.attribute),this.options.attribute==="title"&&this.options.removeTitle&&(this.$anchor.attr("data-original-title",this.tipContent),this.$anchor.removeAttr("title"))),this.$el=e("
",{"class":this.options.classes,html:this.tipContent}).css({"z-index":"9999",left:"-9999px",position:"absolute"}),this.$el.appendTo("body");var t=this._getPosition();t=this._checkOverflow(t),this.$el.detach().css(t),this.options.hasArrow&&this._addArrowClass()},_bindEvents:function(){switch(this.options.trigger){case"click":this.$anchor.click(e.proxy(this.toggle,this));break;case"manual":break;case"focus":this.$anchor.focus(e.proxy(this.show,this)),this.$anchor.blur(e.proxy(this.hide,this));break;default:this.$anchor.hover(e.proxy(this.show,this),e.proxy(this.hide,this))}e(t).resize(e.proxy(this._setPosition,this))},_setState:function(e){this.state=e;switch(e){case"visible":this.$el.appendTo("body"),this._checkContent(),this._setPosition(),this.options.onShown.call(this),this.$anchor.trigger("shown");break;case"hidden":this.$el.detach(),this.options.onHidden.call(this),this.$anchor.trigger("hidden")}},_checkContent:function(){this.options.selector&&(this.tipContent=e(this.options.selector).html(),this.$el.html(this.tipContent))},_addArrowClass:function(){switch(this.options.position){case"left":this.$el.addClass("arrow-right");break;case"right":this.$el.addClass("arrow-left");break;case"bottom":this.$el.addClass("arrow-top");break;default:this.$el.addClass("arrow-bottom")}},_getPosition:function(){var e=this.$anchor.offset();switch(this.options.position){case"left":e.left=e.left-this.$el.outerWidth()-this.options.offset,e.top=e.top+this.$anchor.outerHeight()/2-this.$el.outerHeight()/2;break;case"right":e.left=e.left+this.$anchor.outerWidth()+this.options.offset,e.top=e.top+this.$anchor.outerHeight()/2-this.$el.outerHeight()/2;break;case"bottom":e.top=e.top+this.$anchor.outerHeight()+this.options.offset,e.left=e.left+this.$anchor.outerWidth()/2-this.$el.outerWidth()/2;break;default:e.top=e.top-this.$el.outerHeight()-this.options.offset,e.left=e.left+this.$anchor.outerWidth()/2-this.$el.outerWidth()/2}return e},_checkOverflow:function(n){var r=this.options.position;return n.top<0&&(this.options.position="bottom"),n.top+this.$el.height()>e(t).height()&&(this.options.position="top"),n.left<0&&(this.options.position="right"),n.left+this.$el.width()>e(t).width()&&(this.options.position="left"),this.options.position!==r&&(n=this._getPosition(),this.$el.attr("class",this.options.classes),this._addArrowClass()),n},_setPosition:function(){var e=this._getPosition();e=this._checkOverflow(e),this.$el.css(e)},show:function(){var e=this,t=typeof this.options.delay=="object"?parseInt(this.options.delay.show):parseInt(this.options.delay);clearTimeout(this.timeout),this.timeout=t===0?this._setState("visible"):setTimeout(function(){e._setState("visible")},t)},hide:function(){var e=this;delay=typeof this.options.delay=="object"?parseInt(this.options.delay.hide):parseInt(this.options.delay),clearTimeout(this.timeout),this.timeout=delay===0?this._setState("hidden"):setTimeout(function(){e._setState("hidden")},delay)},toggle:function(){this.state==="visible"?this.hide():this.show()},addClass:function(e){typeof e=="string"&&this.$el.addClass(e)},removeClass:function(e){typeof e=="string"&&this.$el.removeClass(e)}},e.fn[i]=function(t,n){if(typeof t=="string")switch(t){case"show":this.each(function(){e.data(this,"plugin_"+i).show()});break;case"hide":this.each(function(){e.data(this,"plugin_"+i).hide()});break;case"toggle":this.each(function(){e.data(this,"plugin_"+i).toggle()});break;case"addClass":this.each(function(){e.data(this,"plugin_"+i).addClass(n)});break;case"removeClass":this.each(function(){e.data(this,"plugin_"+i).removeClass(n)})}return this.each(function(){e.data(this,"plugin_"+i)||e.data(this,"plugin_"+i,new o(this,t))})}})(jQuery,window,document);