{% extends "master.html" %}

{% block title %}Home{% endblock %}
{% set tag = "home" %}i

{% from "_render_repo.html" import render_repos, render_user_repos%}
{% from "_browseheader.html" import browse_header %}


{% block header %}
<link href="{{ url_for('static', filename='selectize.bootstrap3.css') }}"
  rel="stylesheet" />
{% endblock %}

{% block content %}
<div class="repo-header p-t-1">
  <div class="container">
    {{browse_header(select=select)}}
  </div>
</div>
  <div class="container">
    {{ render_repos(
        repos, total_page, 'page', page,
        'All Projects', repos_length, 'repos', username, sorting=sorting) }}
  </div>

{% endblock %}

{% block jscripts %}
    {{ super() }}
<script src="//cdn.jsdelivr.net/jdenticon/1.3.2/jdenticon.min.js" async></script>
<script src="{{ url_for('static', filename='selectize.min.js') }}" type="text/javascript"> </script>
<script src="{{ url_for('static', filename='jquery.dotdotdot.min.js') }}" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
  $('#headerSearch').on('keypress keydown keyup', function(e) {
    if (e.which == 13) {
        e.preventDefault();
        return false;
    }
});
  $('#term').selectize({
    valueField: 'name',
    labelField: 'name',
    onType: function(value){
      if (value == ""){
      this.close();
      }
    },
    onChange: function(value){
      if (value != ""){
        $('#headerSearch').submit();
      }
    },
    searchField: 'name',
    maxItems: 1,
    create: false,
    load: function(query, callback) {
      if (!query.length) return callback();
      $.getJSON(
        "{{ url_for('api_ns.api_projects') }}", {
          pattern: "*"+query+"*"
        },
        function( data ) {
          callback( data.projects );
        }
      );
    },
    render: {
      option: function(item, escape) {
        {% set reponame = 'item.name' %}
        return '<div>' +
            '<div class="projecticon-search pull-xs-left"><span class="oi" data-glyph="document"></span></div>'+
            '<div class="title">' +
                '<span class="name"><strong>' + escape(item.name) + '</strong></span>' +
            '</div>' +
            '<div class="description"><small>' + escape(item.description) + '</small></div>' +
        '</div>';
      }
    },
  });
});
</script>
{% if username %}
<script type="text/javascript">
  $(function(){
      $('.show_parts input[type="checkbox"]').change(function(){
          $('#' + $(this).attr('name')).toggle();
      });
  });
</script>
{% endif %}

<script type="text/javascript">
  $(document).ready(function() {
      $(".repo_desc").dotdotdot({
          watch:"window"
      });
  });
</script>

{% endblock %}
