Commit b8d3016a authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett Committed by Sean McGivern

Added frontend collapsible behavior

parent 78496e8c
class @Diff class @Diff
UNFOLD_COUNT = 20 UNFOLD_COUNT = 20
constructor: -> constructor: ->
$('.files .diff-file').singleDiff()
$(document).off('click', '.js-unfold') $(document).off('click', '.js-unfold')
$(document).on('click', '.js-unfold', (event) => $(document).on('click', '.js-unfold', (event) =>
target = $(event.target) target = $(event.target)
......
...@@ -160,6 +160,7 @@ class @MergeRequestTabs ...@@ -160,6 +160,7 @@ class @MergeRequestTabs
$('#diffs').html data.html $('#diffs').html data.html
gl.utils.localTimeAgo($('.js-timeago', 'div#diffs')) gl.utils.localTimeAgo($('.js-timeago', 'div#diffs'))
$('#diffs .js-syntax-highlight').syntaxHighlight() $('#diffs .js-syntax-highlight').syntaxHighlight()
$('#diffs .diff-file').singleDiff()
@expandViewContainer() if @diffViewType() is 'parallel' @expandViewContainer() if @diffViewType() is 'parallel'
@diffsLoaded = true @diffsLoaded = true
@scrollToElement("#diffs") @scrollToElement("#diffs")
......
class @SingleDiff
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>'
constructor: (@file) ->
@content = $('.diff-content', @file)
@diffForPath = @content.data 'diff-for-path'
@setOpenState()
$('.file-title > a', @file).on 'click', @toggleDiff
setOpenState: ->
if @diffForPath
@isOpen = false
else
@isOpen = true
@contentHTML = @content.html()
return
toggleDiff: (e) =>
e.preventDefault()
@isOpen = !@isOpen
if not @isOpen and not @hasError
@content.empty()
return
if @contentHTML
@setContentHTML()
else
@getContentHTML()
return
getContentHTML: ->
@content.html(LOADING_HTML).addClass 'loading'
$.get @diffForPath, (data) =>
if data.html
@setContentHTML data.html
else
@hasError = true
@content.html ERROR_HTML
@content.removeClass 'loading'
return
setContentHTML: (contentHTML) ->
@contentHTML = contentHTML if contentHTML
@content.html @contentHTML
@content.syntaxHighlight()
$.fn.singleDiff = ->
return @each ->
if not $.data this, 'singleDiff'
$.data this, 'singleDiff', new SingleDiff this
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment