/* * WebUI Popover - v1.0.0 * An enhancement popover plugin for Bootstrap! * https://github.com/sandywalker/webui-popover * * Made by Sandy Walker * Under MIT License */ !function(a,b,c){function d(b,c){this.$element=a(b),this.options=a.extend({},g,c),console.log(this.options),this._defaults=g,this._name=e,this.init()}var e="webuiPopover",f="webui-popover",g={placement:"auto",width:"auto",height:"auto",trigger:"click",style:"",delay:300,cache:!0,multi:!1,arrow:!0,title:"",content:"",closeable:!1,padding:!0,iframe:!1,url:"",template:'
'};d.prototype={init:function(){"click"===this.options.trigger?this.$element.off("click").on("click",a.proxy(this.toggle,this)):this.$element.off("mouseenter mouseleave").on("mouseenter",a.proxy(this.mouseenterHandler,this)).on("mouseleave",a.proxy(this.mouseleaveHandler,this)),this._poped=!1,this._inited=!0},destroy:function(){this.hide(),this.$element.data("plugin_"+e,null),this.$element.off(),this.$target&&this.$target.remove()},hide:function(a){a&&a.preventDefault(),this.$target&&this.$target.removeClass("in").hide()},toggle:function(a){a&&a.preventDefault(),this[this.getTarget().hasClass("in")?"hide":"show"]()},hideAll:function(){a("div.webui-popover").removeClass("in").hide()},getTarget:function(){return this.$target||(this.$target=a(this.options.template)),this.$target},getTitleElement:function(){return this.getTarget().find("."+f+"-title")},getContentElement:function(){return this.getTarget().find("."+f+"-content")},getTitle:function(){return this.options.title||this.$element.attr("data-title")||this.$element.attr("title")},setTitle:function(a){var b=this.getTitleElement();a?b.html(a):b.remove()},getContent:function(){if(this.options.url)this.options.iframe?this.content=a('').attr("src",this.options.url):a.ajax({url:this.options.url,type:"GET",async:!1,success:function(a){this.content=a}});else if(!this.content){var b="";b=a.isFunction(this.options.content)?this.options.content.apply(this.$element[0],arguments):this.options.content,this.content=this.$element.attr("data-content")||b}return this.content},setContent:function(a){var b=this.getTarget();this.getContentElement().html(a),this.$target=b,this.options.onSetContent&&this.options.onSetContent(b[0])},mouseenterHandler:function(){var a=this;a._timeout&&clearTimeout(a._timeout),a.getTarget().is(":visible")||a.show()},mouseleaveHandler:function(){var a=this;a._timeout=setTimeout(function(){a.hide()},a.options.delay)},triggerShowEvent:function(){if(this.options.onShow&&"function"==typeof this.options.onShow){var a=this.$target[0];this.options.onShow(a)}},initTargetEvents:function(){"click"!==this.options.trigger&&this.$target.off("mouseenter mouseleave").on("mouseenter",a.proxy(this.mouseenterHandler,this)).on("mouseleave",a.proxy(this.mouseleaveHandler,this)),this.$target.find(".close").off("click").on("click",a.proxy(this.hide,this))},getPlacement:function(a,b){var d,e=c.documentElement,f=c.body,g=e.clientWidth,h=Math.max(f.scrollTop,e.scrollTop),i=Math.max(f.scrollLeft,e.scrollLeft),j=Math.max(0,a.left-i),k=Math.max(0,a.top-h),l=20;return d="function"==typeof this.options.placement?this.options.placement(this.$element):this.options.placement,"auto"===d&&(d=g/3>j?k>b+l?"top-right":"bottom-right":2*g/3>j?k>b+l?"top":"bottom":k>b+l?"top-left":"bottom-left"),d},getElementPosition:function(){return a.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight})},getTargetPositin:function(a,b,c,d){var e=a,f=this.$element.outerWidth(),g={},h={},i=this.options.arrow?0:0;switch(b){case"bottom":g={top:e.top+e.height,left:e.left+e.width/2-c/2};break;case"top":g={top:e.top-d-i,left:e.left+e.width/2-c/2};break;case"left":g={top:e.top+e.height/2-d/2,left:e.left-c-i};break;case"right":g={top:e.top+e.height/2-d/2,left:e.left+e.width};break;case"top-right":g={top:e.top-d-i,left:e.left},h={left:f/2};break;case"top-left":g={top:e.top-d-i,left:e.left-c+e.width},h={left:c-f/2};break;case"bottom-right":g={top:e.top+e.height,left:e.left},h={left:f/2};break;case"bottom-left":g={top:e.top+e.height,left:e.left-c+e.width},h={left:c-f/2}}return{position:g,arrowOffset:h}},show:function(){var a=this.getElementPosition(),b=this.getTarget().removeClass().addClass(f),d=this.getContentElement(),e=b[0].offsetWidth,g=b[0].offsetHeight,h="bottom";this.options.multi||this.hideAll(),this.options.cache&&this._poped||(this.setContent(this.getContent()),this.setTitle(this.getTitle()),this.options.closeable||b.find(".close").off("click").remove(),b.show()),"auto"!==this.options.width&&b.width(this.options.width),"auto"!==this.options.height&&d.height(this.options.height),this.options.arrow||b.find(".arrow").remove(),b.remove().css({top:-1e3,left:-1e3,display:"block"}).appendTo(c.body),e=b[0].offsetWidth,g=b[0].offsetHeight,h=this.getPlacement(a,g),this.initTargetEvents();var i=this.getTargetPositin(a,h,e,g);if(this.$target.css(i.position).addClass(h).addClass("in"),this.options.iframe){var j=b.find("iframe");j.width(b.width()).height(j.parent().height())}this.options.style&&this.$target.addClass(f+"-"+this.options.style),this.options.padding||(d.css("height",d.outerHeight()),this.$target.addClass("webui-no-padding")),this.options.arrow||this.$target.css({margin:0}),this.options.arrow&&i.arrowOffset&&this.$target.find(".arrow").css(i.arrowOffset),this._poped=!0,this.triggerShowEvent()}},a.fn[e]=function(b){return this.each(function(){var c=a.data(this,"plugin_"+e);c?"destroy"===b?c.destroy():"string"==typeof b&&c[b]():(b?"string"==typeof b?"destroy"!==b&&(c=new d(this,null),c[b]()):"object"==typeof b&&(c=new d(this,b)):c=new d(this,null),a.data(this,"plugin_"+e,c))})}}(jQuery,window,document);