Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Simplify implementation of ngYearOrder, add example and update minifi…
Browse files Browse the repository at this point in the history
…ed file
  • Loading branch information
jfmcode committed Mar 3, 2016
1 parent be87332 commit a07f2a9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngComboDatePicker",
"version": "1.1.1",
"version": "1.1.2",
"authors": [
"jfmdev <[email protected]>"
],
Expand Down
12 changes: 12 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ <h2>Define attributtes</h2>
<p>Choose a date: <ng-combo-date-picker ng-model="attrs" ng-attrs-date='{"style": "color:red"}' ng-attrs-month='{"style": "color:green"}' ng-attrs-year='{"style": "color:blue"}'></ng-combo-date-picker></p>
<p>Current selection is: <strong>{{ attrs }}</strong>
</div>


<h2>Change years order</h2>
<script type="text/javascript">
app.controller('yearsOrderCtrl', function ($scope) {
$scope.yearsOrder = new Date();
});
</script>
<div ng-controller="yearsOrderCtrl">
<p>Choose a date: <ng-combo-date-picker ng-model="yearsOrder" ng-year-order="desc"></ng-combo-date-picker></p>
<p>Current selection is: <strong>{{ yearsOrder }}</strong>
</div>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-combo-date-picker",
"version": "1.1.1",
"version": "1.1.2",
"description": "An Angular directive to select dates using combo boxes",
"main": "source/ngComboDatePicker.js",
"scripts": {
Expand Down
22 changes: 10 additions & 12 deletions source/ngComboDatePicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ngComboDatePicker v1.1.1
* ngComboDatePicker v1.1.2
* http://github.com/jfmdev/ngComboDatePicker
* «Copyright 2015 Jose F. Maldonado»
* License: LGPLv3 (http://www.gnu.org/licenses/lgpl-3.0.html)
Expand All @@ -22,7 +22,7 @@ angular.module("ngComboDatePicker", [])
ngAttrsDate: '@',
ngAttrsMonth: '@',
ngAttrsYear: '@',
ngYearOrder: '@'
ngYearOrder: '@'
},
controller: ['$scope', function($scope) {
// Define function for parse dates.
Expand Down Expand Up @@ -100,17 +100,15 @@ angular.module("ngComboDatePicker", [])
if($scope.ngModel > $scope.maxDate) $scope.ngModel = $scope.maxDate;

// Initialize list of years.
$scope.ngYearOrder = $scope.ngYearOrder ? $scope.ngYearOrder : "asc"; //set default order value
$scope.years = [];
if($scope.ngYearOrder == "desc") {
for(var i=$scope.maxDate.getFullYear(); i>=$scope.minDate.getFullYear(); i--) {
$scope.years.push(i);
}
} else {//"asc" order by default
for(var i=$scope.minDate.getFullYear(); i<=$scope.maxDate.getFullYear(); i++) {
$scope.years.push(i);
}
}
for(var i=$scope.minDate.getFullYear(); i<=$scope.maxDate.getFullYear(); i++) {
$scope.years.push(i);
}

// Verify if the order of the years must be reversed.
if(typeof $scope.ngYearOrder == 'string' && $scope.ngYearOrder.indexOf('des') == 0) {
$scope.years.reverse();
}

// Initialize list of months names.
var monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Expand Down
2 changes: 1 addition & 1 deletion source/ngComboDatePicker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a07f2a9

Please sign in to comment.