{% extends 'allura:templates/repo/repo_master.html' %}
{% do g.register_forge_css('css/forge/hilite.css') %}

{% block title %}
  {{c.project.name}} / {{c.app.config.options.mount_label}} /
  {{blob.commit.shorthand_id()}}
  {{h.really_unicode(blob.path())}}
{% endblock %}

{% block header %}
<a href="{{blob.commit.url()}}">{{blob.commit.shorthand_id()}}</a>:
{{lib.path_links(blob.path().split('/')[1:-1])}} {{h.really_unicode(blob.name)}}
{% endblock %}

{% block actions %}
<a href="{{blob.commit.url()}}log/">
  <b data-icon="{{g.icons.history.char}}" class="ico {{g.icons.history.css}}" title="History"> </b> History
</a>
{% endblock %}

{% block extra_js %}
{{ super() }}
<script type="text/javascript">(function() {
  $(window).bind('hashchange', function(e) {
    var hash = window.location.hash.substring(1);
	if ('originalEvent' in e && 'oldURL' in e.originalEvent) {
      $('#' + e.originalEvent.oldURL.split('#')[1]).css('background-color', 'transparent');
	}
    if (hash !== '' && hash.substring(0, 1) === 'l' && !isNaN(hash.substring(1))) {
      $('#' + hash).css('background-color', '#ffff99');
    }
  }).trigger('hashchange');

  $('.code_block').each(function(index, element) {
    $(element).bind('click', function() {
      var hash = window.location.hash.substring(1);
      if (hash !== '' && hash.substring(0, 1) === 'l' && !isNaN(hash.substring(1))) {
        $('#' + hash).css('background-color', 'transparent');
      }
      $(element).css('background-color', '#ffff99');
      window.location.href = '#' + $(element).attr('id');
    });
  });
}());
</script>
{% endblock %}

{% block content %}
  {{ clone_info(c.app.repo) }}
  {% if prev %}
  <p>
    Parent:
    <a href="{{prev.url()}}">{{prev.commit.shorthand_id()}}</a>
    <a href="?diff={{prev.commit.object_id}}">(diff)</a>
  </p>
  {% endif %}

  {% if next %}
  <p>
    Child:
    <a href="{{next.url()}}">{{next.commit.shorthand_id()}}</a>
    <a href="{{next.url()}}?diff={{blob.commit.object_id}}">(diff)</a>
  </p>
  {% endif %}

  {% if blob.has_image_view %}
    <img src="?format=raw" alt=""/>
  {% elif blob.has_html_view or blob.has_pypeline_view or force_display %}
    <p><a href="?format=raw">Download this file</a></p>
    <div class="clip grid-19">
      <h3><span class="ico-l"><b data-icon="{{g.icons['table'].char}}" class="ico {{g.icons['table'].css}}"></b> {{h.really_unicode(blob.name)}}</span></h3>
      {% if blob.has_pypeline_view %}
        {{h.render_any_markup(blob.name, blob.text, code_mode=True, linenumbers_style=h.TABLE)}}
      {% else %}
        {{g.highlight(blob.text, filename=blob.name)}}
      {% endif %}
    </div>
  {% else %}
    <p>{{h.really_unicode(blob.name)}} is not known to be viewable in your browser.
    Try to <a href="?force=True">display it</a> anyway or
    <a href="?format=raw">download it</a> instead.</p>
  {% endif %}
{% endblock %}
