How can you assign multiple Javascript functions to the upload_start_handler for WordPress's SWFUplo

Posted by Byron on Stack Overflow See other posts from Stack Overflow or by Byron
Published on 2010-04-08T17:28:49Z Indexed on 2010/04/08 17:33 UTC
Read the original article Hit count: 503

I've got 2 WordPress plugins (PhotoSmash and TwitPic-It) that need to hook into the SWFUploader for the Media Uploader in WordPress. SWFUpload has a setting "upload_start_handler" where you can specify a javascript function that will run immediately before the upload begins. The trouble is that I need to assign 2 different functions to run in separate plugins that may or may not coexist in a given user's WordPress blog. I want to make the implementation so that it allows other plugin authors to hook their own javascript functions.

I don't know that I have access to the actual event being fired. The "upload_start_handler" is a setting on a JS object, not an event hook on the flash object. You set it like:

swfu.settings.upload_start_handler = function(){ runFlashStartUploadFunctions(); }

My current plan is to add a 2 functions and an array variable (check if they exists first). The array variable is intended to hold an array of function names (strings) to run when "runFlashStartUploadFunctions" gets called at upload start. The first function is to add new functions to the array. The second function is "runFlashStartUploadFunctions", and it will iterate through the array and eval each function name.

Is there a better way?

Thanks, Byron

© Stack Overflow or respective owner

Related posts about wordpress-plugin

Related posts about Wordpress