Skip to content

Commit

Permalink
Moved resize options into it's own object.
Browse files Browse the repository at this point in the history
Added new custom upload examples and updated some of the old ones.
  • Loading branch information
spocke committed Jan 27, 2010
1 parent 5ee2e60 commit 1c97de7
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 103 deletions.
85 changes: 85 additions & 0 deletions examples/custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="css/plupload.queue.css" type="text/css" media="screen" />
<title>Plupload - Queue widget example</title>
<style type="text/css">
body {background: #9A7C5F;}
</style>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3");
</script>
<script type="text/javascript" src="../js/gears_init.js"></script>
<script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
<!-- Load source versions of the plupload script files -->
<script type="text/javascript" src="../src/javascript/plupload.js"></script>
<script type="text/javascript" src="../src/javascript/plupload.gears.js"></script>
<script type="text/javascript" src="../src/javascript/plupload.silverlight.js"></script>
<script type="text/javascript" src="../src/javascript/plupload.flash.js"></script>
<script type="text/javascript" src="../src/javascript/plupload.browserplus.js"></script>
<script type="text/javascript" src="../src/javascript/plupload.html5.js"></script>
<script type="text/javascript" src="../src/javascript/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script>
<script>
// Custom example logic
$().ready(function() {
var uploader = new plupload.Uploader({
runtimes : 'gears,html5,flash,silverlight,browserplus',
browse_button : 'pickfiles',
max_file_size : '10mb',
url : 'upload.php',
resize : {width : 320, height : 240, quality : 90},
flash_swf_url : '/plupload/js/plupload.flash.swf',
silverlight_xap_url : '/plupload/js/plupload.silverlight.xap',
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
});

uploader.bind('Init', function(up, params) {
$('#filelist').html("<div>Current runtime: " + params.runtime + "</div>");
});

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

uploader.bind('UploadProgress', function(up, file) {
$('#' + file.id + " b").html(file.percent + "%");
});

$('#uploadfiles').click(function(e) {
uploader.start();
e.preventDefault();
});

uploader.init();
});
</script>
<!-- <script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script> -->
</head>
<body>

<form method="post" action="dump.php">
<h1>Custom example</h1>

<p>Shows you how to use the core plupload API.</p>

<div>
<div id="filelist">No runtime found.</div>
<br />
<a id="pickfiles" href="#">[Select files]</a>
<a id="uploadfiles" href="#">[Upload files]</a>
</div>
</form>

</body>
</html>
20 changes: 10 additions & 10 deletions examples/queue_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
chunk_size : '1mb',
unique_names : true,
filters : [
{title : "Image files", extensions : "*.jpg;*.gif;*.png", mac_types : "JPEG;jp2_;GIFF"},
{title : "Other files", extensions : "*.exe", mac_types : "EXE;jp2_;GIFF"}
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],

// Flash settings
Expand All @@ -43,8 +43,8 @@
chunk_size : '1mb',
unique_names : true,
filters : [
{title : "Image files", extensions : "*.jpg;*.gif;*.png", mac_types : "JPEG;jp2_;GIFF"},
{title : "Other files", extensions : "*.exe", mac_types : "EXE;jp2_;GIFF"}
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
});

Expand All @@ -57,8 +57,8 @@
chunk_size : '1mb',
unique_names : true,
filters : [
{title : "Image files", extensions : "*.jpg;*.gif;*.png", mac_types : "JPEG;jp2_;GIFF"},
{title : "Other files", extensions : "*.exe", mac_types : "EXE;jp2_;GIFF"}
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],

// Silverlight settings
Expand All @@ -74,8 +74,8 @@
chunk_size : '1mb',
unique_names : true,
filters : [
{title : "Image files", extensions : "*.jpg;*.gif;*.png", mac_types : "JPEG;jp2_;GIFF"},
{title : "Other files", extensions : "*.exe", mac_types : "EXE;jp2_;GIFF"}
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
});

