From 21d6a81a92c9f4758154e57cb5282a72ba8b149b Mon Sep 17 00:00:00 2001 From: danillo Date: Sun, 21 Aug 2016 21:06:16 -0300 Subject: [PATCH 1/2] Progress Bar Inverse. Default false. --- README.md | 1 + dist/angular-toastr.js | 5 + dist/angular-toastr.min.js | 2 +- dist/angular-toastr.tpls.js | 111 +++++++++--------- dist/angular-toastr.tpls.min.js | 2 +- .../progressbar/progressbar.directive.js | 2 + src/directives/toast/toast.directive.js | 1 + src/directives/toast/toast.html | 2 +- src/toastr.config.js | 1 + src/toastr.js | 1 + 10 files changed, 72 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index c86f1a2..9480c37 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,7 @@ app.config(function(toastrConfig) { * **iconClasses**: The default type classes for the different toasts. * **messageClass**: The class for the toast's message. * **progressBar**: A progress bar to see the timeout in real time. +* **progressBarInverse**: Growing Progress Bar. * **tapToDismiss**: Whether the toast should be dismissed when it is clicked. * **templates**: To override the default path of the templates. * **timeOut**: The timeout before the toasts disappear. diff --git a/dist/angular-toastr.js b/dist/angular-toastr.js index 642e8c9..11f7847 100644 --- a/dist/angular-toastr.js +++ b/dist/angular-toastr.js @@ -215,6 +215,7 @@ onShown: generateEvent('onShown'), onTap: generateEvent('onTap'), progressBar: options.progressBar, + progressBarInverse: options.progressBarInverse, tapToDismiss: options.tapToDismiss, timeOut: options.timeOut, titleClass: options.titleClass, @@ -318,6 +319,7 @@ preventDuplicates: false, preventOpenDuplicates: false, progressBar: false, + progressBarInverse: false, tapToDismiss: true, target: 'body', templates: { @@ -351,6 +353,7 @@ var intervalId, currentTimeOut, hideTime; toastCtrl.progressBar = scope; + toastCtrl.progressBarInverse = "true" === attrs.progressBarInverse; scope.start = function(duration) { if (intervalId) { @@ -370,6 +373,7 @@ function updateProgress() { var percentage = ((hideTime - (new Date().getTime())) / currentTimeOut) * 100; + if(toastCtrl.progressBarInverse) percentage = 100 - percentage; element.css('width', percentage + '%'); } @@ -428,6 +432,7 @@ scope.titleClass = scope.options.titleClass; scope.messageClass = scope.options.messageClass; scope.progressBar = scope.options.progressBar; + scope.progressBarInverse = scope.options.progressBarInverse; if (wantsCloseButton()) { var button = angular.element(scope.options.closeHtml), diff --git a/dist/angular-toastr.min.js b/dist/angular-toastr.min.js index 89f0b66..0e078b1 100644 --- a/dist/angular-toastr.min.js +++ b/dist/angular-toastr.min.js @@ -1 +1 @@ -!function(){"use strict";function t(t,e,n,s,o,r,a){function i(){return B.length}function l(t){if(1!==arguments.length||t)if(t)d(t.toastId);else for(var e=0;e=0&&t.scope.refreshTimer(e)}function d(e,n){function s(t){for(var e=0;e=e&&B[e-1].open.resolve(),o()&&(O.remove(),O=null,$=a.defer())}))}function g(t,e,n,s){return angular.isObject(n)&&(s=n,n=null),C({iconClass:t,message:e,optionsOverride:s,title:n})}function v(){return angular.extend({},r)}function h(e){if(O)return $.promise;O=angular.element("
"),O.attr("id",e.containerId),O.addClass(e.positionClass),O.css({"pointer-events":"auto"});var n=angular.element(document.querySelector(e.target));if(!n||!n.length)throw"Target for toasts doesn't exist";return t.enter(O,n).then(function(){$.resolve()}),$.promise}function C(n){function r(){return f.autoDismiss&&f.maxOpened&&B.length>f.maxOpened}function i(t,e,n){function s(e){if(n[e])return function(){n[e](t)}}n.allowHtml?(t.scope.allowHtml=!0,t.scope.title=o.trustAsHtml(e.title),t.scope.message=o.trustAsHtml(e.message)):(t.scope.title=e.title,t.scope.message=e.message),t.scope.toastType=t.iconClass,t.scope.toastId=t.toastId,t.scope.extraData=n.extraData,t.scope.options={extendedTimeOut:n.extendedTimeOut,messageClass:n.messageClass,onHidden:n.onHidden,onShown:s("onShown"),onTap:s("onTap"),progressBar:n.progressBar,tapToDismiss:n.tapToDismiss,timeOut:n.timeOut,titleClass:n.titleClass,toastClass:n.toastClass},n.closeButton&&(t.scope.options.closeHtml=n.closeHtml)}function l(){function t(t){for(var e=["containerId","iconClasses","maxOpened","newestOnTop","positionClass","preventDuplicates","preventOpenDuplicates","templates"],n=0,s=e.length;n"),s=e.get("$compile");return s(n)(t)}function u(){return f.maxOpened&&B.length<=f.maxOpened||!f.maxOpened}function p(){var t=f.preventDuplicates&&n.message===x,e=f.preventOpenDuplicates&&w[n.message];return!(!t&&!e)||(x=n.message,w[n.message]=!0,!1)}var f=v();if(!p()){var m=l();if(B.push(m),r())for(var g=B.slice(0,B.length-f.maxOpened),C=0,$=g.length;C<$;C++)d(g[C].toastId);return u()&&m.open.resolve(),m.open.promise.then(function(){h(f).then(function(){if(m.isOpened=!0,f.newestOnTop)t.enter(m.el,O).then(function(){m.scope.init()});else{var e=O[0].lastChild?angular.element(O[0].lastChild):null;t.enter(m.el,O,e).then(function(){m.scope.init()})}})}),m}}var O,T=0,B=[],x="",w={},$=a.defer(),D={active:i,clear:l,error:c,info:u,remove:d,success:p,warning:f,refreshTimer:m};return D}angular.module("toastr",[]).factory("toastr",t),t.$inject=["$animate","$injector","$document","$rootScope","$sce","toastrConfig","$q"]}(),function(){"use strict";angular.module("toastr").constant("toastrConfig",{allowHtml:!1,autoDismiss:!1,closeButton:!1,closeHtml:"",containerId:"toast-container",extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},maxOpened:0,messageClass:"toast-message",newestOnTop:!0,onHidden:null,onShown:null,onTap:null,positionClass:"toast-top-right",preventDuplicates:!1,preventOpenDuplicates:!1,progressBar:!1,tapToDismiss:!0,target:"body",templates:{toast:"directives/toast/toast.html",progressbar:"directives/progressbar/progressbar.html"},timeOut:5e3,titleClass:"toast-title",toastClass:"toast"})}(),function(){"use strict";function t(t){function e(t,e,n,s){function o(){var t=(i-(new Date).getTime())/a*100;e.css("width",t+"%")}var r,a,i;s.progressBar=t,t.start=function(t){r&&clearInterval(r),a=parseFloat(t),i=(new Date).getTime()+a,r=setInterval(o,10)},t.stop=function(){r&&clearInterval(r)},t.$on("$destroy",function(){clearInterval(r)})}return{require:"^toast",templateUrl:function(){return t.templates.progressbar},link:e}}angular.module("toastr").directive("progressBar",t),t.$inject=["toastrConfig"]}(),function(){"use strict";function t(){this.progressBar=null,this.startProgressBar=function(t){this.progressBar&&this.progressBar.start(t)},this.stopProgressBar=function(){this.progressBar&&this.progressBar.stop()}}angular.module("toastr").controller("ToastController",t)}(),function(){"use strict";function t(t,e,n,s){function o(n,o,r,a){function i(t){return a.startProgressBar(t),e(function(){a.stopProgressBar(),s.remove(n.toastId)},t,1)}function l(){n.progressBar=!1,a.stopProgressBar()}function c(){return n.options.closeHtml}var u;if(n.toastClass=n.options.toastClass,n.titleClass=n.options.titleClass,n.messageClass=n.options.messageClass,n.progressBar=n.options.progressBar,c()){var p=angular.element(n.options.closeHtml),f=t.get("$compile");p.addClass("toast-close-button"),p.attr("ng-click","close(true, $event)"),f(p)(n),o.children().prepend(p)}n.init=function(){n.options.timeOut&&(u=i(n.options.timeOut)),n.options.onShown&&n.options.onShown()},o.on("mouseenter",function(){l(),u&&e.cancel(u)}),n.tapToast=function(){angular.isFunction(n.options.onTap)&&n.options.onTap(),n.options.tapToDismiss&&n.close(!0)},n.close=function(t,e){e&&angular.isFunction(e.stopPropagation)&&e.stopPropagation(),s.remove(n.toastId,t)},n.refreshTimer=function(t){u&&(e.cancel(u),u=i(t||n.options.timeOut))},o.on("mouseleave",function(){0===n.options.timeOut&&0===n.options.extendedTimeOut||(n.$apply(function(){n.progressBar=n.options.progressBar}),u=i(n.options.extendedTimeOut))})}return{templateUrl:function(){return n.templates.toast},controller:"ToastController",link:o}}angular.module("toastr").directive("toast",t),t.$inject=["$injector","$interval","toastrConfig","toastr"]}(); \ No newline at end of file +!function(){"use strict";function e(e,t,s,n,o,r,a){function i(){return T.length}function l(e){if(1!==arguments.length||e)if(e)m(e.toastId);else for(var t=0;t=0&&e.scope.refreshTimer(t)}function m(t,s){function n(e){for(var t=0;t=t&&T[t-1].open.resolve(),o()&&(O.remove(),O=null,w=a.defer())}))}function d(e,t,s,n){return angular.isObject(s)&&(n=s,s=null),C({iconClass:e,message:t,optionsOverride:n,title:s})}function v(){return angular.extend({},r)}function h(t){if(O)return w.promise;O=angular.element("
"),O.attr("id",t.containerId),O.addClass(t.positionClass),O.css({"pointer-events":"auto"});var s=angular.element(document.querySelector(t.target));if(!s||!s.length)throw"Target for toasts doesn't exist";return e.enter(O,s).then(function(){w.resolve()}),w.promise}function C(s){function r(){return g.autoDismiss&&g.maxOpened&&T.length>g.maxOpened}function i(e,t,s){function n(t){if(s[t])return function(){s[t](e)}}s.allowHtml?(e.scope.allowHtml=!0,e.scope.title=o.trustAsHtml(t.title),e.scope.message=o.trustAsHtml(t.message)):(e.scope.title=t.title,e.scope.message=t.message),e.scope.toastType=e.iconClass,e.scope.toastId=e.toastId,e.scope.extraData=s.extraData,e.scope.options={extendedTimeOut:s.extendedTimeOut,messageClass:s.messageClass,onHidden:s.onHidden,onShown:n("onShown"),onTap:n("onTap"),progressBar:s.progressBar,progressBarInverse:s.progressBarInverse,tapToDismiss:s.tapToDismiss,timeOut:s.timeOut,titleClass:s.titleClass,toastClass:s.toastClass},s.closeButton&&(e.scope.options.closeHtml=s.closeHtml)}function l(){function e(e){for(var t=["containerId","iconClasses","maxOpened","newestOnTop","positionClass","preventDuplicates","preventOpenDuplicates","templates"],s=0,n=t.length;s"),n=t.get("$compile");return n(s)(e)}function u(){return g.maxOpened&&T.length<=g.maxOpened||!g.maxOpened}function p(){var e=g.preventDuplicates&&s.message===I,t=g.preventOpenDuplicates&&x[s.message];return!(!e&&!t)||(I=s.message,x[s.message]=!0,!1)}var g=v();if(!p()){var f=l();if(T.push(f),r())for(var d=T.slice(0,T.length-g.maxOpened),C=0,w=d.length;C×",containerId:"toast-container",extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},maxOpened:0,messageClass:"toast-message",newestOnTop:!0,onHidden:null,onShown:null,onTap:null,positionClass:"toast-top-right",preventDuplicates:!1,preventOpenDuplicates:!1,progressBar:!1,progressBarInverse:!1,tapToDismiss:!0,target:"body",templates:{toast:"directives/toast/toast.html",progressbar:"directives/progressbar/progressbar.html"},timeOut:5e3,titleClass:"toast-title",toastClass:"toast"})}(),function(){"use strict";function e(e){function t(e,t,s,n){function o(){var e=(i-(new Date).getTime())/a*100;n.progressBarInverse&&(e=100-e),t.css("width",e+"%")}var r,a,i;n.progressBar=e,n.progressBarInverse="true"===s.progressBarInverse,e.start=function(e){r&&clearInterval(r),a=parseFloat(e),i=(new Date).getTime()+a,r=setInterval(o,10)},e.stop=function(){r&&clearInterval(r)},e.$on("$destroy",function(){clearInterval(r)})}return{require:"^toast",templateUrl:function(){return e.templates.progressbar},link:t}}angular.module("toastr").directive("progressBar",e),e.$inject=["toastrConfig"]}(),function(){"use strict";function e(){this.progressBar=null,this.startProgressBar=function(e){this.progressBar&&this.progressBar.start(e)},this.stopProgressBar=function(){this.progressBar&&this.progressBar.stop()}}angular.module("toastr").controller("ToastController",e)}(),function(){"use strict";function e(e,t,s,n){function o(s,o,r,a){function i(e){return a.startProgressBar(e),t(function(){a.stopProgressBar(),n.remove(s.toastId)},e,1)}function l(){s.progressBar=!1,a.stopProgressBar()}function c(){return s.options.closeHtml}var u;if(s.toastClass=s.options.toastClass,s.titleClass=s.options.titleClass,s.messageClass=s.options.messageClass,s.progressBar=s.options.progressBar,s.progressBarInverse=s.options.progressBarInverse,c()){var p=angular.element(s.options.closeHtml),g=e.get("$compile");p.addClass("toast-close-button"),p.attr("ng-click","close(true, $event)"),g(p)(s),o.children().prepend(p)}s.init=function(){s.options.timeOut&&(u=i(s.options.timeOut)),s.options.onShown&&s.options.onShown()},o.on("mouseenter",function(){l(),u&&t.cancel(u)}),s.tapToast=function(){angular.isFunction(s.options.onTap)&&s.options.onTap(),s.options.tapToDismiss&&s.close(!0)},s.close=function(e,t){t&&angular.isFunction(t.stopPropagation)&&t.stopPropagation(),n.remove(s.toastId,e)},s.refreshTimer=function(e){u&&(t.cancel(u),u=i(e||s.options.timeOut))},o.on("mouseleave",function(){0===s.options.timeOut&&0===s.options.extendedTimeOut||(s.$apply(function(){s.progressBar=s.options.progressBar}),u=i(s.options.extendedTimeOut))})}return{templateUrl:function(){return s.templates.toast},controller:"ToastController",link:o}}angular.module("toastr").directive("toast",e),e.$inject=["$injector","$interval","toastrConfig","toastr"]}(); \ No newline at end of file diff --git a/dist/angular-toastr.tpls.js b/dist/angular-toastr.tpls.js index 14e2d21..795478d 100644 --- a/dist/angular-toastr.tpls.js +++ b/dist/angular-toastr.tpls.js @@ -215,6 +215,7 @@ onShown: generateEvent('onShown'), onTap: generateEvent('onTap'), progressBar: options.progressBar, + progressBarInverse: options.progressBarInverse, tapToDismiss: options.tapToDismiss, timeOut: options.timeOut, titleClass: options.titleClass, @@ -318,6 +319,7 @@ preventDuplicates: false, preventOpenDuplicates: false, progressBar: false, + progressBarInverse: false, tapToDismiss: true, target: 'body', templates: { @@ -330,57 +332,6 @@ }); }()); -(function() { - 'use strict'; - - angular.module('toastr') - .directive('progressBar', progressBar); - - progressBar.$inject = ['toastrConfig']; - - function progressBar(toastrConfig) { - return { - require: '^toast', - templateUrl: function() { - return toastrConfig.templates.progressbar; - }, - link: linkFunction - }; - - function linkFunction(scope, element, attrs, toastCtrl) { - var intervalId, currentTimeOut, hideTime; - - toastCtrl.progressBar = scope; - - scope.start = function(duration) { - if (intervalId) { - clearInterval(intervalId); - } - - currentTimeOut = parseFloat(duration); - hideTime = new Date().getTime() + currentTimeOut; - intervalId = setInterval(updateProgress, 10); - }; - - scope.stop = function() { - if (intervalId) { - clearInterval(intervalId); - } - }; - - function updateProgress() { - var percentage = ((hideTime - (new Date().getTime())) / currentTimeOut) * 100; - element.css('width', percentage + '%'); - } - - scope.$on('$destroy', function() { - // Failsafe stop - clearInterval(intervalId); - }); - } - } -}()); - (function() { 'use strict'; @@ -428,6 +379,7 @@ scope.titleClass = scope.options.titleClass; scope.messageClass = scope.options.messageClass; scope.progressBar = scope.options.progressBar; + scope.progressBarInverse = scope.options.progressBarInverse; if (wantsCloseButton()) { var button = angular.element(scope.options.closeHtml), @@ -505,5 +457,58 @@ } }()); -angular.module("toastr").run(["$templateCache", function($templateCache) {$templateCache.put("directives/progressbar/progressbar.html","
\n"); -$templateCache.put("directives/toast/toast.html","
\n
\n
{{title}}
\n
{{message}}
\n
\n
\n
\n \n
\n");}]); \ No newline at end of file +(function() { + 'use strict'; + + angular.module('toastr') + .directive('progressBar', progressBar); + + progressBar.$inject = ['toastrConfig']; + + function progressBar(toastrConfig) { + return { + require: '^toast', + templateUrl: function() { + return toastrConfig.templates.progressbar; + }, + link: linkFunction + }; + + function linkFunction(scope, element, attrs, toastCtrl) { + var intervalId, currentTimeOut, hideTime; + + toastCtrl.progressBar = scope; + toastCtrl.progressBarInverse = "true" === attrs.progressBarInverse; + + scope.start = function(duration) { + if (intervalId) { + clearInterval(intervalId); + } + + currentTimeOut = parseFloat(duration); + hideTime = new Date().getTime() + currentTimeOut; + intervalId = setInterval(updateProgress, 10); + }; + + scope.stop = function() { + if (intervalId) { + clearInterval(intervalId); + } + }; + + function updateProgress() { + var percentage = ((hideTime - (new Date().getTime())) / currentTimeOut) * 100; + if(toastCtrl.progressBarInverse) percentage = 100 - percentage; + element.css('width', percentage + '%'); + } + + scope.$on('$destroy', function() { + // Failsafe stop + clearInterval(intervalId); + }); + } + } +}()); + +angular.module("toastr").run(["$templateCache", function($templateCache) {$templateCache.put("directives/progressbar/progressbar.html","
\r\n"); +$templateCache.put("directives/toast/toast.html","
\r\n
\r\n
{{title}}
\r\n
{{message}}
\r\n
\r\n
\r\n
\r\n \r\n
\r\n");}]); \ No newline at end of file diff --git a/dist/angular-toastr.tpls.min.js b/dist/angular-toastr.tpls.min.js index ae15aa6..cceb118 100644 --- a/dist/angular-toastr.tpls.min.js +++ b/dist/angular-toastr.tpls.min.js @@ -1 +1 @@ -!function(){"use strict";function t(t,e,s,n,o,r,a){function i(){return w.length}function l(t){if(1!==arguments.length||t)if(t)m(t.toastId);else for(var e=0;e=0&&t.scope.refreshTimer(e)}function m(e,s){function n(t){for(var e=0;e=e&&w[e-1].open.resolve(),o()&&(O.remove(),O=null,$=a.defer())}))}function f(t,e,s,n){return angular.isObject(s)&&(n=s,s=null),C({iconClass:t,message:e,optionsOverride:n,title:s})}function v(){return angular.extend({},r)}function h(e){if(O)return $.promise;O=angular.element("
"),O.attr("id",e.containerId),O.addClass(e.positionClass),O.css({"pointer-events":"auto"});var s=angular.element(document.querySelector(e.target));if(!s||!s.length)throw"Target for toasts doesn't exist";return t.enter(O,s).then(function(){$.resolve()}),$.promise}function C(s){function r(){return g.autoDismiss&&g.maxOpened&&w.length>g.maxOpened}function i(t,e,s){function n(e){if(s[e])return function(){s[e](t)}}s.allowHtml?(t.scope.allowHtml=!0,t.scope.title=o.trustAsHtml(e.title),t.scope.message=o.trustAsHtml(e.message)):(t.scope.title=e.title,t.scope.message=e.message),t.scope.toastType=t.iconClass,t.scope.toastId=t.toastId,t.scope.extraData=s.extraData,t.scope.options={extendedTimeOut:s.extendedTimeOut,messageClass:s.messageClass,onHidden:s.onHidden,onShown:n("onShown"),onTap:n("onTap"),progressBar:s.progressBar,tapToDismiss:s.tapToDismiss,timeOut:s.timeOut,titleClass:s.titleClass,toastClass:s.toastClass},s.closeButton&&(t.scope.options.closeHtml=s.closeHtml)}function l(){function t(t){for(var e=["containerId","iconClasses","maxOpened","newestOnTop","positionClass","preventDuplicates","preventOpenDuplicates","templates"],s=0,n=e.length;s"),n=e.get("$compile");return n(s)(t)}function u(){return g.maxOpened&&w.length<=g.maxOpened||!g.maxOpened}function p(){var t=g.preventDuplicates&&s.message===B,e=g.preventOpenDuplicates&&x[s.message];return!(!t&&!e)||(B=s.message,x[s.message]=!0,!1)}var g=v();if(!p()){var d=l();if(w.push(d),r())for(var f=w.slice(0,w.length-g.maxOpened),C=0,$=f.length;C<$;C++)m(f[C].toastId);return u()&&d.open.resolve(),d.open.promise.then(function(){h(g).then(function(){if(d.isOpened=!0,g.newestOnTop)t.enter(d.el,O).then(function(){d.scope.init()});else{var e=O[0].lastChild?angular.element(O[0].lastChild):null;t.enter(d.el,O,e).then(function(){d.scope.init()})}})}),d}}var O,T=0,w=[],B="",x={},$=a.defer(),b={active:i,clear:l,error:c,info:u,remove:m,success:p,warning:g,refreshTimer:d};return b}angular.module("toastr",[]).factory("toastr",t),t.$inject=["$animate","$injector","$document","$rootScope","$sce","toastrConfig","$q"]}(),function(){"use strict";angular.module("toastr").constant("toastrConfig",{allowHtml:!1,autoDismiss:!1,closeButton:!1,closeHtml:"",containerId:"toast-container",extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},maxOpened:0,messageClass:"toast-message",newestOnTop:!0,onHidden:null,onShown:null,onTap:null,positionClass:"toast-top-right",preventDuplicates:!1,preventOpenDuplicates:!1,progressBar:!1,tapToDismiss:!0,target:"body",templates:{toast:"directives/toast/toast.html",progressbar:"directives/progressbar/progressbar.html"},timeOut:5e3,titleClass:"toast-title",toastClass:"toast"})}(),function(){"use strict";function t(t){function e(t,e,s,n){function o(){var t=(i-(new Date).getTime())/a*100;e.css("width",t+"%")}var r,a,i;n.progressBar=t,t.start=function(t){r&&clearInterval(r),a=parseFloat(t),i=(new Date).getTime()+a,r=setInterval(o,10)},t.stop=function(){r&&clearInterval(r)},t.$on("$destroy",function(){clearInterval(r)})}return{require:"^toast",templateUrl:function(){return t.templates.progressbar},link:e}}angular.module("toastr").directive("progressBar",t),t.$inject=["toastrConfig"]}(),function(){"use strict";function t(){this.progressBar=null,this.startProgressBar=function(t){this.progressBar&&this.progressBar.start(t)},this.stopProgressBar=function(){this.progressBar&&this.progressBar.stop()}}angular.module("toastr").controller("ToastController",t)}(),function(){"use strict";function t(t,e,s,n){function o(s,o,r,a){function i(t){return a.startProgressBar(t),e(function(){a.stopProgressBar(),n.remove(s.toastId)},t,1)}function l(){s.progressBar=!1,a.stopProgressBar()}function c(){return s.options.closeHtml}var u;if(s.toastClass=s.options.toastClass,s.titleClass=s.options.titleClass,s.messageClass=s.options.messageClass,s.progressBar=s.options.progressBar,c()){var p=angular.element(s.options.closeHtml),g=t.get("$compile");p.addClass("toast-close-button"),p.attr("ng-click","close(true, $event)"),g(p)(s),o.children().prepend(p)}s.init=function(){s.options.timeOut&&(u=i(s.options.timeOut)),s.options.onShown&&s.options.onShown()},o.on("mouseenter",function(){l(),u&&e.cancel(u)}),s.tapToast=function(){angular.isFunction(s.options.onTap)&&s.options.onTap(),s.options.tapToDismiss&&s.close(!0)},s.close=function(t,e){e&&angular.isFunction(e.stopPropagation)&&e.stopPropagation(),n.remove(s.toastId,t)},s.refreshTimer=function(t){u&&(e.cancel(u),u=i(t||s.options.timeOut))},o.on("mouseleave",function(){0===s.options.timeOut&&0===s.options.extendedTimeOut||(s.$apply(function(){s.progressBar=s.options.progressBar}),u=i(s.options.extendedTimeOut))})}return{templateUrl:function(){return s.templates.toast},controller:"ToastController",link:o}}angular.module("toastr").directive("toast",t),t.$inject=["$injector","$interval","toastrConfig","toastr"]}(),angular.module("toastr").run(["$templateCache",function(t){t.put("directives/progressbar/progressbar.html",'
\n'),t.put("directives/toast/toast.html",'
\n
\n
{{title}}
\n
{{message}}
\n
\n
\n
\n \n
\n')}]); \ No newline at end of file +!function(){"use strict";function e(e,t,s,n,o,r,a){function i(){return T.length}function l(e){if(1!==arguments.length||e)if(e)m(e.toastId);else for(var t=0;t=0&&e.scope.refreshTimer(t)}function m(t,s){function n(e){for(var t=0;t=t&&T[t-1].open.resolve(),o()&&(O.remove(),O=null,x=a.defer())}))}function f(e,t,s,n){return angular.isObject(s)&&(n=s,s=null),C({iconClass:e,message:t,optionsOverride:n,title:s})}function v(){return angular.extend({},r)}function h(t){if(O)return x.promise;O=angular.element("
"),O.attr("id",t.containerId),O.addClass(t.positionClass),O.css({"pointer-events":"auto"});var s=angular.element(document.querySelector(t.target));if(!s||!s.length)throw"Target for toasts doesn't exist";return e.enter(O,s).then(function(){x.resolve()}),x.promise}function C(s){function r(){return g.autoDismiss&&g.maxOpened&&T.length>g.maxOpened}function i(e,t,s){function n(t){if(s[t])return function(){s[t](e)}}s.allowHtml?(e.scope.allowHtml=!0,e.scope.title=o.trustAsHtml(t.title),e.scope.message=o.trustAsHtml(t.message)):(e.scope.title=t.title,e.scope.message=t.message),e.scope.toastType=e.iconClass,e.scope.toastId=e.toastId,e.scope.extraData=s.extraData,e.scope.options={extendedTimeOut:s.extendedTimeOut,messageClass:s.messageClass,onHidden:s.onHidden,onShown:n("onShown"),onTap:n("onTap"),progressBar:s.progressBar,progressBarInverse:s.progressBarInverse,tapToDismiss:s.tapToDismiss,timeOut:s.timeOut,titleClass:s.titleClass,toastClass:s.toastClass},s.closeButton&&(e.scope.options.closeHtml=s.closeHtml)}function l(){function e(e){for(var t=["containerId","iconClasses","maxOpened","newestOnTop","positionClass","preventDuplicates","preventOpenDuplicates","templates"],s=0,n=t.length;s"),n=t.get("$compile");return n(s)(e)}function u(){return g.maxOpened&&T.length<=g.maxOpened||!g.maxOpened}function p(){var e=g.preventDuplicates&&s.message===w,t=g.preventOpenDuplicates&&I[s.message];return!(!e&&!t)||(w=s.message,I[s.message]=!0,!1)}var g=v();if(!p()){var d=l();if(T.push(d),r())for(var f=T.slice(0,T.length-g.maxOpened),C=0,x=f.length;C×",containerId:"toast-container",extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},maxOpened:0,messageClass:"toast-message",newestOnTop:!0,onHidden:null,onShown:null,onTap:null,positionClass:"toast-top-right",preventDuplicates:!1,preventOpenDuplicates:!1,progressBar:!1,progressBarInverse:!1,tapToDismiss:!0,target:"body",templates:{toast:"directives/toast/toast.html",progressbar:"directives/progressbar/progressbar.html"},timeOut:5e3,titleClass:"toast-title",toastClass:"toast"})}(),function(){"use strict";function e(){this.progressBar=null,this.startProgressBar=function(e){this.progressBar&&this.progressBar.start(e)},this.stopProgressBar=function(){this.progressBar&&this.progressBar.stop()}}angular.module("toastr").controller("ToastController",e)}(),function(){"use strict";function e(e,t,s,n){function o(s,o,r,a){function i(e){return a.startProgressBar(e),t(function(){a.stopProgressBar(),n.remove(s.toastId)},e,1)}function l(){s.progressBar=!1,a.stopProgressBar()}function c(){return s.options.closeHtml}var u;if(s.toastClass=s.options.toastClass,s.titleClass=s.options.titleClass,s.messageClass=s.options.messageClass,s.progressBar=s.options.progressBar,s.progressBarInverse=s.options.progressBarInverse,c()){var p=angular.element(s.options.closeHtml),g=e.get("$compile");p.addClass("toast-close-button"),p.attr("ng-click","close(true, $event)"),g(p)(s),o.children().prepend(p)}s.init=function(){s.options.timeOut&&(u=i(s.options.timeOut)),s.options.onShown&&s.options.onShown()},o.on("mouseenter",function(){l(),u&&t.cancel(u)}),s.tapToast=function(){angular.isFunction(s.options.onTap)&&s.options.onTap(),s.options.tapToDismiss&&s.close(!0)},s.close=function(e,t){t&&angular.isFunction(t.stopPropagation)&&t.stopPropagation(),n.remove(s.toastId,e)},s.refreshTimer=function(e){u&&(t.cancel(u),u=i(e||s.options.timeOut))},o.on("mouseleave",function(){0===s.options.timeOut&&0===s.options.extendedTimeOut||(s.$apply(function(){s.progressBar=s.options.progressBar}),u=i(s.options.extendedTimeOut))})}return{templateUrl:function(){return s.templates.toast},controller:"ToastController",link:o}}angular.module("toastr").directive("toast",e),e.$inject=["$injector","$interval","toastrConfig","toastr"]}(),function(){"use strict";function e(e){function t(e,t,s,n){function o(){var e=(i-(new Date).getTime())/a*100;n.progressBarInverse&&(e=100-e),t.css("width",e+"%")}var r,a,i;n.progressBar=e,n.progressBarInverse="true"===s.progressBarInverse,e.start=function(e){r&&clearInterval(r),a=parseFloat(e),i=(new Date).getTime()+a,r=setInterval(o,10)},e.stop=function(){r&&clearInterval(r)},e.$on("$destroy",function(){clearInterval(r)})}return{require:"^toast",templateUrl:function(){return e.templates.progressbar},link:t}}angular.module("toastr").directive("progressBar",e),e.$inject=["toastrConfig"]}(),angular.module("toastr").run(["$templateCache",function(e){e.put("directives/progressbar/progressbar.html",'
\r\n'),e.put("directives/toast/toast.html",'
\r\n
\r\n
{{title}}
\r\n
{{message}}
\r\n
\r\n
\r\n
\r\n \r\n
\r\n')}]); \ No newline at end of file diff --git a/src/directives/progressbar/progressbar.directive.js b/src/directives/progressbar/progressbar.directive.js index 690010b..3209b43 100644 --- a/src/directives/progressbar/progressbar.directive.js +++ b/src/directives/progressbar/progressbar.directive.js @@ -19,6 +19,7 @@ var intervalId, currentTimeOut, hideTime; toastCtrl.progressBar = scope; + toastCtrl.progressBarInverse = "true" === attrs.progressBarInverse; scope.start = function(duration) { if (intervalId) { @@ -38,6 +39,7 @@ function updateProgress() { var percentage = ((hideTime - (new Date().getTime())) / currentTimeOut) * 100; + if(toastCtrl.progressBarInverse) percentage = 100 - percentage; element.css('width', percentage + '%'); } diff --git a/src/directives/toast/toast.directive.js b/src/directives/toast/toast.directive.js index 12a3b79..97437e9 100644 --- a/src/directives/toast/toast.directive.js +++ b/src/directives/toast/toast.directive.js @@ -22,6 +22,7 @@ scope.titleClass = scope.options.titleClass; scope.messageClass = scope.options.messageClass; scope.progressBar = scope.options.progressBar; + scope.progressBarInverse = scope.options.progressBarInverse; if (wantsCloseButton()) { var button = angular.element(scope.options.closeHtml), diff --git a/src/directives/toast/toast.html b/src/directives/toast/toast.html index 74274bd..01ad03a 100644 --- a/src/directives/toast/toast.html +++ b/src/directives/toast/toast.html @@ -5,5 +5,5 @@
- + diff --git a/src/toastr.config.js b/src/toastr.config.js index e5f5ce3..df32540 100644 --- a/src/toastr.config.js +++ b/src/toastr.config.js @@ -25,6 +25,7 @@ preventDuplicates: false, preventOpenDuplicates: false, progressBar: false, + progressBarInverse: false, tapToDismiss: true, target: 'body', templates: { diff --git a/src/toastr.js b/src/toastr.js index a92ffb3..1d9c475 100644 --- a/src/toastr.js +++ b/src/toastr.js @@ -215,6 +215,7 @@ onShown: generateEvent('onShown'), onTap: generateEvent('onTap'), progressBar: options.progressBar, + progressBarInverse: options.progressBarInverse, tapToDismiss: options.tapToDismiss, timeOut: options.timeOut, titleClass: options.titleClass, From 534e7d851780da506a67ad6b62104df4489aeba5 Mon Sep 17 00:00:00 2001 From: danillo Date: Sun, 21 Aug 2016 21:36:55 -0300 Subject: [PATCH 2/2] increment version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index a25be5c..40a9583 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-toastr", - "version": "2.1.1", + "version": "2.1.2", "authors": [ "Jesus Rodriguez " ],