יצחק גולדסטנד > Apache-UploadMeter > JavaScript_Guide

Download:
Apache-UploadMeter-0.9915.tar.gz

Annotate this POD

View/Report Bugs
Source  

NAME ^

JavaScript_Guide for Apache::UploadMeter

SYNOPSIS ^

    // Register a global callback
    UploadMeter.Responders.register({
        onCreate: function (meter) {
            Element.update(meter.desc, "Please wait...");
        }
    });
    
    // Create a new UploadMeter
    var um = new UploadMeter(el, meter_id, meter_url, {
        // Callback to be executed every time we get a status update
        onUpdate: function (status, last) {
            Element.update('file', "Now uploading: " + status.filename);
            Element.update('bytes', status.seen + "/" + status.total + "  bytes transfered (" + Util.formatDec(status.currentrate) + " bytes/sec)");
            Element.update('time', Util.formatTime(status.elapsed) + " elapsed (" + Util.formatTime(status.remaining) + " remaining)"); 
        },
        onFinished: function(status, last) {
        // Callback to be executed when we've detected a complete upload and stop the meter
            Element.show('closeme');
        }
    });
    
    // Start our uploadmeter - only do this once the corresponding upload has started (or is about to start)
    um.start();
    
    // Stop (or pause) a previouslky start()ed meter
    um.stop();
    
    // Un-register the default pop-up window behavior 
    Event.stopObserving(aum_el, 'submit', aum_popup);

DESCRIPTION ^

Apache::UploadMeter includes several JavaScript objects to help quickly create a customized GUI interface for Apache::UploadMeter using the JSON meter type

DOM, JavaScript and Cascading StyleSheet rules ^

Although we aim to give maximum customizability, in order to keep a balance between ease of initial set-up and basic usage, and customizability, the built-in UploadMeter includes JS code and CSS rules for a simple graphical progress-bar. At the current moment, the constructor for the UploadMeter object requires a reference to a DOM node as one of the parameters, to be used as the base for creating this progress bar. If you don't want to use the built-in progress-bar, but also don't want to muck with the UploadMeter object to get around this, just create an empty DIV on your page, set the style to hidden (eg, display: none), and pass that to the UploadMeter object. If you do wish to use this built-in object, ensure that the CSS class of this div is "uploadmeter" (and don't hide it!)

Also, it is worth noting that the default behavior looks for an element class named "uploadform" and attempts to add to the onSubmit code for it, to trigger the bundled default pop-up window. If you don't want this to happen, just run:

Event.stopObserving(aum_el, 'submit', aum_popup);

API Documentation ^

UploadMeter Object

This is where most of the action happens. The public interface to this object consists of a constructor, start and stop methods, and some callbacks that can be used to do extra stuff at various key points in the UploadMeter's lifetime.

UploadMeter.Responders

In addition to adding handlers to individual UploadMeter objects, as described above, you can also add global callbacks which will be called for *every* uploadmeter on the page. This might be useful, for example, for Web 2.0 applications that allow for multiple asynchronous uploads in separate requests. In such a case, rather than registering identical handlers for each UploadMeter instance, you can register a single function globally and it will be called for the appropriate callback for all UploadMeter instances running on the page.

Callbacks that are registered this way will receive, as the first parameter, the UploadMeter object of the instance which is currently calling into it.

Util

The Util namespace is not an object, but rather a namespace to group some helper utility functions that may make your life a bit easier when creating your custom user interface.

AUTHOR AND COPYRIGHT ^

Copyright (c) 2001-2007 Issac Goldstand <margol@beamartyr.net> - All rights reserved.

This library is free software. It can be redistributed and/or modified under the same terms as Perl itself.

This software contains third-party components licensed under BSD and MIT style open-source licenses.

SEE ALSO ^

Apache::UploadMeter

syntax highlighting: