Apache-UploadMeter
view release on metacpan or search on metacpan
lib/Apache/UploadMeter/Resources/JavaScript.pm view on Meta::CPAN
if(Builder._isStringOrNumber(e))
element.appendChild(Builder._text(e));
});
} else
if(Builder._isStringOrNumber(children))
element.appendChild(Builder._text(children));
},
_isStringOrNumber: function(param) {
return(typeof param=='string' || typeof param=='number');
},
build: function(html) {
var element = this.node('div');
$(element).update(html.strip());
return element.down();
},
dump: function(scope) {
if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
"BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
"FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
"KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
"PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
"TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
tags.each( function(tag){
scope[tag] = function() {
return Builder.node.apply(Builder, [tag].concat($A(arguments)));
}
});
}
}
SCRIPTACULOUS-END
$r->print($output);
return Apache2::Const::OK;
}
sub json_js {
my $r = shift;
$r->content_type("application/x-javascript");
$r->set_etag();
return Apache2::Const::OK if $r->header_only();
my $output=<<'AUM-END';
// UploadMeter Object (makes assumptions about the target DOM, but still useful as a reference point)
var UploadMeter = Class.create();
UploadMeter.prototype = {
status: undefined,
ajax: undefined,
options: {
delay: 3.0 // Delay in seconds between requests (also almost duration of sliding effect for smoothest exerience)
},
// We can't seem to Element.extend our elements in a seperate window... Dunno why yet
// but it makes for uglier code :-(
// Constructor - Parameters are:
// el: Outer div to bind widget to
// meter: uploadmeter id
// url: uploadmeter ajax url
// options: additional callbacks, etc
initialize: function(el, meter, url, options) {
this.url = url;
this.meter = meter;
this.main = $(el);
Object.extend(this.options, options || {});
this.desc = Builder.node( "div", {className:'metercontent'});
this.main.appendChild(this.desc);
this.desc = $(this.desc);
Position.absolutize(this.desc);
Position.clone(this.main, this.desc);
this.ul = Builder.node( "div", {className:'meterunderlay'});
this.main.appendChild(this.ul);
this.ul = $(this.ul);
Position.absolutize(this.ul);
Position.clone(this.main, this.ul);
this.ul.setStyle({width: "0px"});
},
start: function() {
// Restart paused meter
if (this.ajax !== undefined) {
this.ajax.start();
return;
}
// Call onCreate hook
try {
(this.options.onCreate || Prototype.emptyFunction)();
UploadMeter.Responders.dispatch('onCreate', this);
} catch (e) {
this.dispatchException(e);
}
var errorFunc = function (transport) {
Element.setStyle(this.main, {'border-color': 'yellow'});
Element.update(this.desc, "Unknown");
Element.setStyle(this.ul, {'background-color': 'yellow'}).hide();
Position.clone(this.main, this.ul);
Element.show(this.ul);
}.bind(this);
// New meter
var params = "format=json&meter_id=" + this.meter;
new Ajax.Request(this.url, {
parameters: params,
onSuccess: function(transport) {
// Handle response
this.__onSuccess(transport);
// Start periodic
params = params + "&returned=1";
this.ajax = new PeriodicalExecuter(function() {
new Ajax.Request(this.url, {
parameters: params,
onSuccess: this.__onSuccess.bind(this)
});}.bind(this), this.options.delay);
}.bind(this),
on404: errorFunc,
on400: errorFunc
}); /* first request */
},
stop: function() {
try {this.ajax.stop();} catch (e) {}
( run in 2.629 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )