|
1 | 1 | function loadStyle (source, callback) {
|
2 |
| - var link = document.createElement('link'); |
3 |
| - link.setAttribute('rel', 'stylesheet'); |
4 |
| - link.setAttribute('href', source); |
| 2 | + var link = document.createElement('link') |
| 3 | + link.setAttribute('rel', 'stylesheet') |
| 4 | + link.setAttribute('href', source) |
5 | 5 | link.onload = callback
|
6 |
| - document.head.appendChild(link); |
| 6 | + document.head.appendChild(link) |
7 | 7 | }
|
8 | 8 |
|
9 | 9 | function loadScript (source) {
|
10 |
| - var script = document.createElement('script'); |
11 |
| - script.setAttribute('src', source); |
12 |
| - script.async = false; |
13 |
| - document.head.appendChild(script); |
| 10 | + var script = document.createElement('script') |
| 11 | + script.setAttribute('src', source) |
| 12 | + script.async = false |
| 13 | + document.head.appendChild(script) |
14 | 14 | }
|
15 | 15 |
|
16 | 16 | function loadScriptsAndStyles (source) {
|
17 |
| - var matches = window.location.search.match('source=([^&]+)'); |
18 |
| - var baseDir = 'https://npmcdn.com/react-virtualized/'; |
| 17 | + var baseDir = 'https://npmcdn.com/react-virtualized/' |
| 18 | + var sourceParam = getUrlParam('source') |
19 | 19 |
|
20 |
| - if (matches) { |
21 |
| - baseDir = matches[1] === 'local' |
| 20 | + if (sourceParam) { |
| 21 | + baseDir = sourceParam === 'local' |
22 | 22 | ? '../'
|
23 |
| - : `https://npmcdn.com/react-virtualized@${matches[1]}/` |
| 23 | + : `https://npmcdn.com/react-virtualized@${sourceParam}/` |
24 | 24 | }
|
25 | 25 |
|
26 |
| - |
27 |
| - |
28 |
| - var styleSource = baseDir + 'styles.css'; |
29 |
| - var scriptSource = baseDir + 'dist/umd/react-virtualized.js'; |
30 |
| - var appSource = source; |
| 26 | + var styleSource = baseDir + 'styles.css' |
| 27 | + var scriptSource = baseDir + 'dist/umd/react-virtualized.js' |
| 28 | + var appSource = source |
31 | 29 |
|
32 | 30 | loadStyle(styleSource, function() {
|
33 |
| - loadScript(scriptSource); |
34 |
| - loadScript(appSource); |
35 |
| - }); |
| 31 | + loadScript(scriptSource) |
| 32 | + loadScript(appSource) |
| 33 | + }) |
36 | 34 | }
|
37 | 35 |
|
38 | 36 | function loadReact () {
|
39 |
| - var matches = window.location.search.match('react=([^&]+)'); |
40 | 37 | var baseDir = 'https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0'
|
| 38 | + var reactParam = getUrlParam('react') |
41 | 39 |
|
42 |
| - if (matches) { |
43 |
| - baseDir = matches[1] === 'latest' |
| 40 | + if (reactParam) { |
| 41 | + baseDir = reactParam === 'latest' |
44 | 42 | ? 'http://react.zpao.com/builds/master/latest'
|
45 |
| - : `https://cdnjs.cloudflare.com/ajax/libs/react/${matches[1]}` |
| 43 | + : `https://cdnjs.cloudflare.com/ajax/libs/react/${reactParam}` |
46 | 44 | }
|
47 | 45 |
|
48 |
| - loadScript(`${baseDir}/react-with-addons.min.js`); |
49 |
| - loadScript(`${baseDir}/react-dom.min.js`); |
| 46 | + loadScript(`${baseDir}/react-with-addons.min.js`) |
| 47 | + loadScript(`${baseDir}/react-dom.min.js`) |
50 | 48 | }
|
0 commit comments