Skip to content

Commit 77eaabf

Browse files
author
Oliver Eivak
committed
apply patch ebondu#universal-support (edcarroll/pull/270)
1 parent 348d2e5 commit 77eaabf

File tree

24 files changed

+101
-59
lines changed

24 files changed

+101
-59
lines changed

demo/src/app/components/sidebar/sidebar.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Component, HostBinding, Output, EventEmitter, HostListener, isDevMode } from "@angular/core";
2-
// Polyfill for IE
3-
import "element-closest";
42

53
interface IAugmentedElement extends Element {
64
closest(selector:string):IAugmentedElement;

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"dependencies": {
5252
"bowser": "^1.7.2",
5353
"date-fns": "2.0.0-alpha.1",
54-
"element-closest": "^2.0.2",
5554
"extend": "^3.0.1",
5655
"is-ua-webview": "^1.0.0",
5756
"popper.js": "^1.14.0",

src/misc/util/helpers/closest.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// element-closest | CC0-1.0 | github.com/jonathantneal/closest
2+
3+
/** @this {Foo} */
4+
if (typeof Element !== "undefined") {
5+
if (typeof Element.prototype.matches !== "function") {
6+
Element.prototype.matches = Element.prototype.msMatchesSelector ||
7+
(Element as any).prototype["mozMatchesSelector"] ||
8+
Element.prototype.webkitMatchesSelector ||
9+
function matches(selector:any):boolean {
10+
const element = this;
11+
const elements = (element.document || element.ownerDocument).querySelectorAll(selector);
12+
let index = 0;
13+
14+
while (elements[index] && elements[index] !== element) {
15+
++index;
16+
}
17+
18+
return Boolean(elements[index]);
19+
};
20+
}
21+
22+
if (typeof Element.prototype["closest"] !== "function") {
23+
Element.prototype["closest"] = function closest(selector:any):any {
24+
let element = this;
25+
26+
while (element && element.nodeType === 1) {
27+
if (element.matches(selector)) {
28+
return element;
29+
}
30+
31+
element = element.parentNode;
32+
}
33+
34+
return undefined;
35+
};
36+
}
37+
}

src/modules/checkbox/components/checkbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class SuiCheckbox implements ICustomValueAccessorHost<boolean> {
6767
}
6868

6969
@HostListener("mousedown", ["$event"])
70-
public onMouseDown(e:MouseEvent):void {
70+
public onMouseDown(e:any):void {
7171
e.preventDefault();
7272
}
7373

src/modules/checkbox/components/radio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class SuiRadio<T> implements ICustomValueAccessorHost<T> {
7777
}
7878

7979
@HostListener("mousedown", ["$event"])
80-
public onMouseDown(e:MouseEvent):void {
80+
public onMouseDown(e:any):void {
8181
e.preventDefault();
8282
}
8383

src/modules/datepicker/components/datepicker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class SuiDatepicker {
4545
}
4646

4747
@HostListener("mousedown", ["$event"])
48-
public onMouseDown(e:MouseEvent):void {
48+
public onMouseDown(e:any):void {
4949
e.preventDefault();
5050
}
5151
}

src/modules/datepicker/directives/datepicker.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class SuiDatepickerDirective
189189
}
190190

191191
@HostListener("keydown", ["$event"])
192-
public onKeyDown(e:KeyboardEvent):void {
192+
public onKeyDown(e:any):void {
193193
if (e.keyCode === KeyCode.Escape) {
194194
this.close();
195195
}

src/modules/datepicker/views/calendar-view.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export abstract class CalendarView implements AfterViewInit, OnDestroy {
5454
this._type = viewType;
5555
this.ranges = ranges;
5656

57-
this._documentKeyDownListener = renderer.listen("document", "keydown", (e:KeyboardEvent) => this.onDocumentKeyDown(e));
57+
this._documentKeyDownListener = renderer.listen("document", "keydown", (e:any) => this.onDocumentKeyDown(e));
5858
}
5959

6060
// Template Methods
@@ -111,7 +111,7 @@ export abstract class CalendarView implements AfterViewInit, OnDestroy {
111111
}
112112
}
113113

114-
private onDocumentKeyDown(e:KeyboardEvent):void {
114+
private onDocumentKeyDown(e:any):void {
115115
if (this._highlightedItem && e.keyCode === KeyCode.Enter) {
116116
this.setDate(this._highlightedItem);
117117
return;

src/modules/dropdown/directives/dropdown-menu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Transition, SuiTransition, TransitionController, TransitionDirection }
66
import { HandledEvent, IAugmentedElement, KeyCode } from "../../../misc/util/index";
77
import { DropdownService, DropdownAutoCloseType } from "../services/dropdown.service";
88
// Polyfill for IE
9-
import "element-closest";
9+
import "../../../misc/util/helpers/closest";
1010

1111
@Directive({
1212
// We must attach to every '.item' as Angular doesn't support > selectors.
@@ -144,11 +144,11 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
144144
this.menuAutoSelectFirst = false;
145145
this.menuSelectedItemClass = "selected";
146146

147-
this._documentKeyDownListener = renderer.listen("document", "keydown", (e:KeyboardEvent) => this.onDocumentKeyDown(e));
147+
this._documentKeyDownListener = renderer.listen("document", "keydown", (e:any) => this.onDocumentKeyDown(e));
148148
}
149149

150150
@HostListener("click", ["$event"])
151-
public onClick(e:HandledEvent & MouseEvent):void {
151+
public onClick(e:HandledEvent & any):void {
152152
if (!e.eventHandled) {
153153
e.eventHandled = true;
154154

@@ -162,7 +162,7 @@ export class SuiDropdownMenu extends SuiTransition implements AfterContentInit,
162162
}
163163
}
164164

165-
public onDocumentKeyDown(e:KeyboardEvent):void {
165+
public onDocumentKeyDown(e:any):void {
166166
// Only the root dropdown (i.e. not nested dropdowns) is responsible for keeping track of the currently selected item.
167167
if (this._service.isOpen && !this._service.isNested) {
168168
// Stop document events like scrolling while open.

0 commit comments

Comments
 (0)