summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorWu Cheng-Han2015-09-25 18:48:45 +0800
committerWu Cheng-Han2015-09-25 18:48:45 +0800
commit2b57b1849fa1598f013f6d42b6a9216d9b0453b4 (patch)
treef3edc93986471b0f560e5537feae29af599766e5 /public
parent529c5f6c1356206ccb87f30db35c3886a17f5ad3 (diff)
Added support of titleReminder and handle when change occur on offline
Diffstat (limited to 'public')
-rw-r--r--public/js/index.js58
1 files changed, 40 insertions, 18 deletions
diff --git a/public/js/index.js b/public/js/index.js
index 41d4c5e5..40e5c5df 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -352,9 +352,32 @@ ui.area.codemirror.on('touchstart', function () {
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() {
emitUserStatus();
updateOnlineStatus();
+ if (!idle.isAway)
+ setHaveUnreadChanges(false);
+ updateTitleReminder();
}
function setNeedRefresh() {
@@ -381,7 +404,9 @@ Visibility.change(function (e, state) {
editor.focus();
wasFocus = false;
}
+ setHaveUnreadChanges(false);
}
+ updateTitleReminder();
});
//when page ready
@@ -867,8 +892,8 @@ function generateScrollspy() {
ui.toc.affix.hide();
ui.toc.toc.show();
}
- $(document.body).scroll();
- ui.area.view.scroll();
+ //$(document.body).scroll();
+ //ui.area.view.scroll();
}
function updateScrollspy() {
@@ -1674,24 +1699,19 @@ editor.on('beforeChange', function (cm, change) {
}
var isIgnoreEmitEvent = (ignoreEmitEvents.indexOf(change.origin) != -1);
if (!isIgnoreEmitEvent) {
- switch (permission) {
- case "freely":
- //na
- break;
- case "editable":
- if (!personalInfo.login) {
- change.canceled = true;
- $('.signin-modal').modal('show');
- }
- break;
- case "locked":
- if (personalInfo.userid != owner) {
- change.canceled = true;
- $('.locked-modal').modal('show');
- }
- break;
+ if (!havePermission()) {
+ change.canceled = true;
+ $('.signin-modal').modal('show');
+ }
+ } else {
+ if (change.origin == 'ignoreHistory') {
+ setHaveUnreadChanges(true);
+ updateTitleReminder();
}
}
+ if (cmClient && !socket.connected)
+ cmClient.editorAdapter.ignoreNextChange = true;
+});
editor.on('changes', function (cm, changes) {
updateHistory();
preventSyncScroll = true;
@@ -1836,6 +1856,8 @@ function updateViewInner() {
isDirty = false;
clearMap();
//buildMap();
+ updateTitleReminder();
+}
var updateHistoryDebounce = 600;