forked from joseph/Monocle
/
legacy.js
169 lines (137 loc) · 4.15 KB
/
legacy.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
Monocle.Flippers.Legacy = function (reader, setPageFn) {
if (Monocle.Flippers == this) {
return new Monocle.Flippers.Legacy(reader, setPageFn);
}
// Constants
var k = {
LEGACY_MESSAGE: "Your browser doesn't support Monocle's full feature set. " +
'You could try <a href="http://mozilla.com/firefox">Firefox</a>, ' +
'Apple\'s <a href="http://apple.com/safari">Safari</a> or ' +
'Google\'s <a href="http://google.com/chrome">Chrome</a>.',
buttonText: {
PREV: "... Previous part",
NEXT: "Next part..."
}
}
// Properties
var p = {
pageCount: 1,
divs: {}
}
var API = {
constructor: Monocle.Flippers.Legacy,
properties: p,
constants: k
}
function initialize() {
p.reader = reader;
p.setPageFn = setPageFn;
}
function addPage(pageDiv) {
p.page = pageDiv;
}
function visiblePages() {
return [p.page];
}
function getPlace() {
return p.reader.getBook().placeFor(p.page.contentDiv);
}
function moveTo(locus) {
var rslt = p.setPageFn(p.page, locus, updateButtons);
p.reader.dispatchEvent('monocle:turn');
return rslt;
}
function overrideDimensions() {
p.page.scrollerDiv.style.right = "0";
p.page.scrollerDiv.style.overflow = "auto";
p.page.contentDiv.style.position = "relative";
p.page.contentDiv.style.width = "100%";
p.page.contentDiv.style.minWidth = "0%";
if (!p.divs.legacyMessage) {
p.divs.legacyMessage = document.createElement('div');
p.divs.legacyMessage.innerHTML = k.LEGACY_MESSAGE;
p.divs.legacyMessage.style.cssText = Monocle.Styles.ruleText(
Monocle.Styles.Flippers.Legacy.message
);
p.page.scrollerDiv.insertBefore(p.divs.legacyMessage, p.page.contentDiv);
}
if (!p.divs.prevButton) {
p.divs.prevButton = document.createElement('div');
p.divs.prevButton.innerHTML = k.buttonText.PREV;
p.divs.prevButton.style.cssText = Monocle.Styles.ruleText(
Monocle.Styles.Flippers.Legacy.button
);
p.page.scrollerDiv.insertBefore(p.divs.prevButton, p.page.contentDiv);
}
if (!p.divs.nextButton) {
p.divs.nextButton = document.createElement('div');
p.divs.nextButton.innerHTML = k.buttonText.NEXT;
p.divs.nextButton.style.cssText = Monocle.Styles.ruleText(
Monocle.Styles.Flippers.Legacy.button
);
p.page.scrollerDiv.appendChild(p.divs.nextButton);
}
}
function updateButtons() {
var cIndex = getPlace().properties.component.properties.index;
if (cIndex == 0) {
p.divs.legacyMessage.style.display = "block";
p.divs.prevButton.style.display = "none";
} else {
p.divs.legacyMessage.style.display = "none";
p.divs.prevButton.style.display = "block";
}
if (cIndex == p.reader.getBook().properties.lastCIndex) {
p.divs.nextButton.style.display = "none";
} else {
p.divs.nextButton.style.display = "block";
}
}
function listenForInteraction() {
Monocle.addListener(
p.divs.prevButton,
'click',
function () { moveTo({ percent: -0.5 }) }
)
Monocle.addListener(
p.divs.nextButton,
'click',
function () { moveTo({ percent: 1.5 }) }
)
}
// THIS IS THE CORE API THAT ALL FLIPPERS MUST PROVIDE.
API.pageCount = p.pageCount;
API.addPage = addPage;
API.visiblePages = visiblePages;
API.getPlace = getPlace;
API.moveTo = moveTo;
API.listenForInteraction = listenForInteraction;
API.overrideDimensions = overrideDimensions;
initialize();
return API;
}
Monocle.Styles.Flippers.Legacy = {
message: {
"border": "1px solid #987",
"background": "#FFC",
"color": "#333",
"font-family": "Helvetica, Arial, sans-serif",
"font-size": "11px",
"margin-right": "3px",
"margin-bottom": "3px",
"padding": "0.5em 1em"
},
button: {
"background": "#DDD",
"padding": "6px",
"border": "1px solid #666",
"color": "#009",
"font": "bold 12px Helvetica, Arial, sans-serif",
"text-shadow": "-1px -1px #EEE",
"border-radius": "5px",
"margin-right": "3px",
"margin-bottom": "3px",
"margin-top": "3px"
}
}
Monocle.pieceLoaded('flippers/legacy');