UNPKG

angular-toastr

Version:

[![Code Climate](https://codeclimate.com/github/Foxandxss/angular-toastr.png)](https://codeclimate.com/github/Foxandxss/angular-toastr) [![Build Status](https://travis-ci.org/Foxandxss/angular-toastr.svg?branch=master)](https://travis-ci.org/Foxandxss/ang

51 lines (40 loc) 1.2 kB
(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); }); } } }());