mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-27 21:44:21 -04:00
Marked as 0.2.9
This commit is contained in:
parent
4e64583a0b
commit
f7f8c901f4
33 changed files with 2972 additions and 242 deletions
|
@ -3,38 +3,62 @@ var domain = 'change this';
|
|||
var checkAuth = false;
|
||||
var profile = null;
|
||||
var lastLoginState = getLoginState();
|
||||
var lastUserId = getUserId();
|
||||
var loginStateChangeEvent = null;
|
||||
|
||||
function resetCheckAuth() {
|
||||
checkAuth = false;
|
||||
}
|
||||
|
||||
function setLoginState(bool) {
|
||||
function setLoginState(bool, id) {
|
||||
Cookies.set('loginstate', bool, {
|
||||
expires: 14
|
||||
});
|
||||
if (loginStateChangeEvent && bool != lastLoginState)
|
||||
loginStateChangeEvent();
|
||||
if (id) {
|
||||
Cookies.set('userid', id, {
|
||||
expires: 14
|
||||
});
|
||||
} else {
|
||||
Cookies.remove('userid');
|
||||
}
|
||||
lastLoginState = bool;
|
||||
lastUserId = id;
|
||||
checkLoginStateChanged();
|
||||
}
|
||||
|
||||
function checkLoginStateChanged() {
|
||||
if (getLoginState() != lastLoginState || getUserId() != lastUserId) {
|
||||
if(loginStateChangeEvent)
|
||||
loginStateChangeEvent();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getLoginState() {
|
||||
return Cookies.get('loginstate') === "true";
|
||||
}
|
||||
|
||||
function getUserId() {
|
||||
return Cookies.get('userid');
|
||||
}
|
||||
|
||||
function clearLoginState() {
|
||||
Cookies.remove('loginstate');
|
||||
}
|
||||
|
||||
function checkIfAuth(yesCallback, noCallback) {
|
||||
var cookieLoginState = getLoginState();
|
||||
if (checkLoginStateChanged())
|
||||
checkAuth = false;
|
||||
if (!checkAuth || typeof cookieLoginState == 'undefined') {
|
||||
$.get('/me')
|
||||
.done(function (data) {
|
||||
if (data && data.status == 'ok') {
|
||||
profile = data;
|
||||
yesCallback(profile);
|
||||
setLoginState(true);
|
||||
setLoginState(true, data.id);
|
||||
} else {
|
||||
noCallback();
|
||||
setLoginState(false);
|
||||
|
@ -43,8 +67,10 @@ function checkIfAuth(yesCallback, noCallback) {
|
|||
.fail(function () {
|
||||
noCallback();
|
||||
setLoginState(false);
|
||||
})
|
||||
.always(function () {
|
||||
checkAuth = true;
|
||||
});
|
||||
checkAuth = true;
|
||||
} else if (cookieLoginState) {
|
||||
yesCallback(profile);
|
||||
} else {
|
||||
|
|
|
@ -229,6 +229,44 @@ var source = $("#template").html();
|
|||
var template = Handlebars.compile(source);
|
||||
var context = {
|
||||
release: [
|
||||
{
|
||||
version: "0.2.9",
|
||||
tag: "wildfire",
|
||||
date: moment("201505301400", 'YYYYMMDDhhmm').fromNow(),
|
||||
detail: [
|
||||
{
|
||||
title: "Features",
|
||||
item: [
|
||||
"+ Support text auto complete",
|
||||
"+ Support cursor tag and random last name",
|
||||
"+ Support online user list",
|
||||
"+ Support show user info in blockquote"
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "Enhancements",
|
||||
item: [
|
||||
"* Added more code highlighting support",
|
||||
"* Added more continue list support",
|
||||
"* Adjust menu and history filter UI for better UX",
|
||||
"* Adjust sync scoll animte to gain performance",
|
||||
"* Change compression method of dynamic data",
|
||||
"* Optimized render script"
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "Fixes",
|
||||
item: [
|
||||
"* Access history fallback might get wrong",
|
||||
"* Sync scroll not accurate",
|
||||
"* Sync scroll reach bottom range too much",
|
||||
"* Detect login state change not accurate",
|
||||
"* Detect editor focus not accurate",
|
||||
"* Server not handle some editor events"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
version: "0.2.8",
|
||||
tag: "flame",
|
||||
|
|
|
@ -65,6 +65,7 @@ function finishView(view) {
|
|||
try {
|
||||
for (var i = 0; i < mathjaxdivs.length; i++) {
|
||||
MathJax.Hub.Queue(["Typeset", MathJax.Hub, mathjaxdivs[i].innerHTML]);
|
||||
MathJax.Hub.Queue(viewAjaxCallback);
|
||||
$(mathjaxdivs[i]).removeClass("mathjax");
|
||||
}
|
||||
} catch(err) {
|
||||
|
@ -101,6 +102,18 @@ function finishView(view) {
|
|||
//render title
|
||||
document.title = renderTitle(view);
|
||||
}
|
||||
|
||||
//regex for blockquote
|
||||
var spaceregex = /\s*/;
|
||||
var notinhtmltagregex = /(?![^<]*>|[^<>]*<\/)/;
|
||||
var coloregex = /\[color=([#|\(|\)|\s|\,|\w]*)\]/;
|
||||
coloregex = new RegExp(coloregex.source + notinhtmltagregex.source, "g");
|
||||
var nameregex = /\[name=([-|_|\s|\w]*)\]/;
|
||||
var timeregex = /\[time=([:|,|+|-|\(|\)|\s|\w]*)\]/;
|
||||
var nameandtimeregex = new RegExp(nameregex.source + spaceregex.source + timeregex.source + notinhtmltagregex.source, "g");
|
||||
nameregex = new RegExp(nameregex.source + notinhtmltagregex.source, "g");
|
||||
timeregex = new RegExp(timeregex.source + notinhtmltagregex.source, "g");
|
||||
|
||||
//only static transform should be here
|
||||
function postProcess(code) {
|
||||
var result = $('<div>' + code + '</div>');
|
||||
|
@ -121,6 +134,20 @@ function postProcess(code) {
|
|||
lis[i].setAttribute('class', 'task-list-item');
|
||||
}
|
||||
}
|
||||
//blockquote
|
||||
var blockquote = result.find("blockquote");
|
||||
blockquote.each(function (key, value) {
|
||||
var html = $(value).html();
|
||||
html = html.replace(coloregex, '<span class="color" data-color="$1"></span>');
|
||||
html = html.replace(nameandtimeregex, '<small><i class="fa fa-user"></i> $1 <i class="fa fa-clock-o"></i> $2</small>');
|
||||
html = html.replace(nameregex, '<small><i class="fa fa-user"></i> $1</small>');
|
||||
html = html.replace(timeregex, '<small><i class="fa fa-clock-o"></i> $1</small>');
|
||||
$(value).html(html);
|
||||
});
|
||||
var blockquotecolor = result.find("blockquote .color");
|
||||
blockquotecolor.each(function (key, value) {
|
||||
$(value).closest("blockquote").css('border-left-color', $(value).attr('data-color'));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -195,7 +222,7 @@ function highlightRender(code, lang) {
|
|||
if (/\=$/.test(lang)) {
|
||||
var lines = result.value.split('\n');
|
||||
var linenumbers = [];
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
for (var i = 0; i < lines.length - 1; i++) {
|
||||
linenumbers[i] = "<div class='linenumber'>" + (i + 1) + "</div>";
|
||||
}
|
||||
var linegutter = "<div class='gutter'>" + linenumbers.join('\n') + "</div>";
|
||||
|
|
|
@ -47,7 +47,7 @@ function saveHistoryToStorage(notehistory) {
|
|||
if (store.enabled)
|
||||
store.set('notehistory', JSON.stringify(notehistory));
|
||||
else
|
||||
saveHistoryToCookie(notehistory);
|
||||
saveHistoryToStorage(notehistory);
|
||||
}
|
||||
|
||||
function saveHistoryToCookie(notehistory) {
|
||||
|
@ -146,11 +146,14 @@ function writeHistoryToServer(view) {
|
|||
} catch (err) {
|
||||
var notehistory = [];
|
||||
}
|
||||
if(!notehistory)
|
||||
notehistory = [];
|
||||
|
||||
var newnotehistory = generateHistory(view, notehistory);
|
||||
saveHistoryToServer(newnotehistory);
|
||||
})
|
||||
.fail(function () {
|
||||
writeHistoryToCookie(view);
|
||||
writeHistoryToStorage(view);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -160,7 +163,9 @@ function writeHistoryToCookie(view) {
|
|||
} catch (err) {
|
||||
var notehistory = [];
|
||||
}
|
||||
|
||||
if(!notehistory)
|
||||
notehistory = [];
|
||||
|
||||
var newnotehistory = generateHistory(view, notehistory);
|
||||
saveHistoryToCookie(newnotehistory);
|
||||
}
|
||||
|
@ -174,6 +179,9 @@ function writeHistoryToStorage(view) {
|
|||
var notehistory = data;
|
||||
} else
|
||||
var notehistory = [];
|
||||
if(!notehistory)
|
||||
notehistory = [];
|
||||
|
||||
var newnotehistory = generateHistory(view, notehistory);
|
||||
saveHistoryToStorage(newnotehistory);
|
||||
} else {
|
||||
|
@ -241,7 +249,7 @@ function getServerHistory(callback) {
|
|||
}
|
||||
})
|
||||
.fail(function () {
|
||||
getCookieHistory(callback);
|
||||
getStorageHistory(callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -282,7 +290,7 @@ function parseServerToHistory(list, callback) {
|
|||
}
|
||||
})
|
||||
.fail(function () {
|
||||
parseCookieToHistory(list, callback);
|
||||
parseStorageToHistory(list, callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -144,10 +144,14 @@ md.renderer.rules.code = function (tokens, idx /*, options, env */ ) {
|
|||
return '<code>' + Remarkable.utils.escapeHtml(tokens[idx].content) + '</code>';
|
||||
};
|
||||
|
||||
//var editorScrollThrottle = 100;
|
||||
var buildMapThrottle = 100;
|
||||
|
||||
var viewScrolling = false;
|
||||
var viewScrollingDelay = 200;
|
||||
var viewScrollingTimer = null;
|
||||
|
||||
//editor.on('scroll', _.throttle(syncScrollToView, editorScrollThrottle));
|
||||
editor.on('scroll', syncScrollToView);
|
||||
ui.area.view.on('scroll', function () {
|
||||
viewScrolling = true;
|
||||
|
@ -168,10 +172,12 @@ function clearMap() {
|
|||
lineHeightMap = null;
|
||||
}
|
||||
|
||||
var buildMap = _.throttle(buildMapInner, buildMapThrottle);
|
||||
|
||||
// Build offsets for each line (lines can be wrapped)
|
||||
// That's a bit dirty to process each line everytime, but ok for demo.
|
||||
// Optimizations are required only for big texts.
|
||||
function buildMap() {
|
||||
function buildMapInner(syncBack) {
|
||||
var i, offset, nonEmptyList, pos, a, b, _lineHeightMap, linesCount,
|
||||
acc, sourceLikeDiv, textarea = ui.area.codemirror,
|
||||
wrap = $('.CodeMirror-wrap pre'),
|
||||
|
@ -182,8 +188,6 @@ function buildMap() {
|
|||
visibility: 'hidden',
|
||||
height: 'auto',
|
||||
width: wrap.width(),
|
||||
padding: wrap.css('padding'),
|
||||
margin: wrap.css('margin'),
|
||||
'font-size': textarea.css('font-size'),
|
||||
'font-family': textarea.css('font-family'),
|
||||
'line-height': textarea.css('line-height'),
|
||||
|
@ -198,21 +202,23 @@ function buildMap() {
|
|||
_lineHeightMap = [];
|
||||
|
||||
acc = 0;
|
||||
editor.getValue().split('\n').forEach(function (str) {
|
||||
var lines = editor.getValue().split('\n');
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
var str = lines[i];
|
||||
var h, lh;
|
||||
|
||||
_lineHeightMap.push(acc);
|
||||
|
||||
if (str.length === 0) {
|
||||
acc++;
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
sourceLikeDiv.text(str);
|
||||
h = parseFloat(sourceLikeDiv.css('height'));
|
||||
lh = parseFloat(sourceLikeDiv.css('line-height'));
|
||||
acc += Math.round(h / lh);
|
||||
});
|
||||
}
|
||||
sourceLikeDiv.remove();
|
||||
_lineHeightMap.push(acc);
|
||||
linesCount = acc;
|
||||
|
@ -224,9 +230,10 @@ function buildMap() {
|
|||
nonEmptyList.push(0);
|
||||
_scrollMap[0] = 0;
|
||||
|
||||
ui.area.markdown.find('.part').each(function (n, el) {
|
||||
var $el = $(el),
|
||||
t = $el.data('startline') - 1;
|
||||
var parts = ui.area.markdown.find('.part').toArray();
|
||||
for (i = 0; i < parts.length; i++) {
|
||||
var $el = $(parts[i]),
|
||||
t = $el.attr('data-startline') - 1;
|
||||
if (t === '') {
|
||||
return;
|
||||
}
|
||||
|
@ -235,7 +242,7 @@ function buildMap() {
|
|||
nonEmptyList.push(t);
|
||||
}
|
||||
_scrollMap[t] = Math.round($el.offset().top + offset);
|
||||
});
|
||||
}
|
||||
|
||||
nonEmptyList.push(linesCount);
|
||||
_scrollMap[linesCount] = ui.area.view[0].scrollHeight;
|
||||
|
@ -256,6 +263,9 @@ function buildMap() {
|
|||
|
||||
scrollMap = _scrollMap;
|
||||
lineHeightMap = _lineHeightMap;
|
||||
|
||||
if(loaded && syncBack)
|
||||
syncScrollToView();
|
||||
}
|
||||
|
||||
function getPartByEditorLineNo(lineNo) {
|
||||
|
@ -290,20 +300,20 @@ function getEditorLineNoByTop(top) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function syncScrollToView(_lineNo) {
|
||||
function syncScrollToView(event, _lineNo) {
|
||||
if (currentMode != modeType.both) return;
|
||||
var lineNo, posTo;
|
||||
var scrollInfo = editor.getScrollInfo();
|
||||
if (!scrollMap || !lineHeightMap) {
|
||||
buildMap();
|
||||
buildMap(true);
|
||||
return;
|
||||
}
|
||||
if (typeof _lineNo != "number") {
|
||||
if (!_lineNo) {
|
||||
var topDiffPercent, posToNextDiff;
|
||||
var textHeight = editor.defaultTextHeight();
|
||||
lineNo = Math.floor(scrollInfo.top / textHeight);
|
||||
var lineCount = editor.lineCount();
|
||||
var lastLineHeight = editor.getLineHandle(lineCount - 1).height;
|
||||
//if reach last line, then scroll to end
|
||||
if (scrollInfo.top + scrollInfo.clientHeight >= scrollInfo.height - lastLineHeight) {
|
||||
//if reach bottom, then scroll to end
|
||||
if (scrollInfo.top + scrollInfo.clientHeight >= scrollInfo.height - defaultTextHeight) {
|
||||
posTo = ui.area.view[0].scrollHeight - ui.area.view.height();
|
||||
} else {
|
||||
topDiffPercent = (scrollInfo.top % textHeight) / textHeight;
|
||||
|
@ -316,12 +326,18 @@ function syncScrollToView(_lineNo) {
|
|||
posTo = scrollMap[lineHeightMap[_lineNo]];
|
||||
}
|
||||
var posDiff = Math.abs(ui.area.view.scrollTop() - posTo);
|
||||
var duration = posDiff / 50;
|
||||
ui.area.view.stop(true, true).animate({
|
||||
scrollTop: posTo
|
||||
}, duration >= 100 ? duration : 100, "linear");
|
||||
/*
|
||||
if (posDiff > scrollInfo.clientHeight / 5) {
|
||||
var duration = posDiff / 50;
|
||||
ui.area.view.stop(true).animate({
|
||||
ui.area.view.stop(true, true).animate({
|
||||
scrollTop: posTo
|
||||
}, duration >= 50 ? duration : 100, "linear");
|
||||
}, duration >= 100 ? duration : 100, "linear");
|
||||
} else {
|
||||
ui.area.view.stop(true).scrollTop(posTo);
|
||||
ui.area.view.stop(true, true).scrollTop(posTo);
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue