-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up more buttons on the playground
- Loading branch information
Showing
5 changed files
with
103 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import lzstring from './vendor/lzstring.min' | ||
|
||
/** | ||
* Grabs the sourcecode for an example from the query hash or local storage | ||
* @param fallback if nothing is found return this | ||
* @param location DI'd copy of document.location | ||
*/ | ||
export const getInitialCode = (fallback: string, location: Location) => { | ||
// Old school support | ||
if (location.hash.startsWith('#src')) { | ||
const code = location.hash.replace('#src=', '').trim() | ||
return decodeURIComponent(code) | ||
} | ||
|
||
// New school support | ||
if (location.hash.startsWith('#code')) { | ||
const code = location.hash.replace('#code/', '').trim() | ||
let userCode = lzstring.decompressFromEncodedURIComponent(code) | ||
// Fallback incase there is an extra level of decoding: | ||
// https://gitter.im/Microsoft/TypeScript?at=5dc478ab9c39821509ff189a | ||
if (!userCode) userCode = lzstring.decompressFromEncodedURIComponent(decodeURIComponent(code)) | ||
return userCode | ||
} | ||
|
||
// Local copy fallback | ||
if (localStorage.getItem('sandbox-history')) { | ||
return localStorage.getItem('sandbox-history')! | ||
} | ||
|
||
return fallback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters