|
218 | 218 | * @ngInject @constructor
|
219 | 219 | */
|
220 | 220 | function DatePickerCtrl($scope, $element, $attrs, $window, $mdConstant,
|
221 |
| - $mdTheming, $mdUtil, $mdDateLocale, $$mdDateUtil, $$rAF) { |
| 221 | + $mdTheming, $mdUtil, $mdDateLocale, $$mdDateUtil, $$rAF, $mdGesture) { |
222 | 222 |
|
223 | 223 | /** @final */
|
224 | 224 | this.$window = $window;
|
|
312 | 312 | /** Pre-bound click handler is saved so that the event listener can be removed. */
|
313 | 313 | this.bodyClickHandler = angular.bind(this, this.handleBodyClick);
|
314 | 314 |
|
315 |
| - /** Pre-bound resize handler so that the event listener can be removed. */ |
316 |
| - this.windowResizeHandler = $mdUtil.debounce(angular.bind(this, this.closeCalendarPane), 100); |
| 315 | + /** |
| 316 | + * Name of the event that will trigger a close. Necessary to sniff the browser, because |
| 317 | + * the resize event doesn't make sense on mobile and can have a negative impact since it |
| 318 | + * triggers whenever the browser zooms in on a focused input. |
| 319 | + */ |
| 320 | + this.windowEventName = ($mdGesture.isIos || $mdGesture.isAndroid) ? 'orientationchange' : 'resize'; |
| 321 | + |
| 322 | + /** Pre-bound close handler so that the event listener can be removed. */ |
| 323 | + this.windowEventHandler = $mdUtil.debounce(angular.bind(this, this.closeCalendarPane), 100); |
317 | 324 |
|
318 | 325 | /** Pre-bound handler for the window blur event. Allows for it to be removed later. */
|
319 | 326 | this.windowBlurHandler = angular.bind(this, this.handleWindowBlur);
|
|
690 | 697 | self.documentElement.on('click touchstart', self.bodyClickHandler);
|
691 | 698 | }, false);
|
692 | 699 |
|
693 |
| - window.addEventListener('resize', this.windowResizeHandler); |
| 700 | + window.addEventListener(this.windowEventName, this.windowEventHandler); |
694 | 701 | }
|
695 | 702 | };
|
696 | 703 |
|
|
704 | 711 | self.evalAttr('ngBlur');
|
705 | 712 |
|
706 | 713 | self.documentElement.off('click touchstart', self.bodyClickHandler);
|
707 |
| - window.removeEventListener('resize', self.windowResizeHandler); |
| 714 | + window.removeEventListener(self.windowEventName, self.windowEventHandler); |
708 | 715 |
|
709 | 716 | self.calendarPaneOpenedFrom.focus();
|
710 | 717 | self.calendarPaneOpenedFrom = null;
|
|
0 commit comments