diff options
author | Cheng-Han, Wu | 2016-03-15 10:45:02 +0800 |
---|---|---|
committer | Cheng-Han, Wu | 2016-03-15 10:45:02 +0800 |
commit | 526f5c7e2eeee21ef9d87bda8668903844e95f53 (patch) | |
tree | a6d78ff929f9424b33fcfb51a2a44b79f7bec4ac | |
parent | 30d194bba4a49867acba9839a2f7a7c89240203b (diff) |
Improved update last info methods, only change DOM when necessary
Diffstat (limited to '')
-rw-r--r-- | public/js/extra.js | 24 | ||||
-rw-r--r-- | public/js/index.js | 22 | ||||
-rw-r--r-- | public/views/body.ejs | 2 |
3 files changed, 31 insertions, 17 deletions
diff --git a/public/js/extra.js b/public/js/extra.js index dc3eac3e..a72ca5e1 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -14,16 +14,20 @@ function updateLastChange() { } setInterval(updateLastChange, 60000); -function updateLastChangeUser(data) { - if (data.lastchangeuserprofile) { - var icon = lastchangeui.user.children('i'); - icon.attr('title', data.lastchangeuserprofile.name).tooltip('fixTitle'); - icon.attr('style', 'background-image:url(' + data.lastchangeuserprofile.photo + ')'); - lastchangeui.user.show(); - lastchangeui.nouser.hide(); - } else { - lastchangeui.user.hide(); - lastchangeui.nouser.show(); +var lastchangeuser = null; +var lastchangeuserprofile = null; +function updateLastChangeUser() { + if (lastchangeui) { + if (lastchangeuser && lastchangeuserprofile) { + var icon = lastchangeui.user.children('i'); + icon.attr('title', lastchangeuserprofile.name).tooltip('fixTitle'); + icon.attr('style', 'background-image:url(' + lastchangeuserprofile.photo + ')'); + lastchangeui.user.show(); + lastchangeui.nouser.hide(); + } else { + lastchangeui.user.hide(); + lastchangeui.nouser.show(); + } } } diff --git a/public/js/index.js b/public/js/index.js index 4625af05..1656e680 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1481,10 +1481,21 @@ socket.on('version', function (data) { if (data != version) setNeedRefresh(); }); +function updateLastInfo(data) { + //console.log(data); + if (lastchangetime !== data.updatetime) { + lastchangetime = data.updatetime; + updateLastChange(); + } + if (lastchangeuser !== data.lastchangeuser) { + lastchangeuser = data.lastchangeuser; + lastchangeuserprofile = data.lastchangeuserprofile; + updateLastChangeUser(); + } +} socket.on('check', function (data) { - lastchangetime = data.updatetime; - updateLastChange(); - updateLastChangeUser(data); + //console.log(data); + updateLastInfo(data); }); socket.on('permission', function (data) { updatePermission(data.permission); @@ -1494,14 +1505,13 @@ var otk = null; var owner = null; var permission = null; socket.on('refresh', function (data) { + //console.log(data); docmaxlength = data.docmaxlength; editor.setOption("maxLength", docmaxlength); otk = data.otk; owner = data.owner; updatePermission(data.permission); - lastchangetime = data.updatetime; - updateLastChange(); - updateLastChangeUser(data); + updateLastInfo(data); if (!loaded) { var nocontent = editor.getValue().length <= 0; if (nocontent) { diff --git a/public/views/body.ejs b/public/views/body.ejs index 805c11e1..54562ea6 100644 --- a/public/views/body.ejs +++ b/public/views/body.ejs @@ -6,7 +6,7 @@ <div class="ui-infobar container-fluid unselectable hidden-print"> <small> <span> - <span class="ui-lastchangeuser"> <i class="ui-user-icon small" data-toggle="tooltip" data-placement="right"></i></span> + <span class="ui-lastchangeuser" style="display: none;"> <i class="ui-user-icon small" data-toggle="tooltip" data-placement="right"></i></span> <span class="ui-no-lastchangeuser"> <i class="fa fa-clock-o"></i></span> <span class="text-uppercase">changed</span> <span class="ui-lastchange text-uppercase"></span> |