Note that there are some explanatory texts on larger screens.

plurals
  1. POTurning a javascript applet into a javascript button
    primarykey
    data
    text
    <p>This title may not be 100% accurate with regards to my question, and I apologize beforehand if that's the case. Here's my problem, I found this cool applet that allows you to paste an image from your clipboard without the need for an upload. However, my site does not use explicitly written HTML, so I don't know how to insert this applet. For example, here is my code for an Upload button, the kind you would use normally to input an image:</p> <pre><code>getUploadControl: function(data) { var uploadData = data.uploadData || {}, resultHandler = generateCallbackHandler({ success: data.onSuccess, error: data.onError, busyMethod: noop }), eventHandler = function(e) { var jsonResponse = parseJSON(e.XMLHttpRequest.responseText); resultHandler(jsonResponse); }; return extend(true, { type: "upload", options: { async: { saveUrl: window.CaledonianAPIWebServiceRoot + "WriteFile.aspx" }, multiple: false, upload: function(e) { var ud = copyNestedProperties({}, uploadData); api.addAuthToData(ud); e.data = ud; }, success: eventHandler, error: eventHandler } }, data); }, </code></pre> <p>I would like to make a similar button like this using the <a href="http://supa.sourceforge.net/" rel="nofollow">SUPA Applet</a>. Here is a <a href="http://supa.sourceforge.net/demo.php" rel="nofollow">demo</a> of the applet. </p> <p>I have downloaded the source code for Supa.js, here it is, not very long. </p> <pre><code>function Supa() { this.ping = function (supaApplet) { try { // IE will throw an exception if you try to access the method in a // scalar context, i.e. if( supaApplet.pasteFromClipboard ) ... return supaApplet.ping(); } catch (e) { return false; } }; this.ajax_post = function (actionUrl, bytes, fieldname_filename, filename, params) { // some constants for the request body //FIXME: make sure boundaryString is not part of bytes or the form values var boundaryString = 'AaB03x' + parseInt(Math.random() * 9999999, 10), boundary = '--' + boundaryString, cr = '\r\n', body, i, isAsync, xrequest; // sanity checks if (!fieldname_filename || fieldname_filename === "") { throw "Developer Error: fieldname_filename not set or empty"; } if (!filename || filename === "") { throw "Filename required"; } // build request body body = ''; body += boundary + cr; if (isArray(params)) { for (i = 0; i &lt; params.length; i += 1) { body += "Content-disposition: form-data; name=\"" + escape(params[i].name) + "\";" + cr; body += cr; body += encodeURI(params[i].value) + cr; body += boundary + cr; } } // add the screenshot as a file body += "Content-Disposition: form-data; name=\"" + escape(fieldname_filename) + "\"; filename=\"" + encodeURI(filename) + "\"" + cr; body += "Content-Type: application/octet-stream" + cr; body += "Content-Transfer-Encoding: base64" + cr; body += cr; body += bytes + cr; // last boundary, no extra cr here! body += boundary + "--" + cr; // finally, the Ajax request isAsync = false; xrequest = new XMLHttpRequest(); xrequest.open("POST", actionUrl, isAsync); // set request headers xrequest.setRequestHeader("Content-Type", "multipart/form-data; charset=UTF-8; boundary=" + boundaryString); xrequest.send(body); return xrequest.responseText; }; } function supa() { return new Supa(); } </code></pre> <p>My question is how do I make a similar widget to use this library for the pasting process? The paste() method can be found in the source HTML for the <a href="http://supa.sourceforge.net/demo.php" rel="nofollow">demo</a> I referenced earlier, it's not in Supa.js, the main file. Plus, I'm not using HTML, so I might have to combine all that code into one? Anyway, any help is appreciated, to get me going on the right track.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload