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,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;YACtD,CAAC,CAAC;iBACD,EAAE,CAAC,SAAS,EAAE,UAAU,KAAwB;gBAK7C,IAAI,KAAK,CAAC,GAAG,IAAI,OAAO,EAAE;oBACtB,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;iBACrD;YACL,CAAC,CAAC,CAAC;YAGP,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE;gBACzB,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;YACzD,CAAC,CAAC,CAAC;YAEH,CAAC,CAAC,OAAO,CAAC,CAAC;QACf,CAAC;QArBe,0CAAuB,0BAqBtC,CAAA;QAAA,CAAC;QAEF,SAAS,UAAU,CAAC,OAAoB,EAAE,KAAU,EAAE,aAAuC;YACzF,IAAM,cAAc,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAA4B,CAAC;YAEtF,IAAI,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;YAC9C,aAAa,CAAC,IAAI,CAAC,CAAC;YAEpB,IAAI,IAAI,EAAE;gBACN,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;aAC7D;iBAAM;gBACH,cAAc,CAAC,UAAU,EAAE,CAAC;aAC/B;QACL,CAAC;QAAA,CAAC;IACN,CAAC,EArEa,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAqE/B","file":"timePickerServices.js","sourcesContent":["import * as $ from \"jquery\";\nimport * as _ from \"underscore\";\nimport * as moment from \"moment\";\n\n// Types\nimport Moment = moment.Moment;\n\n// Models\nimport { TimePickerOptions } from \"Content/ts/Models/Shared/DateTime/timePickerConfiguration\";\nimport { DatePickerLibraryEvents } from \"Content/ts/Models/Shared/DateTime/datePickerConfiguration\";\n\n// Services\nimport { DateTimeFormatterService } from \"Content/ts/Shared/Controls/DateTime/Services/dateTimeFormatterService\";\n\nexport module TimePickerServices {\n const LocalisedTimeFormat = DateTimeFormatterService.LocalisedMomentTimeFormat as string;\n\n // Purpose : Zebra doesn't have a standard configuration for 'steps'. However, the 'enabled_minutes' implementation is\n // it's equivalent so this method takes the steps and sets selectable minutes.\n export function ConfigureEnabledMinutes(configuration: TimePickerOptions): false | Array {\n if (configuration.MinutesStep == null || configuration.MinutesStep == undefined) {\n return false;\n }\n\n const startMinutesValue = 0 as number,\n maximumMinutesValue = 59 as number;\n\n return _.range(startMinutesValue, maximumMinutesValue, configuration.MinutesStep);\n };\n\n export function TimePickerOnLoad(element: HTMLElement, value: KnockoutComputed): void {\n const dateTimePicker = $(element).data(\"Zebra_DatePicker\") as DatePickerLibraryEvents;\n\n // Purpose : Will bind the value to the component text box at binding load if a value has been provided.\n if (value()) {\n let currentValue = value().format(LocalisedTimeFormat);\n\n if (!value().isValid()) {\n currentValue = moment().startOf(\"day\").format(LocalisedTimeFormat);\n }\n\n dateTimePicker.set_date(currentValue);\n }\n };\n\n // Important: Cannot be done via a standard subscribe due to the way Zebra works. When the datepicker is initialised the Knockout context\n // is mostly destroyed so you lose some visibility on the HTML element. Due to this a couple of change events are bound to the\n // object so these are detected without the user having to unfocus from the element when dealing with a form.\n export function ConfigureKeyPressEvents(element: HTMLElement, valueToUpdate: KnockoutComputed): void {\n $(element)\n .on(\"blur\", function () {\n UpdateTime(element, $(this).val(), valueToUpdate);\n })\n .on(\"keydown\", function (event: JQueryEventObject) {\n // Important: 'keyCode' and 'which' have been deprecated across all browsers. Said codes didn't have a consistent implementation\n // across all browsers so we've gone for this implementation as it seems to be more stable.\n // Sources : https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode\n // https://stackoverflow.com/questions/56771542/how-to-call-the-jquery-click-method-when-pressing-enter-on-the-keyboard\n if (event.key == \"Enter\") {\n UpdateTime(element, $(this).val(), valueToUpdate);\n }\n });\n\n // Add to the icon button so times will update\n $(element).next().on(\"blur\", () => {\n UpdateTime(element, $(element).val(), valueToUpdate);\n });\n\n $(element);\n };\n\n function UpdateTime(element: HTMLElement, value: any, valueToUpdate: KnockoutComputed): void {\n const dateTimePicker = $(element).data(\"Zebra_DatePicker\") as DatePickerLibraryEvents;\n\n let time = moment(value, LocalisedTimeFormat);\n valueToUpdate(time);\n\n if (time) {\n dateTimePicker.set_date(time.format(LocalisedTimeFormat));\n } else {\n dateTimePicker.clear_date();\n }\n };\n}"]}