Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.idea/
node_modules/
bower_components/
.DS_Store/
.DS_Store/
plugins/
test/hooks/

# Custom for project
bower_dependencies/
2 changes: 1 addition & 1 deletion dist/ionic-datepicker.bundle.min.js

Large diffs are not rendered by default.

64 changes: 40 additions & 24 deletions src/ionic-datepicker.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ angular.module('ionic-datepicker.provider', [])

//Previous month
$scope.prevMonth = function () {
if ($scope.currentDate.getMonth() === 1) {
$scope.currentDate.setFullYear($scope.currentDate.getFullYear());
}
$scope.currentDate.setMonth($scope.currentDate.getMonth() - 1);
var fromDateTmp = new Date($scope.fromDate);
if ($scope.currentDate.getFullYear() <= fromDateTmp.getFullYear() &&
$scope.currentDate.getMonth() <= fromDateTmp.getMonth()) return;
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
selectedDate.getMonth() - 1,
selectedDate.getFullYear() - (selectedDate.getMonth() == 0 ? 1 : 0));
$scope.currentDate = resetHMSM(new Date($scope.currentDate.getFullYear(), $scope.currentDate.getMonth() - 1, newDay));
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
refreshDateList($scope.currentDate);
Expand All @@ -53,25 +57,32 @@ angular.module('ionic-datepicker.provider', [])

//Next month
$scope.nextMonth = function () {
if ($scope.currentDate.getMonth() === 11) {
$scope.currentDate.setFullYear($scope.currentDate.getFullYear());
}
$scope.currentDate.setDate(1);
$scope.currentDate.setMonth($scope.currentDate.getMonth() + 1);
var toDateTmp = new Date($scope.toDate);
if ($scope.currentDate.getFullYear() >= toDateTmp.getFullYear() &&
$scope.currentDate.getMonth() >= toDateTmp.getMonth()) return;
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
selectedDate.getMonth() + 1,
selectedDate.getFullYear() + (selectedDate.getMonth() == 11 ? 1 : 0));
$scope.currentDate = resetHMSM(new Date($scope.currentDate.getFullYear(), $scope.currentDate.getMonth() + 1, newDay));
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.monthChanged($scope.currentDate.getMonth());
refreshDateList(new Date());
refreshDateList($scope.currentDate);
changeDaySelected();
};

var changeDaySelected = function() {
var newSelectedDate = new Date($scope.selctedDateEpoch);
newSelectedDate.setMonth($scope.currentDate.getMonth());
newSelectedDate.setYear($scope.currentDate.getFullYear());
$scope.selctedDateEpoch = newSelectedDate.getTime();
$scope.mainObj.callback($scope.selctedDateEpoch);
}
//Get the acceptable day
var getAcceptableDay = function(currentDay, newMonth, newYear) {
var nbDaysInMonth = new Date(newYear, newMonth+1, 0).getDate();
if(currentDay > nbDaysInMonth) {
currentDay = nbDaysInMonth;
}
return currentDay;
};

var changeDaySelected = function() {
$scope.selctedDateEpoch = resetHMSM(new Date($scope.currentDate.getFullYear(), $scope.currentDate.getMonth(), $scope.currentDate.getDate())).getTime();
};

//Date selected
$scope.dateSelected = function (selectedDate) {
Expand All @@ -89,9 +100,8 @@ angular.module('ionic-datepicker.provider', [])

//Set today as date for the modal
$scope.setIonicDatePickerTodayDate = function () {
var today = new Date();
refreshDateList(new Date());
$scope.selctedDateEpoch = resetHMSM(today).getTime();
$scope.selctedDateEpoch = resetHMSM(new Date()).getTime();
if ($scope.mainObj.closeOnSelect) {
$scope.mainObj.callback($scope.selctedDateEpoch);
closeModal();
Expand Down Expand Up @@ -175,17 +185,23 @@ angular.module('ionic-datepicker.provider', [])
//Month changed
$scope.monthChanged = function (month) {
var monthNumber = $scope.monthsList.indexOf(month);
$scope.currentDate.setMonth(monthNumber);
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
monthNumber,
selectedDate.getFullYear());
$scope.currentDate = resetHMSM(new Date($scope.currentDate.getFullYear(), monthNumber, newDay));
refreshDateList($scope.currentDate);

changeDaySelected();
};

//Year changed
$scope.yearChanged = function (year) {
$scope.currentDate.setFullYear(year);
var selectedDate = new Date($scope.selctedDateEpoch);
var newDay = getAcceptableDay(selectedDate.getDate(),
selectedDate.getMonth(),
year);
$scope.currentDate = resetHMSM(new Date(year, $scope.currentDate.getMonth(), newDay));
refreshDateList($scope.currentDate);

changeDaySelected();
};

Expand Down
3 changes: 3 additions & 0 deletions test/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "www/lib"
}
14 changes: 14 additions & 0 deletions test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Test project
This test project is built from a blank ionic app and allows to visually test the ionic date picker.
7 changes: 7 additions & 0 deletions test/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "HelloIonic",
"private": "true",
"devDependencies": {
"ionic": "driftyco/ionic-bower#1.3.2"
}
}
22 changes: 22 additions & 0 deletions test/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.test313715" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>test</name>
<description>
An Ionic Framework and Cordova project.
</description>
<author email="[email protected]" href="http://example.com/">
Your Name Here
</author>
<content src="index.html"/>
<access origin="*"/>
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="SplashScreenDelay" value="2000"/>
<preference name="FadeSplashScreenDuration" value="2000"/>
<preference name="android-minSdkVersion" value="16"/>
<preference name="BackupWebStorage" value="none"/>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
</widget>
51 changes: 51 additions & 0 deletions test/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var gulp = require('gulp');
var gutil = require('gulp-util');
var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sh = require('shelljs');

var paths = {
sass: ['./scss/**/*.scss']
};

gulp.task('default', ['sass']);

gulp.task('sass', function(done) {
gulp.src('./scss/ionic.app.scss')
.pipe(sass())
.on('error', sass.logError)
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
});

gulp.task('watch', ['sass'], function() {
gulp.watch(paths.sass, ['sass']);
});

gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});

gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});
4 changes: 4 additions & 0 deletions test/ionic.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test",
"app_id": ""
}
26 changes: 26 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "test",
"version": "1.1.1",
"description": "test: An Ionic project",
"dependencies": {
"gulp": "^3.5.6",
"gulp-sass": "^2.0.4",
"gulp-concat": "^2.2.0",
"gulp-minify-css": "^0.3.0",
"gulp-rename": "^1.2.0"
},
"devDependencies": {
"bower": "^1.3.3",
"gulp-util": "^2.2.14",
"shelljs": "^0.3.0"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": []
}
23 changes: 23 additions & 0 deletions test/scss/ionic.app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
To customize the look and feel of Ionic, you can override the variables
in ionic's _variables.scss file.

For example, you might change some of the default colors:

$light: #fff !default;
$stable: #f8f8f8 !default;
$positive: #387ef5 !default;
$calm: #11c1f3 !default;
$balanced: #33cd5f !default;
$energized: #ffc900 !default;
$assertive: #ef473a !default;
$royal: #886aea !default;
$dark: #444 !default;
*/

// The path for our ionicons font files, relative to the built CSS in www/css
$ionicons-font-path: "../lib/ionic/fonts" !default;

// Include all of Ionic
@import "www/lib/ionic/scss/ionic";

Loading