Skip to content

Commit

Permalink
Fixes #96, #103
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillardo committed Mar 11, 2016
1 parent f386d88 commit eec6106
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 47 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-ui-datetime-picker",
"version": "2.2.2",
"version": "2.2.3",
"homepage": "https://github.com/Gillardo/bootstrap-ui-datetime-picker",
"authors": [
"Gillardo <[email protected]>"
Expand Down
38 changes: 21 additions & 17 deletions datetime-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
if (scope.showPicker != 'time' && date != null) {
// if time is enabled, swap to timePicker
if (scope.enableTime) {
// need to delay this, else timePicker never shown
$timeout(function() {
scope.showPicker = 'time';
}, 0);

// in order to update the timePicker, we need to update the model reference!
// as found here https://angular-ui.github.io/bootstrap/#/timepicker
$timeout(function() {
scope.date = new Date(scope.date);
}, 100);
scope.open('time');
} else {
scope.close(false);
}
Expand Down Expand Up @@ -368,6 +359,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
scope.$broadcast('uib:datepicker.focus');
$document.bind('click', documentClickBind);
}, 0, false);

scope.open(scope.showPicker);
} else {
$document.unbind('click', documentClickBind);
}
Expand Down Expand Up @@ -408,6 +401,24 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
scope.close();
};

scope.open = function (picker, evt) {
if (angular.isDefined(evt)) {
evt.preventDefault();
evt.stopPropagation();
}

// need to delay this, else timePicker never shown
$timeout(function() {
scope.showPicker = picker;
}, 0);

// in order to update the timePicker, we need to update the model reference!
// as found here https://angular-ui.github.io/bootstrap/#/timepicker
$timeout(function() {
scope.date = new Date(scope.date);
}, 50);
};

scope.close = function (closePressed) {
scope.isOpen = false;

Expand All @@ -423,13 +434,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
element[0].focus();
};

scope.changePicker = function (evt, picker) {
evt.preventDefault();
evt.stopPropagation();

scope.showPicker = picker;
};

