8 lines
4.5 KiB
JavaScript
8 lines
4.5 KiB
JavaScript
|
/**
|
||
|
* angular-ui-notification - Angular.js service providing simple notifications using Bootstrap 3 styles with css transitions for animating
|
||
|
* @author Alex_Crack
|
||
|
* @version v0.3.6
|
||
|
* @link https://github.com/alexcrack/angular-ui-notification
|
||
|
* @license MIT
|
||
|
*/
|
||
|
angular.module("ui-notification",[]),angular.module("ui-notification").provider("Notification",function(){this.options={delay:5e3,startTop:10,startRight:10,verticalSpacing:10,horizontalSpacing:10,positionX:"right",positionY:"top",replaceMessage:!1,templateUrl:"angular-ui-notification.html",onClose:void 0,onClick:void 0,closeOnClick:!0,maxCount:0,container:"body",priority:10},this.setOptions=function(t){if(!angular.isObject(t))throw new Error("Options should be an object!");this.options=angular.extend({},this.options,t)},this.$get=["$timeout","$http","$compile","$templateCache","$rootScope","$injector","$sce","$q","$window",function(t,i,n,e,o,s,a,r,l){var c=this.options,p=c.startTop,u=c.startRight,d=c.verticalSpacing,f=c.horizontalSpacing,m=c.delay,g=[],h=!1,y=function(s,y){function C(i){function e(t){["-webkit-transition","-o-transition","transition"].forEach(function(i){C.css(i,t)})}var o=s.scope.$new();o.message=a.trustAsHtml(s.message),o.title=a.trustAsHtml(s.title),o.t=s.type.substr(0,1),o.delay=s.delay,o.onClose=s.onClose,o.onClick=s.onClick;var r=function(t,i){return t._priority-i._priority},m=function(t,i){return i._priority-t._priority},y=function(){var t=0,i=0,n=p,e=u,o=[];"top"===s.positionY?g.sort(r):"bottom"===s.positionY&&g.sort(m);for(var a=g.length-1;a>=0;a--){var l=g[a];if(s.replaceMessage&&a<g.length-1)l.addClass("killed");else{var h=parseInt(l[0].offsetHeight),y=parseInt(l[0].offsetWidth),C=o[l._positionY+l._positionX];k+h>window.innerHeight&&(C=p,i++,t=0);var k=n=C?0===t?C:C+d:p,v=e+i*(f+y);l.css(l._positionY,k+"px"),"center"===l._positionX?l.css("left",parseInt(window.innerWidth/2-y/2)+"px"):l.css(l._positionX,v+"px"),o[l._positionY+l._positionX]=k+h,c.maxCount>0&&g.length>c.maxCount&&0===a&&l.scope().kill(!0),t++}}},C=n(i)(o);C._positionY=s.positionY,C._positionX=s.positionX,C._priority=s.priority,C.addClass(s.type);var v=function(t){t=t.originalEvent||t,("click"===t.type||"opacity"===t.propertyName&&t.elapsedTime>=1)&&(o.onClose&&o.$apply(o.onClose(C)),"click"===t.type&&o.onClick&&o.$apply(o.onClick(C)),C.remove(),g.splice(g.indexOf(C),1),o.$destroy(),y())};s.closeOnClick&&(C.addClass("clickable"),C.bind("click",v)),C.bind("webkitTransitionEnd oTransitionEnd otransitionend transitionend msTransitionEnd",v),angular.isNumber(s.delay)&&t(function(){C.addClass("killed")},s.delay),e("none"),angular.element(document.querySelector(s.container)).append(C);var _=-(parseInt(C[0].offsetHeight)+50);if(C.css(C._positionY,_+"px"),g.push(C),"center"==s.positionX){var w=parseInt(C[0].offsetWidth);C.css("left",parseInt(window.innerWidth/2-w/2)+"px")}t(function(){e("")}),o._templateElement=C,o.kill=function(i){i?(o.onClose&&o.$apply(o.onClose(o._templateElement)),g.splice(g.indexOf(o._templateElement),1),o._templateElement.remove(),o.$destroy(),t(y)):o._templateElement.addClass("killed")},t(y),h||(angular.element(l).bind("resize",function(i){t(y)}),h=!0),k.resolve(o)}var k=r.defer();"object"==typeof s&&null!==s||(s={message:s}),s.scope=s.scope?s.scope:o,s.template=s.templateUrl?s.templateUrl:c.templateUrl,s.delay=angular.isUndefined(s.delay)?m:s.delay,s.type=y||s.type||c.type||"",s.positionY=s.positionY?s.positionY:c.positionY,s.positionX=s.positionX?s.positionX:c.positionX,s.replaceMessage=s.replaceMessage?s.replaceMessage:c.replaceMessage,s.onClose=s.onClose?s.onClose:c.onClose,s.onClick=s.onClick?s.onClick:c.onClick,s.closeOnClick=null!==s.closeOnClick&&void 0!==s.closeOnClick?s.closeOnClick:c.closeOnClick,s.container=s.container?s.container:c.container,s.priority=s.priority?s.priority:c.priority;var v=e.get(s.template);return v?C(v):i.get(s.template,{cache:!0}).then(function(t){C(t.data)})["catch"](function(t){throw new Error("Template ("+s.template+") could not be loaded. "+t)}),k.promise};return y.primary=function(t){return this(t,"primary")},y.error=function(t){return this(t,"error")},y.success=function(t){return this(t,"success")},y.info=function(t){return this(t,"info")},y.warning=function(t){return this(t,"warning")},y.clearAll=function(){angular.forEach(g,function(t){t.addClass("killed")})},y}]}),angular.
|