Fixed comments extensions
This commit is contained in:
parent
6f6c10c601
commit
9af0858186
@ -317,6 +317,7 @@ define([
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
eventMgr.addListener('onLayoutResize', adjustCursorPosition);
|
eventMgr.addListener('onLayoutResize', adjustCursorPosition);
|
||||||
|
editor.adjustCursorPosition = adjustCursorPosition;
|
||||||
|
|
||||||
var textContent;
|
var textContent;
|
||||||
function setValue(value) {
|
function setValue(value) {
|
||||||
|
@ -28,7 +28,7 @@ define([
|
|||||||
"extensions/toc",
|
"extensions/toc",
|
||||||
"extensions/mathJax",
|
"extensions/mathJax",
|
||||||
"extensions/emailConverter",
|
"extensions/emailConverter",
|
||||||
"extensions/scrollLink",
|
"extensions/scrollSync",
|
||||||
"extensions/buttonSync",
|
"extensions/buttonSync",
|
||||||
"extensions/buttonPublish",
|
"extensions/buttonPublish",
|
||||||
"extensions/buttonStat",
|
"extensions/buttonStat",
|
||||||
|
@ -69,11 +69,6 @@ define([
|
|||||||
var newCommentElt = crel('a', {
|
var newCommentElt = crel('a', {
|
||||||
class: 'discussion icon-comment new'
|
class: 'discussion icon-comment new'
|
||||||
});
|
});
|
||||||
var cursorY;
|
|
||||||
comments.onCursorCoordinates = function(x, y) {
|
|
||||||
cursorY = y;
|
|
||||||
setCommentEltCoordinates(newCommentElt, cursorY);
|
|
||||||
};
|
|
||||||
|
|
||||||
function Context(commentElt, fileDesc) {
|
function Context(commentElt, fileDesc) {
|
||||||
this.commentElt = commentElt;
|
this.commentElt = commentElt;
|
||||||
@ -124,6 +119,7 @@ define([
|
|||||||
offsetMap = {};
|
offsetMap = {};
|
||||||
var discussionList = _.values(currentFileDesc.discussionList);
|
var discussionList = _.values(currentFileDesc.discussionList);
|
||||||
function refreshOne() {
|
function refreshOne() {
|
||||||
|
var coordinates;
|
||||||
if(discussionList.length === 0) {
|
if(discussionList.length === 0) {
|
||||||
// Remove outdated commentElt
|
// Remove outdated commentElt
|
||||||
_.filter(commentEltMap, function(commentElt, discussionIndex) {
|
_.filter(commentEltMap, function(commentElt, discussionIndex) {
|
||||||
@ -133,8 +129,9 @@ define([
|
|||||||
delete commentEltMap[commentElt.discussionIndex];
|
delete commentEltMap[commentElt.discussionIndex];
|
||||||
});
|
});
|
||||||
// Move newCommentElt
|
// Move newCommentElt
|
||||||
setCommentEltCoordinates(newCommentElt, cursorY);
|
|
||||||
if(currentContext && !currentContext.discussionIndex) {
|
if(currentContext && !currentContext.discussionIndex) {
|
||||||
|
coordinates = selectionMgr.getCoordinates(currentContext.getDiscussion().selectionEnd);
|
||||||
|
setCommentEltCoordinates(newCommentElt, coordinates.y);
|
||||||
inputElt.scrollTop += parseInt(newCommentElt.style.top) - inputElt.scrollTop - inputElt.offsetHeight * 3 / 4;
|
inputElt.scrollTop += parseInt(newCommentElt.style.top) - inputElt.scrollTop - inputElt.offsetHeight * 3 / 4;
|
||||||
movePopover(newCommentElt);
|
movePopover(newCommentElt);
|
||||||
}
|
}
|
||||||
@ -163,7 +160,7 @@ define([
|
|||||||
className += isReplied ? ' replied' : ' added';
|
className += isReplied ? ' replied' : ' added';
|
||||||
commentElt.className = className;
|
commentElt.className = className;
|
||||||
commentElt.discussionIndex = discussion.discussionIndex;
|
commentElt.discussionIndex = discussion.discussionIndex;
|
||||||
var coordinates = selectionMgr.getCoordinates(discussion.selectionEnd);
|
coordinates = selectionMgr.getCoordinates(discussion.selectionEnd);
|
||||||
var lineIndex = setCommentEltCoordinates(commentElt, coordinates.y);
|
var lineIndex = setCommentEltCoordinates(commentElt, coordinates.y);
|
||||||
offsetMap[lineIndex] = (offsetMap[lineIndex] || 0) + 1;
|
offsetMap[lineIndex] = (offsetMap[lineIndex] || 0) + 1;
|
||||||
|
|
||||||
@ -325,8 +322,10 @@ define([
|
|||||||
commentList: []
|
commentList: []
|
||||||
};
|
};
|
||||||
currentFileDesc.newDiscussion = discussion;
|
currentFileDesc.newDiscussion = discussion;
|
||||||
|
var coordinates = selectionMgr.getCoordinates(selectionStart);
|
||||||
|
setCommentEltCoordinates(newCommentElt, coordinates.y);
|
||||||
}
|
}
|
||||||
context.selectionRange = selectionMgr.setSelectionStartEnd(discussion.selectionStart, discussion.selectionEnd, undefined, true);
|
context.selectionRange = selectionMgr.createRange(discussion.selectionStart, discussion.selectionEnd);
|
||||||
inputElt.scrollTop += parseInt(evt.target.style.top) - inputElt.scrollTop - inputElt.offsetHeight * 3 / 4;
|
inputElt.scrollTop += parseInt(evt.target.style.top) - inputElt.scrollTop - inputElt.offsetHeight * 3 / 4;
|
||||||
|
|
||||||
}).on('shown.bs.popover', '#wmd-input > .editor-margin', function(evt) {
|
}).on('shown.bs.popover', '#wmd-input > .editor-margin', function(evt) {
|
||||||
@ -351,7 +350,8 @@ define([
|
|||||||
case 27:
|
case 27:
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
closeCurrentPopover();
|
closeCurrentPopover();
|
||||||
inputElt.focus();
|
editor.focus();
|
||||||
|
editor.adjustCursorPosition();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -445,7 +445,7 @@ define([
|
|||||||
var $commentElt = $newCommentElt;
|
var $commentElt = $newCommentElt;
|
||||||
if(currentContext) {
|
if(currentContext) {
|
||||||
if(!currentContext.discussionIndex) {
|
if(!currentContext.discussionIndex) {
|
||||||
$commentElt = $(_.first(sortedCommentEltList) || newCommentElt);
|
$commentElt = $(_.first(sortedCommentEltList));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var curentIndex = -1;
|
var curentIndex = -1;
|
||||||
@ -455,13 +455,14 @@ define([
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$commentElt = $(sortedCommentEltList[(curentIndex + 1) % sortedCommentEltList.length]);
|
$commentElt = $(sortedCommentEltList[(curentIndex + 1)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(currentContext && currentContext.commentElt === $commentElt[0]) {
|
if($commentElt.length === 0) {
|
||||||
// Close the popover properly
|
// Close the popover properly
|
||||||
closeCurrentPopover();
|
closeCurrentPopover();
|
||||||
inputElt.focus();
|
editor.focus();
|
||||||
|
editor.adjustCursorPosition();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$commentElt.click();
|
$commentElt.click();
|
||||||
|
@ -2,23 +2,23 @@ define([
|
|||||||
"jquery",
|
"jquery",
|
||||||
"underscore",
|
"underscore",
|
||||||
"classes/Extension",
|
"classes/Extension",
|
||||||
"text!html/scrollLinkSettingsBlock.html"
|
"text!html/scrollSyncSettingsBlock.html"
|
||||||
], function($, _, Extension, scrollLinkSettingsBlockHTML) {
|
], function($, _, Extension, scrollSyncSettingsBlockHTML) {
|
||||||
|
|
||||||
var scrollLink = new Extension("scrollLink", "Scroll Link", true, true);
|
var scrollSync = new Extension("scrollSync", "Scroll Link", true, true);
|
||||||
scrollLink.settingsBlock = scrollLinkSettingsBlockHTML;
|
scrollSync.settingsBlock = scrollSyncSettingsBlockHTML;
|
||||||
|
|
||||||
$.easing.easeOutSine = function( p ) {
|
$.easing.easeOutSine = function( p ) {
|
||||||
return Math.cos((1 - p) * Math.PI / 2 );
|
return Math.cos((1 - p) * Math.PI / 2 );
|
||||||
};
|
};
|
||||||
|
|
||||||
var sectionList;
|
var sectionList;
|
||||||
scrollLink.onSectionsCreated = function(sectionListParam) {
|
scrollSync.onSectionsCreated = function(sectionListParam) {
|
||||||
sectionList = sectionListParam;
|
sectionList = sectionListParam;
|
||||||
};
|
};
|
||||||
|
|
||||||
var isPreviewVisible = true;
|
var isPreviewVisible = true;
|
||||||
scrollLink.onPreviewToggle = function(isOpen) {
|
scrollSync.onPreviewToggle = function(isOpen) {
|
||||||
isPreviewVisible = isOpen;
|
isPreviewVisible = isOpen;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ define([
|
|||||||
// apply Scroll Link (-10 to have a gap > 9px)
|
// apply Scroll Link (-10 to have a gap > 9px)
|
||||||
lastEditorScrollTop = -10;
|
lastEditorScrollTop = -10;
|
||||||
lastPreviewScrollTop = -10;
|
lastPreviewScrollTop = -10;
|
||||||
doScrollLink();
|
doScrollSync();
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
var isScrollEditor = false;
|
var isScrollEditor = false;
|
||||||
@ -99,7 +99,7 @@ define([
|
|||||||
var isEditorMoving = false;
|
var isEditorMoving = false;
|
||||||
var isPreviewMoving = false;
|
var isPreviewMoving = false;
|
||||||
var scrollingHelper = $('<div>');
|
var scrollingHelper = $('<div>');
|
||||||
var doScrollLink = _.throttle(function() {
|
var doScrollSync = _.throttle(function() {
|
||||||
if(!isPreviewVisible || mdSectionList.length === 0 || mdSectionList.length !== htmlSectionList.length) {
|
if(!isPreviewVisible || mdSectionList.length === 0 || mdSectionList.length !== htmlSectionList.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -140,12 +140,12 @@ define([
|
|||||||
lastPreviewScrollTop = previewScrollTop;
|
lastPreviewScrollTop = previewScrollTop;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scrollingHelper.stop('scrollLinkFx', true).css('value', 0).animate({
|
scrollingHelper.stop('scrollSyncFx', true).css('value', 0).animate({
|
||||||
value: destScrollTop - previewScrollTop
|
value: destScrollTop - previewScrollTop
|
||||||
}, {
|
}, {
|
||||||
easing: 'easeOutSine',
|
easing: 'easeOutSine',
|
||||||
duration: 200,
|
duration: 200,
|
||||||
queue: 'scrollLinkFx',
|
queue: 'scrollSyncFx',
|
||||||
step: function(now) {
|
step: function(now) {
|
||||||
isPreviewMoving = true;
|
isPreviewMoving = true;
|
||||||
lastPreviewScrollTop = previewScrollTop + now;
|
lastPreviewScrollTop = previewScrollTop + now;
|
||||||
@ -156,7 +156,7 @@ define([
|
|||||||
isPreviewMoving = false;
|
isPreviewMoving = false;
|
||||||
}, 10);
|
}, 10);
|
||||||
},
|
},
|
||||||
}).dequeue('scrollLinkFx');
|
}).dequeue('scrollSyncFx');
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(isScrollPreview === true) {
|
else if(isScrollPreview === true) {
|
||||||
@ -176,12 +176,12 @@ define([
|
|||||||
lastEditorScrollTop = editorScrollTop;
|
lastEditorScrollTop = editorScrollTop;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scrollingHelper.stop('scrollLinkFx', true).css('value', 0).animate({
|
scrollingHelper.stop('scrollSyncFx', true).css('value', 0).animate({
|
||||||
value: destScrollTop - editorScrollTop
|
value: destScrollTop - editorScrollTop
|
||||||
}, {
|
}, {
|
||||||
easing: 'easeOutSine',
|
easing: 'easeOutSine',
|
||||||
duration: 200,
|
duration: 200,
|
||||||
queue: 'scrollLinkFx',
|
queue: 'scrollSyncFx',
|
||||||
step: function(now) {
|
step: function(now) {
|
||||||
isEditorMoving = true;
|
isEditorMoving = true;
|
||||||
lastEditorScrollTop = editorScrollTop + now;
|
lastEditorScrollTop = editorScrollTop + now;
|
||||||
@ -192,21 +192,21 @@ define([
|
|||||||
isEditorMoving = false;
|
isEditorMoving = false;
|
||||||
}, 10);
|
}, 10);
|
||||||
},
|
},
|
||||||
}).dequeue('scrollLinkFx');
|
}).dequeue('scrollSyncFx');
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
scrollLink.onLayoutResize = function() {
|
scrollSync.onLayoutResize = function() {
|
||||||
isScrollEditor = true;
|
isScrollEditor = true;
|
||||||
buildSections();
|
buildSections();
|
||||||
};
|
};
|
||||||
|
|
||||||
scrollLink.onFileClosed = function() {
|
scrollSync.onFileClosed = function() {
|
||||||
mdSectionList = [];
|
mdSectionList = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
var scrollAdjust = false;
|
var scrollAdjust = false;
|
||||||
scrollLink.onReady = function() {
|
scrollSync.onReady = function() {
|
||||||
$previewElt = $(".preview-container");
|
$previewElt = $(".preview-container");
|
||||||
$editorElt = $("#wmd-input");
|
$editorElt = $("#wmd-input");
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ define([
|
|||||||
if(isPreviewMoving === false && scrollAdjust === false) {
|
if(isPreviewMoving === false && scrollAdjust === false) {
|
||||||
isScrollPreview = true;
|
isScrollPreview = true;
|
||||||
isScrollEditor = false;
|
isScrollEditor = false;
|
||||||
doScrollLink();
|
doScrollSync();
|
||||||
}
|
}
|
||||||
scrollAdjust = false;
|
scrollAdjust = false;
|
||||||
});
|
});
|
||||||
@ -222,13 +222,13 @@ define([
|
|||||||
if(isEditorMoving === false) {
|
if(isEditorMoving === false) {
|
||||||
isScrollEditor = true;
|
isScrollEditor = true;
|
||||||
isScrollPreview = false;
|
isScrollPreview = false;
|
||||||
doScrollLink();
|
doScrollSync();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var $previewContentsElt;
|
var $previewContentsElt;
|
||||||
scrollLink.onPagedownConfigure = function(editor) {
|
scrollSync.onPagedownConfigure = function(editor) {
|
||||||
$previewContentsElt = $("#preview-contents");
|
$previewContentsElt = $("#preview-contents");
|
||||||
editor.getConverter().hooks.chain("postConversion", function(text) {
|
editor.getConverter().hooks.chain("postConversion", function(text) {
|
||||||
// To avoid losing scrolling position before elements are fully loaded
|
// To avoid losing scrolling position before elements are fully loaded
|
||||||
@ -237,7 +237,7 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
scrollLink.onPreviewFinished = function() {
|
scrollSync.onPreviewFinished = function() {
|
||||||
// Now set the correct height
|
// Now set the correct height
|
||||||
var previousHeight = $previewContentsElt.height();
|
var previousHeight = $previewContentsElt.height();
|
||||||
$previewContentsElt.height("auto");
|
$previewContentsElt.height("auto");
|
||||||
@ -250,5 +250,5 @@ define([
|
|||||||
buildSections();
|
buildSections();
|
||||||
};
|
};
|
||||||
|
|
||||||
return scrollLink;
|
return scrollSync;
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user