Added support of titleReminder and handle when change occur on offline

This commit is contained in:
Wu Cheng-Han 2015-09-25 18:48:45 +08:00
parent 529c5f6c13
commit 2b57b1849f

View file

@ -352,9 +352,32 @@ ui.area.codemirror.on('touchstart', function () {
idle.onActive(); idle.onActive();
}); });
var haveUnreadChanges = false;
function setHaveUnreadChanges(bool) {
if (!loaded) return;
if (bool && (idle.isAway || Visibility.hidden())) {
haveUnreadChanges = true;
} else if (!bool && !idle.isAway && !Visibility.hidden()) {
haveUnreadChanges = false;
}
}
function updateTitleReminder() {
if (!loaded) return;
if (haveUnreadChanges) {
document.title = '• ' + renderTitle(ui.area.view);
} else {
document.title = renderTitle(ui.area.view);
}
}
function idleStateChange() { function idleStateChange() {
emitUserStatus(); emitUserStatus();
updateOnlineStatus(); updateOnlineStatus();
if (!idle.isAway)
setHaveUnreadChanges(false);
updateTitleReminder();
} }
function setNeedRefresh() { function setNeedRefresh() {
@ -381,7 +404,9 @@ Visibility.change(function (e, state) {
editor.focus(); editor.focus();
wasFocus = false; wasFocus = false;
} }
setHaveUnreadChanges(false);
} }
updateTitleReminder();
}); });
//when page ready //when page ready
@ -867,8 +892,8 @@ function generateScrollspy() {
ui.toc.affix.hide(); ui.toc.affix.hide();
ui.toc.toc.show(); ui.toc.toc.show();
} }
$(document.body).scroll(); //$(document.body).scroll();
ui.area.view.scroll(); //ui.area.view.scroll();
} }
function updateScrollspy() { function updateScrollspy() {
@ -1674,24 +1699,19 @@ editor.on('beforeChange', function (cm, change) {
} }
var isIgnoreEmitEvent = (ignoreEmitEvents.indexOf(change.origin) != -1); var isIgnoreEmitEvent = (ignoreEmitEvents.indexOf(change.origin) != -1);
if (!isIgnoreEmitEvent) { if (!isIgnoreEmitEvent) {
switch (permission) { if (!havePermission()) {
case "freely": change.canceled = true;
//na $('.signin-modal').modal('show');
break; }
case "editable": } else {
if (!personalInfo.login) { if (change.origin == 'ignoreHistory') {
change.canceled = true; setHaveUnreadChanges(true);
$('.signin-modal').modal('show'); updateTitleReminder();
}
break;
case "locked":
if (personalInfo.userid != owner) {
change.canceled = true;
$('.locked-modal').modal('show');
}
break;
} }
} }
if (cmClient && !socket.connected)
cmClient.editorAdapter.ignoreNextChange = true;
});
editor.on('changes', function (cm, changes) { editor.on('changes', function (cm, changes) {
updateHistory(); updateHistory();
preventSyncScroll = true; preventSyncScroll = true;
@ -1836,6 +1856,8 @@ function updateViewInner() {
isDirty = false; isDirty = false;
clearMap(); clearMap();
//buildMap(); //buildMap();
updateTitleReminder();
}
var updateHistoryDebounce = 600; var updateHistoryDebounce = 600;