deserialize state values

edit
Hakim El Hattab 2014-03-12 08:51:51 +01:00
parent e8ab2641da
commit 1c2f4a2e92
2 changed files with 23 additions and 12 deletions

View File

@ -754,6 +754,22 @@ var Reveal = (function(){
} }
/**
* Utility for deserializing a value.
*/
function deserialize( value ) {
if( typeof value === 'string' ) {
if( value === 'null' ) return null;
else if( value === 'true' ) return true;
else if( value === 'false' ) return false;
else if( value.match( /^\d+$/ ) ) return parseFloat( value );
}
return value;
}
/** /**
* Measures the distance in pixels between point a * Measures the distance in pixels between point a
* and point b. * and point b.
@ -2352,9 +2368,9 @@ var Reveal = (function(){
function setState( state ) { function setState( state ) {
if( typeof state === 'object' ) { if( typeof state === 'object' ) {
slide( state.indexh, state.indexv, state.indexf ); slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) );
togglePause( state.paused ); togglePause( deserialize( state.paused ) );
toggleOverview( state.overview ); toggleOverview( deserialize( state.overview ) );
} }
} }
@ -3430,12 +3446,7 @@ var Reveal = (function(){
for( var i in query ) { for( var i in query ) {
var value = query[ i ]; var value = query[ i ];
query[ i ] = unescape( value ); query[ i ] = deserialize( unescape( value ) );
if( value === 'null' ) query[ i ] = null;
else if( value === 'true' ) query[ i ] = true;
else if( value === 'false' ) query[ i ] = false;
else if( value.match( /^\d+$/ ) ) query[ i ] = parseFloat( value );
} }
return query; return query;

6
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long