From eb2ad9f840d09cfca03d63cac396122013775b44 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Thu, 30 Aug 2012 11:14:24 -0300 Subject: [PATCH] Fix path .key now returns undefined on failure so path can be 0. If path is undefined then use an empty string. --- .../frontend/public/gollum/livepreview/js/livepreview.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 += '/'; }