diff --git a/js/ngPopover.js b/js/ngPopover.js index 77b1316..5799ef2 100644 --- a/js/ngPopover.js +++ b/js/ngPopover.js @@ -1,6 +1,6 @@ -var module = angular.module('ngPopover', []); +angular.module('ngPopover', []) -module.provider('ngPopover', function () { +provider('ngPopover', function () { var open = false; var smallScreenBreakpoint = 500; @@ -259,10 +259,9 @@ module.provider('ngPopover', function () { } } }] -}); +}) - -module.directive('ngPopover', ['ngPopover', function(ngPopover) { +.directive('ngPopover', ['ngPopover', function(ngPopover) { return { restrict: 'A', @@ -271,4 +270,4 @@ module.directive('ngPopover', ['ngPopover', function(ngPopover) { } } -}]); \ No newline at end of file +}]); diff --git a/js/ngPopover.min.js b/js/ngPopover.min.js index ba13c70..667f6cc 100644 --- a/js/ngPopover.min.js +++ b/js/ngPopover.min.js @@ -1 +1 @@ -var module=angular.module("ngPopover",[]);module.provider("ngPopover",function(){var o,t=!1,e=500,n=0,r=15,p=[];$(document).on("click",function(e){if(t){var n=p.some(function(o){return 0!=$(o).has(e.target).length});if(!$("#ng-popover").is(e.target)&&0==$("#ng-popover").has(e.target).length&&!n){var r=200,i=$(e.target);(i.attr("ng-popover")||i.parents(["ng-popover"]))&&(r=0),$("#ng-popover").fadeOut(r,function(){$(this).remove(),t=!1,o!=e.target&&(i.attr("ng-popover")||i.parents(["ng-popover"]))&&i.trigger("click")})}}});var i=function(o,t,p,i,a,l){var v=$(o).offset(),f=$(o).outerWidth(),c=$(o).outerHeight(),s=$("#ng-popover").outerWidth(),g=$("#ng-popover").outerHeight(),d=$(window).width();l&&($("#ng-popover").css({maxWidth:+l}),s=$("#ng-popover").outerWidth()),i&&(s=f,$("#ng-popover").css({width:s}));var h=$(window),u={top:h.scrollTop(),left:h.scrollLeft()};u.right=u.left+h.width(),u.bottom=u.top+h.height();var m;if("left"===t&&(m={left:v.left-s,top:v.top+c/2-g/2}),"right"===t&&(m={left:v.left+f,top:v.top+c/2-g/2}),"bottom"===t&&(m={left:v.left+f/2-s/2,top:v.top+c}),"top"===t&&(m={left:v.left-s/2,top:v.top-g}),"left"===t||"right"===t){var w=0;(m.top+g>u.bottom||m.topu.right&&(b=Math.min(m.left,m.left+s-u.right),m.left-=b+r,$("#ng-popover .arrow").css({left:b+r+s/2}))}if(a){var y=$(o).find(a);anchorPosition=y.offset(),anchorWidth=y.outerWidth(),$("#ng-popover .arrow").css({left:anchorPosition.left-v.left+anchorWidth/2-1})}if(e>d&&p){var k=s-$("#ng-popover").width();$("#ng-popover").width(d-k-2*n),m.left=n,("bottom"===t||"top"===t)&&$("#ng-popover .arrow").css({left:v.left+f/2-n})}else $("#ng-popover").width(s);return m};$("body").on("keyup",function(o){27===o.keyCode&&$("#ng-popover").fadeOut(200,function(){$(this).remove(),t=!1})}),this.$get=["$rootScope","$templateCache","$compile",function(r,a,l){return{setup:function(o){e=o.smallScreenBreakpoint||500,n=o.maximizeMargin||0,p=o.overlayClasses||[]},close:function(o){r.$broadcast("ng-popover-hide",o)},open:function(e,n,p){var v=a.get(p.template||p.ngPopover);v||(v=p.template||p.ngPopover);var f=p.placement||"bottom",c=p.maximize||!1,s=p.title||"",g=p.useparentwidth||!1,d=p.anchorselector||"",h=p.maxwidth||null;p.data&&(n=n.$new(),n.rrData=p.data);var u=function(){$("body").append(""),l($("#ng-popover").contents())(n),n.$apply();var o=i(e,f,c,g,d,h);$(".close-pop").on("click",function(){$("#ng-popover").fadeOut(200,function(){$(this).remove(),t=!1})});var r=f;"bottom"===f&&""===s&&(r="bottom-no-title"),$("#ng-popover").css({left:o.left,top:o.top}).toggleClass(r).fadeIn(100,function(){t=!0})};$(e).on("click",function(e){if(!t)if(o=e.target,r.$broadcast("ng-popover-show",n),p.init){var i=n.$eval(p.init);"object"==typeof i?i.then(function(){setTimeout(u,0)}):u()}else u()}),n.$on("ng-popover-hide",function(){$("#ng-popover").fadeOut(100,function(){$(this).remove(),t=!1})})}}}]}),module.directive("ngPopover",["ngPopover",function(o){return{restrict:"A",link:function(t,e,n){o.open(e,t,n)}}}]); \ No newline at end of file +angular.module("ngPopover",[]),provider("ngPopover",function(){var t,o=!1,e=500,n=0,r=15,p=[];$(document).on("click",function(e){if(o){var n=p.some(function(t){return 0!=$(t).has(e.target).length});if(!$("#ng-popover").is(e.target)&&0==$("#ng-popover").has(e.target).length&&!n){var r=200,i=$(e.target);(i.attr("ng-popover")||i.parents(["ng-popover"]))&&(r=0),$("#ng-popover").fadeOut(r,function(){$(this).remove(),o=!1,t!=e.target&&(i.attr("ng-popover")||i.parents(["ng-popover"]))&&i.trigger("click")})}}});var i=function(t,o,p,i,a,l){var f=$(t).offset(),v=$(t).outerWidth(),c=$(t).outerHeight(),s=$("#ng-popover").outerWidth(),g=$("#ng-popover").outerHeight(),d=$(window).width();l&&($("#ng-popover").css({maxWidth:+l}),s=$("#ng-popover").outerWidth()),i&&(s=v,$("#ng-popover").css({width:s}));var h=$(window),u={top:h.scrollTop(),left:h.scrollLeft()};u.right=u.left+h.width(),u.bottom=u.top+h.height();var m;if("left"===o&&(m={left:f.left-s,top:f.top+c/2-g/2}),"right"===o&&(m={left:f.left+v,top:f.top+c/2-g/2}),"bottom"===o&&(m={left:f.left+v/2-s/2,top:f.top+c}),"top"===o&&(m={left:f.left-s/2,top:f.top-g}),"left"===o||"right"===o){var w=0;(m.top+g>u.bottom||m.topu.right&&(b=Math.min(m.left,m.left+s-u.right),m.left-=b+r,$("#ng-popover .arrow").css({left:b+r+s/2}))}if(a){var y=$(t).find(a);anchorPosition=y.offset(),anchorWidth=y.outerWidth(),$("#ng-popover .arrow").css({left:anchorPosition.left-f.left+anchorWidth/2-1})}if(e>d&&p){var k=s-$("#ng-popover").width();$("#ng-popover").width(d-k-2*n),m.left=n,("bottom"===o||"top"===o)&&$("#ng-popover .arrow").css({left:f.left+v/2-n})}else $("#ng-popover").width(s);return m};$("body").on("keyup",function(t){27===t.keyCode&&$("#ng-popover").fadeOut(200,function(){$(this).remove(),o=!1})}),this.$get=["$rootScope","$templateCache","$compile",function(r,a,l){return{setup:function(t){e=t.smallScreenBreakpoint||500,n=t.maximizeMargin||0,p=t.overlayClasses||[]},close:function(t){r.$broadcast("ng-popover-hide",t)},open:function(e,n,p){var f=a.get(p.template||p.ngPopover);f||(f=p.template||p.ngPopover);var v=p.placement||"bottom",c=p.maximize||!1,s=p.title||"",g=p.useparentwidth||!1,d=p.anchorselector||"",h=p.maxwidth||null;p.data&&(n=n.$new(),n.rrData=p.data);var u=function(){$("body").append(""),l($("#ng-popover").contents())(n),n.$apply();var t=i(e,v,c,g,d,h);$(".close-pop").on("click",function(){$("#ng-popover").fadeOut(200,function(){$(this).remove(),o=!1})});var r=v;"bottom"===v&&""===s&&(r="bottom-no-title"),$("#ng-popover").css({left:t.left,top:t.top}).toggleClass(r).fadeIn(100,function(){o=!0})};$(e).on("click",function(e){if(!o)if(t=e.target,r.$broadcast("ng-popover-show",n),p.init){var i=n.$eval(p.init);"object"==typeof i?i.then(function(){setTimeout(u,0)}):u()}else u()}),n.$on("ng-popover-hide",function(){$("#ng-popover").fadeOut(100,function(){$(this).remove(),o=!1})})}}}]}).directive("ngPopover",["ngPopover",function(t){return{restrict:"A",link:function(o,e,n){t.open(e,o,n)}}}]); \ No newline at end of file