JSFiddle - React, Tailwind, and code Playground

by Steven Senkus

JavaScript

/*global angular */
/*
 jQuery UI Datepicker plugin wrapper

 @note If ? IE8 make sure you have a polyfill for Date.toISOString()
 @param [ui-date] {object} Options to pass to $.fn.datepicker() merged onto ui.config
 */

angular.module('ui.directives')
	.directive('uiDate', [
		'ui.config', 'baseValidator', 'dateFacade', function (uiConfig, baseValidator, dateFacade) {
			'use strict';
			var options;

			options = {};
			if (angular.isObject(uiConfig.date)) {
				angular.extend(options, uiConfig.date);
			}
			return {
				require: '?ngModel',
				compile: function () {
					return {
						pre: function () {
							if ($('.jq-date-wrapper').length > 0) {
								return;
							} else {
								var containerHtml = $('<div class="availability jq-date-wrapper">' +
									'<div class="jq-date-range"></div>' +
									'</div>');

								$('body').append(containerHtml);
							}
						},
						post: function (scope, element, attrs, controller) {
							var currentDate,
								previousDate,
								divWrapper = $('.jq-date-wrapper'),
								getOptions = function () {
									return angular.extend({
										dateRangeParseFunc: dateFacade.parseDateRange,
										dateInterpreterFunc: dateFacade.interpretMMDDDate
									}, uiConfig.date, scope.$eval(attrs.uiDate));
								},

								KEY_CODES = {
									TAB: 9,
									ENTER: 13,
									SHIFT: 16,
									LEFT_ARROW: 37,
									UP_ARROW: 38,
									RIGHT_ARROW: 39,
									DOWN_ARROW: 40

								},

								dateState = {
									isDateTyped: false,
									isDateRange: false,
									keycode: null,
									curVal: null,
									changed: false
								},

							initDateWidget = function () {
								var opts = getOptions(),
									start,
									end,
									divContainerPrevScrollPosition;

								// If we have a controller (i.e. ngModelController) then wire it up
								if (controller) {

									var setDate = function (val) {
										controller.$setViewValue(val);

										if...