Restore path support to livepreview.js.

This commit is contained in:
bootstraponline
2012-07-03 23:55:28 -06:00
parent bb9effa282
commit 8c8b72d482
@@ -74,8 +74,13 @@ $.key = function( key ) {
// True if &create=true
var create = $.key( 'create' );
// The name of the page being edited.
// The path and name of the page being edited.
var pageName = $.key( 'page' );
var pathName = $.key( 'path' );
if ( pathName === 0 ) {
pathName = undefined;
}
defaultCommitMessage = function() {
var msg = pageName + ' (markdown)';
@@ -97,14 +102,20 @@ $.save = function( commitMessage ) {
var markdown = 'markdown';
var txt = editorSession.getValue();
var msg = defaultCommitMessage();
var newLocation = location.protocol + '//' + location.host + '/' + pageName;
var newLocation = location.protocol + '//' + location.host;
if (pathName) {
newLocation += '/' + pathName;
}
newLocation += '/' + pageName;
// if &create=true then handle create instead of edit.
if ( create ) {
jQuery.ajax( {
type: POST,
url: '/create',
data: { page: pageName, format: markdown, content: txt, message: commitMessage || msg },
data: { path: pathName, page: pageName, format: markdown, content: txt, message: commitMessage || msg },
success: function() {
win.location = newLocation;
}
@@ -113,7 +124,7 @@ $.save = function( commitMessage ) {
jQuery.ajax( {
type: POST,
url: '/edit/' + pageName,
data: { format: markdown, content: txt, message: commitMessage || msg },
data: { path: pathName, page: pageName, format: markdown, content: txt, message: commitMessage || msg },
success: function() {
win.location = newLocation;
}