|
| 1 | +<!doctype html> |
| 2 | +<!-- See http://www.firepad.io/docs/ for detailed embedding docs. --> |
| 3 | +<html> |
| 4 | +<head> |
| 5 | + <meta charset="utf-8" /> |
| 6 | + <!-- Firebase --> |
| 7 | + <script src="https://www.gstatic.com/firebasejs/5.5.4/firebase.js"></script> |
| 8 | + <!-- CodeMirror and its JavaScript mode file --> |
| 9 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/codemirror.js"></script> |
| 10 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/mode/javascript/javascript.js"></script> |
| 11 | + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/codemirror.css" /> |
| 12 | + |
| 13 | + <!-- Firepad --> |
| 14 | + <link rel="stylesheet" href="https://cdn.firebase.com/libs/firepad/1.4.0/firepad.css" /> |
| 15 | + <script src="https://cdn.firebase.com/libs/firepad/1.4.0/firepad.min.js"></script> |
| 16 | + |
| 17 | + <style> |
| 18 | + html { height: 100%; } |
| 19 | + body { margin: 0; height: 100%; position: relative; } |
| 20 | + /* Height / width / positioning can be customized for your use case. |
| 21 | + For demo purposes, we make firepad fill the entire browser. */ |
| 22 | + #firepad-container { |
| 23 | + width: 100%; |
| 24 | + height: 100%; |
| 25 | + } |
| 26 | + </style> |
| 27 | +</head> |
| 28 | + |
| 29 | +<body onload="init()"> |
| 30 | + <div id="firepad-container"></div> |
| 31 | + |
| 32 | + <script> |
| 33 | + function init() { |
| 34 | + //// Initialize Firebase. |
| 35 | + //// TODO: replace with your Firebase project configuration. |
| 36 | + var config = { |
| 37 | + apiKey: '<API_KEY>', |
| 38 | + authDomain: "firepad-tests.firebaseapp.com", |
| 39 | + databaseURL: "https://firepad-tests.firebaseio.com" |
| 40 | + }; |
| 41 | + firebase.initializeApp(config); |
| 42 | + |
| 43 | + //// Get Firebase Database reference. |
| 44 | + var firepadRef = getExampleRef(); |
| 45 | + |
| 46 | + //// Create CodeMirror (with line numbers and the JavaScript mode). |
| 47 | + var codeMirror = CodeMirror(document.getElementById('firepad-container'), { |
| 48 | + lineNumbers: true, |
| 49 | + mode: 'javascript' |
| 50 | + }); |
| 51 | + |
| 52 | + //// Create Firepad. |
| 53 | + var firepad = Firepad.fromCodeMirror(firepadRef, codeMirror, { |
| 54 | + defaultText: '// JavaScript Editing with Firepad!\nfunction go() {\n var message = "Hello, world.";\n console.log(message);\n}' |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + // Helper to get hash from end of URL or generate a random one. |
| 59 | + function getExampleRef() { |
| 60 | + var ref = firebase.database().ref(); |
| 61 | + var hash = window.location.hash.replace(/#/g, ''); |
| 62 | + if (hash) { |
| 63 | + ref = ref.child(hash); |
| 64 | + } else { |
| 65 | + ref = ref.push(); // generate unique location. |
| 66 | + window.location = window.location + '#' + ref.key; // add it as a hash to the URL. |
| 67 | + } |
| 68 | + if (typeof console !== 'undefined') { |
| 69 | + console.log('Firebase data: ', ref.toString()); |
| 70 | + } |
| 71 | + return ref; |
| 72 | + } |
| 73 | + </script> |
| 74 | +</body> |
| 75 | +</html> |
0 commit comments