Update get /data

Remove leading slash from page
Fix edge case with path set to '/'
This commit is contained in:
bootstraponline
2012-08-30 11:40:07 -03:00
parent bb6fb0c253
commit 8575049de5
@@ -339,15 +339,22 @@ var applyTimeout = function () {
~-1 == false; !~-1 == true; ~-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 / // ensure leading / is removed from path and that it ends with /
var path = unescape( $.key( 'path' ) || '' ).replace( /^\/+/, '' ); var path = key_no_leading_slash( 'path' );
if ( path.charAt( path.length - 1 ) !== '/' ) { // don't append '/' if path is empty from removing leading slash
if ( path !== '' && path.charAt( path.length - 1 ) !== '/' ) {
path += '/'; path += '/';
} }
jQuery.ajax( { jQuery.ajax( {
type: 'GET', type: 'GET',
url: baseUrl + '/data/' + path + $.key( 'page' ), url: baseUrl + '/data/' + path + key_no_leading_slash( 'page' ),
success: function( data ) { success: function( data ) {
editorSession.setValue( data ); editorSession.setValue( data );
} }