Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with django image uploads #13

Open
kmturley opened this issue Mar 16, 2015 · 0 comments
Open

Integration with django image uploads #13

kmturley opened this issue Mar 16, 2015 · 0 comments

Comments

@kmturley
Copy link

Great work with this so far. I've found that when selecting images you have to select a new upload.

I've created a way that you could do this by opening a popup showing the Django file list, after selecting a file it returns the image back to sir trevor. My demo uses django-filer as that supports the popup and callback out of the box.

Could you add this as a real feature to your version?

Here is my example script you embed on the same page as sir trevor, and it adds the events to load the popup window and listen to the returned value

/**
 * Editor
 * @class Editor
 * @example var editor = new Editor();
 **/

/*globals window, SirTrevor*/

(function () {
    'use strict';

    var module = {
        popup: 'popup.html', // '/admin/filer/folder/7/list/?_popup=1',
        /**
         * @method init
         */
        init: function () {
            var me = this;
            // on page load, add sir trevor event
            this.addEvent('load', window, function (e) {
                SirTrevor.EventBus.on('block:create:new', function (e) {
                    me.addClick(e.el);
                });
                me.checkAll();
            });
            // when callback is fired from popup window
            window.dismissRelatedImageLookupPopup = function (win, chosenId, src) {
                document.getElementById(me.current).innerHTML = '<img src="http://djangosuit.com' + src + '" alt="" id="' + chosenId + '" />';
                win.close();
            };
        },
        /**
         * @method checkAll
         */
        checkAll: function (el) {
            var i = 0,
                divs = document.getElementsByTagName('div');
            for (i = 0; i < divs.length; i += 1) {
                if (divs[i].getAttribute('data-type') === 'image') {
                    this.addClick(divs[i]);
                }
            }
        },
        /**
         * @method addClick
         */
        addClick: function (el) {
            var me = this,
                win;
            this.addEvent('click', el.firstChild, function (e) {
                e.preventDefault();
                me.current = el.id;
                win = window.open(me.popup, 'files', 'height=500,width=800,resizable=yes,scrollbars=yes');
                win.focus();
            });
        },
        /**
         * @method addEvent
         */
        addEvent: function (name, el, func) {
            if (el.addEventListener) {
                el.addEventListener(name, func, false);
            } else if (el.attachEvent) {
                el.attachEvent('on' + name, func);
            } else {
                el[name] = func;
            }
        }
    };
    module.init();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant