-
-
Save mlesikov/dc2837e6b9614cacb3090c9ecb8f0864 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
angular | |
.module('datetimepicker', []) | |
.provider('datetimepicker', function () { | |
var default_options = {}; | |
this.setOptions = function (options) { | |
default_options = options; | |
}; | |
this.$get = function () { | |
return { | |
getOptions: function () { | |
return default_options; | |
} | |
}; | |
}; | |
}) | |
.directive('datetimepicker', [ | |
'$timeout', | |
'datetimepicker', | |
function ($timeout, | |
datetimepicker) { | |
var default_options = datetimepicker.getOptions(); | |
return { | |
require: '?ngModel', | |
restrict: 'AE', | |
scope: { | |
datetimepickerOptions: '@' | |
}, | |
link: function ($scope, $element, $attrs, controller) { | |
var passed_in_options = $scope.$eval($attrs.datetimepickerOptions); | |
var options = jQuery.extend({}, default_options, passed_in_options); | |
$element.on('dp.change', function (ev) { | |
$timeout(function () { | |
var dtp = $element.data("DateTimePicker"); | |
controller.$setViewValue(dtp.date()); | |
}); | |
}); | |
function setPickerValue() { | |
var result = null; | |
if (!!controller && !!controller.$viewValue) { | |
result = controller.$viewValue; | |
} | |
var dtp = $element.data("DateTimePicker"); | |
dtp.date(result); | |
} | |
controller.$render = function (value) { | |
setPickerValue(); | |
}; | |
$element.datetimepicker(options); | |
setPickerValue(); | |
} | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment