mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-23 22:13:34 +00:00
Updating to Rangy 1.3 alpha
We previously tried Rangy 1.3 alpha but rolled back due to a bug with getting cursor position in IE. Rangy developer Tim Down fixed the issue here: https://code.google.com/p/rangy/source/detail?r=780 Both 1.2 (filenames without file versions) and 1.3 in the repo for now. Change-Id: I26263fc1d10e3c2bdda7f1c9135544ca3bc05d97
This commit is contained in:
parent
f94d5cccc1
commit
69e1cc3280
|
@ -66,8 +66,8 @@ $wgVisualEditorEnableSectionEditLinks = false;
|
|||
$wgResourceModules += array(
|
||||
'rangy' => $wgVisualEditorResourceTemplate + array(
|
||||
'scripts' => array(
|
||||
'rangy/rangy-core.js',
|
||||
'rangy/rangy-position.js',
|
||||
'rangy/rangy-core-1.3.js',
|
||||
'rangy/rangy-position-1.3.js',
|
||||
'rangy/rangy-export.js',
|
||||
),
|
||||
),
|
||||
|
|
|
@ -69,8 +69,8 @@ $html = file_get_contents( $page );
|
|||
<!-- Dependencies -->
|
||||
<script src="../../modules/jquery/jquery.js"></script>
|
||||
<script src="../../modules/jquery/jquery.client.js"></script>
|
||||
<script src="../../modules/rangy/rangy-core.js"></script>
|
||||
<script src="../../modules/rangy/rangy-position.js"></script>
|
||||
<script src="../../modules/rangy/rangy-core-1.3.js"></script>
|
||||
<script src="../../modules/rangy/rangy-position-1.3.js"></script>
|
||||
<script src="../../modules/unicodejs/unicodejs.js"></script>
|
||||
<script src="../../modules/unicodejs/unicodejs.textstring.js"></script>
|
||||
<script src="../../modules/unicodejs/unicodejs.wordbreak.groups.js"></script>
|
||||
|
|
|
@ -59,8 +59,8 @@ class MakeStaticLoader extends Maintenance {
|
|||
'scripts' => array(
|
||||
'jquery/jquery.js',
|
||||
'jquery/jquery.client.js',
|
||||
'rangy/rangy-core.js',
|
||||
'rangy/rangy-position.js',
|
||||
'rangy/rangy-core-1.3.js',
|
||||
'rangy/rangy-position-1.3.js',
|
||||
'unicodejs/unicodejs.js',
|
||||
'unicodejs/unicodejs.textstring.js',
|
||||
'unicodejs/unicodejs.wordbreak.groups.js',
|
||||
|
|
|
@ -67,13 +67,13 @@ rangy = rangy || (function() {
|
|||
function isTextRange(range) {
|
||||
return range && areHostMethods(range, textRangeMethods) && areHostProperties(range, textRangeProperties);
|
||||
}
|
||||
|
||||
|
||||
function getBody(doc) {
|
||||
return isHostObject(doc, "body") ? doc.body : doc.getElementsByTagName("body")[0];
|
||||
}
|
||||
|
||||
var modules = {};
|
||||
|
||||
|
||||
var api = {
|
||||
version: "1.3alpha.772",
|
||||
initialized: false,
|
||||
|
@ -191,11 +191,11 @@ rangy = rangy || (function() {
|
|||
} else {
|
||||
fail("Document does not have required addEventListener or attachEvent method");
|
||||
}
|
||||
|
||||
|
||||
api.util.addListener = addListener;
|
||||
|
||||
var initListeners = [];
|
||||
|
||||
|
||||
function getErrorDesc(ex) {
|
||||
return ex.message || ex.description || String(ex);
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ rangy = rangy || (function() {
|
|||
module.init();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Call init listeners
|
||||
for (var i = 0, len = initListeners.length; i < len; ++i) {
|
||||
try {
|
||||
|
@ -338,14 +338,14 @@ rangy = rangy || (function() {
|
|||
api.requireModules = function(moduleNames) {
|
||||
for (var i = 0, len = moduleNames.length, module, moduleName; i < len; ++i) {
|
||||
moduleName = moduleNames[i];
|
||||
|
||||
|
||||
module = modules[moduleName];
|
||||
if (!module || !(module instanceof Module)) {
|
||||
throw new Error("required module '" + moduleName + "' not found");
|
||||
}
|
||||
|
||||
module.init();
|
||||
|
||||
|
||||
if (!module.supported) {
|
||||
throw new Error("required module '" + moduleName + "' not supported");
|
||||
}
|
||||
|
@ -1670,7 +1670,7 @@ rangy.createModule("DomRange", function(api, module) {
|
|||
this.setStartAfter(node);
|
||||
this.collapse(true);
|
||||
},
|
||||
|
||||
|
||||
getBookmark: function(containerNode) {
|
||||
var doc = getRangeDocument(this);
|
||||
var preSelectionRange = api.createRange(doc);
|
||||
|
@ -1691,7 +1691,7 @@ rangy.createModule("DomRange", function(api, module) {
|
|||
containerNode: containerNode
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
moveToBookmark: function(bookmark) {
|
||||
var containerNode = bookmark.containerNode;
|
||||
var charIndex = 0;
|
||||
|
@ -1733,7 +1733,7 @@ rangy.createModule("DomRange", function(api, module) {
|
|||
isValid: function() {
|
||||
return isRangeValid(this);
|
||||
},
|
||||
|
||||
|
||||
inspect: function() {
|
||||
return inspect(this);
|
||||
}
|
||||
|
@ -1872,7 +1872,7 @@ rangy.createModule("DomRange", function(api, module) {
|
|||
|
||||
boundaryUpdater(this, sc, so, ec, eo);
|
||||
},
|
||||
|
||||
|
||||
setBoundary: function(node, offset, isStart) {
|
||||
this["set" + (isStart ? "Start" : "End")](node, offset);
|
||||
},
|
||||
|
@ -2366,7 +2366,7 @@ rangy.createModule("WrappedRange", function(api, module) {
|
|||
};
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
if (api.features.implementsTextRange) {
|
||||
/*
|
||||
This is a workaround for a bug where IE returns the wrong container element from the TextRange's parentElement()
|
||||
|
@ -3231,7 +3231,7 @@ rangy.createModule("WrappedSelection", function(api, module) {
|
|||
if (this.docSelection.type == CONTROL) {
|
||||
addRangeToControlSelection(this, range);
|
||||
} else {
|
||||
WrappedRange.rangeToTextRange(range).select();
|
||||
api.WrappedTextRange.rangeToTextRange(range).select();
|
||||
this._ranges[0] = range;
|
||||
this.rangeCount = 1;
|
||||
this.isCollapsed = this._ranges[0].collapsed;
|
||||
|
@ -3523,7 +3523,7 @@ rangy.createModule("WrappedSelection", function(api, module) {
|
|||
} );
|
||||
return results;
|
||||
};
|
||||
|
||||
|
||||
function createStartOrEndSetter(isStart) {
|
||||
return function(node, offset) {
|
||||
var range;
|
||||
|
@ -3540,7 +3540,7 @@ rangy.createModule("WrappedSelection", function(api, module) {
|
|||
|
||||
selProto.setStart = createStartOrEndSetter(true);
|
||||
selProto.setEnd = createStartOrEndSetter(false);
|
||||
|
||||
|
||||
// Add cheeky select() method to Range prototype
|
||||
api.rangePrototype.select = function(direction) {
|
||||
getSelection( this.getDocument() ).setSingleRange(this, direction);
|
||||
|
|
|
@ -19,8 +19,9 @@ rangy.createModule("Position", function(api, module) {
|
|||
|
||||
var NUMBER = "number", UNDEF = "undefined";
|
||||
var WrappedRange = api.WrappedRange;
|
||||
var WrappedTextRange = api.WrappedTextRange;
|
||||
var dom = api.dom, util = api.util, DomPosition = dom.DomPosition;
|
||||
|
||||
|
||||
// Feature detection
|
||||
|
||||
//var caretPositionFromPointSupported = (typeof document.caretPositionFromPoint != UNDEF);
|
||||
|
@ -107,7 +108,7 @@ rangy.createModule("Position", function(api, module) {
|
|||
Math.min.apply(Math, lefts)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function getTextRangePosition(doc, x, y) {
|
||||
var textRange = dom.getBody(doc).createTextRange();
|
||||
textRange.moveToPoint(x, y);
|
||||
|
@ -137,7 +138,7 @@ rangy.createModule("Position", function(api, module) {
|
|||
|
||||
function positionFromPoint(doc, x, y, favourPrecedingPosition) {
|
||||
var el = doc.elementFromPoint(x, y);
|
||||
|
||||
|
||||
console.log("elementFromPoint is ", el);
|
||||
|
||||
var range = api.createRange(doc);
|
||||
|
@ -207,7 +208,7 @@ rangy.createModule("Position", function(api, module) {
|
|||
throw module.createError("createCaretPositionFromPointGetter(): Browser does not provide a recognised method to create a selection from pixel coordinates");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createRangeFromPoints(startX, startY, endX, endY, doc) {
|
||||
doc = dom.getContentDocument(doc, module, "createRangeFromPoints");
|
||||
var positionFinder = createCaretPositionFromPointGetter(doc);
|
||||
|
@ -242,7 +243,7 @@ rangy.createModule("Position", function(api, module) {
|
|||
sel.setSingleRange(range);
|
||||
return sel;
|
||||
}
|
||||
|
||||
|
||||
// Test that <span> elements support getBoundingClientRect
|
||||
var span = document.createElement("span");
|
||||
var elementSupportsGetBoundingClientRect = util.isHostMethod(span, "getBoundingClientRect");
|
||||
|
@ -280,7 +281,7 @@ rangy.createModule("Position", function(api, module) {
|
|||
if (api.features.implementsTextRange && elementSupportsGetBoundingClientRect) {
|
||||
rangeProto.getBoundingClientRect = function() {
|
||||
// We need a TextRange
|
||||
var textRange = WrappedRange.rangeToTextRange(this);
|
||||
var textRange = WrappedTextRange.rangeToTextRange(this);
|
||||
|
||||
// Work around table problems (table cell bounding rects seem not to count if TextRange spans cells)
|
||||
var cells = this.getNodes([1], function(el) {
|
||||
|
@ -303,7 +304,7 @@ rangy.createModule("Position", function(api, module) {
|
|||
subRange.setStartAfter(lastTable);
|
||||
}
|
||||
subRange.setEndBefore(table);
|
||||
rects.push(WrappedRange.rangeToTextRange(subRange).getBoundingClientRect());
|
||||
rects.push(WrappedTextRange.rangeToTextRange(subRange).getBoundingClientRect());
|
||||
}
|
||||
|
||||
if (this.containsNode(cell)) {
|
||||
|
@ -326,7 +327,7 @@ rangy.createModule("Position", function(api, module) {
|
|||
if (!endTable && lastTable) {
|
||||
subRange = this.cloneRange();
|
||||
subRange.setStartAfter(lastTable);
|
||||
rects.push(WrappedRange.rangeToTextRange(subRange).getBoundingClientRect());
|
||||
rects.push(WrappedTextRange.rangeToTextRange(subRange).getBoundingClientRect());
|
||||
}
|
||||
rect = mergeRects(rects);
|
||||
} else {
|
||||
|
@ -528,12 +529,12 @@ rangy.createModule("Position", function(api, module) {
|
|||
getStartDocumentPos: createSelectionBoundaryPosGetter(true, true),
|
||||
getEndDocumentPos: createSelectionBoundaryPosGetter(false, true)
|
||||
});
|
||||
|
||||
|
||||
api.positionFromPoint = function(x, y, doc) {
|
||||
doc = dom.getContentDocument(doc, module, "positionFromPoint");
|
||||
return createCaretPositionFromPointGetter(doc)(doc, x, y);
|
||||
};
|
||||
|
||||
|
||||
api.createRangeFromPoints = createRangeFromPoints;
|
||||
api.moveSelectionToPoints = moveSelectionToPoints;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue