gitpitch/public/libs/js/bootstrap-modal-popover-2.0.1.js
2016-08-27 09:49:46 +07:00

1 line
2.8 KiB
JavaScript

!function(t){var o=function(o,e){this.options=e,this.$body=t(document.body),this.$element=t(o).delegate('[data-dismiss="modal-popup"]',"click.dismiss.modal-popup",t.proxy(this.hide,this)),this.$dialog=this.$element.find(".modal-dialog"),this.options.remote&&this.$element.find(".popover-content").load(this.options.remote),this.$parent=e.$parent};o.prototype=t.extend({},t.fn.modal.Constructor.prototype,{constructor:o,getPosition:function(){var o=this.$parent,e="body"===this.options.modalPosition?o.offset():o.position();return t.extend({},e,{width:o[0].offsetWidth,height:o[0].offsetHeight})},show:function(){var o=this.$element;o.css({top:0,left:0,display:"block","z-index":1050});var e,i="function"==typeof this.options.placement?this.options.placement.call(this,$tip[0],this.$element[0]):this.options.placement,s=this.getPosition(),a=o[0].offsetWidth,n=o[0].offsetHeight;switch(i){case"bottom":e={top:s.top+s.height,left:s.left+s.width/2-a/2};break;case"top":e={top:s.top-n,left:s.left+s.width/2-a/2};break;case"left":e={top:s.top+s.height/2-n/2,left:s.left-a};break;case"right":e={top:s.top+s.height/2-n/2,left:s.left+s.width}}o.css(e).addClass(i).addClass("in"),t.fn.modal.Constructor.prototype.show.call(this,arguments)},backdrop:function(o){var e=this.$element.hasClass("fade")?"fade":"";if(this.isShown&&this.options.backdrop){var i=t.support.transition&&e;this.$backdrop=t('<div class="modal-backdrop '+e+'" style="background:none" />').appendTo(document.body),"static"!=this.options.backdrop&&this.$backdrop.click(t.proxy(this.hide,this)),i&&this.$backdrop[0].offsetWidth,this.$backdrop.addClass("in"),i?this.$backdrop.one(t.support.transition.end,o):o()}else!this.isShown&&this.$backdrop?(this.$backdrop.removeClass("in"),t.support.transition&&this.$element.hasClass("fade")?this.$backdrop.one(t.support.transition.end,t.proxy(this.removeBackdrop,this)):this.removeBackdrop(),this.$body.removeClass("modal-open")):o&&o()}}),t.fn.modalPopover=function(e){return this.each(function(){var i=t(this),s="string"==typeof e?i.data("modal-popover"):void 0,a=t.extend({},t.fn.modalPopover.defaults,i.data(),"object"==typeof e&&e);a.$parent=s&&s.$parent||e.$parent||t(a.target),s||i.data("modal-popover",s=new o(this,a)),"string"==typeof e&&s[e]()})},t.fn.modalPopover.Constructor=o,t.fn.modalPopover.defaults=t.extend({},t.fn.modal.defaults,{placement:"right",modalPosition:"body",keyboard:!0,backdrop:!0}),t(function(){t("body").on("click.modal-popover.data-api",'[data-toggle="modal-popover"]',function(o){var e=t(this),i=e.attr("href"),s=t(e.attr("data-target")||i&&i.replace(/.*(?=#[^\s]+$)/,"")),a=s.data("modal-popover")?"toggle":t.extend({remote:!/#/.test(i)&&i},s.data(),e.data());a.$parent=e,o.preventDefault(),s.modalPopover(a).modalPopover("show").one("hide",function(){e.focus()})})})}(window.jQuery);