|
2 | 2 | * Rangy, a cross-browser JavaScript range and selection library |
3 | 3 | * https://github.com/timdown/rangy |
4 | 4 | * |
5 | | - * Copyright 2015, Tim Down |
| 5 | + * Copyright 2019, Tim Down |
6 | 6 | * Licensed under the MIT license. |
7 | | - * Version: 1.3.1-dev |
8 | | - * Build date: 20 May 2015 |
| 7 | + * Version: 1.3.2 |
| 8 | + * Build date: 2 January 2019 |
9 | 9 | */ |
10 | 10 |
|
11 | 11 | (function(factory, root) { |
|
109 | 109 | }; |
110 | 110 |
|
111 | 111 | var api = { |
112 | | - version: "1.3.1-dev", |
| 112 | + version: "1.3.2", |
113 | 113 | initialized: false, |
114 | 114 | isBrowser: isBrowser, |
115 | 115 | supported: true, |
|
222 | 222 | })(); |
223 | 223 |
|
224 | 224 | // Very simple event handler wrapper function that doesn't attempt to solve issues such as "this" handling or |
225 | | - // normalization of event properties |
| 225 | + // normalization of event properties because we don't need this. |
226 | 226 | var addListener; |
227 | 227 | if (isBrowser) { |
228 | 228 | if (isHostMethod(document, "addEventListener")) { |
|
1303 | 1303 | var getDocumentOrFragmentContainer = createAncestorFinder( [9, 11] ); |
1304 | 1304 | var getReadonlyAncestor = createAncestorFinder(readonlyNodeTypes); |
1305 | 1305 | var getDocTypeNotationEntityAncestor = createAncestorFinder( [6, 10, 12] ); |
| 1306 | + var getElementAncestor = createAncestorFinder( [1] ); |
1306 | 1307 |
|
1307 | 1308 | function assertNoDocTypeNotationEntityAncestor(node, allowSelf) { |
1308 | 1309 | if (getDocTypeNotationEntityAncestor(node, allowSelf)) { |
|
1365 | 1366 | var htmlParsingConforms = false; |
1366 | 1367 | try { |
1367 | 1368 | styleEl.innerHTML = "<b>x</b>"; |
1368 | | - htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Opera incorrectly creates an element node |
| 1369 | + htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Pre-Blink Opera incorrectly creates an element node |
1369 | 1370 | } catch (e) { |
1370 | 1371 | // IE 6 and 7 throw |
1371 | 1372 | } |
|
1966 | 1967 | break; |
1967 | 1968 | } |
1968 | 1969 |
|
| 1970 | + assertNoDocTypeNotationEntityAncestor(sc, true); |
| 1971 | + assertValidOffset(sc, so); |
| 1972 | + |
| 1973 | + assertNoDocTypeNotationEntityAncestor(ec, true); |
| 1974 | + assertValidOffset(ec, eo); |
| 1975 | + |
1969 | 1976 | boundaryUpdater(this, sc, so, ec, eo); |
1970 | 1977 | }, |
1971 | 1978 |
|
|
2128 | 2135 | assertNoDocTypeNotationEntityAncestor(node, true); |
2129 | 2136 | assertValidOffset(node, offset); |
2130 | 2137 | this.setStartAndEnd(node, offset); |
| 2138 | + }, |
| 2139 | + |
| 2140 | + parentElement: function() { |
| 2141 | + assertRangeValid(this); |
| 2142 | + var parentNode = this.commonAncestorContainer; |
| 2143 | + return parentNode ? getElementAncestor(this.commonAncestorContainer, true) : null; |
2131 | 2144 | } |
2132 | 2145 | }); |
2133 | 2146 |
|
|
2149 | 2162 | range.endContainer = endContainer; |
2150 | 2163 | range.endOffset = endOffset; |
2151 | 2164 | range.document = dom.getDocument(startContainer); |
2152 | | - |
2153 | 2165 | updateCollapsedAndCommonAncestor(range); |
2154 | 2166 | } |
2155 | 2167 |
|
2156 | 2168 | function Range(doc) { |
2157 | | - this.startContainer = doc; |
2158 | | - this.startOffset = 0; |
2159 | | - this.endContainer = doc; |
2160 | | - this.endOffset = 0; |
2161 | | - this.document = doc; |
2162 | | - updateCollapsedAndCommonAncestor(this); |
| 2169 | + updateBoundaries(this, doc, 0, doc, 0); |
2163 | 2170 | } |
2164 | 2171 |
|
2165 | 2172 | createPrototypeRange(Range, updateBoundaries); |
|
0 commit comments