diff --git a/.gitignore b/.gitignore
index 3882e7d..211209d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/.idea
node_modules
/notes.txt
/tmp
diff --git a/README.md b/README.md
index 1a7a89d..25be3c6 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,13 @@
-# __pikaday-angular__ v2.0.0
-__pikaday-angular__ is a directive wraper that aims to make using __[Pikaday](https://github.com/dbushell/Pikaday)__ with __[AngularJS](https://angularjs.org/)__ as simple as possible. [Examples →](http://nverba.github.io/pikaday-angular/)
+# __ng-pikaday__ v2.0.1
+__ng-pikaday__ is a directive wraper that aims to make using __[Pikaday](https://github.com/dbushell/Pikaday)__ with __[AngularJS](https://angularjs.org/)__ as simple as possible. [Examples →](http://nverba.github.io/pikaday-angular/)
+
+## Install (NPM & Bower)
+
+```
+[npm || bower] install --save ng-pikaday
+```
+
+ng-pikaday is provided in a [UMD](https://github.com/umdjs/umd) wrapper, making it compatible with several build systems & preprocessors such as [Browserify](http://browserify.org/), see the [source of the Example page](https://github.com/nverba/pikaday-angular/tree/gh-pages) to see ng-pikaday being used with Browserify & Gulp.
__How simple?__ - Include the module as a dependency.
@@ -11,9 +19,9 @@ angular.module('YourApp', ['pikaday'])
Then use the `pikaday` attribute to bind the picker to a scope.
```HTML
-
+
```
-You now have access to Pikaday's methods from the scoped object `myPickerObject`.
+You now have access to Pikaday's methods from the scoped object `myPickerObject`. and `date`'s value will be a date object representing the value.
## Attributes
@@ -22,9 +30,11 @@ Any of Pikaday's options can be passed to the corresponding attribute, the direc
*With the exception of function expressions, which are bound as callbacks. see: [Functions](#functions)
```HTML
-
+
```
+`minDate` and `maxDate` are watched, so that you can change max/min date dynamically.
+
## Global config
Optionally, you may provide a global config* object for all pickers by creating a `pikadayConfigProvider`.
@@ -117,14 +127,6 @@ If you load [Moment.js](http://momentjs.com/) anywhere in your HTML, Pikaday wil
To get Moment.js to handle i18n output formatting, you need to load the appropriate Moment.js locale file. _Moment will automatically default to the most recently loaded locale file_. Explicit locale selection can be made programmatically by calling `moment.locale("")` [with the key of a loaded locale](http://momentjs.com/docs/#/i18n/instance-locale/).
-## NPM & Bower
-
-```
-[npm || bower] install --save pikaday-angular
-```
-
-pikaday-angular is provided in a [UMD](https://github.com/umdjs/umd) wrapper, making it compatible with several build systems & preprocessors such as [Browserify](http://browserify.org/), see the [source of the Example page](https://github.com/nverba/pikaday-angular/tree/gh-pages) to see pikaday-angular being used with Browserify & Gulp.
-
## Testing
The coercion tests can be run after installing the required [npm](https://www.npmjs.com/) packages.
diff --git a/bower.json b/bower.json
index 4996a9d..f58a2c5 100644
--- a/bower.json
+++ b/bower.json
@@ -1,11 +1,11 @@
{
- "name": "pikaday-angular",
- "version": "2.0.0",
+ "name": "ng-pikaday",
+ "version": "2.0.2",
"authors": [
"nverba "
],
"description": "an AngularJS directive wraper that aims to make using Pikaday with Angular as simple as possible.",
- "main": "pikaday-angular.js",
+ "main": "ng-pikaday.js",
"keywords": [
"angular",
"angularjs",
@@ -16,7 +16,7 @@
"datepicker"
],
"license": "MIT",
- "homepage": "https://github.com/nverba/pikaday-angular",
+ "homepage": "https://github.com/fxding/ng-pikaday",
"dependencies": {
"angular": "^1.3.15",
"pikaday": "^1.3.2"
diff --git a/karma.conf.js b/karma.conf.js
index 00cccbc..01a52d7 100644
--- a/karma.conf.js
+++ b/karma.conf.js
@@ -18,7 +18,7 @@ module.exports = function(config) {
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'node_modules/pikaday/pikaday.js',
- 'pikaday-angular.js',
+ 'ng-pikaday.js',
'test/*_test.js'
],
diff --git a/pikaday-angular.js b/ng-pikaday.js
similarity index 71%
rename from pikaday-angular.js
rename to ng-pikaday.js
index e39d475..97aed26 100644
--- a/pikaday-angular.js
+++ b/ng-pikaday.js
@@ -32,12 +32,19 @@
function pikadayDirectiveFn(pikadayConfig) {
return {
-
restrict: 'A',
scope: {
- pikaday: '=', onSelect: '&', onOpen: '&', onClose: '&', onDraw: '&', disableDayFn: '&'
+ pikaday: '=',
+ minDate: '=',
+ maxDate: '=',
+ onSelect: '&',
+ onOpen: '&',
+ onClose: '&',
+ onDraw: '&',
+ disableDayFn: '&'
},
- link: function (scope, elem, attrs) {
+ require: '?ngModel',
+ link: function (scope, elem, attrs, modelCtrl) {
// Init config Object
@@ -46,7 +53,7 @@
scope.$apply();
});
}};
-
+ var hasMoment = typeof moment === 'function';
// Decorate config with globals
angular.forEach(pikadayConfig, function (value, key) {
@@ -109,10 +116,20 @@
// Dates
case "minDate":
+ scope.$watch('minDate', function (nValue) {
+ if (!nValue) return;
+ picker.setMinDate(nValue);
+ });
+ break;
case "maxDate":
+ scope.$watch('maxDate', function (nValue) {
+ if (!nValue) return;
+ picker.setMaxDate(nValue);
+ });
+ break;
case "defaultDate":
- config[attr] = new Date(value);
+ config[attr] = (value === 'now')? new Date(): new Date(value);
break;
// Elements
@@ -131,11 +148,30 @@
}
}
-
// instantiate pikaday with config, bind to scope, add destroy event callback
-
var picker = new Pikaday(config);
- scope.pikaday = picker;
+ if (attrs.pikaday) {
+ scope.pikaday = picker;
+ }
+
+ if (modelCtrl) {
+ modelCtrl.$formatters.push(function (modelValue) {
+ if (!modelValue) {
+ return modelValue
+ }
+ var date = new Date(Date.parse(modelValue));
+ if (date == "Invalid Date") {
+ modelCtrl.$setValidity('date', false);
+ return modelValue;
+ }
+ return hasMoment? moment(date).format(picker._o.format) : date.toDateString();
+ });
+
+ modelCtrl.$parsers.push(function (viewValue) {
+ return picker.getDate();
+ });
+ }
+
scope.$on('$destroy', function () {
picker.destroy();
});
diff --git a/package.json b/package.json
index 307a051..b6b477c 100644
--- a/package.json
+++ b/package.json
@@ -1,14 +1,14 @@
{
- "name": "pikaday-angular",
- "version": "2.0.0",
+ "name": "ng-pikaday",
+ "version": "2.0.2",
"description": "an AngularJS directive wraper that aims to make using Pikaday with Angular as simple as possible.",
- "main": "pikaday-angular.js",
+ "main": "ng-pikaday.js",
"scripts": {
"test": "karma start karma.conf.js"
},
"repository": {
"type": "git",
- "url": "https://github.com/nverba/angular-pikaday.git"
+ "url": "https://github.com/fxding/ng-pikaday.git"
},
"keywords": [
"angular",
@@ -22,9 +22,9 @@
"author": "nverba ",
"license": "MIT",
"bugs": {
- "url": "https://github.com/nverba/angular-pikaday/issues"
+ "url": "https://github.com/fxding/ng-pikaday/issues"
},
- "homepage": "https://github.com/nverba/angular-pikaday",
+ "homepage": "https://github.com/fxding/ng-pikaday",
"dependencies": {
"angular": "^1.3.15",
"pikaday": "^1.3.2"
diff --git a/sample/examples.html b/sample/examples.html
deleted file mode 100644
index 9717368..0000000
--- a/sample/examples.html
+++ /dev/null
@@ -1,66 +0,0 @@
-
-
-
-
- pikaday-angular by nverba
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
pikaday-angular
-
-
An AngularJS directive wraper for the Pikaday datepicker