Sha256: 39ba40b9271097d72466005f2510a14f96ecb2cc208744457935b238e1a5817a

Contents?: true

Size: 2 KB

Versions: 8

Compression:

Stored size: 2 KB

Contents

/*
---
description: This class gives you a method to upload files 'the ajax way'

license: MIT-style

authors:
- Arian Stolwijk

requires: [Class, Options, Events, Element, Element.Event, Element.Style]

provides: [Element.iFrameFormRequest, iFrameFormRequest]

...
*/

/**
 * @author Arian Stolwijk
 * Idea taken from http://www.webtoolkit.info/ajax-file-upload.html
 */

var iFrameFormRequest = new Class({

	Implements: [Options, Events],

	options: { /*
		onRequest: function(){},
		onComplete: function(data){},
		onFailure: function(){}, */
		eventName: 'submit'
	},

	initialize: function(form, options){
		this.setOptions(options);
		var frameId = this.frameId = String.uniqueID();
		var loading = false;

		this.form = document.id(form);

		this.formEvent = function(){
			loading = true;
			this.fireEvent('request');
		}.bind(this);

		this.iframe = new IFrame({
			name: frameId,
			styles: {
				display: 'none'
			},
			src: 'about:blank',
			events: {
				load: function(contentWindow){
          // if (loading){
						var doc = this.iframe.contentWindow.document;
						if (doc && doc.location.href != 'about:blank'){
              // this.fireEvent('complete', doc.body.innerHTML);
						  var response = doc.body.getElementsByTagName('textarea')[0].value;
						  this.fireEvent('complete', response);              
						} else {
							this.fireEvent('failure');
						}
          //  loading = false;
          // }
				}.bind(this)
			}
		}).inject(document.body);

		this.attach();
	},

	send: function(){
		this.form.submit();
	},

	attach: function(){
		this.target = this.form.get('target');
		this.form.set('target', this.frameId)
			.addEvent(this.options.eventName, this.formEvent);
	},

	detach: function(){
		this.form.set('target', this.target)
			.removeEvent(this.options.eventName, this.formEvent);
	},

	toElement: function(){
		return this.iframe;
	}

});

Element.implement('iFrameFormRequest', function(options){
	this.store('iFrameFormRequest', new iFrameFormRequest(this, options));
	return this;
});

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rad_common_interface-0.0.14 app/static/vendor/iFrameFormRequest.js
rad_common_interface-0.0.13 app/static/vendor/iFrameFormRequest.js
rad_common_interface-0.0.12 app/static/vendor/iFrameFormRequest.js
rad_common_interface-0.0.11 app/static/vendor/iFrameFormRequest.js
rad_common_interface-0.0.10 app/static/vendor/iFrameFormRequest.js
rad_common_interface-0.0.9 app/static/vendor/iFrameFormRequest.js
rad_common_interface-0.0.8 app/static/vendor/iFrameFormRequest.js
rad_common_interface-0.0.7 app/static/vendor/iFrameFormRequest.js