Skip to content

Instantly share code, notes, and snippets.

@ichiban
Created May 27, 2013 18:11
Show Gist options
  • Save ichiban/5658362 to your computer and use it in GitHub Desktop.
Save ichiban/5658362 to your computer and use it in GitHub Desktop.
jquery-simple-datetimepickerを無理矢理Angular.jsのdirectiveにしちゃう
// a Angular.js directive that activates jquery-simple-datetimepicker
//
// jquery-simple-datetimepicker:
//
// https://github.com/mugifly/jquery-simple-datetimepicker
//
// usage:
//
// <input type="text" ng-model="datetime" ng-dtpicker ng-change="doSomething(datetime)" />
//
angular.module('dtpicker', [])
.directive('ngDtpicker', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elm, attr, ngModelCtrl) {
$(function() {
var $e = $(elm);
elm.bind('click', function() {
$e.appendDtpicker({'inline' : true});
var $next = $e.next();
var $picker = $next.children('.datepicker');
$picker.attr('tabindex', -1);
$picker.focusout(function() {
$next.remove();
scope.$apply(function() {
ngModelCtrl.$setViewValue(elm.val());
});
});
});
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment