Skip to content

Momentjs - bower_components #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Mar 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b86d7e5
add momentjs in bower.js
Feb 13, 2015
a659cc9
init momentjs instead of Date object + default language english if th…
Feb 13, 2015
826068f
remove dist folder from git
Feb 13, 2015
037ab53
add moment to index
Feb 13, 2015
7124125
update gitignore
Feb 13, 2015
f1eeb6b
i18n with humanize duration
Feb 13, 2015
2d39ff7
refactor: i18nService
Feb 17, 2015
a1256c3
bower.json update angular and install humanduration
Feb 17, 2015
ab899c1
update angular bower
Feb 17, 2015
6feb449
remove bower_components from gits. They should be installed via a bow…
Feb 17, 2015
70c35ed
view: index humanduration
Feb 17, 2015
41ab4cc
merge
Feb 17, 2015
181bd83
merge miss
Feb 17, 2015
4f1a3b9
test config
Feb 17, 2015
d322572
update test for angular 1.3
Feb 17, 2015
97a18e3
add i18n e2e tests
Feb 17, 2015
8a6dd4d
update humanize-duration bower-components
Feb 17, 2015
de71269
travis
Feb 17, 2015
350544d
angular mocks added to bower.json
Feb 17, 2015
530b793
travis : install bower
Feb 17, 2015
dacc7ee
updates docs with available units and remove fullUnit, was the same a…
Feb 17, 2015
136c7a3
update documentation title
Feb 17, 2015
d4cf93b
add changelog.md
Feb 17, 2015
e456762
complete examples and attribute documentation on index.html
Feb 18, 2015
1c5c058
examples with angular 1.3
Feb 18, 2015
8d11f2a
add bower components inside gruntFile
Feb 18, 2015
01dbc18
remove useless comment
Feb 18, 2015
4010b83
Remove grunt changes, and update README.md to include momentjs and hu…
Feb 18, 2015
2960796
replace by to get the value of a variable when initializing the dir…
Feb 20, 2015
f7a571d
dual binding and allow variable or string as language attribut value
Feb 20, 2015
a07cba1
update readme and index.html
Feb 20, 2015
1745f44
Fixing the file paths
siddii Feb 21, 2015
028b63d
Merge pull request #156 from siddii/polomarcus-momentjs
siddii Feb 21, 2015
e70ad4a
bower components
Feb 21, 2015
691da4a
merge
Feb 21, 2015
97cef1c
chores: update gitignore with dist and bower_components
Mar 2, 2015
41f3fa2
suggest removing momentjs.local('lang')
Mar 2, 2015
62329cc
merge
Mar 2, 2015
e11ffb9
merge, bower install
Mar 2, 2015
5986d1b
bower components
Mar 2, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ notifications:

before_script:
- npm install -g grunt-cli
- npm install bower
- bower install

script:
- grunt tests
4 changes: 2 additions & 2 deletions dist/CHANGELOG.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
##Change Log
-##Change Log

###Version 1.2.0
* Reset method https://github.com/siddii/angular-timer/pull/46
Expand Down Expand Up @@ -63,4 +63,4 @@
* 'auto-start' attribute name change to 'autostart' in support of Angular 1.2. See #14

###Version 1.0.3
* Successful Bower integration!
* Successful Bower integration!
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function (grunt) {
banner: '<%= meta.banner %>'
},
src: [
'app/**/*.js'
'app/**/*.js'
],
dest: '<%= dist_dir %>/<%= pkg.name %>.js'
}
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ With any of the following options...
* Install angular-timer using [Bower](http://bower.io) - `bower install angular-timer`
* Add ``timer`` to your list of modules

### Requirements
With Bower install :
* Install humanize-duration using [Bower](http://bower.io) - `bower install humanize-duration`
* Install momentjs using [Bower](http://bower.io) - `bower install momentjs`

And include these scripts in your webpage :
* bower_components/momentjs/min/moment.min.js
* bower_components/momentjs/min/locales.min.js
* bower_components/humanize-duration/humanize-duration.js


### Running locally
Install all bower components - `bower install`
Using [Grunt](http://gruntjs.com/) type `grunt` from command line, the default task will open index.html page in your
default browser

Expand Down
65 changes: 43 additions & 22 deletions app/js/timer.js → app/js/_timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ var timerModule = angular.module('timer', [])
countdownattr: '=countdown',
finishCallback: '&finishCallback',
autoStart: '&autoStart',
language: '@?',
maxTimeUnit: '='
},
controller: ['$scope', '$element', '$attrs', '$timeout', '$interpolate', function ($scope, $element, $attrs, $timeout, $interpolate) {
controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate) {

// Checking for trim function since IE8 doesn't have it
// If not a function, create tirm with RegEx to mimic native trim
Expand All @@ -27,6 +28,18 @@ var timerModule = angular.module('timer', [])
//backward and forward compatibility.
$scope.autoStart = $attrs.autoStart || $attrs.autostart;


$scope.language = $scope.language || 'en';

//allow to change the language of the directive while already launched
$scope.$watch('language', function() {
i18nService.init($scope.language);
});

//init momentJS i18n, default english
var i18nService = new I18nService();
i18nService.init($scope.language);

if ($element.html().trim().length === 0) {
$element.append($compile('<span>' + $interpolate.startSymbol() + 'millis' + $interpolate.endSymbol() + '</span>')($scope));
} else {
Expand Down Expand Up @@ -54,11 +67,11 @@ var timerModule = angular.module('timer', [])
$scope.$on('timer-clear', function () {
$scope.clear();
});

$scope.$on('timer-reset', function () {
$scope.reset();
});

$scope.$on('timer-set-countdown', function (e, countdown) {
$scope.countdown = countdown;
});
Expand All @@ -76,8 +89,8 @@ var timerModule = angular.module('timer', [])
});

$scope.start = $element[0].start = function () {
$scope.startTime = $scope.startTimeAttr ? new Date($scope.startTimeAttr) : new Date();
$scope.endTime = $scope.endTimeAttr ? new Date($scope.endTimeAttr) : null;
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;
if (!$scope.countdown) {
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
}
Expand All @@ -91,7 +104,7 @@ var timerModule = angular.module('timer', [])
if ($scope.countdownattr) {
$scope.countdown += 1;
}
$scope.startTime = new Date() - ($scope.stoppedTime - $scope.startTime);
$scope.startTime = moment().diff((moment($scope.stoppedTime).diff(moment($scope.startTime))));
tick();
$scope.isRunning = true;
};
Expand All @@ -104,31 +117,37 @@ var timerModule = angular.module('timer', [])

$scope.clear = $element[0].clear = function () {
// same as stop but without the event being triggered
$scope.stoppedTime = new Date();
$scope.stoppedTime = moment();
resetTimeout();
$scope.timeoutId = null;
$scope.isRunning = false;
};

$scope.reset = $element[0].reset = function () {
$scope.startTime = $scope.startTimeAttr ? new Date($scope.startTimeAttr) : new Date();
$scope.endTime = $scope.endTimeAttr ? new Date($scope.endTimeAttr) : null;
$scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();
$scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;
$scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;
resetTimeout();
tick();
$scope.isRunning = false;
$scope.clear();
};

$element.bind('$destroy', function () {
resetTimeout();
$scope.isRunning = false;
});


function calculateTimeUnits() {
var timeUnits = {}; //will contains time with units

if ($attrs.startTime !== undefined){
$scope.millis = new Date() - new Date($scope.startTimeAttr);
$scope.millis = moment().diff(moment($scope.startTimeAttr));
}

timeUnits = i18nService.getTimeUnits($scope.millis);

// compute time values based on maxTimeUnit specification
if (!$scope.maxTimeUnit || $scope.maxTimeUnit === 'day') {
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
Expand Down Expand Up @@ -180,13 +199,16 @@ var timerModule = angular.module('timer', [])
$scope.daysS = ($scope.days === 1)? '' : 's';
$scope.monthsS = ($scope.months === 1)? '' : 's';
$scope.yearsS = ($scope.years === 1)? '' : 's';


// new plural-singular unit decision functions (for custom units and multilingual support)
$scope.secondUnit = function(singleSecond, pluralSecond){if($scope.seconds === 1){if(singleSecond){return singleSecond;} return 'second';} if(pluralSecond){return pluralSecond;} return 'seconds';};
$scope.minuteUnit = function(singleMinute, pluralMinute){if($scope.minutes === 1){if(singleMinute){return singleMinute;} return 'minute';} if(pluralMinute){return pluralMinute;} return 'minutes';};
$scope.hourUnit = function(singleHour, pluralHour){if($scope.hours === 1){if(singleHour){return singleHour;} return 'hour';} if(pluralHour){return pluralHour;} return 'hours';};
$scope.dayUnit = function(singleDay, pluralDay){if($scope.days === 1){if(singleDay){return singleDay;} return 'day';} if(pluralDay){return pluralDay;} return 'days';};
$scope.monthUnit = function(singleMonth, pluralMonth){if($scope.months === 1){if(singleMonth){return singleMonth;} return 'month';} if(pluralMonth){return pluralMonth;} return 'months';};
$scope.yearUnit = function(singleYear, pluralYear){if($scope.years === 1){if(singleYear){return singleYear;} return 'year';} if(pluralYear){return pluralYear;} return 'years';};
$scope.secondUnit = timeUnits.seconds;
$scope.minuteUnit = timeUnits.minutes;
$scope.hourUnit = timeUnits.hours;
$scope.dayUnit = timeUnits.days;
$scope.monthUnit = timeUnits.months;
$scope.yearUnit = timeUnits.years;

//add leading zero if number is smaller than 10
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
Expand Down Expand Up @@ -229,17 +251,16 @@ var timerModule = angular.module('timer', [])
}
calculateTimeUnits();

var tick = function () {
var tick = function tick() {

$scope.millis = new Date() - $scope.startTime;
$scope.millis = moment().diff($scope.startTime);
var adjustment = $scope.millis % 1000;

if ($scope.endTimeAttr) {
$scope.millis = $scope.endTime - new Date();
$scope.millis = moment($scope.endTime).diff(moment());
adjustment = $scope.interval - $scope.millis % 1000;
}


if ($scope.countdownattr) {
$scope.millis = $scope.countdown * 1000;
}
Expand Down Expand Up @@ -279,7 +300,7 @@ var timerModule = angular.module('timer', [])
}
}]
};
}]);
}]);

/* commonjs package manager support (eg componentjs) */
if (typeof module !== "undefined" && typeof exports !== "undefined" && module.exports === exports){
Expand Down
52 changes: 52 additions & 0 deletions app/js/i18nService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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;
});
17 changes: 12 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@
"url": "git://github.com/siddii/angular-timer.git"
},
"dependencies": {
"angular": ">= 1.0.7"
"angular": ">= 1.0.7",
"momentjs": "~2.9.0",
"humanize-duration": "~2.4.0",
"angular-mocks": "~1.3.13"
},
"devDependencies": {
"bootstrap": "2.3.2",
"angular-scenario": ">= 1.0.7",
"angular-mocks": ">= 1.0.7"
"bootstrap": "2.3.2",
"angular-scenario": ">= 1.0.7",
"angular-mocks": ">= 1.0.7"
},
"main": "./dist/angular-timer.js",
"ignore": [
"node_modules",
"bower_components"
]
],
"resolutions": {
"angular": "~1.3.13",
"humanize-duration": "~2.4.0"
}
}
11 changes: 6 additions & 5 deletions bower_components/angular-mocks/.bower.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"name": "angular-mocks",
"version": "1.2.0-rc.2",
"version": "1.3.14",
"main": "./angular-mocks.js",
"ignore": [],
"dependencies": {
"angular": "1.2.0-rc.2"
"angular": "1.3.14"
},
"homepage": "https://github.com/angular/bower-angular-mocks",
"_release": "1.2.0-rc.2",
"_release": "1.3.14",
"_resolution": {
"type": "version",
"tag": "v1.2.0-rc.2",
"commit": "9bdf39463a7e59c35f4f6163853c8da4fbf81ea3"
"tag": "v1.3.14",
"commit": "b33962810730adca9a0f7165ecd4835b6bf40abb"
},
"_source": "git://github.com/angular/bower-angular-mocks.git",
"_target": ">= 1.0.7",
Expand Down
65 changes: 62 additions & 3 deletions bower_components/angular-mocks/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
bower-angular-mocks
===================
# packaged angular-mocks

angular-mocks.js bower repo
This repo is for distribution on `npm` and `bower`. The source for this module is in the
[main AngularJS repo](https://github.com/angular/angular.js/tree/master/src/ngMock).
Please file issues and pull requests against that repo.

## Install

You can install this package either with `npm` or with `bower`.

### npm

```shell
npm install angular-mocks
```

You can `require` ngMock modules:

```js
var angular = require('angular');
angular.module('myMod', [
require('angular-animate'),
require('angular-mocks/ngMock')
require('angular-mocks/ngAnimateMock')
]);
```

### bower

```shell
bower install angular-mocks
```

The mocks are then available at `bower_components/angular-mocks/angular-mocks.js`.

## Documentation

Documentation is available on the
[AngularJS docs site](https://docs.angularjs.org/guide/unit-testing).

## License

The MIT License

Copyright (c) 2010-2015 Google, Inc. http://angularjs.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading