Skip to content

Commit

Permalink
Move the local _isSafari() into dom-util.ts
Browse files Browse the repository at this point in the history
The isSafari() function was introduced in master by this commit [1]
and then cherry-picked straight to stable-3.2[2]. However, since the
dom-util.ts did not exist in 3.2, the function was added directly into
the gr-diff.js file. as a local method (_isSafari()).

When stable-3.2 was merge into stable-3.3, the _isSafari() method was
never replaced by the dom-utils.ts.

[1]https://gerrit-review.googlesource.com/c/gerrit/+/296582
[2]https://gerrit-review.googlesource.com/c/gerrit/+/297615

Change-Id: Id61a7f6614bcabb8fe1b701a659c8e2dc7f83f04
  • Loading branch information
frankborden authored and syntonyze committed May 24, 2021
1 parent f202455 commit 4c13690
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 3 additions & 8 deletions polygerrit-ui/app/elements/diff/gr-diff/gr-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
// @ts-ignore
import * as shadow from 'shadow-selection-polyfill/shadow.js';

import {isSafari} from '../../../utils/dom-util';

const NO_NEWLINE_BASE = 'No newline at end of base file.';
const NO_NEWLINE_REVISION = 'No newline at end of revision file.';

Expand Down Expand Up @@ -361,7 +363,7 @@ export class GrDiff extends GestureEventListeners(
// element. This takes the shadow DOM selection if one exists.
return this.root instanceof ShadowRoot && this.root.getSelection
? this.root.getSelection()
: this._isSafari()
: isSafari()
? shadow.getRange(this.root)
: document.getSelection();
}
Expand Down Expand Up @@ -1074,13 +1076,6 @@ export class GrDiff extends GestureEventListeners(
}
}, 0);
}

_isSafari() {
return (
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) ||
(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
);
}
}

declare global {
Expand Down
8 changes: 8 additions & 0 deletions polygerrit-ui/app/utils/dom-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,11 @@ export function getSharedApiEl(): JsApiService {
}
return _sharedApiEl;
}

// Whether the browser is Safari. Used for polyfilling unique browser behavior.
export function isSafari() {
return (
/^((?!chrome|android).)*safari/i.test(navigator.userAgent) ||
(/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream)
);
}

0 comments on commit 4c13690

Please sign in to comment.