|
| 1 | +document.addEventListener('DOMContentLoaded', function () { |
| 2 | + // Regex for matching version strings |
| 3 | + // Example match: "0.21.123" |
| 4 | + var rx = /^\d+\.\d+(\.\d+)?$/ |
| 5 | + |
| 6 | + // :: String, String -> String |
| 7 | + function toVersion (acc, pair) { |
| 8 | + var splitPair = pair.split('=') |
| 9 | + |
| 10 | + return splitPair[0] === 'v' && rx.test(splitPair[1]) ? splitPair[1] : acc |
| 11 | + } |
| 12 | + |
| 13 | + var version = location.search.substr(1).split('&').reduce(toVersion, 'latest') |
| 14 | + |
| 15 | + var ramdaUrl = '//cdn.jsdelivr.net/ramda/' + version + '/ramda.min.js' |
| 16 | + |
| 17 | + |
| 18 | + ramdaRepl(document.querySelector('.ramda-repl-target'), { |
| 19 | + apiUrl: 'https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyDhbAvT5JqkxFPkoeezJp19-S_mAJudxyk', |
| 20 | + |
| 21 | + // If unset, initialValue will use the value or textcontent of the |
| 22 | + // target element. |
| 23 | + initialValue: URI.decode(window.location.hash).substring(2), |
| 24 | + |
| 25 | + // Called with the pre-compiled content |
| 26 | + onChange: function (code) { |
| 27 | + window.location.hash = '?' + URI.encode(code) |
| 28 | + }, |
| 29 | + |
| 30 | + // The following config defines scripts that will be dynamically |
| 31 | + // loaded upon creating the REPL. Each has the following properties: |
| 32 | + // |
| 33 | + // src - The source of the script, a URL |
| 34 | + // global - (Optional) a name of a global that the script introduces |
| 35 | + // exposeAs - (Optional) a name that can alias the global |
| 36 | + // expose - (Optional) a list of methods to expose globally |
| 37 | + |
| 38 | + // Required. |
| 39 | + // As ramda may be a dependency for other scripts, it will |
| 40 | + // be intentionally loaded before any other script. |
| 41 | + ramdaScript: { |
| 42 | + global: 'R', |
| 43 | + src: ramdaUrl |
| 44 | + }, |
| 45 | + |
| 46 | + returnUrl: 'http://ramdajs.com/repl/', |
| 47 | + |
| 48 | + // Optional. |
| 49 | + // Here we can declare a list of libraries that we wish to have |
| 50 | + // loaded and exposed in the repl. |
| 51 | + scripts: [ |
| 52 | + { |
| 53 | + exposeAs: 'S', |
| 54 | + global: 'sanctuary', |
| 55 | + src: '//wzrd.in/standalone/sanctuary@latest' |
| 56 | + }, |
| 57 | + { |
| 58 | + expose: [ |
| 59 | + 'Either', |
| 60 | + 'Future', |
| 61 | + 'Identity', |
| 62 | + 'IO', |
| 63 | + 'lift2', |
| 64 | + 'lift3', |
| 65 | + 'Maybe', |
| 66 | + 'Reader', |
| 67 | + 'Tuple' |
| 68 | + ], |
| 69 | + global: 'ramdaFantasy', |
| 70 | + src: '//wzrd.in/standalone/ramda-fantasy@latest' |
| 71 | + } |
| 72 | + ] |
| 73 | + }) |
| 74 | +}, false) |
0 commit comments