diff --git a/builder/build.js b/builder/build.js index a96e6737..0f174d98 100644 --- a/builder/build.js +++ b/builder/build.js @@ -166,7 +166,12 @@ function copyModuleScripts() { '(function(factory, root) {', ' if (typeof define == "function" && define.amd) {', ' // AMD. Register as an anonymous module with a dependency on Rangy.', - ' define(["./rangy-core"], factory);', + ' if ( require && require.s.contexts._.defined.rangy ) {', + ' // in case when the rangy module is already required with name \'rangy\'', + ' factory(require.s.contexts._.defined.rangy);', + ' } else {', + ' define(["./rangy-core"], factory);', + ' }', ' } else if (typeof module != "undefined" && typeof exports == "object") {', ' // Node/CommonJS style', ' module.exports = factory( require("rangy") );', diff --git a/lib/rangy-classapplier.js b/lib/rangy-classapplier.js index 9fe90d85..59869525 100644 --- a/lib/rangy-classapplier.js +++ b/lib/rangy-classapplier.js @@ -7,15 +7,20 @@ * * Depends on Rangy core. * - * Copyright 2015, Tim Down + * Copyright 2016, Tim Down * Licensed under the MIT license. * Version: 1.3.1-dev - * Build date: 20 May 2015 + * Build date: 27 April 2016 */ (function(factory, root) { if (typeof define == "function" && define.amd) { // AMD. Register as an anonymous module with a dependency on Rangy. - define(["./rangy-core"], factory); + if ( require && require.s.contexts._.defined.rangy ) { + // in case when the rangy module is already required with name 'rangy' + factory(require.s.contexts._.defined.rangy); + } else { + define(["./rangy-core"], factory); + } } else if (typeof module != "undefined" && typeof exports == "object") { // Node/CommonJS style module.exports = factory( require("rangy") ); @@ -698,13 +703,10 @@ // Normalizes nodes after applying a class to a Range. postApply: function(textNodes, range, positionsToPreserve, isUndo) { var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1]; - var merges = [], currentMerge; - var rangeStartNode = firstNode, rangeEndNode = lastNode; var rangeStartOffset = 0, rangeEndOffset = lastNode.length; - - var textNode, precedingTextNode; + var precedingTextNode; // Check for every required merge and create a Merge object for each forEach(textNodes, function(textNode) { @@ -741,7 +743,7 @@ // Apply the merges if (merges.length) { - for (i = 0, len = merges.length; i < len; ++i) { + for (var i = 0, len = merges.length; i < len; ++i) { merges[i].doMerge(positionsToPreserve); } diff --git a/lib/rangy-core.js b/lib/rangy-core.js index dafb1ce1..ef7fbe4b 100644 --- a/lib/rangy-core.js +++ b/lib/rangy-core.js @@ -2,10 +2,10 @@ * Rangy, a cross-browser JavaScript range and selection library * https://github.com/timdown/rangy * - * Copyright 2015, Tim Down + * Copyright 2016, Tim Down * Licensed under the MIT license. * Version: 1.3.1-dev - * Build date: 20 May 2015 + * Build date: 27 April 2016 */ (function(factory, root) { @@ -222,7 +222,7 @@ })(); // Very simple event handler wrapper function that doesn't attempt to solve issues such as "this" handling or - // normalization of event properties + // normalization of event properties because we don't need this. var addListener; if (isBrowser) { if (isHostMethod(document, "addEventListener")) { @@ -1303,6 +1303,7 @@ var getDocumentOrFragmentContainer = createAncestorFinder( [9, 11] ); var getReadonlyAncestor = createAncestorFinder(readonlyNodeTypes); var getDocTypeNotationEntityAncestor = createAncestorFinder( [6, 10, 12] ); + var getElementAncestor = createAncestorFinder( [1] ); function assertNoDocTypeNotationEntityAncestor(node, allowSelf) { if (getDocTypeNotationEntityAncestor(node, allowSelf)) { @@ -1365,7 +1366,7 @@ var htmlParsingConforms = false; try { styleEl.innerHTML = "x"; - htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Opera incorrectly creates an element node + htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Pre-Blink Opera incorrectly creates an element node } catch (e) { // IE 6 and 7 throw } @@ -1966,6 +1967,12 @@ break; } + assertNoDocTypeNotationEntityAncestor(sc, true); + assertValidOffset(sc, so); + + assertNoDocTypeNotationEntityAncestor(ec, true); + assertValidOffset(ec, eo); + boundaryUpdater(this, sc, so, ec, eo); }, @@ -2128,6 +2135,12 @@ assertNoDocTypeNotationEntityAncestor(node, true); assertValidOffset(node, offset); this.setStartAndEnd(node, offset); + }, + + parentElement: function() { + assertRangeValid(this); + var parentNode = this.commonAncestorContainer; + return parentNode ? getElementAncestor(this.commonAncestorContainer, true) : null; } }); @@ -2149,17 +2162,11 @@ range.endContainer = endContainer; range.endOffset = endOffset; range.document = dom.getDocument(startContainer); - updateCollapsedAndCommonAncestor(range); } function Range(doc) { - this.startContainer = doc; - this.startOffset = 0; - this.endContainer = doc; - this.endOffset = 0; - this.document = doc; - updateCollapsedAndCommonAncestor(this); + updateBoundaries(this, doc, 0, doc, 0); } createPrototypeRange(Range, updateBoundaries); diff --git a/lib/rangy-highlighter.js b/lib/rangy-highlighter.js index bde6ba43..d33df7de 100644 --- a/lib/rangy-highlighter.js +++ b/lib/rangy-highlighter.js @@ -4,15 +4,20 @@ * * Depends on Rangy core, ClassApplier and optionally TextRange modules. * - * Copyright 2015, Tim Down + * Copyright 2016, Tim Down * Licensed under the MIT license. * Version: 1.3.1-dev - * Build date: 20 May 2015 + * Build date: 27 April 2016 */ (function(factory, root) { if (typeof define == "function" && define.amd) { // AMD. Register as an anonymous module with a dependency on Rangy. - define(["./rangy-core"], factory); + if ( require && require.s.contexts._.defined.rangy ) { + // in case when the rangy module is already required with name 'rangy' + factory(require.s.contexts._.defined.rangy); + } else { + define(["./rangy-core"], factory); + } } else if (typeof module != "undefined" && typeof exports == "object") { // Node/CommonJS style module.exports = factory( require("rangy") ); diff --git a/lib/rangy-selectionsaverestore.js b/lib/rangy-selectionsaverestore.js index b4e35b03..87470133 100644 --- a/lib/rangy-selectionsaverestore.js +++ b/lib/rangy-selectionsaverestore.js @@ -7,15 +7,20 @@ * * Depends on Rangy core. * - * Copyright 2015, Tim Down + * Copyright 2016, Tim Down * Licensed under the MIT license. * Version: 1.3.1-dev - * Build date: 20 May 2015 + * Build date: 27 April 2016 */ (function(factory, root) { if (typeof define == "function" && define.amd) { // AMD. Register as an anonymous module with a dependency on Rangy. - define(["./rangy-core"], factory); + if ( require && require.s.contexts._.defined.rangy ) { + // in case when the rangy module is already required with name 'rangy' + factory(require.s.contexts._.defined.rangy); + } else { + define(["./rangy-core"], factory); + } } else if (typeof module != "undefined" && typeof exports == "object") { // Node/CommonJS style module.exports = factory( require("rangy") ); @@ -24,7 +29,7 @@ factory(root.rangy); } })(function(rangy) { - rangy.createModule("SaveRestore", ["WrappedRange"], function(api, module) { + rangy.createModule("SaveRestore", ["WrappedSelection"], function(api, module) { var dom = api.dom; var removeNode = dom.removeNode; var isDirectionBackward = api.Selection.isDirectionBackward; diff --git a/lib/rangy-serializer.js b/lib/rangy-serializer.js index eec78880..8f03149f 100644 --- a/lib/rangy-serializer.js +++ b/lib/rangy-serializer.js @@ -8,15 +8,20 @@ * * Depends on Rangy core. * - * Copyright 2015, Tim Down + * Copyright 2016, Tim Down * Licensed under the MIT license. * Version: 1.3.1-dev - * Build date: 20 May 2015 + * Build date: 27 April 2016 */ (function(factory, root) { if (typeof define == "function" && define.amd) { // AMD. Register as an anonymous module with a dependency on Rangy. - define(["./rangy-core"], factory); + if ( require && require.s.contexts._.defined.rangy ) { + // in case when the rangy module is already required with name 'rangy' + factory(require.s.contexts._.defined.rangy); + } else { + define(["./rangy-core"], factory); + } } else if (typeof module != "undefined" && typeof exports == "object") { // Node/CommonJS style module.exports = factory( require("rangy") ); diff --git a/lib/rangy-textrange.js b/lib/rangy-textrange.js index 6e380a12..32aedfd6 100644 --- a/lib/rangy-textrange.js +++ b/lib/rangy-textrange.js @@ -24,10 +24,10 @@ * * Depends on Rangy core. * - * Copyright 2015, Tim Down + * Copyright 2016, Tim Down * Licensed under the MIT license. * Version: 1.3.1-dev - * Build date: 20 May 2015 + * Build date: 27 April 2016 */ /** @@ -66,7 +66,12 @@ (function(factory, root) { if (typeof define == "function" && define.amd) { // AMD. Register as an anonymous module with a dependency on Rangy. - define(["./rangy-core"], factory); + if ( require && require.s.contexts._.defined.rangy ) { + // in case when the rangy module is already required with name 'rangy' + factory(require.s.contexts._.defined.rangy); + } else { + define(["./rangy-core"], factory); + } } else if (typeof module != "undefined" && typeof exports == "object") { // Node/CommonJS style module.exports = factory( require("rangy") );