Last active
June 20, 2016 04:15
-
-
Save voltrevo/dac5fc1bbba407f383d86e19a0bc5b81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function loadScript(src) { | |
| const script = document.createElement('script'); | |
| script.src = src; | |
| document.body.appendChild(script); | |
| return new Promise(resolve => | |
| script.addEventListener('load', resolve) | |
| ); | |
| } | |
| function createElement(str) { | |
| const container = document.createElement('div'); | |
| container.innerHTML = str.trim(); | |
| return container.firstChild; | |
| } | |
| function loadVex() { | |
| if (window.vex) { | |
| return Promise.resolve(window.vex); | |
| } | |
| return Promise.resolve() | |
| .then(() => loadScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js')) | |
| .then(() => loadScript('https://cdnjs.cloudflare.com/ajax/libs/vex-js/2.3.4/js/vex.combined.min.js')) | |
| .then(() => { | |
| vex.defaultOptions.className = 'vex-theme-os'; | |
| document.body.appendChild(createElement(` | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vex-js/2.3.4/css/vex.css" /> | |
| `)); | |
| document.body.appendChild(createElement(` | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vex-js/2.3.4/css/vex-theme-os.css" /> | |
| `)); | |
| return window.vex; | |
| }) | |
| ; | |
| } | |
| loadVex().then(vex => { | |
| vex.dialog.alert('hi'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment