lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js in gollum-2.1.7 vs lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js in gollum-2.1.8
- old
+ new
@@ -60,25 +60,22 @@
// Find the app's base url, knowing we are in /livepreview/index.html
var baseUrl = location.pathname.split('/').slice(0,-2).join('/');
// RegExp from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
+// Returns value on success and undefined on failure.
$.key = function( key ) {
var value = new RegExp( '[\\?&]' + key + '=([^&#]*)' ).exec( location.href );
- return ( !value ) ? 0 : value[ 1 ] || 0;
+ return ( !value ) ? undefined : value[ 1 ] || undefined;
}
// True if &create=true
var create = $.key( 'create' );
// 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)';
if (create) {
return 'Created ' + msg;
@@ -98,11 +95,11 @@
var txt = editorSession.getValue();
var msg = defaultCommitMessage();
var newLocation = baseUrl;
function clean( str ) {
- return str.replace(/^\/+/g, '/');
+ return str.replace(/^\/+/, '/');
}
// 'a%2Fb' => a/b
if ( pathName ) {
pathName = unescape( pathName );
@@ -339,14 +336,27 @@
};
/* Load markdown from /data/page into the ace editor.
~-1 == false; !~-1 == true;
*/
- if ( !~location.host.indexOf('github.com') ) {
+ if ( !~ location.host.indexOf( 'github.com' ) ) {
+
+ // returns unescaped key with leading slashes removed
+ function key_no_leading_slash( key ) {
+ return unescape( $.key( key ) || '' ).replace( /^\/+/, '' );
+ }
+
+ // ensure leading / is removed from path and that it ends with /
+ var path = key_no_leading_slash( 'path' );
+ // don't append '/' if path is empty from removing leading slash
+ if ( path !== '' && path.charAt( path.length - 1 ) !== '/' ) {
+ path += '/';
+ }
+
jQuery.ajax( {
type: 'GET',
- url: baseUrl + '/data/' + $.key( 'page' ),
+ url: baseUrl + '/data/' + path + key_no_leading_slash( 'page' ),
success: function( data ) {
editorSession.setValue( data );
}
});
}
@@ -452,9 +462,14 @@
commentHidden;
cssSet( darkness, darknessStyle );
}
win.jsm.resize = resize;
+
+ // remove editor_bg after loading because
+ // it'll cause problems if toggle left right is used
+ var ebg = doc.getElementById('editor_bg');
+ ebg.parentNode.removeChild(ebg);
/*
Resize can be called an absurd amount of times
and will crash the page without debouncing.
http://benalman.com/projects/jquery-throttle-debounce-plugin/