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


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

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

        <script>
            django.jQuery(function() {

                // Get tinymce from parent
                var tinymce = parent.active_tinymce;

                // Make sure we have tinymce
                if (tinymce) {
                    // 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");

                        tinymce.focus()
                        tinymce.selection.setContent(tinymce.dom.createHTML('img', {
                            src: permalink,
                            alt: title,
                            title: title,
                        }));

                        // Prevent default
                        event.preventDefault()

                        // Get the active editor open window
                        var tinymce_popup = parent.active_tinymce_window
                        if(tinymce_popup){
                            tinymce_popup.close()
                        }

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

            });
        </script>

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

    {% endif %}
{% endblock %}
