Fixed className leak in undo/redo buttons

This commit is contained in:
benweet 2014-05-23 23:58:18 +01:00
parent 349d43bd0d
commit 492f5ffbc0
3 changed files with 461 additions and 447 deletions

View File

@ -27,6 +27,7 @@ define([
var pagedownEditor;
var refreshPreviewLater = (function() {
var elapsedTime = 0;
var timeoutId;
var refreshPreview = function() {
var startTime = Date.now();
pagedownEditor.refreshPreview();
@ -36,7 +37,8 @@ define([
return _.debounce(refreshPreview, 500);
}
return function() {
setTimeout(refreshPreview, elapsedTime < 2000 ? elapsedTime : 2000);
clearTimeout(timeoutId);
timeoutId = setTimeout(refreshPreview, elapsedTime < 2000 ? elapsedTime : 2000);
};
})();
eventMgr.addListener('onPagedownConfigure', function(pagedownEditorParam) {
@ -174,9 +176,10 @@ define([
var min = Math.min(this.selectionStart, this.selectionEnd);
var max = Math.max(this.selectionStart, this.selectionEnd);
var range = this.createRange(min, max);
var selection = document.getSelection();
var selection = rangy.getSelection();
selection.removeAllRanges();
selection.addRange(range);
selection.addRange(range, this.selectionStart > this.selectionEnd);
selection.detach();
range.detach();
};
this.setSelectionStartEnd = function(start, end) {
@ -203,7 +206,7 @@ define([
var selectionStart = self.selectionStart;
var selectionEnd = self.selectionEnd;
var range;
var selection = document.getSelection();
var selection = rangy.getSelection();
if(selection.rangeCount > 0) {
var selectionRange = selection.getRangeAt(0);
var element = selectionRange.startContainer;
@ -220,7 +223,7 @@ define([
element = container = container.parentNode;
} while(element && element != inputElt);
if(false) {
if(selection.isBackwards()) {
selectionStart = offset + (range + '').length;
selectionEnd = offset;
}
@ -231,6 +234,7 @@ define([
}
selectionRange.detach();
}
selection.detach();
self.setSelectionStartEnd(selectionStart, selectionEnd);
}
undoMgr.saveSelectionState();

View File

@ -40,6 +40,7 @@ define([
};
var yList = [];
function setCommentEltCoordinates(commentElt, y, isNew) {
y = Math.round(y);
var yListIndex = y - 21;
@ -72,6 +73,7 @@ define([
this.fileDesc = fileDesc;
this.discussionIndex = commentElt.discussionIndex;
}
Context.prototype.getDiscussion = function() {
if(!this.discussionIndex) {
return this.fileDesc.newDiscussion;
@ -82,6 +84,7 @@ define([
return document.querySelector('.comments-popover .popover:last-child');
};
var currentContext;
function movePopover(commentElt) {
// Move popover in the margin
var popoverElt = currentContext.getPopoverElt();
@ -116,6 +119,7 @@ define([
var discussionList = _.sortBy(currentFileDesc.discussionList, function(discussion) {
return discussion.selectionEnd;
});
function refreshOne() {
var coordinates;
if(discussionList.length === 0) {
@ -171,6 +175,7 @@ define([
}
refreshTimeoutId = setTimeout(refreshOne, 5);
}
clearTimeout(refreshTimeoutId);
refreshTimeoutId = setTimeout(refreshOne, 5);
}, 50);
@ -199,7 +204,8 @@ define([
cssApplier.undoToRange(context.rangyRange);
context.rangyRange.detach();
}
catch(e) {}
catch(e) {
}
var discussion = context.getDiscussion();
context.selectionRange = selectionMgr.createRange(discussion.selectionStart, discussion.selectionEnd);
@ -431,8 +437,12 @@ define([
storage['author.name'] = currentContext.$authorInputElt.val();
// Remove highlight
try {
cssApplier.undoToRange(currentContext.rangyRange);
currentContext.rangyRange.detach();
}
catch(e) {
}
currentContext = undefined;
delete currentFileDesc.newDiscussion;
});

View File

@ -1425,6 +1425,7 @@
var disabledYShift = "-20px";
var highlightYShift = "-40px";
var image = button.getElementsByTagName("span")[0];
button.className = button.className.replace(/ disabled/g, "");
if (isEnabled) {
image.style.backgroundPosition = button.XShift + " " + normalYShift;
button.onmouseover = function () {
@ -1454,7 +1455,6 @@
return false;
}
}
button.className = button.className.replace(/ disabled/g, "");
}
else {
image.style.backgroundPosition = button.XShift + " " + disabledYShift;