0) {
this.cancelUpload();
stats = this.getStats();
}
};
SWFUpload.queue.uploadStartHandler = function (file) {
var returnValue;
if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
}
// To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
returnValue = (returnValue === false) ? false : true;
this.queueSettings.queue_cancelled_flag = !returnValue;
return returnValue;
};
SWFUpload.queue.uploadCompleteHandler = function (file) {
var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
var continueUpload;
if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
this.queueSettings.queue_upload_count++;
}
if (typeof(user_upload_complete_handler) === "function") {
continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
} else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
// If the file was stopped and re-queued don't restart the upload
continueUpload = false;
} else {
continueUpload = true;
}
if (continueUpload) {
var stats = this.getStats();
if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
this.startUpload();
} else if (this.queueSettings.queue_cancelled_flag === false) {
this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
this.queueSettings.queue_upload_count = 0;
} else {
this.queueSettings.queue_cancelled_flag = false;
this.queueSettings.queue_upload_count = 0;
}
}
};
}/*
A simple class for displaying file information and progress
Note: This is a demonstration only and not part of SWFUpload.
Note: Some have had problems adapting this class in IE7. It may not be suitable for your application.
*/
// Constructor
// file is a SWFUpload file object
// targetID is the HTML element id attribute that the FileProgress HTML structure will be added to.
// Instantiating a new FileProgress object with an existing file will reuse/update the existing DOM elements
function FileProgress(file, targetID) {
this.fileProgressID = file.id;
this.opacity = 100;
this.height = 0;
this.fileProgressWrapper = document.getElementById(this.fileProgressID);
if (!this.fileProgressWrapper) {
this.fileProgressWrapper = document.createElement("div");
this.fileProgressWrapper.className = "progressWrapper";
this.fileProgressWrapper.id = this.fileProgressID;
this.fileProgressElement = document.createElement("div");
this.fileProgressElement.className = "progressContainer";
var progressCancel = document.createElement("a");
progressCancel.className = "progressCancel";
progressCancel.href = "#";
progressCancel.style.visibility = "hidden";
progressCancel.appendChild(document.createTextNode(" "));
var progressText = document.createElement("div");
progressText.className = "progressName";
progressText.appendChild(document.createTextNode(file.name.substr(0, 20)));
var progressBar = document.createElement("div");
progressBar.className = "progressBarInProgress";
var progressStatus = document.createElement("div");
progressStatus.className = "progressBarStatus";
progressStatus.innerHTML = " ";
this.fileProgressElement.appendChild(progressCancel);
this.fileProgressElement.appendChild(progressText);
this.fileProgressElement.appendChild(progressStatus);
this.fileProgressElement.appendChild(progressBar);
this.fileProgressWrapper.appendChild(this.fileProgressElement);
document.getElementById(targetID).appendChild(this.fileProgressWrapper);
} else {
this.fileProgressElement = this.fileProgressWrapper.firstChild;
this.reset();
}
this.height = this.fileProgressWrapper.offsetHeight;
this.setTimer(null);
}
FileProgress.prototype.setTimer = function (timer) {
this.fileProgressElement["FP_TIMER"] = timer;
};
FileProgress.prototype.getTimer = function (timer) {
return this.fileProgressElement["FP_TIMER"] || null;
};
FileProgress.prototype.reset = function () {
this.fileProgressElement.className = "progressContainer";
this.fileProgressElement.childNodes[2].innerHTML = " ";
this.fileProgressElement.childNodes[2].className = "progressBarStatus";
this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
this.fileProgressElement.childNodes[3].style.width = "0%";
this.appear();
};
FileProgress.prototype.setProgress = function (percentage) {
this.fileProgressElement.className = "progressContainer green";
this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
this.fileProgressElement.childNodes[3].style.width = percentage + "%";
this.appear();
};
FileProgress.prototype.setComplete = function () {
this.fileProgressElement.className = "progressContainer blue";
this.fileProgressElement.childNodes[3].className = "progressBarComplete";
this.fileProgressElement.childNodes[3].style.width = "";
var oSelf = this;
this.setTimer(setTimeout(function () {
oSelf.disappear();
}, 10000));
};
FileProgress.prototype.setError = function () {
this.fileProgressElement.className = "progressContainer red";
this.fileProgressElement.childNodes[3].className = "progressBarError";
this.fileProgressElement.childNodes[3].style.width = "";
var oSelf = this;
this.setTimer(setTimeout(function () {
oSelf.disappear();
}, 5000));
};
FileProgress.prototype.setCancelled = function () {
this.fileProgressElement.className = "progressContainer";
this.fileProgressElement.childNodes[3].className = "progressBarError";
this.fileProgressElement.childNodes[3].style.width = "";
var oSelf = this;
this.setTimer(setTimeout(function () {
oSelf.disappear();
}, 2000));
};
FileProgress.prototype.setStatus = function (status) {
this.fileProgressElement.childNodes[2].innerHTML = status;
};
// Show/Hide the cancel button
FileProgress.prototype.toggleCancel = function (show, swfUploadInstance) {
this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
if (swfUploadInstance) {
var fileID = this.fileProgressID;
this.fileProgressElement.childNodes[0].onclick = function () {
swfUploadInstance.cancelUpload(fileID);
return false;
};
}
};
FileProgress.prototype.appear = function () {
if (this.getTimer() !== null) {
clearTimeout(this.getTimer());
this.setTimer(null);
}
if (this.fileProgressWrapper.filters) {
try {
this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 100;
} catch (e) {
// If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
}
} else {
this.fileProgressWrapper.style.opacity = 1;
}
this.fileProgressWrapper.style.height = "";
this.height = this.fileProgressWrapper.offsetHeight;
this.opacity = 100;
this.fileProgressWrapper.style.display = "";
};
// Fades out and clips away the FileProgress box.
FileProgress.prototype.disappear = function () {
var reduceOpacityBy = 15;
var reduceHeightBy = 4;
var rate = 30; // 15 fps
if (this.opacity > 0) {
this.opacity -= reduceOpacityBy;
if (this.opacity < 0) {
this.opacity = 0;
}
if (this.fileProgressWrapper.filters) {
try {
this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity;
} catch (e) {
// If it is not set initially, the browser will throw an error. This will set it if it is not set yet.
this.fileProgressWrapper.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + this.opacity + ")";
}
} else {
this.fileProgressWrapper.style.opacity = this.opacity / 100;
}
}
if (this.height > 0) {
this.height -= reduceHeightBy;
if (this.height < 0) {
this.height = 0;
}
this.fileProgressWrapper.style.height = this.height + "px";
}
if (this.height > 0 || this.opacity > 0) {
var oSelf = this;
this.setTimer(setTimeout(function () {
oSelf.disappear();
}, rate));
} else {
this.fileProgressWrapper.style.display = "none";
this.setTimer(null);
}
};
var all_images3 = new Array();
var swfu;
jQuery(document).ready(function() {
swfu = new SWFUpload({
post_params: {
'PHPSESSID':'59686488602efa2567650e72c7cede2d',
'return' :'json'
},
upload_url : '/upload/post',
flash_url : '/js/swfupload/new/swfupload.swf',
file_size_limit : '5 MB',
button_image_url : (window.is_in_album)?'/js/swfupload/browse_sprite_small.png':'/js/swfupload/browse_sprite.png',
button_placeholder_id : 'uploadify',
button_width : (window.is_in_album)?290:479,
button_height : (window.is_in_album)?21:34,
button_cursor : SWFUpload.CURSOR.HAND,
button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT,
file_post_name : "Filedata",
file_types : '*.jpg;*.png;*.gif;*.bmp',
file_types_description: '*.jpg;*.png;*.gif;*.bmp',
custom_settings : {
progressTarget : "uploadify_progress"
},
swfupload_preload_handler : swfupload_preload_handler,
swfupload_load_failed_handler : swfupload_load_failed_handler,
swfupload_loaded_handler : swfupload_loaded_handler,
file_queued_handler : file_queued_handler,
file_queue_error_handler : file_queue_error_handler,
file_dialog_complete_handler : file_dialog_complete_handler,
upload_start_handler : upload_start_handler,
upload_progress_handler : upload_progress_handler,
upload_error_handler : upload_error_handler,
upload_success_handler : upload_success_handler,
upload_complete_handler : upload_complete_handler,
queue_complete_handler : queue_complete_handler // Queue plugin event
});
});
function swfupload_preload_handler() {
//do html5 uploader
if (typeof FileReader !== "undefined" && typeof window.opera == 'undefined') {
html5UploadInit();
return false;
}
if (!this.support.loading) {
d("You need the Flash Player 9.028 or above to use SWFUpload.");
return false;
}
}
function swfupload_load_failed_handler() {
d("Something went wrong while loading SWFUpload. If this were a real application we'd clean up and then give you an alternative");
}
function swfupload_loaded_handler() {
if(typeof uploadify_ExtraInit == 'function') uploadify_ExtraInit();
}
function file_queued_handler(file) {
try {
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setStatus("Pending...");
progress.toggleCancel(true, this);
} catch (e) {
this.debug(e);
}
}
function file_queue_error_handler(file, errorCode, message) {
try {
if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
return;
}
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setError();
progress.toggleCancel(false);
switch (errorCode) {
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
progress.setStatus("File is too big.");
this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
progress.setStatus("Cannot upload Zero Byte files.");
this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
progress.setStatus("Invalid File Type.");
this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
default:
if (file !== null) {
progress.setStatus("Unhandled Error");
}
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
}
} catch (e) {
this.debug(e);
}
}
function file_dialog_complete_handler(numFilesSelected, numFilesQueued) {
try {
this.startUpload();
} catch (e) {
this.debug(e);
}
}
function upload_start_handler(file) {
try {
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setStatus("Uploading...");
progress.toggleCancel(true, this);
}
catch (e) {}
return true;
}
function upload_progress_handler(file, bytesLoaded, bytesTotal) {
try {
var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setProgress(percent);
progress.setStatus("Uploading...");
} catch (e) {
this.debug(e);
}
}
function upload_success_handler(file, serverData) {
try {
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setComplete();
progress.setStatus("Complete.");
progress.toggleCancel(false);
d(serverData);
var json = {};
try {
var json = eval('(' + serverData + ')');
}catch(e){}
if(json.error == 0) {
jQuery('#response').append('');
all_images3[all_images3.length] = json.id;
}else{
d(serverData);
jQuery('#response').append(''+file.name+': Error: wrong server response.
');
}
return true;
} catch (e) {
this.debug(e);
}
}
function upload_error_handler(file, errorCode, message) {
try {
var progress = new FileProgress(file, this.customSettings.progressTarget);
progress.setError();
progress.toggleCancel(false);
switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
progress.setStatus("Upload Error: " + message);
this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
progress.setStatus("Upload Failed.");
this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
progress.setStatus("Server (IO) Error");
this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
progress.setStatus("Security Error");
this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
progress.setStatus("Upload limit exceeded.");
this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
progress.setStatus("Failed Validation. Upload skipped.");
this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
// If there aren't any files left (they were all cancelled) disable the cancel button
if (this.getStats().files_queued === 0) {
}
progress.setStatus("Cancelled");
progress.setCancelled();
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
progress.setStatus("Stopped");
break;
default:
progress.setStatus("Unhandled Error: " + errorCode);
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
}
} catch (e) {
this.debug(e);
}
}
function upload_complete_handler(file) {
if (this.getStats().files_queued === 0) {
}
}
// This event comes from the Queue Plugin
function queue_complete_handler(numFilesUploaded) {
// var status = document.getElementById("divStatus");
// status.innerHTML = numFilesUploaded + " file" + (numFilesUploaded === 1 ? "" : "s") + " uploaded.";
jQuery('#upload_form').show();
if(typeof uploadify_ExtraCallback == 'function') uploadify_ExtraCallback();
if(all_images3.length >= 2){
move_to_new_album_guest();
}
}
function html5UploadInit(){
function size(bytes){ // simple function to show a friendly size
var i = 0;
while(1023 < bytes){
bytes /= 1024;
++i;
};
return i ? bytes.toFixed(2) + ["", " Kb", " Mb", " Gb", " Tb"][i] : bytes + " bytes";
};
var placer = document.getElementById('flash_upload');
// create elements
var input = placer.appendChild(document.createElement("input")),
sub = placer.appendChild(document.createElement("div")).appendChild(document.createElement("span")),
bar = placer.appendChild(document.createElement("div")).appendChild(document.createElement("span")),
div = placer.appendChild(document.createElement("div"));
// set input type as file
input.setAttribute("type", "file");
// input.setAttribute("class","file_1");
// enable multiple selection (note: it does not work with direct input.multiple = true assignment)
input.setAttribute("multiple", "true");
// auto upload on files change
input.addEventListener("change", function(){
// disable the input
input.setAttribute("disabled", "true");
var url = '/upload/post/html5/1';
if ( window.is_in_album ) {
albumId = jQuery('#album_id').val();
url += '/albumId/' + albumId;
}
sendMultipleFiles({
url: url,
// list of files to upload
files:input.files,
// clear the container
onloadstart:function(rpe, xhr){
if ( !this.file.fileName.match(/jpg$|jpeg$|gif$|png$|bmp$/i) ){
alert('Only images allowed to upload!');
xhr.abort();
input.removeAttribute("disabled");
return false;
}
div.innerHTML = "Init upload ... ";
sub.style.width = bar.style.width = "0px";
},
// do something during upload ...
onprogress:function(rpe){
var totalwidth=(window.is_in_album)?300:400;
/* div.innerHTML = [
"Uploading:" + subname.substr(0,10),
"Sent: " + size(rpe.loaded) + " of " + size(rpe.total),
"Total Sent: " + size(this.sent + rpe.loaded) + " of " + size(this.total)
].join("
");*/
div.innerHTML = [""];
sub.style.width = ((rpe.loaded * totalwidth / rpe.total) >> 0) + "px";
bar.style.width = (((this.sent + rpe.loaded) * totalwidth / this.total) >> 0) + "px";
sub.innerHTML = [
"Uploading: file", //+ this.file.fileName.substr(0,25),
"Sent: " + size(rpe.loaded) + " of " + size(rpe.total)+""].join(" | ");
bar.innerHTML = [
"Total Sent: " + size(this.sent + rpe.loaded) + " of " + size(this.total)+""];
},
// fired when last file has been uploaded
onload:function(rpe, xhr){
sub.style.width = bar.style.width = "100%";
// magCustomOnUpload(xhr);
// enable the input again
input.removeAttribute("disabled");
input.value = '';
jQuery('#upload_form').show();
if(typeof uploadify_ExtraCallback == 'function') uploadify_ExtraCallback();
if(all_images3.length >= 2){
move_to_new_album_guest();
}
},
// if something is wrong ... (from native instance or because of size)
onerror:function(){
div.innerHTML = "The file " + this.file.fileName + " is too big [" + size(this.file.fileSize) + "]";
// enable the input again
input.removeAttribute("disabled");
}
});
}, false);
sub.parentNode.className = "progress";
bar.parentNode.className = "progress";
}
function magCustomOnUpload(xhr){
var json = {};
try {
var json = eval('(' + xhr.responseText + ')');
}catch(e){}
if(json.error == 0) {
jQuery('#response').append('');
all_images3[all_images3.length] = json.id;
}else{
d(xhr.responseText);
jQuery('#response').append(': Error: wrong server response. Details: '+json.info+'.
');
}
}