{% from theme('_helpers.html') import load_comment_area, load_tags_area, load_share_area, load_recommendation_area, load_page_header, load_page_time, load_page_content  with context %}
{% extends theme("base.html") %}

{%block title%} {{content.title}} | {{channel.long_slug.split('/')|join(' | ')}} | {{Config.get('site', 'site_name', 'Quokka site')}} {% endblock %}

{% block seo_meta %}
<meta name="description" content="{{content.summary}}">
<meta name="keywords" content="{{content.tags|join(',')}}">
{% endblock %}

{% block front %}

    {{load_page_header(content)}}
    <div class="col-6 col-sm-6 col-lg-6">
        <small>{{load_page_time(content)}}</small>
    </div>
    <div class="col-6 col-sm-6 col-lg-6">
        {{load_share_area(content)}}
    </div>

    <div style="margin-top:25px;" class="clearfix"></div>
{% endblock %}

{% block content %}

    <div class="col-12 col-sm-12 col-lg-12">

        {{load_page_content(content)}}

        {{load_tags_area(content)}}

        {{load_recommendation_area(content)}}

        {{load_comment_area(content)}}

    </div>
{% endblock %}


{% block js_footer %}
{% if Config.get('comments', 'system') == 'internal' %}
<script>
$(function(){

    function bind_comment_form_submit(){
        $("form").on("submit", function(e){
            var postData = $(this).serializeArray();
            var formURL = $(this).attr("action");
            $.ajax(
            {
                url : formURL,
                type: "POST",
                data : postData,
                success:function(data, textStatus, jqXHR)
                {
                    //data: return data from server
                    $("#comment-area").html(data);
                    bind_comment_form_submit();
                },
                error: function(jqXHR, textStatus, errorThrown)
                {
                    //if fails
                }
            });
            e.preventDefault(); //STOP default action
        })
    }

    function load_internal_comments(){
        var comment_area = $("#comment-area" );
        comment_area.empty();
        comment_area.load( comment_area.attr('data-path'), function() {
            console.log( "Load was performed." );
            bind_comment_form_submit();
        });
    }

    load_internal_comments();

})
</script>
{% endif %}
{% endblock %}