Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea
node_modules
/notes.txt
/tmp
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# __pikaday-angular__ <sup>v2.0.0 </sup>
__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 &#8594;](http://nverba.github.io/pikaday-angular/)
# __ng-pikaday__ <sup>v2.0.1 </sup>
__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 &#8594;](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.
Expand All @@ -11,9 +19,9 @@ angular.module('YourApp', ['pikaday'])
Then use the `pikaday` attribute to bind the picker to a scope.

```HTML
<input pikaday="myPickerObject">
<input pikaday="myPickerObject" ng-model="date">
```
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

Expand All @@ -22,9 +30,11 @@ Any of Pikaday's options can be passed to the corresponding attribute, the direc
<sub> *With the exception of function expressions, which are bound as callbacks. see: [Functions](#functions) </sub>

```HTML
<input pikaday="myPickerObject" number-of-months="2">
<input pikaday ng-model="date" number-of-months="2" min-date="minDate" maxDate="maxDate">
```

`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`.
Expand Down Expand Up @@ -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("<key>")` [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.
Expand Down
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "pikaday-angular",
"version": "2.0.0",
"name": "ng-pikaday",
"version": "2.0.2",
"authors": [
"nverba <distantstate@gmail.com>"
],
"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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],

Expand Down
52 changes: 44 additions & 8 deletions pikaday-angular.js → ng-pikaday.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -46,7 +53,7 @@
scope.$apply();
});
}};

var hasMoment = typeof moment === 'function';
// Decorate config with globals

angular.forEach(pikadayConfig, function (value, key) {
Expand Down Expand Up @@ -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
Expand All @@ -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();
});
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -22,9 +22,9 @@
"author": "nverba <distantstate@gmail.com>",
"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"
Expand Down
66 changes: 0 additions & 66 deletions sample/examples.html

This file was deleted.

8 changes: 4 additions & 4 deletions sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

<h2>Sample</h2>

<input pikaday="myPickerObject1" on-select="sample.onPikadaySelect(pikaday)">

<input pikaday="myPickerObject2" default-date="01/17/2007" set-default-date="true">
<input pikaday ng-model="sample.date1" max-date="sample.date2" on-select="sample.onPikadaySelect(pikaday)">

<input pikaday="myPickerObject3" number-of-months="2" disable-day-fn="sample.filterDays(date)" i18n="{{ sample.local }}">
<input pikaday="myPickerObject2" ng-model="sample.date2" min-date="sample.date1" max-date="sample.date3">

<input pikaday="myPickerObject3" ng-model="sample.date3" number-of-months="2" disable-day-fn="sample.filterDays(date)" i18n="{{ sample.local }}">

<script src="../node_modules/pikaday/pikaday.js"></script>
<script src="../node_modules/angular/angular.js"></script>
<script src="../pikaday-angular.js"></script>
<script src="../ng-pikaday.js"></script>

<script>

Expand Down