diff --git a/bower.json b/bower.json index b93798f..4f17d4b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ui-datetime-picker", - "version": "1.0.7", + "version": "1.0.8", "homepage": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", "authors": [ "Gillardo " diff --git a/datetime-picker.js b/datetime-picker.js index 645317b..408882e 100644 --- a/datetime-picker.js +++ b/datetime-picker.js @@ -24,8 +24,8 @@ scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar; // determine which pickers should be available. Defaults to date and time - scope.enableDate = !(scope.enableDate == false); - scope.enableTime = !(scope.enableTime == false); + scope.enableDate = scope.enableDate === false; + scope.enableTime = scope.enableTime === false; // default picker view scope.showPicker = scope.enableDate ? 'date' : 'time'; @@ -50,10 +50,10 @@ // popup element used to display calendar var popupEl = angular.element('' + '
' + - '
' + - '
' + - '
' + - '
' + + '
' + + '
' + + '
' + + '
' + '
'); // get attributes from directive @@ -117,6 +117,16 @@ } else if (angular.isString(viewValue)) { var date = dateParser.parse(viewValue, dateFormat) || new Date(viewValue); + // has problem parsing a time only, so create a date + // with the time added on the end, and a dummy formatter + // and use this to see if the time is valid + if (scope.enableTime && !scope.enableDate) { + var timeFormat = 'EEE MMM dd yyyy ' + dateFormat; + var newTime = 'Fri Mar 12 2015 ' + viewValue; + + date = dateParser.parse(newTime, timeFormat) || new Date(newTime); + } + if (isNaN(date)) { ngModel.$setValidity('date', false); return undefined; @@ -172,7 +182,7 @@ element.bind('input change keyup', function () { scope.$apply(function () { - scope.date = parseDate(ngModel.$viewValue); + scope.date = ngModel.$modelValue; }); }); diff --git a/dist/datetime-picker.js b/dist/datetime-picker.js index 62cd274..3c5afdf 100644 --- a/dist/datetime-picker.js +++ b/dist/datetime-picker.js @@ -1,6 +1,6 @@ // https://github.com/Gillardo/bootstrap-ui-datetime-picker -// Version: 1.0.7 -// Released: 2015-03-12 +// Version: 1.0.8 +// Released: 2015-03-13 angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position']) .directive('datetimePicker', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig', function ($compile, $parse, $document, $position, dateFilter, dateParser, datepickerPopupConfig) { @@ -27,8 +27,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar; // determine which pickers should be available. Defaults to date and time - scope.enableDate = !(scope.enableDate == false); - scope.enableTime = !(scope.enableTime == false); + scope.enableDate = scope.enableDate === false; + scope.enableTime = scope.enableTime === false; // default picker view scope.showPicker = scope.enableDate ? 'date' : 'time'; @@ -53,10 +53,10 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo // popup element used to display calendar var popupEl = angular.element('' + '
' + - '
' + - '
' + - '
' + - '
' + + '
' + + '
' + + '
' + + '
' + '
'); // get attributes from directive @@ -120,6 +120,16 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo } else if (angular.isString(viewValue)) { var date = dateParser.parse(viewValue, dateFormat) || new Date(viewValue); + // has problem parsing a time only, so create a date + // with the time added on the end, and a dummy formatter + // and use this to see if the time is valid + if (scope.enableTime && !scope.enableDate) { + var timeFormat = 'EEE MMM dd yyyy ' + dateFormat; + var newTime = 'Fri Mar 12 2015 ' + viewValue; + + date = dateParser.parse(newTime, timeFormat) || new Date(newTime); + } + if (isNaN(date)) { ngModel.$setValidity('date', false); return undefined; @@ -175,7 +185,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo element.bind('input change keyup', function () { scope.$apply(function () { - scope.date = parseDate(ngModel.$viewValue); + scope.date = ngModel.$modelValue; }); }); diff --git a/dist/datetime-picker.min.js b/dist/datetime-picker.min.js index 60b11a4..a69cb3d 100644 --- a/dist/datetime-picker.min.js +++ b/dist/datetime-picker.min.js @@ -1,4 +1,4 @@ // https://github.com/Gillardo/bootstrap-ui-datetime-picker -// Version: 1.0.7 -// Released: 2015-03-12 -angular.module("ui.bootstrap.datetimepicker",["ui.bootstrap.dateparser","ui.bootstrap.position"]).directive("datetimePicker",["$compile","$parse","$document","$position","dateFilter","dateParser","datepickerPopupConfig",function(a,b,c,d,e,f,g){return{restrict:"A",require:"ngModel",scope:{isOpen:"=?",enableDate:"=?",enableTime:"=?",todayText:"@",nowText:"@",dateText:"@",timeText:"@",clearText:"@",closeText:"@",dateDisabled:"&"},link:function(h,i,j,k){function l(a){return a.replace(/([A-Z])/g,function(a){return"-"+a.toLowerCase()})}function m(a){if(a){if(angular.isDate(a)&&!isNaN(a))return k.$setValidity("date",!0),a;if(angular.isString(a)){var b=f.parse(a,n)||new Date(a);return isNaN(b)?void k.$setValidity("date",!1):(k.$setValidity("date",!0),b)}return void k.$setValidity("date",!1)}return k.$setValidity("date",!0),null}var n,o,p=angular.isDefined(j.closeOnDateSelection)?h.$parent.$eval(j.closeOnDateSelection):g.closeOnDateSelection,q=angular.isDefined(j.datepickerAppendToBody)?h.$parent.$eval(j.datepickerAppendToBody):g.appendToBody;h.showButtonBar=angular.isDefined(j.showButtonBar)?h.$parent.$eval(j.showButtonBar):g.showButtonBar,h.enableDate=!(0==h.enableDate),h.enableTime=!(0==h.enableTime),h.showPicker=h.enableDate?"date":"time",h.todayText=h.todayText||"Today",h.nowText=h.nowText||"Now",h.clearText=h.clearText||"Clear",h.closeText=h.closeText||"Close",h.dateText=h.dateText||"Date",h.timeText=h.timeText||"Time",h.getText=function(a){return h[a+"Text"]||g[a+"Text"]},j.$observe("datetimePicker",function(a){n=a||g.datepickerPopup,k.$render()});var r=angular.element('
');r.attr({"ng-model":"date","ng-change":"dateSelection()"});var s=angular.element(r.children()[0]);j.datepickerOptions&&angular.forEach(h.$parent.$eval(j.datepickerOptions),function(a,b){s.attr(l(b),a)});var t=angular.element(r.children()[1].children[0]);j.timepickerOptions&&angular.forEach(h.$parent.$eval(j.timepickerOptions),function(a,b){t.attr(l(b),a)}),h.watchData={},angular.forEach(["minDate","maxDate","datepickerMode"],function(a){if(j[a]){var c=b(j[a]);if(h.$parent.$watch(c,function(b){h.watchData[a]=b}),s.attr(l(a),"watchData."+a),"datepickerMode"===a){var d=c.assign;h.$watch("watchData."+a,function(a,b){a!==b&&d(h.$parent,a)})}}}),j.dateDisabled&&s.attr("date-disabled","dateDisabled({ date: date, mode: mode })"),k.$parsers.unshift(m),h.dateSelection=function(a){h.enableDate&&h.enableTime&&"time"==h.showPicker&&o&&null!==o&&null!==h.date&&(o.setHours(h.date.getHours()),o.setMinutes(h.date.getMinutes()),o.setSeconds(h.date.getSeconds()),o.setMilliseconds(h.date.getMilliseconds()),h.date=o),o=h.date,angular.isDefined(a)&&(h.date=a),k.$setViewValue(h.date),k.$render(),p&&"time"!=h.showPicker&&(h.enableTime?h.showPicker="time":(h.isOpen=!1,i[0].focus()))},i.bind("input change keyup",function(){h.$apply(function(){h.date=m(k.$viewValue)})}),k.$render=function(){var a=k.$viewValue?m(k.$viewValue):null,b=a?e(a,n):"";i.val(b),h.date=a};var u=function(a){h.isOpen&&a.target!==i[0]&&h.$apply(function(){h.isOpen=!1})},v=function(a){h.keydown(a)};i.bind("keydown",v),h.keydown=function(a){27===a.which?(a.preventDefault(),a.stopPropagation(),h.close()):40!==a.which||h.isOpen||(h.isOpen=!0)},h.$watch("isOpen",function(a){a?(h.$broadcast("datepicker.focus"),h.position=q?d.offset(i):d.position(i),h.position.top=h.position.top+i.prop("offsetHeight"),c.bind("click",u)):c.unbind("click",u)}),h.select=function(a){if("today"===a||"now"==a){var b=new Date;angular.isDate(k.$modelValue)?(a=new Date(k.$modelValue),a.setFullYear(b.getFullYear(),b.getMonth(),b.getDate()),a.setHours(b.getHours(),b.getMinutes(),b.getSeconds(),b.getMilliseconds())):a=b}h.dateSelection(a)},h.close=function(){h.isOpen=!1,i[0].focus()},h.changePicker=function(a){h.showPicker=a};var w=a(r)(h);r.remove(),q?c.find("body").append(w):i.after(w),h.$on("$destroy",function(){w.remove(),i.unbind("keydown",v),c.unbind("click",u)})}}}]).directive("datetimePickerPopup",function(){return{restrict:"EA",replace:!0,transclude:!0,templateUrl:"template/datetime-picker.html",link:function(a,b){b.bind("click",function(a){a.preventDefault(),a.stopPropagation()})}}}),angular.module("ui.bootstrap.datetimepicker").run(["$templateCache",function(a){"use strict";a.put("template/datetime-picker.html",'')}]); \ No newline at end of file +// Version: 1.0.8 +// Released: 2015-03-13 +angular.module("ui.bootstrap.datetimepicker",["ui.bootstrap.dateparser","ui.bootstrap.position"]).directive("datetimePicker",["$compile","$parse","$document","$position","dateFilter","dateParser","datepickerPopupConfig",function(a,b,c,d,e,f,g){return{restrict:"A",require:"ngModel",scope:{isOpen:"=?",enableDate:"=?",enableTime:"=?",todayText:"@",nowText:"@",dateText:"@",timeText:"@",clearText:"@",closeText:"@",dateDisabled:"&"},link:function(h,i,j,k){function l(a){return a.replace(/([A-Z])/g,function(a){return"-"+a.toLowerCase()})}function m(a){if(a){if(angular.isDate(a)&&!isNaN(a))return k.$setValidity("date",!0),a;if(angular.isString(a)){var b=f.parse(a,n)||new Date(a);if(h.enableTime&&!h.enableDate){var c="EEE MMM dd yyyy "+n,d="Fri Mar 12 2015 "+a;b=f.parse(d,c)||new Date(d)}return isNaN(b)?void k.$setValidity("date",!1):(k.$setValidity("date",!0),b)}return void k.$setValidity("date",!1)}return k.$setValidity("date",!0),null}var n,o,p=angular.isDefined(j.closeOnDateSelection)?h.$parent.$eval(j.closeOnDateSelection):g.closeOnDateSelection,q=angular.isDefined(j.datepickerAppendToBody)?h.$parent.$eval(j.datepickerAppendToBody):g.appendToBody;h.showButtonBar=angular.isDefined(j.showButtonBar)?h.$parent.$eval(j.showButtonBar):g.showButtonBar,h.enableDate=h.enableDate===!1,h.enableTime=h.enableTime===!1,h.showPicker=h.enableDate?"date":"time",h.todayText=h.todayText||"Today",h.nowText=h.nowText||"Now",h.clearText=h.clearText||"Clear",h.closeText=h.closeText||"Close",h.dateText=h.dateText||"Date",h.timeText=h.timeText||"Time",h.getText=function(a){return h[a+"Text"]||g[a+"Text"]},j.$observe("datetimePicker",function(a){n=a||g.datepickerPopup,k.$render()});var r=angular.element('
');r.attr({"ng-model":"date","ng-change":"dateSelection()"});var s=angular.element(r.children()[0]);j.datepickerOptions&&angular.forEach(h.$parent.$eval(j.datepickerOptions),function(a,b){s.attr(l(b),a)});var t=angular.element(r.children()[1].children[0]);j.timepickerOptions&&angular.forEach(h.$parent.$eval(j.timepickerOptions),function(a,b){t.attr(l(b),a)}),h.watchData={},angular.forEach(["minDate","maxDate","datepickerMode"],function(a){if(j[a]){var c=b(j[a]);if(h.$parent.$watch(c,function(b){h.watchData[a]=b}),s.attr(l(a),"watchData."+a),"datepickerMode"===a){var d=c.assign;h.$watch("watchData."+a,function(a,b){a!==b&&d(h.$parent,a)})}}}),j.dateDisabled&&s.attr("date-disabled","dateDisabled({ date: date, mode: mode })"),k.$parsers.unshift(m),h.dateSelection=function(a){h.enableDate&&h.enableTime&&"time"==h.showPicker&&o&&null!==o&&null!==h.date&&(o.setHours(h.date.getHours()),o.setMinutes(h.date.getMinutes()),o.setSeconds(h.date.getSeconds()),o.setMilliseconds(h.date.getMilliseconds()),h.date=o),o=h.date,angular.isDefined(a)&&(h.date=a),k.$setViewValue(h.date),k.$render(),p&&"time"!=h.showPicker&&(h.enableTime?h.showPicker="time":(h.isOpen=!1,i[0].focus()))},i.bind("input change keyup",function(){h.$apply(function(){h.date=k.$modelValue})}),k.$render=function(){var a=k.$viewValue?m(k.$viewValue):null,b=a?e(a,n):"";i.val(b),h.date=a};var u=function(a){h.isOpen&&a.target!==i[0]&&h.$apply(function(){h.isOpen=!1})},v=function(a){h.keydown(a)};i.bind("keydown",v),h.keydown=function(a){27===a.which?(a.preventDefault(),a.stopPropagation(),h.close()):40!==a.which||h.isOpen||(h.isOpen=!0)},h.$watch("isOpen",function(a){a?(h.$broadcast("datepicker.focus"),h.position=q?d.offset(i):d.position(i),h.position.top=h.position.top+i.prop("offsetHeight"),c.bind("click",u)):c.unbind("click",u)}),h.select=function(a){if("today"===a||"now"==a){var b=new Date;angular.isDate(k.$modelValue)?(a=new Date(k.$modelValue),a.setFullYear(b.getFullYear(),b.getMonth(),b.getDate()),a.setHours(b.getHours(),b.getMinutes(),b.getSeconds(),b.getMilliseconds())):a=b}h.dateSelection(a)},h.close=function(){h.isOpen=!1,i[0].focus()},h.changePicker=function(a){h.showPicker=a};var w=a(r)(h);r.remove(),q?c.find("body").append(w):i.after(w),h.$on("$destroy",function(){w.remove(),i.unbind("keydown",v),c.unbind("click",u)})}}}]).directive("datetimePickerPopup",function(){return{restrict:"EA",replace:!0,transclude:!0,templateUrl:"template/datetime-picker.html",link:function(a,b){b.bind("click",function(a){a.preventDefault(),a.stopPropagation()})}}}),angular.module("ui.bootstrap.datetimepicker").run(["$templateCache",function(a){"use strict";a.put("template/datetime-picker.html",'')}]); \ No newline at end of file diff --git a/package.json b/package.json index a272bc7..a3af262 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bootstrap-ui-datetime-picker", "url": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", - "version": "1.0.7", + "version": "1.0.8", "devDependencies": { "grunt": "^0.4.5", "grunt-angular-templates": "^0.5.7",