-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinterface.js
96 lines (81 loc) · 2.07 KB
/
interface.js
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
Interface =
{
init: function()
{
console.log('Interface.init()');
main();
$('snapback').onclick = Interface.showSnapback;
$('restart').onclick = Interface.restart;
$('share').onclick = Interface.showShare;
},
restart: function()
{
if (confirm('Are you sure you want to restart this story?'))
state.restart();
},
showShare: function (event)
{
Interface.hideAllMenus();
Interface.showMenu(event, $('shareMenu'))
},
showSnapback: function (event)
{
Interface.hideAllMenus();
Interface.buildSnapback();
Interface.showMenu(event, $('snapbackMenu'));
},
buildSnapback: function()
{
var hasItems = false;
removeChildren($('snapbackMenu'));
for (var i = state.history.length - 1; i >= 0; i--)
if (state.history[i].passage &&
state.history[i].passage.tags.indexOf('bookmark') != -1)
{
var el = document.createElement('div');
el.hash = state.history[i].hash;
el.onclick = function() { window.location.hash = this.hash };
el.innerHTML = state.history[i].passage.excerpt();
$('snapbackMenu').appendChild(el);
hasItems = true;
};
if (! hasItems)
{
var el = document.createElement('div');
el.innerHTML = '<i>No passages available</i>';
$('snapbackMenu').appendChild(el);
};
},
hideAllMenus: function()
{
$('shareMenu').style.display = 'none';
$('snapbackMenu').style.display = 'none';
},
showMenu: function (event, el)
{
if (! event)
event = window.event;
var pos = { x: 0, y: 0 };
if (event.pageX || event.pageY)
{
pos.x = event.pageX;
pos.y = event.pageY;
}
else
if (event.clientX || event.clientY)
{
pos.x = event.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
pos.y = event.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
};
el.style.top = pos.y + 'px';
el.style.left = pos.x + 'px';
el.style.display = 'block';
document.onclick = Interface.hideAllMenus;
event.cancelBubble = true;
if (event.stopPropagation)
event.stopPropagation();
}
};
window.onload = Interface.init;