forked from HiveProject/hiveproject.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
95 lines (85 loc) · 3.84 KB
/
index.html
File metadata and controls
95 lines (85 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>Google Realtime Quickstart - version 1</title>
<!-- Load Styles -->
<link href="https://www.gstatic.com/realtime/quickstart-styles.css" rel="stylesheet" type="text/css"/>
<!-- Load the Realtime JavaScript library -->
<script src="https://apis.google.com/js/api.js"></script>
<!-- Load the utility library -->
<script src="https://www.gstatic.com/realtime/realtime-client-utils.js"></script>
</head>
<body>
<main>
<h1>Realtime Collaboration Quickstart</h1>
<p>Now that your application is running, simply type in either text box and see your changes instantly appear in the other one. Open
this same document in a <a onclick="window.open(window.location.href);return false;" target="_blank">new tab</a> to see it work across tabs.</p>
<textarea id="text_area_1"></textarea>
<textarea id="text_area_2"></textarea>
<button id="auth_button">Authorize</button>
</main>
<script>
var clientId = '763227956228-btgo7elk6eclu3b3fho6sutsi52884io.apps.googleusercontent.com';
if (!/^([0-9])$/.test(clientId[0])) {
alert('Invalid Client ID - did you forget to insert your application Client ID?');
}
// Create a new instance of the realtime utility with your client ID.
var realtimeUtils = new utils.RealtimeUtils({ clientId: clientId });
authorize();
function authorize() {
// Attempt to authorize
realtimeUtils.authorize(function(response){
if(response.error){
// Authorization failed because this is the first time the user has used your application,
// show the authorize button to prompt them to authorize manually.
var button = document.getElementById('auth_button');
button.classList.add('visible');
button.addEventListener('click', function () {
realtimeUtils.authorize(function(response){
start();
}, true);
});
} else {
start();
}
}, false);
}
function start() {
// With auth taken care of, load a file, or create one if there
// is not an id in the URL.
var id = '0B7Fr-eaQNfHDWWVKQXFsMmtwY3c';
if (id) {
// Load the document id from the URL
realtimeUtils.load(id.replace('/', ''), onFileLoaded, onFileInitialize);
} else {
// Create a new document, add it to the URL
realtimeUtils.createRealtimeFile('New Quickstart File', function(createResponse) {
window.history.pushState(null, null, '?id=' + createResponse.id);
realtimeUtils.load(createResponse.id, onFileLoaded, onFileInitialize);
});
}
}
// The first time a file is opened, it must be initialized with the
// document structure. This function will add a collaborative string
// to our model at the root.
function onFileInitialize(model) {
var string = model.createString();
string.setText('Welcome to the Quickstart App!');
model.getRoot().set('demo_string', string);
}
// After a file has been initialized and loaded, we can access the
// document. We will wire up the data model to the UI.
function onFileLoaded(doc) {
var collaborativeString = doc.getModel().getRoot().get('demo_string');
wireTextBoxes(collaborativeString);
}
// Connects the text boxes to the collaborative string
function wireTextBoxes(collaborativeString) {
var textArea1 = document.getElementById('text_area_1');
var textArea2 = document.getElementById('text_area_2');
gapi.drive.realtime.databinding.bindString(collaborativeString, textArea1);
gapi.drive.realtime.databinding.bindString(collaborativeString, textArea2);
}
</script>
</body>
</html>