/**
 * angular-strap
 * @version v2.1.3 - 2014-11-06
 * @link http://mgcrea.github.io/angular-strap
 * @author Olivier Louvignes (olivier@mg-crea.com)
 * @license MIT License, http://www.opensource.org/licenses/MIT
 */
"use strict";angular.module("mgcrea.ngStrap.modal",["mgcrea.ngStrap.helpers.dimensions"]).provider("$modal",function(){var e=this.defaults={animation:"am-fade",backdropAnimation:"am-fade",prefixClass:"modal",prefixEvent:"modal",placement:"top",template:"modal/modal.tpl.html",contentTemplate:!1,container:!1,element:null,backdrop:!0,keyboard:!0,html:!1,show:!0};this.$get=["$window","$rootScope","$compile","$q","$templateCache","$http","$animate","$timeout","$sce","dimensions",function(n,t,o,a,i,r,c,l,s){function u(n){function a(){v.$emit(u.prefixEvent+".show",l)}function i(){v.$emit(u.prefixEvent+".hide",l),h.removeClass(u.prefixClass+"-open"),u.animation&&h.removeClass(u.prefixClass+"-with-"+u.animation)}function r(e){e.target===e.currentTarget&&("static"===u.backdrop?l.focus():l.hide())}var l={},u=l.$options=angular.extend({},e,n);l.$promise=m(u.template);var v=l.$scope=u.scope&&u.scope.$new()||t.$new();u.element||u.container||(u.container="body"),p(["title","content"],function(e){u[e]&&(v[e]=s.trustAsHtml(u[e]))}),v.$hide=function(){v.$$postDigest(function(){l.hide()})},v.$show=function(){v.$$postDigest(function(){l.show()})},v.$toggle=function(){v.$$postDigest(function(){l.toggle()})},u.contentTemplate&&(l.$promise=l.$promise.then(function(e){var t=angular.element(e);return m(u.contentTemplate).then(function(e){var o=d('[ng-bind="content"]',t[0]).removeAttr("ng-bind").html(e);return n.template||o.next().remove(),t[0].outerHTML})}));var b,w,k=angular.element('<div class="'+u.prefixClass+'-backdrop"/>');return l.$promise.then(function(e){angular.isObject(e)&&(e=e.data),u.html&&(e=e.replace(g,'ng-bind-html="')),e=f.apply(e),b=o(e),l.init()}),l.init=function(){u.show&&v.$$postDigest(function(){l.show()})},l.destroy=function(){w&&(w.remove(),w=null),k&&(k.remove(),k=null),v.$destroy()},l.show=function(){if(!v.$isShown&&!v.$emit(u.prefixEvent+".show.before",l).defaultPrevented){var e;e=angular.isElement(u.container)?u.container:u.container?d(u.container):null;var n=u.container?null:u.element;w=l.$element=b(v,function(){}),w.css({display:"block"}).addClass(u.placement),u.animation&&(u.backdrop&&k.addClass(u.backdropAnimation),w.addClass(u.animation)),u.backdrop&&c.enter(k,h,null);var t=c.enter(w,e,n,a);t&&t.then&&t.then(a),v.$isShown=!0,v.$$phase||v.$root&&v.$root.$$phase||v.$digest();var o=w[0];$(function(){o.focus()}),h.addClass(u.prefixClass+"-open"),u.animation&&h.addClass(u.prefixClass+"-with-"+u.animation),u.backdrop&&(w.on("click",r),k.on("click",r)),u.keyboard&&w.on("keyup",l.$onKeyUp)}},l.hide=function(){if(v.$isShown&&!v.$emit(u.prefixEvent+".hide.before",l).defaultPrevented){var e=c.leave(w,i);e&&e.then&&e.then(i),u.backdrop&&c.leave(k),v.$isShown=!1,v.$$phase||v.$root&&v.$root.$$phase||v.$digest(),u.backdrop&&(w.off("click",r),k.off("click",r)),u.keyboard&&w.off("keyup",l.$onKeyUp)}},l.toggle=function(){v.$isShown?l.hide():l.show()},l.focus=function(){w[0].focus()},l.$onKeyUp=function(e){27===e.which&&v.$isShown&&(l.hide(),e.stopPropagation())},l}function d(e,n){return angular.element((n||document).querySelectorAll(e))}function m(e){return a.when(i.get(e)||r.get(e)).then(function(n){return angular.isObject(n)?(i.put(e,n.data),n.data):n})}var p=angular.forEach,f=String.prototype.trim,$=n.requestAnimationFrame||n.setTimeout,h=angular.element(n.document.body),g=/ng-bind="/gi;return u}]}).directive("bsModal",["$window","$sce","$modal",function(e,n,t){return{restrict:"EAC",scope:!0,link:function(e,o,a){var i={scope:e,element:o,show:!1};angular.forEach(["template","contentTemplate","placement","backdrop","keyboard","html","container","animation"],function(e){angular.isDefined(a[e])&&(i[e]=a[e])}),angular.forEach(["title","content"],function(t){a[t]&&a.$observe(t,function(o){e[t]=n.trustAsHtml(o)})}),a.bsModal&&e.$watch(a.bsModal,function(n){angular.isObject(n)?angular.extend(e,n):e.content=n},!0);var r=t(i);o.on(a.trigger||"click",r.toggle),e.$on("$destroy",function(){r&&r.destroy(),i=null,r=null})}}}]);
//# sourceMappingURL=modal.min.js.map