Use default commit message in comment window.

This commit is contained in:
bootstraponline
2012-05-18 15:32:14 -06:00
parent 3c10a6bf94
commit f39ed93ca0
@@ -80,37 +80,43 @@ var commentEditorContainer = commentEditor.container;
initAce(commentEditor, commentEditorSession); initAce(commentEditor, commentEditorSession);
window.onload = function() { // RegExp from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
// RegExp from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript $.key = function(key){
$.key = function(key){
var value = new RegExp('[\\?&]' + key + '=([^&#]*)').exec(window.location.href); var value = new RegExp('[\\?&]' + key + '=([^&#]*)').exec(window.location.href);
return (!value) ? 0 : value[1] || 0; return (!value) ? 0 : value[1] || 0;
} }
/* Load markdown from /data/page into the ace editor. */ // True if &create=true
jQuery.ajax({ var create = $.key("create");
type: "GET", // The name of the page being edited.
url: "/data/" + $.key("page"), var pageName = $.key("page");
success: function(data) {
editorSession.setValue(data);
}
});
$.save = function( commitMessage ) { defaultCommitMessage = function() {
// if &create=true then handle create instead of edit. var msg = pageName + " (markdown)";
var create = $.key("create");
if (create) {
return "Created " + msg;
} else {
return "Updated " + msg;
}
}
// Set comment using the default commit message.
commentEditorSession.setValue( defaultCommitMessage() );
$.save = function( commitMessage ) {
var POST = "POST"; var POST = "POST";
var pageName = $.key("page");
var markdown = "markdown"; var markdown = "markdown";
var txt = editorSession.getValue(); var txt = editorSession.getValue();
var msg = pageName + " (" + markdown + ")" var msg = defaultCommitMessage();
var newLocation = window.location.origin + "/" + pageName; var newLocation = window.location.origin + "/" + pageName;
// if &create=true then handle create instead of edit.
if (create) { if (create) {
jQuery.ajax({ jQuery.ajax({
type: POST, type: POST,
url: "/create", url: "/create",
data: { page: pageName, format: markdown, content: txt, message: commitMessage || "Created " + msg }, data: { page: pageName, format: markdown, content: txt, message: commitMessage || msg },
success: function() { success: function() {
window.location = newLocation; window.location = newLocation;
} }
@@ -119,13 +125,23 @@ window.onload = function() {
jQuery.ajax({ jQuery.ajax({
type: POST, type: POST,
url: "/edit/" + pageName, url: "/edit/" + pageName,
data: { format: markdown, content: txt, message: commitMessage || "Updated " + msg }, data: { format: markdown, content: txt, message: commitMessage || msg },
success: function() { success: function() {
window.location = newLocation; window.location = newLocation;
} }
}); });
} // end else } // end else
}
window.onload = function() {
/* Load markdown from /data/page into the ace editor. */
jQuery.ajax({
type: "GET",
url: "/data/" + $.key("page"),
success: function(data) {
editorSession.setValue(data);
} }
});
$("#save").click(function() { $("#save").click(function() {
$.save(); $.save();