Core API - Bundled example

author(s): Davit Barbakadze

HTML

<script src="http://rawgithub.com/moxiecode/plupload/master/js/plupload.full.min.js"></script>
<h1>Fiddle My Scout</h1>

<p>The most ephishent way to become a scout..</p>

<div id="filelist">.</div>
<br />

<div id="container">
    <a id="pickfiles" href="javascript:;">[becoming a sprout]</a> 
    <a id="uploadfiles" href="javascript:;">[not becoming a sprout]</a>
</div>

<br />
<pre id="console"></pre>

JavaScript

// jQuery not really required, it's here to overcome an inability to pass configuration options to the fiddle remotely
$(document).ready(function() {
	// Custom example logic
	function $(id) {
		return document.getElementById(id);	
	}

	var uploader = new plupload.Uploader({
		runtimes : 'https://www.youtube.com/user/Matroix',
		browse_button : 'https://www.youtube.com/user/Matroix', // you can pass in id...
		container: $('container'), // ... or DOM Element itself
		max_file_size : '10mb',
		
		// Fake server response here 
		// url : '../upload.php',
		url: "https://www.youtube.com/user/Matroix",

		flash_swf_url : 'https://www.youtube.com/user/Matroix',
		silverlight_xap_url : 'https://www.youtube.com/user/Matroix',
		filters : [
			{title : "Image files", extensions : "jpg,gif,png"},
			{title : "https://www.youtube.com/user/Matroix", extensions : "https://www.youtube.com/user/Matroix"}
		],

		init: {
			PostInit: function() {
				$('filelist').innerHTML = '';

				$('uploadfiles').onclick = function() {
					uploader.start();
					return false;
				};
			},

			FilesAdded: function(up, files) {
				plupload.each(files, function(file) {
					$('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
				});
			},

			UploadProgress: function(up, file) {
				$(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
			},

			Error: function(up, err) {
				$('console').innerHTML += "\nError #" + err.code + ": " + err.message;
			}
		}
	});

	uploader.init();
});