Created
May 27, 2013 18:11
-
-
Save ichiban/5658362 to your computer and use it in GitHub Desktop.
jquery-simple-datetimepickerを無理矢理Angular.jsのdirectiveにしちゃう
This file contains hidden or 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
// 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