7 lines
6.3 KiB
JavaScript
7 lines
6.3 KiB
JavaScript
|
|
//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: '<div class="input-group" ng-class="templateClass"><input type="text" class="form-control text-center" ng-class="inputClassHour" name="hour" maxlength="2" ng-model="timespan.h" ng-keydown="onHourChange($event)" ng-blur="convertToTime()" autocomplete="off" ng-disabled="ngDisabled" ng-required="ngRequired" placeholder="ساعت"><span class="input-group-addon addon-no-border"><b>:</b></span><input type="text" class="form-control text-center pull-left" ng-class="inputClassMinute" name="minute" maxlength="2" ng-model="timespan.m" ng-keydown="onMinuteChange($event)" ng-blur="convertToTime()" autocomplete="off" ng-disabled="ngDisabled" ng-required="ngRequired" placeholder="دقیقه"><span class="input-group-addon addon-no-border" ng-if="hasSecond"><b>:</b></span><input type="text" class="form-control text-center pull-left" ng-class="inputClassSecond" name="second" maxlength="2" ng-if="hasSecond" ng-model="timespan.s" ng-keydown="onSecondChange($event)" ng-blur="convertToTime()" autocomplete="off" ng-disabled="ngDisabled" ng-required="ngRequired" placeholder="ثانیه"></div>', 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.
|