媒体集元素上的绑定事件WordPress

时间:2014-11-01 作者:Vladimir Lukyanov

早上好!

请帮助获取WordPress Media Upload元素的绑定。当我点击任何库项目时,需要一个自定义功能来启动。

enter image description here

有一个称为“附件”和事件“选择:单一”的主干集合,但我不知道如何访问它们。

谢谢

上帝保佑解决者!:)

//弗拉基米尔

1 个回复
SO网友:Vladimir Lukyanov

(function ($) {
    "use strict";

    $(function () {

        var button = $(\'.upload-image\');


        button.click(function (e) {

            e.preventDefault();

            // If the media frame already exists, reopen it.
            if (file_frame) {
                file_frame.open();
                return;
            }

            var btn = $(this),
                media = wp.media;


            // Create the media frame.
            var file_frame = media.frames.file_frame = media({
                title: jQuery(this).data(\'uploader_title\'),
                button: {
                    text: jQuery(this).data(\'uploader_button_text\')
                },
                library: {
                    type: \'image\'
                },
                multiple: false
            });


            // Finally, open the modal
            file_frame.open();

            var selection = media.frame.state().get(\'selection\');
            // The sidebar boxes get deleted and recreated on each select - hack into this to do the same.
            selection.on( \'selection:single\', function ( event ) {
                console.log(\'selection:single\');
            } );

            selection.on( \'selection:unsingle\', function ( event ) {
                console.log(\'selection:unsingle\');
            } );

        });

    });
}(jQuery));
注意:“选择:不单独”事件将触发两次

结束

相关推荐