Commit dc55127c1dce5f3563a090f65f20b689749f5297

Authored by Dmitriy Zaporozhets
2 parents c7dc20c1 c8cf90d2

Merge branch 'refresh_unless_hidden' into 'master'

Refresh Notes unless the tab is hidden
@@ -7,6 +7,7 @@ v 6.9.0 @@ -7,6 +7,7 @@ v 6.9.0
7 - Add ability to set different ssh host, if different from http/https 7 - Add ability to set different ssh host, if different from http/https
8 - Fix syntax highlighting for code comments blocks 8 - Fix syntax highlighting for code comments blocks
9 - Improve comments loading logic 9 - Improve comments loading logic
  10 + - Stop refreshing comments when the tab is hidden
10 11
11 v 6.8.0 12 v 6.8.0
12 - Ability to at mention users that are participating in issue and merge req. discussion 13 - Ability to at mention users that are participating in issue and merge req. discussion
app/assets/javascripts/notes.js.coffee
@@ -50,6 +50,9 @@ class Notes @@ -50,6 +50,9 @@ class Notes
50 # hide diff note form 50 # hide diff note form
51 $(document).on "click", ".js-close-discussion-note-form", @cancelDiscussionForm 51 $(document).on "click", ".js-close-discussion-note-form", @cancelDiscussionForm
52 52
  53 + # fetch notes when tab becomes visible
  54 + $(document).on "visibilitychange", @visibilityChange
  55 +
53 cleanBinding: -> 56 cleanBinding: ->
54 $(document).off "ajax:success", ".js-main-target-form" 57 $(document).off "ajax:success", ".js-main-target-form"
55 $(document).off "ajax:success", ".js-discussion-note-form" 58 $(document).off "ajax:success", ".js-discussion-note-form"
@@ -63,6 +66,7 @@ class Notes @@ -63,6 +66,7 @@ class Notes
63 $(document).off "click", ".js-choose-note-attachment-button" 66 $(document).off "click", ".js-choose-note-attachment-button"
64 $(document).off "click", ".js-discussion-reply-button" 67 $(document).off "click", ".js-discussion-reply-button"
65 $(document).off "click", ".js-add-diff-note-button" 68 $(document).off "click", ".js-add-diff-note-button"
  69 + $(document).off "visibilitychange"
66 70
67 71
68 initRefresh: -> 72 initRefresh: ->
@@ -72,7 +76,7 @@ class Notes @@ -72,7 +76,7 @@ class Notes
72 , 15000 76 , 15000
73 77
74 refresh: -> 78 refresh: ->
75 - @getContent() 79 + @getContent() unless document.hidden
76 80
77 getContent: -> 81 getContent: ->
78 $.ajax 82 $.ajax
@@ -453,4 +457,10 @@ class Notes @@ -453,4 +457,10 @@ class Notes
453 filename = $(this).val().replace(/^.*[\\\/]/, "") 457 filename = $(this).val().replace(/^.*[\\\/]/, "")
454 form.find(".js-attachment-filename").text filename 458 form.find(".js-attachment-filename").text filename
455 459
  460 + ###
  461 + Called when the tab visibility changes
  462 + ###
  463 + visibilityChange: =>
  464 + @refresh()
  465 +
456 @Notes = Notes 466 @Notes = Notes