|
166 | 166 | /** @final */
|
167 | 167 | this.$$rAF = $$rAF;
|
168 | 168 |
|
| 169 | + /** |
| 170 | + * The root document element. This is used for attaching a top-level click handler to |
| 171 | + * close the calendar panel when a click outside said panel occurs. We use `documentElement` |
| 172 | + * instead of body because, when scrolling is disabled, some browsers consider the body element |
| 173 | + * to be completely off the screen and propagate events directly to the html element. |
| 174 | + * @type {!angular.JQLite} |
| 175 | + */ |
| 176 | + this.documentElement = angular.element(document.documentElement); |
| 177 | + |
169 | 178 | /** @type {!angular.NgModelController} */
|
170 | 179 | this.ngModelCtrl = null;
|
171 | 180 |
|
|
543 | 552 | // click, we don't want it to be immediately propogated up to the body and handled.
|
544 | 553 | var self = this;
|
545 | 554 | this.$mdUtil.nextTick(function() {
|
546 |
| - document.documentElement.addEventListener('click', self.bodyClickHandler); |
| 555 | + // Use 'touchstart` in addition to click in order to work on iOS Safari, where click |
| 556 | + // events aren't propogated under most circumstances. |
| 557 | + // See http://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html |
| 558 | + self.documentElement.on('click touchstart', self.bodyClickHandler); |
547 | 559 | }, false);
|
548 | 560 |
|
549 | 561 | window.addEventListener('resize', this.windowResizeHandler);
|
|
559 | 571 | this.calendarPaneOpenedFrom = null;
|
560 | 572 | this.$mdUtil.enableScrolling();
|
561 | 573 |
|
562 |
| - document.documentElement.removeEventListener('click', this.bodyClickHandler); |
| 574 | + this.documentElement.off('click touchstart', this.bodyClickHandler); |
563 | 575 | window.removeEventListener('resize', this.windowResizeHandler);
|
564 | 576 | }
|
565 | 577 | };
|
|
0 commit comments