{% extends changelist_template_parent %}{% load static %}


{% block extrahead %}
    {{block.super}}

    {% if is_popup %}
        {% include "admin/cms/scripts.html" %}

        <script>
            django.jQuery(function() {

                // Get redactor from parent
                var redactor = parent.active_redactor;

                // Make sure we have redactor
                if (redactor) {
                    // Make the changelist links clickable and remove the original inline click listener.
                    $("div#changelist tr.row1 a, div#changelist tr.row2 a").attr("onclick", null).click(function(event) {

                        // Get information
                        var img = $("img", this);
                        var title = img.attr("title");
                        var permalink = img.attr("cms:permalink");

                        redactor.insert(permalink, title)

                        // Prevent default
                        event.preventDefault()

                    });
                    // Made the add link flagged for CKEditor.
                    $(".object-tools a").attr("href", $(".object-tools a").attr("href") + "&_redactor=1");
                }

                // Get ckeditor from parent
                var ckeditor = parent.active_ckeditor;
                var ckeditor_dialog = parent.active_ckeditor_dialog;

                // Make sure we have ckeditor
                if (ckeditor && ckeditor_dialog) {
                    // Make the changelist links clickable and remove the original inline click listener.
                    $("div#changelist tr.row1 a, div#changelist tr.row2 a").attr("onclick", null).click(function(event) {

                        // Get information
                        var img = $("img", this);
                        var title = img.attr("title");
                        var permalink = img.attr("cms:permalink");

                        ckeditor.insertHtml('<img src="' + permalink + '" title="' + title + '"/>')
                        ckeditor_dialog.hide()

                        // Prevent default
                        event.preventDefault()

                    });
                    // Made the add link flagged for CKEditor.
                    $(".object-tools a").attr("href", $(".object-tools a").attr("href") + "&_ckeditor=1");
                }

            });
        </script>

        <style>
            body {
                background-color: #FFF;
            }
            .popup #suit-center {
                width: 100%;
                padding: 0;
            }
        </style>

    {% endif %}
{% endblock %}
