Skip to content

Commit

Permalink
如果页面处于 Active 状态,直接载入新的回复,而不是显示提示连接;
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Feb 2, 2016
1 parent e6426c8 commit a2aa101
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/assets/javascripts/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
AppView = Backbone.View.extend
el: "body"
repliesPerPage: 50
windowInActive: true

events:
"click a.likeable": "likeable"
Expand Down Expand Up @@ -68,6 +69,9 @@ AppView = Backbone.View.extend
$(el.target).parent().parent().submit()
return false

$(window).off "blur.inactive focus.inactive"
$(window).on "blur.inactive focus.inactive", @updateWindowActiveState

initForDesktopView : () ->
return if typeof(app_mobile) != "undefined"
$("a[rel=twipsy]").tooltip()
Expand Down Expand Up @@ -215,6 +219,18 @@ AppView = Backbone.View.extend
img.attr('src', currentSrc.split('?')[0] + '?' + (new Date()).getTime())
return false

updateWindowActiveState: (e) ->
prevType = $(this).data("prevType")

if prevType != e.type
switch (e.type)
when "blur"
@windowInActive = false
when "focus"
@windowInActive = true

$(this).data("prevType", e.type)

window.App =
locale: 'zh-CN'
notifier : null
Expand Down
5 changes: 4 additions & 1 deletion app/assets/javascripts/topics.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ window.TopicView = Backbone.View.extend
if json.user_id == App.current_user_id
return false
if json.action == 'create'
$(".notify-updated").show()
if App.windowInActive
@updateReplies()
else
$(".notify-updated").show()

followCurrentTopic: ->
@perform 'follow', topic_id: Topics.topic_id
Expand Down

0 comments on commit a2aa101

Please sign in to comment.