Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requirejs amd fix #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion builder/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way.

require.s is private to RequireJS. If you want to mess with it in your own code, that's on you. But making widely-used library mess with RequireJS' private parts is a non-starter.

' // 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") );',
Expand Down
18 changes: 10 additions & 8 deletions lib/rangy-classapplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") );
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down
29 changes: 18 additions & 11 deletions lib/rangy-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -1365,7 +1366,7 @@
var htmlParsingConforms = false;
try {
styleEl.innerHTML = "<b>x</b>";
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
}
Expand Down Expand Up @@ -1966,6 +1967,12 @@
break;
}

assertNoDocTypeNotationEntityAncestor(sc, true);
assertValidOffset(sc, so);

assertNoDocTypeNotationEntityAncestor(ec, true);
assertValidOffset(ec, eo);

boundaryUpdater(this, sc, so, ec, eo);
},

Expand Down Expand Up @@ -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;
}
});

Expand All @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions lib/rangy-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") );
Expand Down
13 changes: 9 additions & 4 deletions lib/rangy-selectionsaverestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") );
Expand All @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions lib/rangy-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") );
Expand Down
11 changes: 8 additions & 3 deletions lib/rangy-textrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -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") );
Expand Down