"destroy" functions are broken
-
“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(){}); }); }
- The topic ‘"destroy" functions are broken’ is closed to new replies.