From 43706f67b3c3dae8f56da5ce3f3a34bd31321723 Mon Sep 17 00:00:00 2001 From: Siddique Hameed Date: Tue, 3 Mar 2015 17:32:11 -0600 Subject: [PATCH] v1.3.0 --- CHANGELOG.md | 2 +- bower.json | 2 +- dist/angular-timer.js | 108 +++++++++++++++++++------------------- dist/angular-timer.min.js | 4 +- package.json | 2 +- 5 files changed, 59 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0a0bbd..6646fab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ -##Change Log -###Version 1.2.2 +###Version 1.3.0 * MomentJS integration - https://github.com/siddii/angular-timer/pull/159 ###Version 1.2.1 diff --git a/bower.json b/bower.json index f02ede1..514bd83 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "author": "Siddique Hameed", "name": "angular-timer", - "version": "1.2.2", + "version": "1.3.0", "homepage": "https://github.com/siddii/angular-timer", "description": "Angular-Timer : A simple AngularJS directive demonstrating re-usability & interoperability", "repository": { diff --git a/dist/angular-timer.js b/dist/angular-timer.js index 9030065..caadc3c 100644 --- a/dist/angular-timer.js +++ b/dist/angular-timer.js @@ -1,10 +1,63 @@ /** - * angular-timer - v1.2.2 - 2015-03-03 1:43 PM + * angular-timer - v1.3.0 - 2015-03-03 5:32 PM * https://github.com/siddii/angular-timer * * Copyright (c) 2015 Siddique Hameed * Licensed MIT */ +var app = angular.module('timer'); + +app.factory('I18nService', function() { + + var I18nService = function() {}; + + I18nService.prototype.language = 'en'; + I18nService.prototype.timeHumanizer = {}; + + I18nService.prototype.init = function init(lang){ + this.language = lang; + //moment init + moment.locale(this.language); //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive + + //human duration init, using it because momentjs does not allow accurate time ( + // momentJS: a few moment ago, human duration : 4 seconds ago + this.timeHumanizer = humanizeDuration.humanizer({ + language: this.language, + halfUnit:false + }); + }; + + /** + * get time with units from momentJS i18n + * @param {int} millis + * @returns {{millis: string, seconds: string, minutes: string, hours: string, days: string, months: string, years: string}} + */ + I18nService.prototype.getTimeUnits = function getTimeUnits(millis) { + var diffFromAlarm = Math.round(millis/1000) * 1000; //time in milliseconds, get rid of the last 3 ms value to avoid 2.12 seconds display + + var time = {}; + + if (typeof this.timeHumanizer != 'undefined'){ + time = { + 'millis' : this.timeHumanizer(diffFromAlarm, { units: ["milliseconds"] }), + 'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["seconds"] }), + 'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["minutes", "seconds"] }) , + 'hours' : this.timeHumanizer(diffFromAlarm, { units: ["hours", "minutes", "seconds"] }) , + 'days' : this.timeHumanizer(diffFromAlarm, { units: ["days", "hours", "minutes", "seconds"] }) , + 'months' : this.timeHumanizer(diffFromAlarm, { units: ["months", "days", "hours", "minutes", "seconds"] }) , + 'years' : this.timeHumanizer(diffFromAlarm, { units: ["years", "months", "days", "hours", "minutes", "seconds"] }) + }; + } + else { + console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'); + } + + return time; + }; + + return I18nService; +}); + var timerModule = angular.module('timer', []) .directive('timer', ['$compile', function ($compile) { return { @@ -313,56 +366,3 @@ var timerModule = angular.module('timer', []) if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){ module.exports = timerModule; } - -var app = angular.module('timer'); - -app.factory('I18nService', function() { - - var I18nService = function() {}; - - I18nService.prototype.language = 'en'; - I18nService.prototype.timeHumanizer = {}; - - I18nService.prototype.init = function init(lang){ - this.language = lang; - //moment init - moment.locale(this.language); //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive - - //human duration init, using it because momentjs does not allow accurate time ( - // momentJS: a few moment ago, human duration : 4 seconds ago - this.timeHumanizer = humanizeDuration.humanizer({ - language: this.language, - halfUnit:false - }); - }; - - /** - * get time with units from momentJS i18n - * @param {int} millis - * @returns {{millis: string, seconds: string, minutes: string, hours: string, days: string, months: string, years: string}} - */ - I18nService.prototype.getTimeUnits = function getTimeUnits(millis) { - var diffFromAlarm = Math.round(millis/1000) * 1000; //time in milliseconds, get rid of the last 3 ms value to avoid 2.12 seconds display - - var time = {}; - - if (typeof this.timeHumanizer != 'undefined'){ - time = { - 'millis' : this.timeHumanizer(diffFromAlarm, { units: ["milliseconds"] }), - 'seconds' : this.timeHumanizer(diffFromAlarm, { units: ["seconds"] }), - 'minutes' : this.timeHumanizer(diffFromAlarm, { units: ["minutes", "seconds"] }) , - 'hours' : this.timeHumanizer(diffFromAlarm, { units: ["hours", "minutes", "seconds"] }) , - 'days' : this.timeHumanizer(diffFromAlarm, { units: ["days", "hours", "minutes", "seconds"] }) , - 'months' : this.timeHumanizer(diffFromAlarm, { units: ["months", "days", "hours", "minutes", "seconds"] }) , - 'years' : this.timeHumanizer(diffFromAlarm, { units: ["years", "months", "days", "hours", "minutes", "seconds"] }) - }; - } - else { - console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'); - } - - return time; - }; - - return I18nService; -}); diff --git a/dist/angular-timer.min.js b/dist/angular-timer.min.js index cca8393..eded15d 100644 --- a/dist/angular-timer.min.js +++ b/dist/angular-timer.min.js @@ -1,8 +1,8 @@ /** - * angular-timer - v1.2.2 - 2015-03-03 1:43 PM + * angular-timer - v1.3.0 - 2015-03-03 5:32 PM * https://github.com/siddii/angular-timer * * Copyright (c) 2015 Siddique Hameed * Licensed MIT */ -var timerModule=angular.module("timer",[]).directive("timer",["$compile",function(a){return{restrict:"EA",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",endTimeAttr:"=endTime",countdownattr:"=countdown",finishCallback:"&finishCallback",autoStart:"&autoStart",language:"@?",maxTimeUnit:"="},controller:["$scope","$element","$attrs","$timeout","I18nService","$interpolate",function(b,c,d,e,f,g){function h(){b.timeoutId&&clearTimeout(b.timeoutId)}function i(){var a={};void 0!==d.startTime&&(b.millis=moment().diff(moment(b.startTimeAttr))),a=j.getTimeUnits(b.millis),b.maxTimeUnit&&"day"!==b.maxTimeUnit?"second"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3),b.minutes=0,b.hours=0,b.days=0,b.months=0,b.years=0):"minute"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4),b.hours=0,b.days=0,b.months=0,b.years=0):"hour"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5),b.days=0,b.months=0,b.years=0):"month"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30),b.years=0):"year"===b.maxTimeUnit&&(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30%12),b.years=Math.floor(b.millis/36e5/24/365)):(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24),b.months=0,b.years=0),b.secondsS=1===b.seconds?"":"s",b.minutesS=1===b.minutes?"":"s",b.hoursS=1===b.hours?"":"s",b.daysS=1===b.days?"":"s",b.monthsS=1===b.months?"":"s",b.yearsS=1===b.years?"":"s",b.secondUnit=a.seconds,b.minuteUnit=a.minutes,b.hourUnit=a.hours,b.dayUnit=a.days,b.monthUnit=a.months,b.yearUnit=a.years,b.sseconds=b.seconds<10?"0"+b.seconds:b.seconds,b.mminutes=b.minutes<10?"0"+b.minutes:b.minutes,b.hhours=b.hours<10?"0"+b.hours:b.hours,b.ddays=b.days<10?"0"+b.days:b.days,b.mmonths=b.months<10?"0"+b.months:b.months,b.yyears=b.years<10?"0"+b.years:b.years}"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),b.autoStart=d.autoStart||d.autostart,b.language=b.language||"en",b.$watch("language",function(){j.init(b.language)});var j=new f;j.init(b.language),c.append(0===c.html().trim().length?a(""+g.startSymbol()+"millis"+g.endSymbol()+"")(b):a(c.contents())(b)),b.startTime=null,b.endTime=null,b.timeoutId=null,b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>=0?parseInt(b.countdownattr,10):void 0,b.isRunning=!1,b.$on("timer-start",function(){b.start()}),b.$on("timer-resume",function(){b.resume()}),b.$on("timer-stop",function(){b.stop()}),b.$on("timer-clear",function(){b.clear()}),b.$on("timer-reset",function(){b.reset()}),b.$on("timer-set-countdown",function(a,c){b.countdown=c}),b.$watch("startTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.start=c[0].start=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown||(b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0),h(),k(),b.isRunning=!0},b.resume=c[0].resume=function(){h(),b.countdownattr&&(b.countdown+=1),b.startTime=moment().diff(moment(b.stoppedTime).diff(moment(b.startTime))),k(),b.isRunning=!0},b.stop=b.pause=c[0].stop=c[0].pause=function(){var a=b.timeoutId;b.clear(),b.$emit("timer-stopped",{timeoutId:a,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.clear=c[0].clear=function(){b.stoppedTime=moment(),h(),b.timeoutId=null,b.isRunning=!1},b.reset=c[0].reset=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0,h(),k(),b.isRunning=!1,b.clear()},c.bind("$destroy",function(){h(),b.isRunning=!1}),b.countdownattr?(b.millis=1e3*b.countdownattr,b.addCDSeconds=c[0].addCDSeconds=function(a){b.countdown+=a,b.$digest(),b.isRunning||b.start()},b.$on("timer-add-cd-seconds",function(a,c){e(function(){b.addCDSeconds(c)})}),b.$on("timer-set-countdown-seconds",function(a,c){b.isRunning||b.clear(),b.countdown=c,b.millis=1e3*c,i()})):b.millis=0,i();var k=function l(){b.millis=moment().diff(b.startTime);var a=b.millis%1e3;return b.endTimeAttr&&(b.millis=moment(b.endTime).diff(moment()),a=b.interval-b.millis%1e3),b.countdownattr&&(b.millis=1e3*b.countdown),b.millis<0?(b.stop(),b.millis=0,i(),void(b.finishCallback&&b.$eval(b.finishCallback))):(i(),b.timeoutId=setTimeout(function(){l(),b.$digest()},b.interval-a),b.$emit("timer-tick",{timeoutId:b.timeoutId,millis:b.millis}),void(b.countdown>0?b.countdown--:b.countdown<=0&&(b.stop(),b.finishCallback&&b.$eval(b.finishCallback))))};(void 0===b.autoStart||b.autoStart===!0)&&b.start()}]}}]);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=timerModule);var app=angular.module("timer");app.factory("I18nService",function(){var a=function(){};return a.prototype.language="en",a.prototype.timeHumanizer={},a.prototype.init=function(a){this.language=a,moment.locale(this.language),this.timeHumanizer=humanizeDuration.humanizer({language:this.language,halfUnit:!1})},a.prototype.getTimeUnits=function(a){var b=1e3*Math.round(a/1e3),c={};return"undefined"!=typeof this.timeHumanizer?c={millis:this.timeHumanizer(b,{units:["milliseconds"]}),seconds:this.timeHumanizer(b,{units:["seconds"]}),minutes:this.timeHumanizer(b,{units:["minutes","seconds"]}),hours:this.timeHumanizer(b,{units:["hours","minutes","seconds"]}),days:this.timeHumanizer(b,{units:["days","hours","minutes","seconds"]}),months:this.timeHumanizer(b,{units:["months","days","hours","minutes","seconds"]}),years:this.timeHumanizer(b,{units:["years","months","days","hours","minutes","seconds"]})}:console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'),c},a}); \ No newline at end of file +var app=angular.module("timer");app.factory("I18nService",function(){var a=function(){};return a.prototype.language="en",a.prototype.timeHumanizer={},a.prototype.init=function(a){this.language=a,moment.locale(this.language),this.timeHumanizer=humanizeDuration.humanizer({language:this.language,halfUnit:!1})},a.prototype.getTimeUnits=function(a){var b=1e3*Math.round(a/1e3),c={};return"undefined"!=typeof this.timeHumanizer?c={millis:this.timeHumanizer(b,{units:["milliseconds"]}),seconds:this.timeHumanizer(b,{units:["seconds"]}),minutes:this.timeHumanizer(b,{units:["minutes","seconds"]}),hours:this.timeHumanizer(b,{units:["hours","minutes","seconds"]}),days:this.timeHumanizer(b,{units:["days","hours","minutes","seconds"]}),months:this.timeHumanizer(b,{units:["months","days","hours","minutes","seconds"]}),years:this.timeHumanizer(b,{units:["years","months","days","hours","minutes","seconds"]})}:console.error('i18nService has not been initialized. You must call i18nService.init("en") for example'),c},a});var timerModule=angular.module("timer",[]).directive("timer",["$compile",function(a){return{restrict:"EA",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",endTimeAttr:"=endTime",countdownattr:"=countdown",finishCallback:"&finishCallback",autoStart:"&autoStart",language:"@?",maxTimeUnit:"="},controller:["$scope","$element","$attrs","$timeout","I18nService","$interpolate",function(b,c,d,e,f,g){function h(){b.timeoutId&&clearTimeout(b.timeoutId)}function i(){var a={};void 0!==d.startTime&&(b.millis=moment().diff(moment(b.startTimeAttr))),a=j.getTimeUnits(b.millis),b.maxTimeUnit&&"day"!==b.maxTimeUnit?"second"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3),b.minutes=0,b.hours=0,b.days=0,b.months=0,b.years=0):"minute"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4),b.hours=0,b.days=0,b.months=0,b.years=0):"hour"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5),b.days=0,b.months=0,b.years=0):"month"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30),b.years=0):"year"===b.maxTimeUnit&&(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30%12),b.years=Math.floor(b.millis/36e5/24/365)):(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24),b.months=0,b.years=0),b.secondsS=1===b.seconds?"":"s",b.minutesS=1===b.minutes?"":"s",b.hoursS=1===b.hours?"":"s",b.daysS=1===b.days?"":"s",b.monthsS=1===b.months?"":"s",b.yearsS=1===b.years?"":"s",b.secondUnit=a.seconds,b.minuteUnit=a.minutes,b.hourUnit=a.hours,b.dayUnit=a.days,b.monthUnit=a.months,b.yearUnit=a.years,b.sseconds=b.seconds<10?"0"+b.seconds:b.seconds,b.mminutes=b.minutes<10?"0"+b.minutes:b.minutes,b.hhours=b.hours<10?"0"+b.hours:b.hours,b.ddays=b.days<10?"0"+b.days:b.days,b.mmonths=b.months<10?"0"+b.months:b.months,b.yyears=b.years<10?"0"+b.years:b.years}"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),b.autoStart=d.autoStart||d.autostart,b.language=b.language||"en",b.$watch("language",function(){j.init(b.language)});var j=new f;j.init(b.language),c.append(0===c.html().trim().length?a(""+g.startSymbol()+"millis"+g.endSymbol()+"")(b):a(c.contents())(b)),b.startTime=null,b.endTime=null,b.timeoutId=null,b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>=0?parseInt(b.countdownattr,10):void 0,b.isRunning=!1,b.$on("timer-start",function(){b.start()}),b.$on("timer-resume",function(){b.resume()}),b.$on("timer-stop",function(){b.stop()}),b.$on("timer-clear",function(){b.clear()}),b.$on("timer-reset",function(){b.reset()}),b.$on("timer-set-countdown",function(a,c){b.countdown=c}),b.$watch("startTimeAttr",function(a,c){a!==c&&b.isRunning&&b.start()}),b.start=c[0].start=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown||(b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0),h(),k(),b.isRunning=!0},b.resume=c[0].resume=function(){h(),b.countdownattr&&(b.countdown+=1),b.startTime=moment().diff(moment(b.stoppedTime).diff(moment(b.startTime))),k(),b.isRunning=!0},b.stop=b.pause=c[0].stop=c[0].pause=function(){var a=b.timeoutId;b.clear(),b.$emit("timer-stopped",{timeoutId:a,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.clear=c[0].clear=function(){b.stoppedTime=moment(),h(),b.timeoutId=null,b.isRunning=!1},b.reset=c[0].reset=function(){b.startTime=b.startTimeAttr?moment(b.startTimeAttr):moment(),b.endTime=b.endTimeAttr?moment(b.endTimeAttr):null,b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0,h(),k(),b.isRunning=!1,b.clear()},c.bind("$destroy",function(){h(),b.isRunning=!1}),b.countdownattr?(b.millis=1e3*b.countdownattr,b.addCDSeconds=c[0].addCDSeconds=function(a){b.countdown+=a,b.$digest(),b.isRunning||b.start()},b.$on("timer-add-cd-seconds",function(a,c){e(function(){b.addCDSeconds(c)})}),b.$on("timer-set-countdown-seconds",function(a,c){b.isRunning||b.clear(),b.countdown=c,b.millis=1e3*c,i()})):b.millis=0,i();var k=function l(){b.millis=moment().diff(b.startTime);var a=b.millis%1e3;return b.endTimeAttr&&(b.millis=moment(b.endTime).diff(moment()),a=b.interval-b.millis%1e3),b.countdownattr&&(b.millis=1e3*b.countdown),b.millis<0?(b.stop(),b.millis=0,i(),void(b.finishCallback&&b.$eval(b.finishCallback))):(i(),b.timeoutId=setTimeout(function(){l(),b.$digest()},b.interval-a),b.$emit("timer-tick",{timeoutId:b.timeoutId,millis:b.millis}),void(b.countdown>0?b.countdown--:b.countdown<=0&&(b.stop(),b.finishCallback&&b.$eval(b.finishCallback))))};(void 0===b.autoStart||b.autoStart===!0)&&b.start()}]}}]);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=timerModule); \ No newline at end of file diff --git a/package.json b/package.json index 1fd7290..55a1e27 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Siddique Hameed", "name": "angular-timer", - "version": "1.2.2", + "version": "1.3.0", "homepage": "https://github.com/siddii/angular-timer", "main":"dist/angular-timer.js", "licenses": {