Skip to content

Commit

Permalink
Optimized IE10 browser detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sumedh-coditas committed Aug 14, 2017
1 parent 2738920 commit eb6366f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/color-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class ColorPickerComponent implements OnInit, AfterViewInit {

private useRootViewContainer: boolean = false;

private isIE10: boolean = false;

@ViewChild('hueSlider') hueSlider: any;
@ViewChild('alphaSlider') alphaSlider: any;
@ViewChild('dialogPopup') dialogElement: any;
Expand Down Expand Up @@ -106,6 +108,8 @@ export class ColorPickerComponent implements OnInit, AfterViewInit {
if (cpOutputFormat === 'hex' && cpAlphaChannel !== 'always' && cpAlphaChannel !== 'hex8') {
this.cpAlphaChannel = 'disabled';
}

this.isIE10 = detectIE() === 10;
}

ngOnInit() {
Expand Down Expand Up @@ -207,7 +211,7 @@ export class ColorPickerComponent implements OnInit, AfterViewInit {
if ((!this.isDescendant(this.el.nativeElement, event.target)
&& event.target != this.directiveElementRef.nativeElement &&
this.cpIgnoredElements.filter((item: any) => item === event.target).length === 0) &&
this.cpDialogDisplay === 'popup' && detectIE() !== 10) {
this.cpDialogDisplay === 'popup' && !this.isIE10) {
if (!this.cpSaveClickOutside) {
this.setColorFromString(this.initialColor, false);
this.directiveInstance.colorChanged(this.initialColor);
Expand All @@ -233,7 +237,7 @@ export class ColorPickerComponent implements OnInit, AfterViewInit {
* but if we implement this color picker in child components then it closes on clicking anywhere (including this component)
* and stopPropagation() does not work
*/
if (detectIE() !== 10) {
if (!this.isIE10) {
document.addEventListener('mousedown', this.listenerMouseDown);
}
window.addEventListener('resize', this.listenerResize);
Expand All @@ -248,7 +252,7 @@ export class ColorPickerComponent implements OnInit, AfterViewInit {
* Required for IE10
* If this is not attached then no need to remove the listener
*/
if (detectIE() !== 10) {
if (!this.isIE10) {
document.removeEventListener('mousedown', this.listenerMouseDown);
}
window.removeEventListener('resize', this.listenerResize);
Expand Down

0 comments on commit eb6366f

Please sign in to comment.