Browse Source

make examples more easily shareable

master
Rich-Harris 8 years ago
parent
commit
29b65d6bac
  1. 17
      src/app/main.js

17
src/app/main.js

@ -14,7 +14,20 @@ if ( supported ) {
console.log( `running Rollup version %c${rollup.VERSION}`, 'font-weight: bold' ); console.log( `running Rollup version %c${rollup.VERSION}`, 'font-weight: bold' );
// recover state from hash fragment // recover state from hash fragment
const json = decodeURIComponent( window.location.hash.slice( 1 ) ); let json;
const match = /shareable=(.+)$/.exec( window.location.search );
if ( match ) {
try {
json = decodeURIComponent( atob( match[1] ) );
} catch ( err ) {
// noop
}
}
if ( !match ) {
// legacy
json = decodeURIComponent( window.location.hash.slice( 1 ) );
}
let saved; let saved;
let selectedExample; let selectedExample;
@ -106,7 +119,7 @@ if ( supported ) {
}); });
// save state as hash fragment // save state as hash fragment
window.location.hash = encodeURIComponent( JSON.stringify({ options, modules }) ); history.replaceState( {}, 'x', `/?shareable=${btoa( encodeURIComponent( JSON.stringify({ options, modules }) ) )}` );
}) })
.catch( error => { .catch( error => {
output.set( 'error', error ); output.set( 'error', error );

Loading…
Cancel
Save