/home/coolpkct/www/websites/cake3.cool.rocks/admin/scripts/plupload/queue.js
/**
* Convert div to queue widget
* Code adapted from http://www.plupload.com/example_queuewidget.php
*/
$(function() {
var initSettings = {
// General settings. Empty object for resize seems necessary.
runtimes : 'html5,flash,html4',
url : '',
chunk_size : '1mb',
unique_names : false,
multiple_queues : true,
resize : {},
filters : [
{title : "Image files", extensions : "jpg,jpeg,gif,png"}
],
// Flash settings
flash_swf_url : 'plupload/js/Moxie.swf',
// PreInit events, bound before any internal events
preinit : {
Init: function(up, info) {
var runtimeName;
switch(info.runtime) {
case('html5') :
runtimeName = 'HTML5';
break;
case('flash') :
runtimeName = 'Flash';
break;
case('html4') :
runtimeName = 'Basic';
break;
default :
runtimeName = info.runtime;
}
$('ul.features').append(
'<li>Using ' + runtimeName + ' upload option</li>'
);
var html5Link = '<a href="index.php?cmd=' + cmd + '&runtime=html5' + sid +'">';
var flashLink = '<a href="index.php?cmd=' + cmd + '&runtime=flash' + sid + '">';
var html4Link = '<a href="index.php?cmd=' + cmd + '&runtime=html4' + sid + '">';
var swapRuntime = 'Change to ' + flashLink + 'Flash upload</a> | ' + html4Link + 'Basic upload</a>';
if (info.runtime == 'flash') {
swapRuntime = 'Change to ' + html5Link + 'HTML5 upload</a> | ' + html4Link + 'Basic upload</a>';
}
if (info.runtime == 'html4') {
swapRuntime = 'Change to ' + html5Link + 'HTML5 upload</a> | ' + flashLink + 'Flash upload</a>';
}
$('#swaps').append(swapRuntime);
$('ul.features').append(
up.features.chunks
? '<li>No file size limit</li>'
: '<li>Max file size ' + maxMBytes + 'MB</li>'
);
$('ul.features').append(
up.features.dragdrop
? '<li>Drag and drop supported</li>'
: '<li class="unsupported">Drag and drop not supported</li>'
);
$('ul.features').append(
up.features.multi_selection
? '<li>Multi-file selection supported</li>'
: '<li class="unsupported">Multi-file selection not supported</li>'
);
/* up.features.jpgresize does not appear to be supported in Plupload 2
switch (true) {
case (up.features.jpgresize && up.features.pngresize) :
resizeMessage = '<li>Jpeg and Png resize supported</li>';
break;
case (up.features.jpgresize && !up.features.pngresize) :
resizeMessage = '<li>Jpeg resize supported</li>';
break;
case (!up.features.jpgresize && up.features.pngresize) :
resizeMessage = '<li>Png resize supported</li>';
break;
default :
resizeMessage = '<li class="unsupported">Image resize not supported</li>';
}
$('ul.features').append(resizeMessage);
if (!up.features.jpgresize && !up.features.pngresize) {
$('#resizeOn').prop({disabled : true, checked : false});
}
*/
},
UploadFile: function(up, file) {
// Override settings before the file is uploaded
// User may have changed resize settings between uploads
var maxImageWidth = parseInt($('#maxImageWidth').val(), 10);
var maxImageHeight = parseInt($('#maxImageHeight').val(), 10);
var compressionQuality =
Math.max(
1, Math.min(100,
parseInt(
$('#compressionQuality').val(), 10
)
)
);
if (
$('#resizeOn').prop('checked')
&& maxImageWidth >= 0
&& maxImageHeight >= 0
) {
up.settings.resize.width = maxImageWidth;
up.settings.resize.height = maxImageHeight;
up.settings.resize.quality = compressionQuality;
} else {
// Setting up.settings.resize = {} seems to work but deleting properties seems safer
delete up.settings.resize.width;
delete up.settings.resize.height;
delete up.settings.resize.quality;
}
}
},
// Post init events, bound after the internal events
init : {
FileUploaded: function(up, file, info) {
// Called when a file has finished uploading
//log('[FileUploaded] File:', file, "Info:", info);
response = jQuery.parseJSON(info.response);
if (response.error && response.error.code){
up.trigger('Error', {
code : response.error.code,
message : response.error.message,
details : response.details,
file : file
});
}
}
}
};
// Overwrite defaults with settings written into page script by php
$.extend(initSettings, phpSettings);
// Initiate queue widget
$("#uploader").pluploadQueue(initSettings);
});