/* Javascript for StaffGradedAssignmentXBlock. */
function StaffGradedAssignmentXBlock(runtime, element) {
    require(["jquery", "underscore", "jquery.fileupload"], function($, _) {
        var uploadUrl = runtime.handlerUrl(element, 'upload_assignment');
        var downloadUrl = runtime.handlerUrl(element, 'download_assignment');
        var template = _.template($(element).find("#sga-tmpl").text());

        function render(state) {
            state.downloadUrl = downloadUrl;
            var content = $(element).find("#sga-content").html(template(state));
            $(content).find("#fileupload").fileupload({
                url: uploadUrl,
                add: function(e, data) {
                    console.log("hey", data);
                    var do_upload = $(content).find("#do-upload")
                        .text("Upload " + data.files[0].name + " ");
                    $('<button/>')
                        .text('Upload now')
                        .appendTo(do_upload)
                        .click(function() {
                            do_upload.text("Uploading...");
                            data.submit();
                        });
                },
                progressall: function(e, data) {
                    var percent = parseInt(data.loaded / data.total * 100, 10);
                    $(content).find("#do-upload").text(
                        "Uploading... " + percent + "%");
                },
                done: function(e, data) { render(data.result); }
            });
        }

        $(function($) { // onLoad
            var state = $(element).find(".sga-block").attr("data-state");
            render(JSON.parse(state));
        });
    });
}

@@ -107,63 +107,8 @@
 %0A   
- require(%5B%22jquery%22, %22underscore%22, %22jquery.fileupload%22%5D,
  fun
@@ -112,16 +112,23 @@
 function
+ xblock
 ($, _) %7B
@@ -645,54 +645,8 @@
 ) %7B%0A
-                    console.log(%22hey%22, data);%0A
     
@@ -1612,13 +1612,915 @@
 );%0A    %7D
-);
+%0A%0A    if (require === undefined) %7B %0A        /** %0A         * The LMS does not use require.js (although it loads it...) and%0A         * does not already load jquery.fileupload.  (It looks like it uses%0A         * jquery.ajaxfileupload instead.  But our XBlock uses %0A         * jquery.fileupload.%0A         */%0A        function loadjs(url) %7B%0A            $(%22%3Cscript%3E%22)%0A                .attr(%22type%22, %22text/javascript%22)%0A                .attr(%22src%22, url)%0A                .appendTo(element);%0A        %7D%0A        loadjs(%22/static/js/vendor/jQuery-File-Upload/js/jquery.iframe-transport.js%22);%0A        loadjs(%22/static/js/vendor/jQuery-File-Upload/js/jquery.fileupload.js%22);%0A        xblock($, _);%0A    %7D%0A    else %7B%0A        /**%0A         * Studio, on the other hand, uses require.js and already knows about%0A         * jquery.fileupload.%0A         */%0A        require(%5B%22jquery%22, %22underscore%22, %22jquery.fileupload%22%5D, xblock);%0A    %7D
 %0A%7D%0A

Make the XBlock javascript work both in Studio and LMS.