Welcome to mirror list, hosted at ThFree Co, Russian Federation.

single_file_diff.js.coffee « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f3e225c37287cc1773896284115403c6bdc1d7b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class @SingleFileDiff

  WRAPPER = '<div class="diff-content diff-wrap-lines"></div>'
  LOADING_HTML = '<i class="fa fa-spinner fa-spin"></i>'
  ERROR_HTML = '<div class="nothing-here-block"><i class="fa fa-warning"></i> Could not load diff</div>'
  COLLAPSED_HTML = '<div class="nothing-here-block diff-collapsed">This diff is collapsed. Click to expand it.</div>'

  constructor: (@file) ->
    @content = $('.diff-content', @file)
    @diffForPath = @content.find('[data-diff-for-path]').data 'diff-for-path'
    @isOpen = !@diffForPath

    if @diffForPath
      @collapsedContent = @content
      @loadingContent = $(WRAPPER).addClass('loading').html(LOADING_HTML).hide()
      @content = null
      @collapsedContent.after(@loadingContent)
    else
      @collapsedContent = $(WRAPPER).html(COLLAPSED_HTML).hide()
      @content.after(@collapsedContent)

    @collapsedContent.on 'click', @toggleDiff

    $('.file-title > a', @file).on 'click', @toggleDiff

  toggleDiff: (e) =>
    @isOpen = !@isOpen
    if not @isOpen and not @hasError
      @content.hide()
      @collapsedContent.show()
    else if @content
      @collapsedContent.hide()
      @content.show()
    else
      @getContentHTML()

  getContentHTML: ->
    @collapsedContent.hide()
    @loadingContent.show()
    $.get @diffForPath, (data) =>
      @loadingContent.hide()
      if data.html
        @content = $(data.html)
        @content.syntaxHighlight()
      else
        @hasError = true
        @content = $(ERROR_HTML)
      @collapsedContent.after(@content)
    return

$.fn.singleFileDiff = ->
  return @each ->
    if not $.data this, 'singleFileDiff'
      $.data this, 'singleFileDiff', new SingleFileDiff this