Last active
August 29, 2015 14:13
-
-
Save dcz-switcher/d9bdf8736f52c6108b9c to your computer and use it in GitHub Desktop.
angular directive for pikaday
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
/* | |
// in html : | |
<link type="text/css" href="pikaday.css" /> | |
<script src="moment.js"></script> | |
<script src="pikaday.js"></script> | |
<script src="mx.pikaday.js"></script> | |
<div ng-controller='mainController as mainCtrl'> | |
<div pikaday pikadate="mainCtrl.date"></div> | |
</div> | |
// in angular app module | |
angular.module('app', ['mxPikaday']); | |
// in angular controller | |
app.controller('mainController', [function () { | |
this.date = "2015-01-21"; | |
}]); | |
*/ | |
var mx = angular.module('mxPikaday', []); | |
mx.directive('pikaday', ['$filter', function ($filter) { | |
return { | |
template : '<div><input model="pikadate"></input></div>', | |
scope: { | |
pikadate: '=' | |
}, | |
link : function (scope, element, attrs) { | |
var picker = new Pikaday({ | |
field: element[0].querySelector('input'), | |
i18n: { | |
previousMonth : 'Mois précédent', | |
nextMonth : 'Mois suivant', | |
months : ['Janvier', 'Février', 'Mars', 'Avri', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'], | |
weekdays : ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'], | |
weekdaysShort : ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'] | |
}, | |
firstDay : 1, | |
format: 'DD/MM/YYYY', | |
defaultDate: new Date(scope.pikadate), | |
setDefaultDate: true, | |
onSelect: function (date) { | |
scope.pikadate = $filter('date')(date, 'yyyy-MM-dd'); | |
scope.$apply(); | |
} | |
}); | |
} | |
}; | |
}]); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment