{% load static %}

{#Extend with an empty block or replace with your version of jquery#}
{%  block jquery %}
    <script src="http://code.jquery.com/jquery-1.12.2.min.js"></script>
{% endblock %}

{# Extend with an empty block if you other mean to deal with AJAX post request in Django #}
{%  block ajax_csrf %}
    <script type="text/javascript">
        // using jQuery
        function getCookie(name) {
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
        var csrftoken = getCookie('csrftoken');
        function csrfSafeMethod(method) {
            // these HTTP methods do not require CSRF protection
            return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
        }
        $.ajaxSetup({
            beforeSend: function(xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                }
            }
        });
    </script>
{% endblock %}

{#This is the actual code that enables the tellme plugin#}
{% block enable_tellme %}
    <script src="{% static 'tellme/feedback.min.js' %}"></script>
    <script type="text/javascript">
        $(function () {
            $.feedback({
                ajaxURL: "{% url 'tellme:post_feedback' %}",
                html2canvasURL: "{% static 'tellme/html2canvas.min.js' %}",
                feedbackButton: "#feedback-btn",
                initButtonText: "{% filter escapejs %}{%  include 'tellme/initButtonText.txt' %}{% endfilter %}",
                postHTML: false,
                tpl: {
                    description: "{% filter escapejs %}{%  include 'tellme/tpl-description.html' %}{% endfilter %}",
                    highlighter: "{% filter escapejs %}{%  include 'tellme/tpl-highlighter.html' %}{% endfilter %}",
    				overview:	 "{% filter escapejs %}{%  include 'tellme/tpl-overview.html' %}{% endfilter %}",
    				submitSuccess:"{% filter escapejs %}{%  include 'tellme/tpl-submit-success.html' %}{% endfilter %}",
    				submitError: "{% filter escapejs %}{%  include 'tellme/tpl-submit-error.html' %}{% endfilter %}"
                },
                initialBox: true
            });
            console.log("{% filter escapejs %}{%  include 'tellme/tpl-description.html' %}{% endfilter %}")
        });
    </script>
{%  endblock %}