forked from ntulip/swfupload-jquery-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding plugin, vendor files and example files.
- Loading branch information
Showing
8 changed files
with
1,314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
SWFUpload jQuery Plugin v1.0.0 | ||
------------------------------- | ||
Copyright (c) 2009 Adam Royle. Licensed under the MIT license. | ||
|
||
|
||
Overview | ||
-------- | ||
|
||
A jQuery plugin that makes working with SWFUpload event easier. | ||
|
||
Features include: | ||
- jQuery-style instantiation | ||
- jQuery-style event handling | ||
- Ability to separate SWFUpload object from UI code | ||
|
||
|
||
Usage | ||
----- | ||
|
||
// create the swfupload instance (settings must be an object) | ||
$('.swfupload-control').swfupload(settings); | ||
|
||
// add some additional handlers (for any plugins if used) | ||
$.swfupload.additionalHandlers('some_extra_handler', 'another_extra_handler'); | ||
|
||
// same as above but as an array | ||
$.swfupload.additionalHandlers(['some_extra_handler', 'another_extra_handler']); | ||
|
||
// or just return an array of the additional handler names | ||
$.swfupload.additionalHandlers(); | ||
|
||
// or return an array of the default handler names | ||
$.swfupload.defaultHandlers(); | ||
|
||
// bind the swfupload event handlers like an other jquery event | ||
$('.swfupload-control') | ||
.bind('swfuploadLoaded', function(event){ | ||
console.debug('swfuploadLoaded!!', event); | ||
}) | ||
.bind('fileQueued', function(event, file){ | ||
$(this).swfupload('startUpload'); | ||
console.debug('fileQueued!!', event); | ||
}); | ||
|
||
|
||
// call methods on the swfupload instances by passing a string as the first parameter | ||
// this method is chainable and therefore does not return any values | ||
$('.swfupload-control').swfupload('startUpload', fileID); | ||
$('.swfupload-control').swfupload('cancelUpload', fileID, triggerErrorEvent); | ||
|
||
// or if you prefer, you can just get the instance directly | ||
// if you need any return values for methods | ||
$.swfupload.getInstance('.swfupload-control'); | ||
|
||
|
||
|
||
Event Names (and, their, params) | ||
-------------------------------- | ||
swfuploadLoaded (event) | ||
fileQueued (event, file) | ||
fileQueueError (event, file, errorCode, message) | ||
fileDialogStart (event) | ||
fileDialogComplete (event, numFilesSelected, numFilesQueued) | ||
uploadStart (event, file) | ||
uploadProgress (event, file, bytesLoaded) | ||
uploadSuccess (event, file, serverData) | ||
uploadComplete (event, file) | ||
uploadError (file, errorCode, message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<!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"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>SWFUpload Example - Single Uploader</title> | ||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> | ||
<script type="text/javascript" src="../vendor/swfupload/swfupload.js"></script> | ||
<script type="text/javascript" src="../src/jquery.swfupload.js"></script> | ||
<script type="text/javascript"> | ||
|
||
$(function(){ | ||
$('#swfupload-control').swfupload({ | ||
upload_url: "upload.php", | ||
file_size_limit : "10240", | ||
file_types : "*.*", | ||
file_types_description : "All Files", | ||
file_upload_limit : "0", | ||
flash_url : "../vendor/swfupload/swfupload.swf", | ||
button_image_url : '../vendor/swfupload/XPButtonUploadText_61x22.png', | ||
button_width : 61, | ||
button_height : 22, | ||
button_placeholder : $('#button')[0], | ||
debug: true, | ||
custom_settings : {something : "here"} | ||
}) | ||
.bind('swfuploadLoaded', function(event){ | ||
$('#log').append('<li>Loaded</li>'); | ||
}) | ||
.bind('fileQueued', function(event, file){ | ||
$('#log').append('<li>File queued - '+file.name+'</li>'); | ||
// start the upload since it's queued | ||
$(this).swfupload('startUpload'); | ||
}) | ||
.bind('fileQueueError', function(event, file, errorCode, message){ | ||
$('#log').append('<li>File queue error - '+message+'</li>'); | ||
}) | ||
.bind('fileDialogStart', function(event){ | ||
$('#log').append('<li>File dialog start</li>'); | ||
}) | ||
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ | ||
$('#log').append('<li>File dialog complete</li>'); | ||
}) | ||
.bind('uploadStart', function(event, file){ | ||
$('#log').append('<li>Upload start - '+file.name+'</li>'); | ||
}) | ||
.bind('uploadProgress', function(event, file, bytesLoaded){ | ||
$('#log').append('<li>Upload progress - '+bytesLoaded+'</li>'); | ||
}) | ||
.bind('uploadSuccess', function(event, file, serverData){ | ||
$('#log').append('<li>Upload success - '+file.name+'</li>'); | ||
}) | ||
.bind('uploadComplete', function(event, file){ | ||
$('#log').append('<li>Upload complete - '+file.name+'</li>'); | ||
// upload has completed, lets try the next one in the queue | ||
$(this).swfupload('startUpload'); | ||
}) | ||
.bind('uploadError', function(file, errorCode, message){ | ||
$('#log').append('<li>Upload error - '+message+'</li>'); | ||
}); | ||
|
||
}); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
|
||
<div id="swfupload-control"> | ||
<ol id="log"></ol> | ||
<input type="button" id="button" /> | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!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"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>SWFUpload Example - Multiple Uploaders</title> | ||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> | ||
<script type="text/javascript" src="../vendor/swfupload/swfupload.js"></script> | ||
<script type="text/javascript" src="../src/jquery.swfupload.js"></script> | ||
<script type="text/javascript"> | ||
|
||
jQuery.fn.bindAll = function(options) { | ||
var $this = this; | ||
jQuery.each(options, function(key, val){ | ||
$this.bind(key, val); | ||
}); | ||
return this; | ||
} | ||
|
||
$(function(){ | ||
|
||
var listeners = { | ||
swfuploadLoaded: function(event){ | ||
$('.log', this).append('<li>Loaded</li>'); | ||
}, | ||
fileQueued: function(event, file){ | ||
$('.log', this).append('<li>File queued - '+file.name+'</li>'); | ||
// start the upload once it is queued | ||
// but only if this queue is not disabled | ||
if (!$('input[name=disabled]:checked', this).length) { | ||
$(this).swfupload('startUpload'); | ||
} | ||
}, | ||
fileQueueError: function(event, file, errorCode, message){ | ||
$('.log', this).append('<li>File queue error - '+message+'</li>'); | ||
}, | ||
fileDialogStart: function(event){ | ||
$('.log', this).append('<li>File dialog start</li>'); | ||
}, | ||
fileDialogComplete: function(event, numFilesSelected, numFilesQueued){ | ||
$('.log', this).append('<li>File dialog complete</li>'); | ||
}, | ||
uploadStart: function(event, file){ | ||
$('.log', this).append('<li>Upload start - '+file.name+'</li>'); | ||
// don't start the upload if this queue is disabled | ||
if ($('input[name=disabled]:checked', this).length) { | ||
event.preventDefault(); | ||
} | ||
}, | ||
uploadProgress: function(event, file, bytesLoaded){ | ||
$('.log', this).append('<li>Upload progress - '+bytesLoaded+'</li>'); | ||
}, | ||
uploadSuccess: function(event, file, serverData){ | ||
$('.log', this).append('<li>Upload success - '+file.name+'</li>'); | ||
}, | ||
uploadComplete: function(event, file){ | ||
$('.log', this).append('<li>Upload complete - '+file.name+'</li>'); | ||
// upload has completed, lets try the next one in the queue | ||
// but only if this queue is not disabled | ||
if (!$('input[name=disabled]:checked', this).length) { | ||
$(this).swfupload('startUpload'); | ||
} | ||
}, | ||
uploadError: function(file, errorCode, message){ | ||
$('.log', this).append('<li>Upload error - '+message+'</li>'); | ||
} | ||
}; | ||
|
||
$('.swfupload-control').bindAll(listeners); | ||
|
||
|
||
// start the queue if the queue is already disabled | ||
$('.swfupload-control input[name=disabled]').click(function(){ | ||
if (!this.checked) { | ||
$(this).parents('.swfupload-control').swfupload('startUpload'); | ||
} | ||
}); | ||
|
||
}); | ||
|
||
$(function(){ | ||
$('.swfupload-control').each(function(){ | ||
$(this).swfupload({ | ||
upload_url: "upload.php", | ||
file_size_limit : "10240", | ||
file_types : "*.*", | ||
file_types_description : "All Files", | ||
file_upload_limit : "0", | ||
flash_url : "../vendor/swfupload/swfupload.swf", | ||
button_image_url : '../vendor/swfupload/XPButtonUploadText_61x22.png', | ||
button_width : 61, | ||
button_height : 22, | ||
button_placeholder : $('.button', this)[0], | ||
debug: true | ||
}); | ||
}); | ||
}); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
|
||
<div style="width:48%;float:left;"> | ||
|
||
<div class="swfupload-control"> | ||
<label><input type="checkbox" name="disabled" /> Disabled</label> | ||
<ol class="log"></ol> | ||
<input type="button" class="button" /> | ||
</div> | ||
|
||
</div> | ||
|
||
<div style="width:48%;float:right;"> | ||
|
||
<div class="swfupload-control"> | ||
<label><input type="checkbox" name="disabled" /> Disabled</label> | ||
<ol class="log"></ol> | ||
<input type="button" class="button" /> | ||
</div> | ||
|
||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// we don't actually save the file, since this is just a demo - we just say that we did | ||
|
||
echo '1'; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* SWFUpload jQuery Plugin v1.0.0 | ||
* | ||
* Copyright (c) 2009 Adam Royle | ||
* Licensed under the MIT license. | ||
* | ||
*/ | ||
|
||
(function($){ | ||
|
||
var defaultHandlers = ['swfupload_loaded_handler','file_queued_handler','file_queue_error_handler','file_dialog_start_handler','file_dialog_complete_handler','upload_start_handler','upload_progress_handler','upload_error_handler','upload_success_handler','upload_complete_handler']; | ||
var additionalHandlers = []; | ||
|
||
$.fn.swfupload = function(){ | ||
var args = $.makeArray(arguments); | ||
return this.each(function(){ | ||
var swfu; | ||
if (args.length == 1 && typeof(args[0]) == 'object') { | ||
swfu = $(this).data('__swfu'); | ||
if (!swfu) { | ||
var settings = args[0]; | ||
var $magicUploadControl = $(this); | ||
var handlers = []; | ||
$.merge(handlers, defaultHandlers, additionalHandlers); | ||
$.each(handlers, function(i, v){ | ||
var eventName = v.replace(/_handler$/, '').replace(/_([a-z])/g, function(){ return arguments[1].toUpperCase(); }); | ||
settings[v] = function() { | ||
var event = $.Event(eventName); | ||
$magicUploadControl.trigger(event, $.makeArray(arguments)); | ||
return !event.isDefaultPrevented(); | ||
}; | ||
}); | ||
$(this).data('__swfu', new SWFUpload(settings)); | ||
} | ||
} else if (args.length > 0 && typeof(args[0]) == 'string') { | ||
var methodName = args.shift(); | ||
swfu = $(this).data('__swfu'); | ||
if (swfu && swfu[methodName]) { | ||
swfu[methodName].apply(swfu, args); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
$.swfupload = { | ||
additionalHandlers: function() { | ||
if (arguments.length === 0) { | ||
return additionalHandlers.slice(); | ||
} else { | ||
$(arguments).each(function(){ | ||
$.merge(additionalHandlers, $.makeArray(this)); | ||
}); | ||
} | ||
}, | ||
defaultHandlers: function() { | ||
return defaultHandlers.slice(); | ||
}, | ||
getInstance: function(el) { | ||
return $(el).data('__swfu'); | ||
} | ||
}; | ||
|
||
})(jQuery); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.