Friday, May 11, 2007

Revision 5.2 update

I have posted an update to SWFUpload Revision 5.2. It does not add new features so I decided to keep the version number. Several function names have changed, however, so you can't just drop in the new swfupload.swf and swfupload.js files.

Changes
  • Added the Application Demo which demonstrates a working upload script and dealing with passing PHP Session IDs to the upload script as a work-around to the Flash/Firefox cookie issue.
  • Restructured the JavaScript code to comply with YUI style suggestions and to make a clean pass at www.jslint.com. This makes for better less error prone code.
    • The major change here is changing all function names to camelCase.
    • Moved the Cookie and Console objects inside the SWFUpload object.
  • Cleaned up some additional logic
  • Created a function this.DebugMessage(msg) to replace all the if (this.debug) Console.Writeln(msg);. Which does the same thing but gets ride of the all ifs and allows for easier changes to debugging in the future.
  • Added a ChangeLog.txt file and removed the 100 lines of comments from the top of the swfupload.js file.
Hopefully these changes will improve my code consistency, make the code easier to read, and make it more compatible with other JS libraries.

I recommend using the full blown swfupload.js for development but then using jsmin to reduce the file from 27 KB to 16 KB.

The demo swfupload.swf also has not had any of the "This script is running too long" patches applied to it. I have not, personally, had any of these errors come up but you may want to apply the patches anyways.

I've decided it's time to learn JavaScript and have started with the resource at http://javascript.crockford.com/ which are very good and reasonable. Hopefully my understanding and coding of JavaScript will improve ;)

Friday, May 04, 2007

HTML <button> tag

I am frequently amazed at the new "old things" I discover as I continue in web development. For example, I'm coming around to using the H tags and the P tag for markup. I've always used spans, divs, and brs.

My most recent "discovery" is the button tag. This little jewel has its problems but it gives me some of the flexibility that an input type="button" just doesn't provide.

See for yourself:



The <button> tag accepts HTML content rather than a simple text value. As far as I know (I don't know much) you can put most anything in there.

It is important to remember that <button> has a type attribute that determines whether it behaves as a submit, reset, or simple button.

Some caveats:

IE does not handle form submission of <button>s correctly.
  • Rather than submitting the value (as specified in the value attribute) it submits the inner HTML of the tag.
  • IE submits all the <button> tags; not just the button that was clicked. This makes it so the server-side script is unable to tell which button was clicked.

Work-arounds:
  • Set the type attribute to button and use JavaScript. If you can't use JavaScript then I'm afraid you may not have much success with the <button> tag (especially if you want to use more than one <button> tag in a form)
  • Button Value: Use the JavaScript onclick event to populate a hidden field with the value from the button. In your server-side scripts you can read out values from the hidden fields and ignore the buttons.
  • Which Button Clicked: Use the JavaScript onclick event to populate a hidden field with a value that identifies which button was clicked. On the server-side use the hidden field to determine action rather than the button.
ASP.Net already uses similar methods for its PostBacks and so these work-arounds aren't necessary. Just remember to set the type attribute to button or you will get two postbacks when a button is clicked. Bind click events in ASP.Net by using the onserverclick event.

Thursday, May 03, 2007

SWFUpload Revision 5.2 Release

Edit: If you downloaded R5.2 before May 4th you should download again. I made some minor fixes that I missed:
  • Zero file size limit fixed to mean unlimited
  • Default flash width/height set to 1px to work better in Linux (also default color set to #FFFFFF since it is visible in Linux.
/Edit

Alright. I've completed another overhaul and feature creep cycle in the SWFUpload Revisions. I'm going to have to take a break for awhile. It's time to get back to work (real work I mean).

Revision 5.2 includes updates to several features, improves the internal processing of the files and takes care of some bugs that I missed because of insufficient testing.

Changes
  • Out of Order file uploads now possible.
  • Per file upload parameters (these are added to the upload target query string. These are also passed to JavaScript with the fileObj).
  • Dynamic modification of cookie and custom parameters (fixed so cookies aren't wiped out when updating other settings).
  • Added a Queue Limit. E.g. Use if you only want users to queue and upload one file at a time you can set the queue limit to 1.
  • Added a QueueStopped event (change from throwing a FileQueued event when the upload was stopped).
  • Fixed the various limits so setting them to zero means unlimited.
  • Added a ui_function setting that allows you to specify the function to call instead of _showUI. This gives you the power to do whatever you want with the UI after SWFUpload has completed loading without having to modify the SWFUpload javascript files.
  • Created a "Features" demo that lets you tweak (almost) all the settings in SWFUpload R5.2 and test it without having to fiddle in the code.
  • ActionScript modifications:
    • Changed from using an ever growing array to track each queued file to a FIFO queue. This simplifies the code in a lot of ways.
    • Wrapped the FileReference object in a custom FileItem object which allows per file parameters and better abstraction.

The Revisions website has been update: http://swfupload.praxion.co.za/index.php

Another big thanks to Tarkheena for providing the great hosting!

Additional Notes

I've been having all kinds of trouble with UTF-8 encoding and byte headers. I tried to get the encoding consistent but may have missed some files. Incorrect encoding has caused issues ranging from PHP errors to JavaScript files not loading. Let me know if there are any problems.

There was a report that SWFUpload R5 (and probably R5.2) does not work under Firefox 1.5 in Linux. I plan to test and hopefully fix this soon.

I tested R5.2 in Ubuntu 6.10 on Firefox 2.0. I fixed a couple small issues that prevented SWFUpload from loading (see Edit above). I noted that it seems like FileProgress events are not called very often. Also, Stopping or Cancelling causes a crash. If you are targeting Linux users you should include JavaScript that detects the Linux Flash Player and prevents these actions. I don't plan to add this kind of detection to my code.

I can create a browser crash in both IE and Firefox on Windows XP SP2. While I have the File Dialog open, I force a page change (reload or move to a different url). I happened on this when I was using <input type="submit" onclick="suo.Browse()">. The File Dialog would open but then the form would submit and change pages. The browser would crash as soon as I clicked Open or Cancel.