Skip to content

Instantly share code, notes, and snippets.

@kevinvaldek
Created October 16, 2009 19:42
Show Gist options
  • Save kevinvaldek/212007 to your computer and use it in GitHub Desktop.
Save kevinvaldek/212007 to your computer and use it in GitHub Desktop.
/**
* Converts regular upload form to a nifty in place uploader (iFrame uploader).
* MooTools Class.
*/
var LiteUpload = new Class({
Implements: [Options, Events],
options: {
onUpload: $empty,
onUploaded: $empty,
iframeId: 'upload_target'
},
initialize: function(form, options) {
this.setOptions(options);
this.form = $(form);
this.fileColumn = this.form.getElement('input[type=file]');
this.prepareUpload();
},
prepareUpload: function() {
this.iframe = new Element('iframe', {
name: this.options.iframeId,
href: '#',
styles: {
display: 'none'
}
}).inject(this.form, 'after');
this.iframe.addEvent('load', function() {
var content = this.iframe.contentWindow.document.body.innerHTML;
this.fireEvent('uploaded', content);
this.fileColumn.set('value', ''); // clear upload field
}.bind(this));
this.form.set('target', this.options.iframeId);
this.form.addEvent('submit', function() {
this.fireEvent('upload');
}.bind(this));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment