Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Brent Fitzgerald http://brentfitzgerald.com/

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Progress Indicator Helper

Use the optional options param to pass custom show or hide functions. Provides functions show/hide.
function ProgressIndicator(element, options) {
        var element = $(element);
        var my_options = {show:Element.show, hide:Element.hide};
        Object.extend(my_options, options || {});
        this.show = function() { my_options.show(element) }
        this.hide = function() { my_options.hide(element) }
        this.hide();
}

Example
var p = new ProgressIndicator($("my_element"));
p.show();

var q = new ProgressIndicator("my_other_element",
                             {show: Effect.Appear, 
                              hide:Effect.Fade});
q.show();
$("my_other_element").onclick = q.hide;


Requires prototype for a few things.

javascript window event handling manager

I've seen a lot of window.onload managers, so I generalized it for any window event handler. This assumes prototype.
// BurntoEventManager
// http://brentfitzgerald.com/
// January 2007

var BurntoEventManager = {
    handlers: {},
    add: function(handler_name, method) {
        if(this.handlers[handler_name] == null) {
            this.handlers[handler_name] = new Array();
        }
        this.handlers[handler_name].push(method);
        
        // Now update the window event handler
        window[handler_name] = function(evt) {
            this.handlers[handler_name].each(function(m) {
                m(evt);
            }.bind(this));
        }.bind(this);
    },
    
    clear: function(handler_name) {
        this.handlers[handler_name] = null;
        window[handler_name] = function() {};
    },
    
    get: function(handler_name) {
        return this.handlers[handler_name];
    }
}

For example, consider if later on in our application we want to add an onclick handler.
BurntoEventManager.add("onclick", function(evt) { alert(evt) });
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS