PDA

View Full Version : Jquery Questions



bluewalrus
03-27-2011, 11:30 PM
Is this
$(function(){ the same as
$(document).ready(function () {?

I'm using the swfUpload uploader. I have this code

I want to separate the button set up,


$(function(){
$('#swfupload-control').swfupload({
upload_url: 'upload-file.php>',
file_post_name: 'uploadfile',
file_size_limit : "0",
file_types : "*.*",
file_types_description : "All files are allowed.",
file_upload_limit : 0,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/upload.png',
button_width : 114,
button_height : 32,
button_placeholder : $('#button')[0],
debug: false
})

from the files being uploaded. I need to separate this out because the button I'm using for the upload won't be on the page when page is loaded, rather when a button is clicked. The button can also be removed and readded and the uploads can continue in the order they are in.


<script type="text/javascript">
var list_of_files = "";
$(function(){
$('#swfupload-control').swfupload({
upload_url: 'upload-file.php>',
file_post_name: 'uploadfile',
file_size_limit : "0",
file_types : "*.*",
file_types_description : "All files are allowed.",
file_upload_limit : 0,
flash_url : "js/swfupload/swfupload.swf",
button_image_url : 'js/swfupload/upload.png',
button_width : 114,
button_height : 32,
button_placeholder : $('#button')[0],
debug: false
})
.bind('fileQueued', function(event, file){
var listitem='<li id="'+file.id+'" >'+
'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB) <span class="progressvalue" ></span>'+
'<div class="progressbar" ><div class="progress" ></div></div>'+
'<p class="status" >Pending</p>'+
'<span class="cancel" >&nbsp;</span>'+
'</li>';
$('#log').append(listitem);
$('li#'+file.id+' .cancel').bind('click', function(){
var swfu = $.swfupload.getInstance('#swfupload-control');
swfu.cancelUpload(file.id);
$('li#'+file.id).slideUp('fast');
});
// start the upload since it's queued
$(this).swfupload('startUpload');
})
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
$('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued);
})
.bind('uploadStart', function(event, file){
$('#log li#'+file.id).find('p.status').text('Uploading...');
$('#log li#'+file.id).find('span.progressvalue').text('0%');
$('#log li#'+file.id).find('span.cancel').hide();
})
.bind('uploadProgress', function(event, file, bytesLoaded){
var percentage=Math.round((bytesLoaded/file.size)*100);
$('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
$('#log li#'+file.id).find('span.progressvalue').text(percentage+'%');
})
.bind('uploadSuccess', function(event, file, serverData){
//insert alert here for file was uploaded successfully
if (list_of_files ==="") {
list_of_files = file.name;
} else {
list_of_files = list_of_files + "\n" + file.name;
}
var item=$('#log li#'+file.id);
item.find('div.progress').css('width', '100%');
item.find('span.progressvalue').text('100%');
var pathtofile='<a target="_blank" href="files/ftp_upload/<?php echo $a_id . "/"; //link to uploaded file?>'+file.name+'">view &raquo;</a>';
item.addClass('success').find('p.status').html('File uploaded successfully | '+pathtofile);
})
.bind('uploadComplete', function(event, file){
document.getElementById("cancel").setAttribute("style", "display:none;");
// upload has completed, try the next one in the queue
$(this).swfupload('startUpload');
})
});
</script>

I'm not following where the 'fileQueued', of .bind('fileQueued', is coming from or where the file object is getting it's values from.

Thanks for any help you can offer.