[wp-hackers] Javascript bind event for 3.5's new uploader?

Luke Bryan lukebryan at sharefaith.com
Thu Dec 20 20:17:18 UTC 2012


Greetings,

In previous versions of Wordpress, it was fairly simple to add
Javascript on a hook for the iframe of the upload/media gallery.
Currently, 3.5 uses a much faster Backbone.js, and templating in
wp-includes/media-template.php, instead of iframe.

I'm trying to add an action when the uploader is displayed, but I
can't seem to call the .on or .bind from external code. The relevant
caller is in media-views.js:1965-1983:
        open: function() {
            var $el = this.$el,
            options = this.options;

            if ($el.is(':visible'))
                return this;

            if (!this.views.attached)
                this.attach();

            // If the `freeze` option is set, record the window's
scroll position.
            if (options.freeze) {
                this._freeze = {
                    scrollTop: $(window).scrollTop()
                };
            }

            $el.show().focus();
            return this.propagate('open');
        },

When I break on the last line, then enter at the console
"this.on('open',function(){alert('hi')});" it works. Code will be run
whenever the dialog opens.
Unfortunately, it seems this can't be added from external code.
wp.media.editor.on, wp.media.editor.bind, and others will not work.

Best regards
Luke


More information about the wp-hackers mailing list