简体   繁体   English

从新的WordPress Media Uploader获取JS回调

[英]Getting a JS callback from the new WordPress Media Uploader

Is there a way to listen for an event when a user chooses an image from the WordPress Media Library/Uploader? 当用户从WordPress媒体库/上传器中选择图像时,是否可以监听事件?

I'm developing an extension for a WordPress framework (Layers), which uses it's own controls for uploading images and I don't trigger the Uploader manually, which means I can't hook up to it's callback. 我正在开发WordPress框架(图层)的扩展程序,该扩展程序使用它自己的控件来上传图片,而且我没有手动触发上传程序,这意味着我无法连接到它的回调。

Is there a way to get the "global" media uploader, or the one that's currently open? 有没有一种方法可以获取“全局”媒体上载器,或当前打开的媒体上载器?

Something like: 就像是:

wp.media().on('insert', function(url) {
    console.log('isnerted image: ' + url);
});

I could not find anything in the WordPress Codex besides this example: http://codex.wordpress.org/Javascript_Reference/wp.media Which assumes that I'm launching the editor myself. 除了此示例外,我在WordPress Codex中找不到任何内容: http : //codex.wordpress.org/Javascript_Reference/wp.media假定我自己启动了编辑器。

Too late for an assist? 来不及提供协助? I've been looking at the same problem, thought I'd add a thought: The wp media-uploader js is here - https://github.com/WordPress/WordPress/blob/master/wp-includes/js/plupload/wp-plupload.js and looking at this problem https://wordpress.stackexchange.com/questions/92415/image-upload-callback-in-new-3-5-media I see there's a method to extend callbacks from it. 我一直在看同样的问题,以为我要加一个想法:wp media-uploader js在这里-https: //github.com/WordPress/WordPress/blob/master/wp-includes/js/plupload /wp-plupload.js并查看此问题https://wordpress.stackexchange.com/questions/92415/image-upload-callback-in-new-3-5-media我看到有一种方法可以从中扩展回调。 After looking at the uploader js I see the following: 查看上载器js之后,我将看到以下内容:

init:     function() {},
error:    function() {},
success:  function() {},
added:    function() {},
progress: function() {},
complete: function() {}

which can all be extended using : 所有这些都可以使用扩展:

$.extend( wp.Uploader.prototype, {
    success : function(){
        console.log( 'callback action replacing this line' );
    }
});

replacing success with one of the six options above (in your case I'm thinking 'insert' becomes either 'added', or 'complete') don't knw if that helps? 用上述六个选项之一代替success (在您的情况下,我认为“插入”变成“添加”或“完成”)是否有帮助?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM