// runEl - run button element
// shareEl - share button element (optional)
// shareURLEl - share URL text input element (optional)
+// shareRedirect - base URL to redirect to on share (optional)
// preCompile - callback to mutate request data before compiling
// postCompile - callback to read response data after compiling
// simple - use plain textarea instead of CodeMirror.
}
$(opts['runEl']).click(run);
- if (opts['shareEl'] == null || opts['shareURLEl'] == null) {
+ if (opts['shareEl'] == null || (opts['shareURLEl'] == null && opts['shareRedirect'] == null)) {
return editor;
}
return (""+href).split("/").slice(0, 3).join("/");
}
- var shareURL = $(opts['shareURLEl']).hide();
+ var shareURL;
+ if (opts['shareURLEl']) {
+ shareURL = $(opts['shareURLEl']).hide();
+ }
var sharing = false;
$(opts['shareEl']).click(function() {
if (sharing) return;
sharing = false;
if (xhr.status != 200) {
alert("Server error; try again.");
- return
+ return;
+ }
+ if (opts['shareRedirect']) {
+ window.location = opts['shareRedirect'] + xhr.responseText;
+ }
+ if (shareURL) {
+ var url = origin(window.location) + "/p/" +
+ xhr.responseText;
+ shareURL.show().val(url).focus().select();
}
- var url = origin(window.location) + "/p/" +
- xhr.responseText;
- shareURL.show().val(url).focus().select();
}
});
});