debian-mirror-gitlab/app/assets/javascripts/diff.js.coffee

52 lines
1.6 KiB
CoffeeScript
Raw Normal View History

2015-04-26 12:48:37 +05:30
class @Diff
2014-09-02 18:07:02 +05:30
UNFOLD_COUNT = 20
constructor: ->
2016-08-24 12:49:21 +05:30
$('.files .diff-file').singleFileDiff()
@filesCommentButton = $('.files .diff-file').filesCommentButton()
2015-04-26 12:48:37 +05:30
$(document).off('click', '.js-unfold')
2014-09-02 18:07:02 +05:30
$(document).on('click', '.js-unfold', (event) =>
target = $(event.target)
unfoldBottom = target.hasClass('js-unfold-bottom')
unfold = true
[old_line, line_number] = @lineNumbers(target.parent())
offset = line_number - old_line
if unfoldBottom
line_number += 1
since = line_number
to = line_number + UNFOLD_COUNT
else
[prev_old_line, prev_new_line] = @lineNumbers(target.parent().prev())
line_number -= 1
to = line_number
if line_number - UNFOLD_COUNT > prev_new_line + 1
since = line_number - UNFOLD_COUNT
else
since = prev_new_line + 1
unfold = false
link = target.parents('.diff-file').attr('data-blob-diff-path')
params =
since: since
to: to
bottom: unfoldBottom
offset: offset
unfold: unfold
2015-09-11 14:41:01 +05:30
# indent is used to compensate for single space indent to fit
# '+' and '-' prepended to diff lines,
# see https://gitlab.com/gitlab-org/gitlab-ce/issues/707
indent: 1
2014-09-02 18:07:02 +05:30
2016-08-24 12:49:21 +05:30
$.get(link, params, (response) ->
2014-09-02 18:07:02 +05:30
target.parent().replaceWith(response)
)
)
lineNumbers: (line) ->
return ([0, 0]) unless line.children().length
lines = line.children().slice(0, 2)
line_numbers = ($(l).attr('data-linenumber') for l in lines)
(parseInt(line_number) for line_number in line_numbers)