• “destroy” functions are broken due to some async operation. To reproduce this bug add an image URL and click preview, wait until the preview is displayed and then click on the video icon. Handler changes to the video handler and then it gets destroyed. It should wait for the handler to get destroyed before changing to the video handler. I don’t understand how destroying the image handler is so slow.

    This is just a workaround so don’t use it for production, handlers need to be rewritten. In fact, IMHO, i think the entire plugin needs to be rewritten.

    Warning: i’m not an expert and this could break your site. Don’t use this code if you don’t know what you are doing, because i’m sure i don’t.

    js/bpfb_interface.js:

    Line 69:

    var destroy = function (callback) {
        $container.empty();
        $('.bpfb_preview_container').empty();
        $('.bpfb_action_container').empty();
        $('#aw-whats-new-submit').show();
        $(window).off("resize.bpfb");
        callback();
    };

    Line 226:

    var destroy = function (callback) {
        $container.empty();
        $('.bpfb_preview_container').empty();
        $('.bpfb_action_container').empty();
        $('#aw-whats-new-submit').show();
        $(window).off("resize.bpfb");
        callback();
    };

    Line 356:

    var destroy = function (callback) {
        removeTempImages(function() {
            $container.empty();
            $('.bpfb_preview_container').empty();
            $('.bpfb_action_container').empty();
            $('#aw-whats-new-submit').show();
            callback();
        });
    };

    Line 402:

    function init () {
        $form = $("#whats-new-form");
        $text = $form.find('textarea[name="whats-new"]');
        $textContainer = $form.find('#whats-new-textarea');
        createMarkup();
        $('#bpfb_addPhotos').click(function () {
            if (_bpfbActiveHandler) {
                _bpfbActiveHandler.destroy(function() {
                    _bpfbActiveHandler = new BpfbPhotoHandler();
                    $("#bpfb_cancel_action").show();
                    return false;
                });
            } else {
                _bpfbActiveHandler = new BpfbPhotoHandler();
                $("#bpfb_cancel_action").show();
                return false;
            }
        });
        $('#bpfb_addLinks').click(function () {
            if (_bpfbActiveHandler) {
                _bpfbActiveHandler.destroy(function() {
                    _bpfbActiveHandler = new BpfbLinkHandler();
                    $("#bpfb_cancel_action").show();
                    return false;
                });
            } else {
                _bpfbActiveHandler = new BpfbLinkHandler();
                $("#bpfb_cancel_action").show();
                return false;
            }
        });
        $('#bpfb_addVideos').click(function () {
            if (_bpfbActiveHandler) {
                _bpfbActiveHandler.destroy(function() {
                    _bpfbActiveHandler = new BpfbVideoHandler();
                    $("#bpfb_cancel_action").show();
                    return false;
                });
            } else {
                _bpfbActiveHandler = new BpfbVideoHandler();
                $("#bpfb_cancel_action").show();
                return false;
            }
        });
        $('#bpfb_cancel_action').click(function () {
            $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");
            _bpfbActiveHandler.destroy(function(){});
            $("#bpfb_cancel_action").hide();
            return false;
        });
        $(".bpfb_toolbarItem").click(function () {
            $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");
            $(this).addClass("bpfb_active");
        });
        $(document).on('click', '#bpfb_submit', function () {
            var params = _bpfbActiveHandler.get();
            var group_id = $('#whats-new-post-in').length ? $('#whats-new-post-in').val() : 0;
            $.post(ajaxurl, {
                "action": "bpfb_update_activity_contents",
                "data": params,
                "content": $text.val(),
                "group_id": group_id
            }, function (data) {
                _bpfbActiveHandler.destroy(function(){});
                $text.val('');
                $('#activity-stream').prepend(data.activity);
                /**
                * Handle image scaling in previews.
                */
                $(".bpfb_final_link img").each(function () {
                    $(this).width($(this).parents('div').width());
                });
            });
        });
        $(document).on('click', '#bpfb_cancel', function () {
            $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");
            _bpfbActiveHandler.destroy(function(){});
        });
    }

    https://wordpress.org/plugins/buddypress-activity-plus/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tempacc1234

    (@tempacc1234)

    Sorry, i can’t edit. I though i could edit if needed, but i can’t.

    If you want to use my code, change “callback()” to “if (callback) callback()” in all the destroy functions and “function(){}” to “false” in the init fuction. The above code works, but it doesn’t update the activity stream until you refresh the page. It works perfect with this changes, at least for me.

    Again, sorry. My good intentions are bigger than my coding skills 😛

    Line 69:

    var destroy = function (callback) {
        $container.empty();
        $('.bpfb_preview_container').empty();
        $('.bpfb_action_container').empty();
        $('#aw-whats-new-submit').show();
        $(window).off("resize.bpfb");
        if (callback) callback();
    };

    Line 226:

    var destroy = function (callback) {
        $container.empty();
        $('.bpfb_preview_container').empty();
        $('.bpfb_action_container').empty();
        $('#aw-whats-new-submit').show();
        $(window).off("resize.bpfb");
        if (callback) callback();
    };

    Line 356:

    var destroy = function (callback) {
        removeTempImages(function() {
            $container.empty();
            $('.bpfb_preview_container').empty();
            $('.bpfb_action_container').empty();
            $('#aw-whats-new-submit').show();
            if (callback) callback();
        });
    };

    Line 402:

    function init () {
        $form = $("#whats-new-form");
        $text = $form.find('textarea[name="whats-new"]');
        $textContainer = $form.find('#whats-new-textarea');
        createMarkup();
        $('#bpfb_addPhotos').click(function () {
            if (_bpfbActiveHandler) {
                _bpfbActiveHandler.destroy(function() {
                    _bpfbActiveHandler = new BpfbPhotoHandler();
                    $("#bpfb_cancel_action").show();
                    return false;
                });
            } else {
                _bpfbActiveHandler = new BpfbPhotoHandler();
                $("#bpfb_cancel_action").show();
                return false;
            }
        });
        $('#bpfb_addLinks').click(function () {
            if (_bpfbActiveHandler) {
                _bpfbActiveHandler.destroy(function() {
                    _bpfbActiveHandler = new BpfbLinkHandler();
                    $("#bpfb_cancel_action").show();
                    return false;
                });
            } else {
                _bpfbActiveHandler = new BpfbLinkHandler();
                $("#bpfb_cancel_action").show();
                return false;
            }
        });
        $('#bpfb_addVideos').click(function () {
            if (_bpfbActiveHandler) {
                _bpfbActiveHandler.destroy(function() {
                    _bpfbActiveHandler = new BpfbVideoHandler();
                    $("#bpfb_cancel_action").show();
                    return false;
                });
            } else {
                _bpfbActiveHandler = new BpfbVideoHandler();
                $("#bpfb_cancel_action").show();
                return false;
            }
        });
        $('#bpfb_cancel_action').click(function () {
            $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");
            _bpfbActiveHandler.destroy(false);
            $("#bpfb_cancel_action").hide();
            return false;
        });
        $(".bpfb_toolbarItem").click(function () {
            $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");
            $(this).addClass("bpfb_active");
        });
        $(document).on('click', '#bpfb_submit', function () {
            var params = _bpfbActiveHandler.get();
            var group_id = $('#whats-new-post-in').length ? $('#whats-new-post-in').val() : 0;
            $.post(ajaxurl, {
                "action": "bpfb_update_activity_contents",
                "data": params,
                "content": $text.val(),
                "group_id": group_id
            }, function (data) {
                _bpfbActiveHandler.destroy(false);
                $text.val('');
                $('#activity-stream').prepend(data.activity);
                /**
                * Handle image scaling in previews.
                */
                $(".bpfb_final_link img").each(function () {
                    $(this).width($(this).parents('div').width());
                });
            });
        });
        $(document).on('click', '#bpfb_cancel', function () {
            $(".bpfb_toolbarItem.bpfb_active").removeClass("bpfb_active");
            _bpfbActiveHandler.destroy(false);
        });
    }
    Plugin Author Bojan Radonic – WPMU DEV Support

    (@wpmudev-support4)

    Hey tempacc1234,

    How are you doing today?

    Thank you for reporting this and for posting your solution.

    I’ll definitely forward this to our developer so he can investigate this further as this appears to be a bug.

    Have a nice day!

    Cheers,
    Bojan

    Thread Starter tempacc1234

    (@tempacc1234)

    This plugin is a big ugly bug. It needs to be rewritten, or removed from this repository.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘"destroy" functions are broken’ is closed to new replies.