uploader-data-source.mustache revision 76438e9b6959cc0bd7e35fb9cf5a11c87a37f744
<style>
#filelist {
margin-top: 15px;
}
#uploadFilesButtonContainer, #selectFilesButtonContainer, #overallProgress {
display: inline-block;
}
#overallProgress {
float: right;
}
.yellowBackground {
background: #F2E699;
}
.serverdata {
font-size: 0.8em;
}
</style>
<div id="exampleContainer">
<div id="uploaderContainer">
<div id="selectFilesButtonContainer">
</div>
<div id="uploadFilesButtonContainer">
<button type="button" id="uploadFilesButton"
class="yui3-button" style="width:250px; height:25px;">Upload Files</button>
</div>
<div id="overallProgress">
</div>
</div>
<div id="filelist">
<table id="filenames">
<thead>
<tr><th>File name</th><th>File size</th><th>Percent uploaded</th><th>Data from Server</th></tr>
<tr id="nofiles">
<td colspan="4" id="ddmessage">
<strong>No files selected.</strong>
</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<script>
YUI({filter:"raw"}).use("uploader", function(Y) {
Y.one("#overallProgress").set("text", "Uploader type: " + Y.Uploader.TYPE);
if (Y.Uploader.TYPE != "none" && !Y.UA.ios) {
var uploader = new Y.Uploader({width: "250px",
height: "25px",
multipleFiles: true,
swfURL: "../build/uploader/assets/flashuploader.swf?t=" + Math.random(),
uploadURL: "http://www.yswfblog.com/upload/simpleupload.php",
simLimit: 2
});
var uploadDone = false;
if (Y.Uploader.TYPE == "html5") {
uploader.set("dragAndDropArea", "body");
Y.one("#ddmessage").setContent("<strong>Drag and drop files here.</strong>");
uploader.on(["dragenter", "dragover"], function (event) {
var ddmessage = Y.one("#ddmessage");
if (ddmessage) {
ddmessage.setContent("<strong>Files detected, drop them here!</strong>");
ddmessage.addClass("yellowBackground");
}
});
uploader.on(["dragleave", "drop"], function (event) {
var ddmessage = Y.one("#ddmessage");
if (ddmessage) {
ddmessage.setContent("<strong>Drag and drop files here.</strong>");
ddmessage.removeClass("yellowBackground");
}
});
}
uploader.render("#selectFilesButtonContainer");
uploader.after("fileselect", function (event) {
var fileList = event.fileList;
var fileTable = Y.one("#filenames tbody");
if (fileList.length > 0 && Y.one("#nofiles")) {
Y.one("#nofiles").remove();
}
if (uploadDone) {
uploadDone = false;
fileTable.setContent("");
}
var perFileVars = {};
Y.each(fileList, function (fileInstance) {
fileTable.append("<tr id='" + fileInstance.get("id") + "_row" + "'>" +
"<td class='filename'>" + fileInstance.get("name") + "</td>" +
"<td class='filesize'>" + fileInstance.get("size") + "</td>" +
"<td class='percentdone'>Hasn't started yet</td>" +
"<td class='serverdata'>&nbsp;</td>");
perFileVars[fileInstance.get("id")] = {filename: fileInstance.get("name")};
});
uploader.set("postVarsPerFile", Y.merge(uploader.get("postVarsPerFile"), perFileVars));
});
uploader.on("uploadprogress", function (event) {
var fileRow = Y.one("#" + event.file.get("id") + "_row");
fileRow.one(".percentdone").set("text", event.percentLoaded + "%");
});
uploader.on("uploadstart", function (event) {
uploader.set("enabled", false);
Y.one("#uploadFilesButton").addClass("yui3-button-disabled");
Y.one("#uploadFilesButton").detach("click");
});
uploader.on("uploadcomplete", function (event) {
var fileRow = Y.one("#" + event.file.get("id") + "_row");
fileRow.one(".percentdone").set("text", "Finished!");
fileRow.one(".serverdata").setContent(event.data);
});
uploader.on("totaluploadprogress", function (event) {
Y.one("#overallProgress").setContent("Total uploaded: <strong>" + event.percentLoaded + "%" + "</strong>");
if (event.bytesLoaded == event.bytesTotal) {
uploadDone = true;
uploader.set("enabled", true);
uploader.set("fileList", []);
Y.one("#uploadFilesButton").removeClass("yui3-button-disabled");
Y.one("#uploadFilesButton").on("click", function () {
uploader.uploadAll();
});
Y.one("#overallProgress").set("text", "Uploads complete!");
// Workaround for bug 2531948
uploader.queue = null;
}
});
Y.one("#uploadFilesButton").on("click", function () {
uploader.uploadAll();
});
}
else {
Y.one("#uploaderContainer").set("text", "We are sorry, but the uploader technology is not supported" +
" on this platform.");
}
});
</script>