Skip to content

Commit

Permalink
Rebuild quill with refactored polyfill detection
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Oct 5, 2018
1 parent 9568d3d commit 3eb8add
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions vendor/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3046,25 +3046,7 @@ var Selection = function () {
}, {
key: 'getNativeRange',
value: function getNativeRange() {
var nativeRange = void 0;

// in Safari 10+ and iOS we need to use shadow selection polyfill
var ua = navigator.userAgent;
var isSafari = /^((?!chrome|android).)*safari/i.test(ua) || /iPad|iPhone/.test(ua);
var hasPolyfill = window.ShadyDOM && window.ShadyDOM.inUse;
var hasShadow = window.ShadowRoot !== undefined && this.rootDocument instanceof ShadowRoot;
var hasSelection = this.rootDocument.getSelection;

if (hasShadow && !hasPolyfill && !hasSelection && isSafari) {
nativeRange = (0, _shadowSelectionPolyfill.getRange)(this.rootDocument);
} else {
// only Chrome has getSelection() API for ShadowRoot, in Firefox 63 document API works
var root = hasShadow && hasSelection ? this.rootDocument : document;
var selection = root.getSelection();
if (selection == null || selection.rangeCount <= 0) return null;
nativeRange = selection.getRangeAt(0);
}

var nativeRange = (0, _shadowSelectionPolyfill.getRange)(this.rootDocument);
if (nativeRange == null) return null;
var range = this.normalizeNative(nativeRange);
debug.info('getNativeRange', range);
Expand Down Expand Up @@ -6363,8 +6345,23 @@ function ignoredTrailingSpace(node) {

var cachedRange = new Map();
function getRange(root) {
if (root.getSelection) {
var s = root.getSelection();
var ua = navigator.userAgent;
var hasSelection = root.getSelection;
var useDocument = false;
if (root === document) {
useDocument = true;
} else {
// fall back to using global API in the following cases:
// 1. no shadow DOM supported / polyfilled
// 2. ShadyDOM polyfill is in use (including case when it is forced)
// 3. Firefox 63 which returns nodes from shadow trees using document API
var isSafari = /^((?!chrome|android).)*safari/i.test(ua) || /iPad|iPhone/.test(ua);
var hasShadow = window.ShadowRoot !== undefined && root instanceof ShadowRoot;
var hasPolyfill = window.ShadyDOM && window.ShadyDOM.inUse;
useDocument = !hasShadow || hasPolyfill || !hasSelection && !isSafari;
}
if (useDocument || hasSelection) {
var s = (useDocument ? document : root).getSelection();
return s.rangeCount ? s.getRangeAt(0) : null;
}

Expand Down

0 comments on commit 3eb8add

Please sign in to comment.