Created
October 16, 2009 19:42
-
-
Save kevinvaldek/212007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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