0

Maybe Im just confusing myself due to being pressed for time, but how would I reuse this function without reloading the page itself?

$(function() {

    var uploadqueue = $("#uploader").pluploadQueue({
        // General settings
        runtimes : 'html4,silverlight',
        url : 'upload_file.json?hdfs_url=<%=@file_name%>&authenticity_token=<%= form_authenticity_token %>',
        max_file_size : '100000000000mb',
        //chunk_size : '1mb',
        unique_names : true,
        multipart: false,
        multiple_queues: true, 
        //multipart_params: {  
        //"authenticity_token" : '<%= form_authenticity_token %>'  
        //},

        // Flash settings
        flash_swf_url : 'javascripts/plupload/plupload.flash.swf',

        // Silverlight settings
        silverlight_xap_url : 'javascripts/plupload/plupload.silverlight.xap',
        init : {

                    Refresh: function(up) {
                        // Called when upload shim is moved
                        $(".plupload_header_title").text("Upload files to HDFS");
                        $(".plupload_header_text").text("Files will go in: <%=@file_name%>");
                    },
                    StateChanged: function(up) {
                        // Called when upload shim is moved
                        $.get("file_tree?dir=<%=@file_name%>", function(data){

                            //alert("<%=@rel_link%>")
                            //alert("Command = ul[name*='<%=@rel_link%>']")
                            //alert("Data Loaded: " + $("ul[name*='<%=@rel_link%>']").html()); 
                            $("ul[name*='<%=@rel_link%>']").html($(data).children());                       
                        });

                    }
                }

    });
1
  • 1
    Can you be more precise. What does this code, what part you consider as your target function, what libraries do you use and, the main, what is the functionality you are going to achieve? Commented Nov 1, 2011 at 21:29

2 Answers 2

2
$(function(){
    var uploadqueue = upload(); 
}); 

function upload()
{
   return  $("#uploader").pluploadQueue({...}); 
}

Then you can call upload() where ever you like, just make sure the document is ready before doing so.

Sign up to request clarification or add additional context in comments.

1 Comment

I just posted almost the exact same answer, a minute to late. +1 for being inside my head.
1

Just define it as a separate function.

function someFunction(){
   // do your stuff
}

$(function(){
    someFunction();
});

Then you can call the function elsewhere.

Note, technically the function wrapper is not needed in document.ready but I find it to be a bit more understandable in this context.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.