diff --git a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js index 058a7be0..87f27923 100644 --- a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js +++ b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js @@ -62,9 +62,10 @@ initAce( commentEditor, commentEditorSession ); 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 @@ -341,9 +342,9 @@ var applyTimeout = function () { /* 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' ) ) { // ensure leading / is removed from path and that it ends with / - var path = unescape($.key( 'path' )).replace(/^\/+/, ''); + var path = unescape( $.key( 'path' ) || '' ).replace( /^\/+/, '' ); if ( path.charAt( path.length - 1 ) !== '/' ) { path += '/'; }