scope.$on('$destroy', function () {
if (scope.isOpen === true) {
if (!$rootScope.$$phase) {
Expand Down
46 changes: 25 additions & 21 deletions dist/datetime-picker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/Gillardo/bootstrap-ui-datetime-picker
// Version: 2.2.2
// Released: 2016-03-04
// Version: 2.2.3
// Released: 2016-03-11
angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position'])
.constant('uiDatetimePickerConfig', {
dateFormat: 'yyyy-MM-dd HH:mm',
Expand Down Expand Up @@ -324,16 +324,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
if (scope.showPicker != 'time' && date != null) {
// if time is enabled, swap to timePicker
if (scope.enableTime) {
// need to delay this, else timePicker never shown
$timeout(function() {
scope.showPicker = 'time';
}, 0);

// in order to update the timePicker, we need to update the model reference!
// as found here https://angular-ui.github.io/bootstrap/#/timepicker
$timeout(function() {
scope.date = new Date(scope.date);
}, 100);
scope.open('time');
} else {
scope.close(false);
}
Expand Down Expand Up @@ -371,6 +362,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
scope.$broadcast('uib:datepicker.focus');
$document.bind('click', documentClickBind);
}, 0, false);

scope.open(scope.showPicker);
} else {
$document.unbind('click', documentClickBind);
}
Expand Down Expand Up @@ -411,6 +404,24 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
scope.close();
};

scope.open = function (picker, evt) {
if (angular.isDefined(evt)) {
evt.preventDefault();
evt.stopPropagation();
}

// need to delay this, else timePicker never shown
$timeout(function() {
scope.showPicker = picker;
}, 0);

// in order to update the timePicker, we need to update the model reference!
// as found here https://angular-ui.github.io/bootstrap/#/timepicker
$timeout(function() {
scope.date = new Date(scope.date);
}, 50);
};

scope.close = function (closePressed) {
scope.isOpen = false;

Expand All @@ -426,13 +437,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
element[0].focus();
};

scope.changePicker = function (evt, picker) {
evt.preventDefault();
evt.stopPropagation();

scope.showPicker = picker;
};

scope.$on('$destroy', function () {
if (scope.isOpen === true) {
if (!$rootScope.$$phase) {
Expand Down Expand Up @@ -588,12 +592,12 @@ angular.module('ui.bootstrap.datetimepicker').run(['$templateCache', function($t
'use strict';

$templateCache.put('template/date-picker.html',
"<ul class=\"dropdown-menu dropdown-menu-left datetime-picker-dropdown\" ng-if=\"isOpen && showPicker == 'date'\" ng-style=dropdownStyle style=left:inherit ng-keydown=keydown($event) ng-click=$event.stopPropagation()><li style=\"padding:0 5px 5px 5px\" class=date-picker-menu><div ng-transclude></div></li><li style=padding:5px ng-if=buttonBar.show><span class=\"btn-group pull-left\" style=margin-right:10px ng-if=\"doShow('today') || doShow('clear')\"><button type=button class=\"btn btn-sm btn-info\" ng-if=\"doShow('today')\" ng-click=\"select('today')\" ng-disabled=\"isDisabled('today')\">{{ getText('today') }}</button> <button type=button class=\"btn btn-sm btn-danger\" ng-if=\"doShow('clear')\" ng-click=\"select('clear')\">{{ getText('clear') }}</button></span> <span class=\"btn-group pull-right\" ng-if=\"(doShow('time') && enableTime) || doShow('close')\"><button type=button class=\"btn btn-sm btn-default\" ng-if=\"doShow('time') && enableTime\" ng-click=\"changePicker($event, 'time')\">{{ getText('time')}}</button> <button type=button class=\"btn btn-sm btn-success\" ng-if=\"doShow('close')\" ng-click=close(true)>{{ getText('close') }}</button></span></li></ul>"
"<ul class=\"dropdown-menu dropdown-menu-left datetime-picker-dropdown\" ng-if=\"isOpen && showPicker == 'date'\" ng-style=dropdownStyle style=left:inherit ng-keydown=keydown($event) ng-click=$event.stopPropagation()><li style=\"padding:0 5px 5px 5px\" class=date-picker-menu><div ng-transclude></div></li><li style=padding:5px ng-if=buttonBar.show><span class=\"btn-group pull-left\" style=margin-right:10px ng-if=\"doShow('today') || doShow('clear')\"><button type=button class=\"btn btn-sm btn-info\" ng-if=\"doShow('today')\" ng-click=\"select('today')\" ng-disabled=\"isDisabled('today')\">{{ getText('today') }}</button> <button type=button class=\"btn btn-sm btn-danger\" ng-if=\"doShow('clear')\" ng-click=\"select('clear')\">{{ getText('clear') }}</button></span> <span class=\"btn-group pull-right\" ng-if=\"(doShow('time') && enableTime) || doShow('close')\"><button type=button class=\"btn btn-sm btn-default\" ng-if=\"doShow('time') && enableTime\" ng-click=\"open('time', $event)\">{{ getText('time')}}</button> <button type=button class=\"btn btn-sm btn-success\" ng-if=\"doShow('close')\" ng-click=close(true)>{{ getText('close') }}</button></span></li></ul>"
);


$templateCache.put('template/time-picker.html',
"<ul class=\"dropdown-menu dropdown-menu-left datetime-picker-dropdown\" ng-if=\"isOpen && showPicker == 'time'\" ng-style=dropdownStyle style=left:inherit ng-keydown=keydown($event) ng-click=$event.stopPropagation()><li style=\"padding:0 5px 5px 5px\" class=time-picker-menu><div ng-transclude></div></li><li style=padding:5px ng-if=buttonBar.show><span class=\"btn-group pull-left\" style=margin-right:10px ng-if=\"doShow('now') || doShow('clear')\"><button type=button class=\"btn btn-sm btn-info\" ng-if=\"doShow('now')\" ng-click=\"select('now')\" ng-disabled=\"isDisabled('now')\">{{ getText('now') }}</button> <button type=button class=\"btn btn-sm btn-danger\" ng-if=\"doShow('clear')\" ng-click=\"select('clear')\">{{ getText('clear') }}</button></span> <span class=\"btn-group pull-right\" ng-if=\"(doShow('date') && enableDate) || doShow('close')\"><button type=button class=\"btn btn-sm btn-default\" ng-if=\"doShow('date') && enableDate\" ng-click=\"changePicker($event, 'date')\">{{ getText('date')}}</button> <button type=button class=\"btn btn-sm btn-success\" ng-if=\"doShow('close')\" ng-click=close(true)>{{ getText('close') }}</button></span></li></ul>"
"<ul class=\"dropdown-menu dropdown-menu-left datetime-picker-dropdown\" ng-if=\"isOpen && showPicker == 'time'\" ng-style=dropdownStyle style=left:inherit ng-keydown=keydown($event) ng-click=$event.stopPropagation()><li style=\"padding:0 5px 5px 5px\" class=time-picker-menu><div ng-transclude></div></li><li style=padding:5px ng-if=buttonBar.show><span class=\"btn-group pull-left\" style=margin-right:10px ng-if=\"doShow('now') || doShow('clear')\"><button type=button class=\"btn btn-sm btn-info\" ng-if=\"doShow('now')\" ng-click=\"select('now')\" ng-disabled=\"isDisabled('now')\">{{ getText('now') }}</button> <button type=button class=\"btn btn-sm btn-danger\" ng-if=\"doShow('clear')\" ng-click=\"select('clear')\">{{ getText('clear') }}</button></span> <span class=\"btn-group pull-right\" ng-if=\"(doShow('date') && enableDate) || doShow('close')\"><button type=button class=\"btn btn-sm btn-default\" ng-if=\"doShow('date') && enableDate\" ng-click=\"open('date', $event)\">{{ getText('date')}}</button> <button type=button class=\"btn btn-sm btn-success\" ng-if=\"doShow('close')\" ng-click=close(true)>{{ getText('close') }}</button></span></li></ul>"
);

}]);
Loading

0 comments on commit eec6106

Please sign in to comment.