-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (71 loc) · 2.57 KB
/
script.js
File metadata and controls
76 lines (71 loc) · 2.57 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
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('clear').addEventListener('click', clearField);
document.getElementById('save').addEventListener('click', cleanUp);
document.getElementById('settingsTitleContainer').addEventListener('click', settings);
init();
});
/**
* Onload, we check the localStorage to see if the user had saved anything, if not, we set a default value
*/
function init() {
//console.log(localStorage.workspace);
if(localStorage.workspace === null || localStorage.workspace === undefined) {
document.getElementById('defaultWS').value = '';
startEngines('all');
} else {
document.getElementById('defaultWS').value = localStorage.workspace;
startEngines(localStorage.workspace);
}
}
/**
* Loads up the appropriate page in the iFrame
* @param {string} workspace The workspace ID to load
*/
function startEngines(workspace) {
var destination = 'http://mobile.hojoki.com/#stream/' + workspace;
var mainframe = document.getElementById('mainframe');
mainframe.setAttribute('src', destination);
mainframe.setAttribute('width', '100%');
mainframe.setAttribute('height', '461px');
mainframe.setAttribute('frameborder', '0');
}
/**
* Brings up the settings slider
*/
function settings() {
var mainframe = document.getElementById('mainframe');
if (parseInt(mainframe.height, 10) < 300){
mainframe.height = 461 + 'px';
} else {
mainframe.height = 47 + 'px';
}
}
/**
* Upon closing, makes sure everything is saved and tidied away
*/
function cleanUp(){
var val = '';
var input = document.getElementById('defaultWS').value;
var character;
for (var i = 0; i < document.getElementById('defaultWS').value.length; i++) {
character = isNaN(input.charAt(i));
if(!character && input.charAt(i) >= 0 && input.charAt(i) <= 9){
val += document.getElementById('defaultWS').value.charAt(i);
}
}
if (val > 0) {
localStorage.workspace = val;
document.getElementById('defaultWS').value = localStorage.workspace;
document.getElementById('mainframe').setAttribute('src', 'http://mobile.hojoki.com/#stream/' + val);
settings();
}
}
/**
* Clears the input field and associated localStorage
*/
function clearField() {
document.getElementById('defaultWS').value = '';
document.getElementById('defaultWS').placeholder = "Workspace ID";
document.getElementById('mainframe').setAttribute('src', 'http://mobile.hojoki.com/#stream/mycloud');
delete localStorage['workspace'];
}