2012-10-03 23:01:16 +02:00
|
|
|
# Code browser tree slider
|
|
|
|
|
|
|
|
$ ->
|
|
|
|
if $('#tree-slider').length > 0
|
|
|
|
# Show the "Loading commit data" for only the first element
|
|
|
|
$('span.log_loading:first').removeClass('hide')
|
|
|
|
|
|
|
|
$('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live "click", ->
|
2013-03-30 12:23:58 +01:00
|
|
|
$("#tree-content-holder").hide("slide", { direction: "left" }, 400)
|
2012-10-03 23:01:16 +02:00
|
|
|
|
|
|
|
# Make the entire tree-item row clickable, but not if clicking another link (like a commit message)
|
|
|
|
$("#tree-slider .tree-item").live 'click', (e) ->
|
|
|
|
$('.tree-item-file-name a', this).trigger('click') if (e.target.nodeName != "A")
|
2013-03-06 16:12:28 +01:00
|
|
|
|
2012-11-01 22:57:12 +01:00
|
|
|
# Maintain forward/back history while browsing the file tree
|
|
|
|
((window) ->
|
|
|
|
History = window.History
|
|
|
|
$ = window.jQuery
|
|
|
|
document = window.document
|
|
|
|
|
|
|
|
# Check to see if History.js is enabled for our Browser
|
|
|
|
unless History.enabled
|
|
|
|
return false
|
|
|
|
|
|
|
|
$('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live 'click', (e) ->
|
2012-11-28 03:09:55 +01:00
|
|
|
History.pushState(null, null, decodeURIComponent($(@).attr('href')))
|
2012-11-01 22:57:12 +01:00
|
|
|
return false
|
|
|
|
|
|
|
|
History.Adapter.bind window, 'statechange', ->
|
|
|
|
state = History.getState()
|
2013-03-06 16:12:28 +01:00
|
|
|
$.ajax({
|
|
|
|
url: state.url,
|
|
|
|
dataType: 'script',
|
|
|
|
beforeSend: -> $('.tree_progress').addClass("loading"),
|
|
|
|
complete: -> $('.tree_progress').removeClass("loading")
|
|
|
|
})
|
2012-11-01 22:57:12 +01:00
|
|
|
)(window)
|
2012-11-10 00:03:46 +01:00
|
|
|
|
|
|
|
# See if there are lines selected
|
|
|
|
# "#L12" and "#L34-56" supported
|
|
|
|
highlightBlobLines = ->
|
|
|
|
if window.location.hash isnt ""
|
2012-11-17 22:25:48 +01:00
|
|
|
matches = window.location.hash.match(/\#L(\d+)(\-(\d+))?/)
|
|
|
|
first_line = parseInt(matches?[1])
|
|
|
|
last_line = parseInt(matches?[3])
|
2012-11-10 00:03:46 +01:00
|
|
|
|
|
|
|
unless isNaN first_line
|
2012-11-17 22:25:48 +01:00
|
|
|
last_line = first_line if isNaN(last_line)
|
2012-11-10 00:03:46 +01:00
|
|
|
$("#tree-content-holder .highlight .line").removeClass("hll")
|
|
|
|
$("#LC#{line}").addClass("hll") for line in [first_line..last_line]
|
|
|
|
$("#L#{first_line}").ScrollTo()
|
|
|
|
|
|
|
|
# Highlight the correct lines on load
|
|
|
|
highlightBlobLines()
|
|
|
|
# Highlight the correct lines when the hash part of the URL changes
|
|
|
|
$(window).on 'hashchange', highlightBlobLines
|