Expand All @@ -88,8 +88,8 @@
chunk_size : '1mb',
unique_names : true,
filters : [
{title : "Image files", extensions : "*.jpg;*.gif;*.png", mac_types : "JPEG;jp2_;GIFF"},
{title : "Other files", extensions : "*.exe", mac_types : "EXE;jp2_;GIFF"}
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
});
});
Expand Down
68 changes: 36 additions & 32 deletions examples/queue_widget_dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
max_file_size : '10mb',
chunk_size : '1mb',
unique_names : true,
image_width : 320,
image_height : 240,
image_quality : 90,
resize : {width : 320, height : 240, quality : 90},
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
Expand All @@ -52,13 +50,11 @@
max_file_size : '10mb',
chunk_size : '1mb',
unique_names : true,
image_width : 320,
image_height : 240,
image_quality : 90,
resize : {width : 320, height : 240, quality : 90},
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],
]
});

// Setup silverlight version
Expand All @@ -69,9 +65,7 @@
max_file_size : '10mb',
chunk_size : '1mb',
unique_names : true,
image_width : 320,
image_height : 240,
image_quality : 90,
resize : {width : 320, height : 240, quality : 90},
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
Expand All @@ -89,9 +83,7 @@
max_file_size : '10mb',
chunk_size : '1mb',
unique_names : true,
image_width : 320,
image_height : 240,
image_quality : 90,
resize : {width : 320, height : 240, quality : 90},
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
Expand All @@ -106,30 +98,35 @@
max_file_size : '10mb',
chunk_size : '1mb',
unique_names : true,
image_width : 320,
image_height : 240,
image_quality : 90,
resize : {width : 320, height : 240, quality : 90},
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
});

var uploader = new plupload.Uploader({
runtimes : 'gears,html5,flash',
browse_button : 'button_id'
});
uploader.bind('Init', function(up) {
alert('Supports drag/drop: ' + (!!up.features.dragdrop));
});
uploader.bind('FilesAdded', function(up, files) {
alert('Selected files: ' + files.length);
});
uploader.bind('QueueChanged', function(up) {
alert('Queued files: ' + uploader.files.length);
});

uploader.init();
// Custom example
var uploader = new plupload.Uploader({
runtimes : 'gears,html5,flash,silverlight,browserplus',
browse_button : 'pickfiles',
url : 'upload.php'
});

uploader.bind('FilesAdded', function(up, files) {
$.each(files, function(i, file) {
$('#filelist').append("<div id=" + file.id + ">File: " + file.name + " (" + plupload.formatSize(file.size) + ") <span></span></div>");
});
});

uploader.bind('UploadProgress', function(up, file) {
$('#' + file.id + " span").html(file.percent + "%");
});

$('#uploadfiles').click(function() {
uploader.start();
});

uploader.init();
});
</script>
<!-- <script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script> -->
Expand All @@ -138,7 +135,7 @@

<form method="post" action="dump.php">
<h1>Queue widget example</h1>
<input id="button_id" />

<p>Shows the jQuery Plupload Queue widget and under different runtimes.</p>

<div style="float: left; margin-right: 20px">
Expand All @@ -160,6 +157,13 @@ <h3>HTML 5 runtime</h3>
<div style="float: left; margin-right: 20px">
<h3>BrowserPlus runtime</h3>
<div id="browserplus_uploader" style="width: 450px; height: 330px;">You browser doesn't have BrowserPlus installed.</div>

<div>
<h3>Custom example</h3>
<div id="filelist"></div>
<input id="pickfiles" type="button" value="Pick files" />
<input id="uploadfiles" type="button" value="Upload" />
</div>
</div>

<br style="clear: both" />
Expand Down
32 changes: 1 addition & 31 deletions examples/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,4 @@

