//Simple Angular UI //Time Picker //Authors: Amir Azizi //Email: web1392@yahoo.com //Version: 1.0.5 var app = angular.module("simpleAngularUI", []); app.directive("suiTimePicker", function (e) { return { restrict: "E", replace: !0, scope: { time: "=", stringTime: "=", hasSecond: "=", ngDisabled: "=", ngRequired: "=", maxHour: "@", size: "@", dirType: "@", validation: "&" }, template: '
::
', link: function (n, t, i) { if (e(function () { return angular.isUndefined(n.ngRequired) ? (console.error("please add ng-required to your input/textarea/select"), !1) : (n.ngRequired && (("undefined" == n.timespan.h || angular.isUndefined(n.timespan.h)) && (n.inputClassHour = "required-alert"), ("undefined" == n.timespan.m || angular.isUndefined(n.timespan.m)) && (n.inputClassMinute = "required-alert"), ("undefined" == n.timespan.s || angular.isUndefined(n.timespan.s)) && (n.inputClassSecond = "required-alert")), t.find("input[name='hour']").bind("blur", function () { "undefined" == n.timespan.h || angular.isUndefined(n.timespan.h) || 0 == n.timespan.h.length ? (n.timespan.h = "", n.inputClassHour = "required-alert") : n.inputClassHour = "required-alert-ok" }), t.find("input[name='minute']").bind("blur", function () { "undefined" == n.timespan.m || angular.isUndefined(n.timespan.m) || 0 == n.timespan.m.length ? (n.timespan.m = "", n.inputClassMinute = "required-alert") : n.inputClassMinute = "required-alert-ok" }), t.find("input[name='second']").bind("blur", function () { "undefined" == n.timespan.s || angular.isUndefined(n.timespan.s) || 0 == n.timespan.s.length ? (n.timespan.s = "", n.inputClassSecond = "required-alert") : n.inputClassSecond = "required-alert-ok" }), !1) }, 1500), n.timespan = { h: "", m: "", s: "" }, n.templateClass = "", "rtl" === n.dirType) switch (n.templateClass = "rtl-timepicker", n.size) { case "lg": n.templateClass = n.templateClass + " input-group-lg rtl-timepicker-lg"; break; case "sm": n.templateClass = n.templateClass + " input-group-sm rtl-timepicker-sm" } else switch (n.size) { case "lg": n.templateClass = "input-group-lg"; break; case "sm": n.templateClass = "input-group-sm" } angular.isUndefined(n.hasSecond) && (n.hasSecond = !0), angular.isUndefined(n.maxHour) && (n.maxHour = 24), n.timeAnalyzer = function (e) { var t, i, a, s = e.split(":"); return n.hasSecond ? (t = s[0], i = s[1], a = s[2], { h: t, m: i, s: a }) : (t = s[0], i = s[1], { h: t, m: i }) }, n.convertToTime = function () { n.stringTime && (1 === n.timespan.h.length && (n.timespan.h = "0" + n.timespan.h), 1 === n.timespan.m.length && (n.timespan.m = "0" + n.timespan.m), n.hasSecond ? (1 === n.timespan.s.length && (n.timespan.s = "0" + n.timespan.s), n.time = n.timespan.h + ":" + n.timespan.m + ":" + n.timespan.s) : n.time = n.timespan.h + ":" + n.timespan.m, n.validation()) }, n.stringTime ? (n.$watch("time", function (e) { e && (angular.isUndefined(n.time) || (n.timespan = n.timeAnalyzer(n.time))) }, !0), n.$watch("timespan", function (e) { n.hasSecond ? n.time = e.h + ":" + e.m + ":" + e.s : n.time = e.h + ":" + e.m }, !0)) : (angular.isUndefined(n.time.h) && console.error("please return object {h:?,m:?,s:?}"), n.$watch("time", function (e) { e && (angular.isUndefined(n.time) || (n.timespan = n.time)) }, !0)), t.find("input[type='text']").each(function () { $(this).on("click", function () { $(this).select() }) }), t.find("input[name='hour']").on("input propertychange", function () { var e = $(this).val(); e = e.replace(/[a-zA-Z?><;,\\"`~»«×÷\.:{}()[\]\-_+=!@\/#$%\^&*|']*/g, ""), e = e.replace(/[\u0600-\u06FF ]/g, ""), e > n.maxHour - 1 && (e = "00", n.timespan.h = 0), $(this).val(e) }), t.find("input[name='minute'], input[name='second']").on("input propertychange", function () { var e = $(this).val(); e = e.replace(/[a-zA-Z?><;,\\"`~»«×÷\.:{}()[\]\-_+=!@\/#$%\^&*|']*/g, ""), e = e.replace(/[\u0600-\u06FF ]/g, ""), e > 59 && (e = "00", n.timespan.m = 0), $(this).val(e) }); var a = function (e) { return window.event ? e.keyCode : e.which }; n.onHourChange = function (e) { var i = a(e); 38 === i && (n.timespan.h < n.maxHour - 1 ? n.timespan.h++ : n.timespan.h = 0), 40 === i && (n.timespan.h > 0 ? n.timespan.h-- : n.timespan.h = n.maxHour - 1), 39 === i && setTimeout(function () { $(t).find("input[name='minute']").select(), n.$apply() }, 0) }, n.onMinuteChange = function (e) { var i = a(e); 38 === i && (n.timespan.m < 59 ? n.timespan.m++ : (n.timespan.m = 0, n.timespan.h < n.maxHour - 1 ? n.timespan.h++ : n.timespan.h = 0)), 40 === i && (n.timespan.m > 0 ? n.timespan.m-- : (n.timespan.m = 59, n.timespan.h > 0 ? n.timespan.h-- : n.timespan.h = n.maxHour - 1)), 39 === i && setTimeout(function () { $(t).find("input[name='second']").select(), n.$apply() }, 0), 37 === i && setTimeout(function () { $(t).find("input[name='hour']").select(), n.$apply() }, 0) }, n.onSecondChange = function (e) { var i = a(e); 38 === i && (n.timespan.s < 59 ? n.timespan.s++ : (n.timespan.s = 0, n.timespan.m < 59 ? n.timespan.m++ : (n.timespan.m = 0, n.timespan.h < n.maxHour - 1 ? n.timespan.h++ : n.timespan.h = 0))), 40 === i && (n.timespan.s > 0 ? n.timespan.s-- : (n.timespan.s = 59, n.timespan.m > 0 ? n.timespan.m-- : (n.timespan.m = 59, n.timespan.h > 0 ? n.timespan.h-- : n.timespan.h = n.maxHour - 1))), 37 === i && setTimeout(function () { $(t).find("input[name='minute']").select(), n.$apply() }, 0) } } } });