From 5bd711548fd27216e772ee26215a4710f4611064 Mon Sep 17 00:00:00 2001 From: Jesus Rodriguez Date: Thu, 16 Oct 2014 17:00:36 +0200 Subject: [PATCH] chore(release): 0.5.1 --- CHANGELOG.md | 4 ++++ dist/angular-toastr.js | 13 ++++++++++--- dist/angular-toastr.min.js | 2 +- package.json | 2 +- src/toastr.js | 13 ++++++++++--- test/toastr_spec.js | 25 +++++++++++++++++++++---- 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2435837..04529ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 0.5.1 + +- newestOnTop, with that you can choose whether to add new toasts on the top or bottom. Top by default. + ## Version 0.5.0 - Angular 1.3.x support diff --git a/dist/angular-toastr.js b/dist/angular-toastr.js index 18ae1af..06bb8a1 100644 --- a/dist/angular-toastr.js +++ b/dist/angular-toastr.js @@ -67,6 +67,7 @@ angular.module('toastr', []) warning: 'toast-warning' }, messageClass: 'toast-message', + newestOnTop: true, positionClass: 'toast-top-right', tapToDismiss: true, timeOut: 5000, @@ -175,9 +176,15 @@ angular.module('toastr', []) toasts.push(newToast); _setContainer(options).then(function() { - $animate.enter(newToast.el, container, container[0].lastChild).then(function() { - newToast.scope.init(); - }); + if (options.newestOnTop) { + $animate.enter(newToast.el, container).then(function() { + newToast.scope.init(); + }); + } else { + $animate.enter(newToast.el, container, container[0].lastChild).then(function() { + newToast.scope.init(); + }); + } }); return newToast; diff --git a/dist/angular-toastr.min.js b/dist/angular-toastr.min.js index 8c74db5..8b69add 100644 --- a/dist/angular-toastr.min.js +++ b/dist/angular-toastr.min.js @@ -1 +1 @@ -angular.module("toastr",[]).directive("toast",["$compile","$timeout","toastr",function(a,b,c){return{replace:!0,templateUrl:"templates/toastr/toastr.html",link:function(d,e){function f(a){return b(function(){c.remove(d.toastId)},a)}var g;if(d.toastClass=d.options.toastClass,d.titleClass=d.options.titleClass,d.messageClass=d.options.messageClass,d.options.closeHtml){var h=angular.element(d.options.closeHtml);h.addClass("toast-close-button"),h.attr("ng-click","close()"),a(h)(d),e.prepend(h)}d.init=function(){d.options.timeOut&&(g=f(d.options.timeOut))},e.on("mouseenter",function(){g&&b.cancel(g)}),d.tapToast=function(){d.options.tapToDismiss&&d.close()},d.close=function(){c.remove(d.toastId)},e.on("mouseleave",function(){(0!==d.options.timeOut||0!==d.options.extendedTimeOut)&&(g=f(d.options.extendedTimeOut))})}}}]).constant("toastrConfig",{allowHtml:!1,closeButton:!1,closeHtml:"",containerId:"toast-container",extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},messageClass:"toast-message",positionClass:"toast-top-right",tapToDismiss:!0,timeOut:5e3,titleClass:"toast-title",toastClass:"toast"}).factory("toastr",["$animate","$compile","$document","$rootScope","$sce","toastrConfig","$q",function(a,b,c,d,e,f,g){function h(a){if(a)p(a.toastId);else for(var b=0;b"),q.attr("id",b.containerId),q.addClass(b.positionClass),q.css({"pointer-events":"auto"});var d=c.find("body").eq(0);return a.enter(q,d).then(function(){t.resolve()}),t.promise}function o(c){function f(a,b,c){c.allowHtml?(a.scope.allowHtml=!0,a.scope.title=e.trustAsHtml(b.title),a.scope.message=e.trustAsHtml(b.message)):(a.scope.title=b.title,a.scope.message=b.message),a.scope.toastType=a.iconClass,a.scope.toastId=a.toastId,a.scope.options={extendedTimeOut:c.extendedTimeOut,messageClass:c.messageClass,tapToDismiss:c.tapToDismiss,timeOut:c.timeOut,titleClass:c.titleClass,toastClass:c.toastClass},c.closeButton&&(a.scope.options.closeHtml=c.closeHtml)}function g(a){var c=angular.element("
");return b(c)(a)}var h=m(),i={toastId:r++,scope:d.$new()};return i.iconClass=c.iconClass,c.optionsOverride&&(h=angular.extend(h,c.optionsOverride),i.iconClass=c.optionsOverride.iconClass||i.iconClass),f(i,c,h),i.el=g(i.scope),s.push(i),n(h).then(function(){a.enter(i.el,q,q[0].lastChild).then(function(){i.scope.init()})}),i}function p(b){function c(a){for(var b=0;b\n
\n
{{title}}
\n
{{message}}
\n
\n
\n
\n')}]); \ No newline at end of file +angular.module("toastr",[]).directive("toast",["$compile","$timeout","toastr",function(a,b,c){return{replace:!0,templateUrl:"templates/toastr/toastr.html",link:function(d,e){function f(a){return b(function(){c.remove(d.toastId)},a)}var g;if(d.toastClass=d.options.toastClass,d.titleClass=d.options.titleClass,d.messageClass=d.options.messageClass,d.options.closeHtml){var h=angular.element(d.options.closeHtml);h.addClass("toast-close-button"),h.attr("ng-click","close()"),a(h)(d),e.prepend(h)}d.init=function(){d.options.timeOut&&(g=f(d.options.timeOut))},e.on("mouseenter",function(){g&&b.cancel(g)}),d.tapToast=function(){d.options.tapToDismiss&&d.close()},d.close=function(){c.remove(d.toastId)},e.on("mouseleave",function(){(0!==d.options.timeOut||0!==d.options.extendedTimeOut)&&(g=f(d.options.extendedTimeOut))})}}}]).constant("toastrConfig",{allowHtml:!1,closeButton:!1,closeHtml:"",containerId:"toast-container",extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},messageClass:"toast-message",newestOnTop:!0,positionClass:"toast-top-right",tapToDismiss:!0,timeOut:5e3,titleClass:"toast-title",toastClass:"toast"}).factory("toastr",["$animate","$compile","$document","$rootScope","$sce","toastrConfig","$q",function(a,b,c,d,e,f,g){function h(a){if(a)p(a.toastId);else for(var b=0;b"),q.attr("id",b.containerId),q.addClass(b.positionClass),q.css({"pointer-events":"auto"});var d=c.find("body").eq(0);return a.enter(q,d).then(function(){t.resolve()}),t.promise}function o(c){function f(a,b,c){c.allowHtml?(a.scope.allowHtml=!0,a.scope.title=e.trustAsHtml(b.title),a.scope.message=e.trustAsHtml(b.message)):(a.scope.title=b.title,a.scope.message=b.message),a.scope.toastType=a.iconClass,a.scope.toastId=a.toastId,a.scope.options={extendedTimeOut:c.extendedTimeOut,messageClass:c.messageClass,tapToDismiss:c.tapToDismiss,timeOut:c.timeOut,titleClass:c.titleClass,toastClass:c.toastClass},c.closeButton&&(a.scope.options.closeHtml=c.closeHtml)}function g(a){var c=angular.element("
");return b(c)(a)}var h=m(),i={toastId:r++,scope:d.$new()};return i.iconClass=c.iconClass,c.optionsOverride&&(h=angular.extend(h,c.optionsOverride),i.iconClass=c.optionsOverride.iconClass||i.iconClass),f(i,c,h),i.el=g(i.scope),s.push(i),n(h).then(function(){h.newestOnTop?a.enter(i.el,q).then(function(){i.scope.init()}):a.enter(i.el,q,q[0].lastChild).then(function(){i.scope.init()})}),i}function p(b){function c(a){for(var b=0;b\n
\n
{{title}}
\n
{{message}}
\n
\n
\n
\n')}]); \ No newline at end of file diff --git a/package.json b/package.json index eec661a..10ce355 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-toastr", - "version": "0.5.0", + "version": "0.5.1", "devDependencies": { "grunt": "~0.4.5", "grunt-contrib-less": "~0.11.3", diff --git a/src/toastr.js b/src/toastr.js index 38080ba..cc2e370 100644 --- a/src/toastr.js +++ b/src/toastr.js @@ -67,6 +67,7 @@ angular.module('toastr', []) warning: 'toast-warning' }, messageClass: 'toast-message', + newestOnTop: true, positionClass: 'toast-top-right', tapToDismiss: true, timeOut: 5000, @@ -175,9 +176,15 @@ angular.module('toastr', []) toasts.push(newToast); _setContainer(options).then(function() { - $animate.enter(newToast.el, container, container[0].lastChild).then(function() { - newToast.scope.init(); - }); + if (options.newestOnTop) { + $animate.enter(newToast.el, container).then(function() { + newToast.scope.init(); + }); + } else { + $animate.enter(newToast.el, container, container[0].lastChild).then(function() { + newToast.scope.init(); + }); + } }); return newToast; diff --git a/test/toastr_spec.js b/test/toastr_spec.js index 042c904..6080b06 100644 --- a/test/toastr_spec.js +++ b/test/toastr_spec.js @@ -1,17 +1,18 @@ describe('toastr', function() { var $animate, $document, $rootScope, $timeout; - var toastr; + var toastr, toastrConfig; beforeEach(module('ngAnimate')); beforeEach(module('ngAnimateMock')); beforeEach(module('toastr')); - beforeEach(inject(function(_$animate_, _$document_, _$rootScope_, _$timeout_, _toastr_) { + beforeEach(inject(function(_$animate_, _$document_, _$rootScope_, _$timeout_, _toastr_, _toastrConfig_) { $animate = _$animate_; $document = _$document_; $rootScope = _$rootScope_; $timeout = _$timeout_; toastr = _toastr_; + toastrConfig = _toastrConfig_; })); beforeEach(function() { @@ -41,8 +42,6 @@ describe('toastr', function() { toHaveToastOpen: function(noOfToastr) { var toastDomEls = this.actual.find('body > #toast-container > .toast'); - // console.log(this.actual.find('body').prop('innerHTML')); - // console.log('----'); return toastDomEls.length === noOfToastr; }, @@ -393,4 +392,22 @@ describe('toastr', function() { expect(toast).toHaveButtonWith('1'); }); }); + + describe('toast order', function() { + it('adds the newest toasts on top by default', function() { + var toast1 = openToast('success', 'I will be on the bottom'); + var toast2 = openToast('info', 'I like the top part!'); + expect($document).toHaveToastWithMessage(toast2.scope.message, 0); + expect($document).toHaveToastWithMessage(toast1.scope.message, 1); + }); + + it('adds the older toasts on top setting newestOnTop to false', function() { + toastrConfig.newestOnTop = false; + + var toast1 = openToast('success', 'I will be on the top now'); + var toast2 = openToast('info', 'I dont like the bottom part!'); + expect($document).toHaveToastWithMessage(toast2.scope.message, 1); + expect($document).toHaveToastWithMessage(toast1.scope.message, 0); + }); + }); });