// Return JSON-RPC response
die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
?> for ($i=0; isset($_FILES['file' . $i]['tmp_name']); $i++) {
$filename = utf8_encode($input["name" . $i]);

// Do nothing in demo mode
if (checkBool($config['general.demo'])) {
$result->add("DEMO_ERROR", $man->encryptPath($file->getAbsolutePath()), "{#error.demo}");
continue;
}

// No access, tool disabled
if (in_array("upload", explode(',', $config['general.disabled_tools'])) || !$file->canWrite() || !checkBool($config["filesystem.writable"])) {
$result->add("ACCESS_ERROR", $man->encryptPath($file->getAbsolutePath()), "{#error.no_access}");
continue;
}

// Get ext to glue back on
$ext = "";
if (strpos(basename($_FILES['file' . $i]['name']), ".") > 0) {
$ar = explode('.', basename($_FILES['file' . $i]['name']));
$ext = array_pop($ar);
}

$file =& $man->getFile($path, $filename . "." . $ext, "", MC_IS_FILE);
if ($man->verifyFile($file, "upload") < 0) {
$result->add("ACCESS_ERROR", $man->encryptPath($file->getAbsolutePath()), $man->getInvalidFileMsg());
continue;
}

$config = $file->getConfig();

if (is_uploaded_file($_FILES['file' . $i]['tmp_name'])) {
?>
16 changes: 7 additions & 9 deletions src/javascript/plupload.browserplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
* @param {function} callback Callback to execute when the runtime initializes or fails to initialize. If it succeeds an object with a parameter name success will be set to true.
*/
init : function(uploader, callback) {
var browserPlus = window.BrowserPlus, browserPlusFiles = {}, imageWidth, imageHeight, settings = uploader.settings;

imageWidth = settings.image_width;
imageHeight = settings.image_height;
var browserPlus = window.BrowserPlus, browserPlusFiles = {}, settings = uploader.settings, resize = settings.resize;

function addSelectedFiles(native_files) {
var files, i, selectedFiles = [], file, id;
Expand Down Expand Up @@ -58,7 +55,7 @@
{service: "FileBrowse", version: "1"}
];

if (imageWidth || imageHeight)
if (resize)
services.push({service : 'ImageAlter', version : "4"});

if (res.success) {
Expand Down Expand Up @@ -194,14 +191,15 @@
});
};

if (/\.(png|jpg|jpeg)$/i.test(file.name) && (imageWidth || imageHeight)) {
// Resize image if it's a supported format and resize is enabled
if (resize && /\.(png|jpg|jpeg)$/i.test(file.name)) {
BrowserPlus.ImageAlter.transform({
file : nativeFile,
quality : up.settings.image_quality,
quality : resize.quality || 90,
actions : [{
scale : {
maxwidth : imageWidth,
maxheight : imageHeight
maxwidth : resize.width,
maxheight : resize.height
}
}]
}, function(res) {
Expand Down
8 changes: 4 additions & 4 deletions src/javascript/plupload.flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

// Wait for Flash to send init event
uploader.bind("Flash:Init", function() {
var lookup = {}, i, filters = uploader.settings.filters;
var lookup = {}, i, filters = uploader.settings.filters, resize = uploader.settings.resize || {};

initialized = true;

Expand All @@ -142,9 +142,9 @@
lookup[file.id],
url,
settings.chunk_size,
settings.image_width,
settings.image_height,
settings.image_quality
resize.width,
resize.height,
resize.quality || 90
);
});

Expand Down
11 changes: 4 additions & 7 deletions src/javascript/plupload.gears.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,14 @@
});

uploader.bind("UploadFile", function(up, file) {
var chunk = 0, chunks, chunkSize, loaded = 0, imageWidth, imageHeight;

imageWidth = up.settings.image_width;
imageHeight = up.settings.image_height;
var chunk = 0, chunks, chunkSize, loaded = 0, resize = up.settings.resize;

chunkSize = up.settings.chunk_size;
chunks = Math.ceil(file.size / chunkSize);

// Scale the image
if (/\.(png|jpg|jpeg)$/i.test(file.name) && (imageWidth || imageHeight))
blobs[file.id] = scaleImage(blobs[file.id], imageWidth, imageHeight, up.settings.image_quality, /\.png$/i.test(file.name) ? 'image/png' : 'image/jpeg');
// If file is png or jpeg and resize is configured then resize it
if (resize && /\.(png|jpg|jpeg)$/i.test(file.name))
blobs[file.id] = scaleImage(blobs[file.id], resize.width, resize.height, resize.quality || 90, /\.png$/i.test(file.name) ? 'image/png' : 'image/jpeg');

file.size = blobs[file.id].length;

Expand Down
Loading

0 comments on commit 1c97de7

Please sign in to comment.