Skip to content

Instantly share code, notes, and snippets.

@cloudmanic
Created March 1, 2016 17:33
Show Gist options
  • Save cloudmanic/205b1ca05e641e4e14f4 to your computer and use it in GitHub Desktop.
Save cloudmanic/205b1ca05e641e4e14f4 to your computer and use it in GitHub Desktop.
//
// Load datepicker
//
app.directive('datepicker', function($compile, $rootScope) {
return {
scope: {
change: '&'
},
require: 'ngModel',
link: function(scope, element, attrs, model) {
// Jquery Knob
setTimeout(function () {
// Datepicker
$(element).datepicker({
selectOtherMonths: true,
showOtherMonths: true,
navigationAsDateFormat: true,
onSelect: scope.change,
nextText: 'MM',
prevText: 'MM',
dayNamesMin: ["SUN", "MON", "TUES", "WED", "THURS", "FRI", "SAT"],
onSelect: function (date) {
scope.$apply(function() {
model.$setViewValue(date);
$(element).blur();
});
//scope.change(date);
}
});
$(element).parent().click(function(e) {
e.preventDefault();
$(this).parent().find('.datepicker').trigger('focus');
});
}, 1);
}
};
});
//
// Load datepicker
//
app.directive('datepicker2', function($compile, $rootScope) {
return {
scope: {
change: '&'
},
require: 'ngModel',
link: function(scope, element, attrs, model) {
// Jquery Knob
setTimeout(function () {
$(element).datepicker({
selectOtherMonths: true,
showOtherMonths: true,
navigationAsDateFormat: true,
nextText: 'MM',
prevText: 'MM',
dayNamesMin: ["MON", "TUES", "WED", "THUR", "FRI", "SAT", "SUN"],
beforeShow: function() {
$('#ui-datepicker-div').addClass('grey-calendar');
},
onSelect: function (date) {
scope.$apply(function() {
model.$setViewValue(date);
$(element).blur();
});
}
});
/*
$('.calendar-link').on('click', function(e) {
e.preventDefault();
$(this).prev().trigger('focus');
});
*/
}, 1);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment