-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaticscroll.js
1429 lines (1228 loc) · 49.3 KB
/
staticscroll.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
var _write = document.write;
document.write = function(t) {
// prevent external scripts from writing to dom
}
var staticscroll = {
prepPage: null,
pages: [0],
processPagesTimerId: 0,
article: null,
goalPage: 0,
currentPage: 0,
lastPage: -1,
topPage: null,
bottomPage: null,
scrollInfo: [],
progressIndicator: null,
topRightHider: null,
scrollSpeed: 25,
playButton: null,
scroll_speed_display:null,
hotKeyDialog: null,
innerHotKeyDialog: null,
settingsDialog: null,
innerSettingsDialog: null,
bugReportDiv: null,
bugReportMetaInput: null,
bugReportButton: null,
bugReportCloseButton: null,
hotKeysEnabled: true,
magicMouse: false,
fontSize: 1,
colorScheme: 0,
rtl: false,
init: function() {
if (typeof(window.stop) != "undefined") {
window.stop();
}
window.scrollTo(0,0);
staticscroll.nextWordLocalVar.prevIndex = 0;
staticscroll.loadScrollSpeed();
if (readability.error) {
staticscroll.showCenteredBugReport();
return;
}
if (!staticscroll.article) {
staticscroll.article = readability.article.replace(/align=('|")(left|right)('|")/gi, "").replace(/></g, "> <");
document.body.className = "ss_body ss_body_cs_" + staticscroll.colorScheme;
if (staticscroll.colorScheme == 0) {
document.body.style.backgroundImage = "url(" + ss_url("images/skewed_print.png") + ")";
} else {
document.body.style.backgroundImage = "none";
}
if (staticscroll.article.search(/dir=['\"]rtl['\"]/img) != -1) {
staticscroll.rtl = true;
}
}
/* Clear the old HTML, insert the new content. */
document.body.innerHTML = "";
document.body.style.height = window.innerHeight + "px!important";
ss_load.show();
/* Initialize pages */
if (!staticscroll.topPage) {
staticscroll.topPage = document.createElement("DIV");
staticscroll.topPage.id = "ss_topPage";
staticscroll.topPage.className = "ss_page fs_" + staticscroll.fontSize + " cs_" + staticscroll.colorScheme;
// staticscroll.topPage.style.backgroundImage = bground;
}
if (!staticscroll.bottomPage) {
staticscroll.bottomPage = document.createElement("DIV");
staticscroll.bottomPage.id = "ss_bottomPage";
staticscroll.bottomPage.className = "ss_page fs_" + staticscroll.fontSize + " cs_" + staticscroll.colorScheme;
staticscroll.bottomPage.innerHTML = staticscroll.article;
// staticscroll.bottomPage.style.backgroundImage =
// bground;
}
if (!staticscroll.prepPage) {
staticscroll.prepPage = document.createElement("DIV");
staticscroll.prepPage.id = "ss_prepPage";
staticscroll.prepPage.className = "ss_page fs_" + staticscroll.fontSize + " cs_" + staticscroll.colorScheme;
}
var width = Math.round(Math.min(window.innerWidth - 60, Math.max(window.innerHeight * 0.618, 400) + 20));
staticscroll.topPage.style.width = width + "px";
staticscroll.bottomPage.style.width = width + "px";
staticscroll.bottomPage.style.height = (staticscroll.getMaxHeight() + 50)+ "px";
staticscroll.prepPage.style.width = width + "px";
var left = (((window.innerWidth - width) / 2) - 30);
staticscroll.topPage.style.left = left + "px";
staticscroll.bottomPage.style.left = left + "px";
staticscroll.prepPage.style.left = left + "px";
document.body.appendChild(staticscroll.topPage);
document.body.appendChild(staticscroll.bottomPage);
document.body.appendChild(staticscroll.prepPage);
staticscroll.progressIndicator = document.createElement("DIV");
staticscroll.progressIndicator.className = "ss_progress_indicator";
staticscroll.progressIndicator.innerHTML = "0%";
staticscroll.progressIndicator.style.width = staticscroll.topPage.clientWidth + "px";
staticscroll.progressIndicator.style.left = staticscroll.topPage.style.left;
document.body.appendChild(staticscroll.progressIndicator);
var topHider = document.createElement("DIV");
topHider.style.top = "0px";
topHider.style.left= (left) + "px";
topHider.style.width = (width + 60) + "px";
topHider.style.height = "31px";
topHider.className = "ss_top_hider";
// topHider.style.backgroundImage = bground;
document.body.appendChild(topHider);
var rightHider = document.createElement("DIV");
rightHider.style.top = "0px";
rightHider.style.left= (left + width + 30) + "px";
rightHider.style.width = "60px";
rightHider.className = "ss_right_hider";
// rightHider.style.backgroundImage = bground;
document.body.appendChild(rightHider);
var leftHider = document.createElement("DIV");
leftHider.style.top = "0px";
leftHider.style.left= (left - 30) + "px";
leftHider.style.width = "60px";
leftHider.className = "ss_right_hider";
document.body.appendChild(leftHider);
var bottomHider = document.createElement("DIV");
bottomHider.style.top = (staticscroll.getMaxHeight() + 30) + "px";
bottomHider.style.left= (left) + "px";
bottomHider.style.width = (width + 60) + "px";
bottomHider.style.height = "50px";
bottomHider.className = "ss_top_hider";
// rightHider.style.backgroundImage = bground;
document.body.appendChild(bottomHider);
staticscroll.topHider = topHider;
staticscroll.rightHider = rightHider;
staticscroll.leftHider = leftHider;
staticscroll.bottomHider = bottomHider;
staticscroll.topRightHider = document.createElement("DIV");
staticscroll.topRightHider.style.top = "30px";
staticscroll.topRightHider.style.left= (left + width + 30) + "px";
staticscroll.topRightHider.style.width = "60px";
staticscroll.topRightHider.className = "ss_top_hider";
// staticscroll.topRightHider.style.backgroundImage = bground;
document.body.appendChild(staticscroll.topRightHider);
var hotkeyPrompt = document.createElement("DIV");
hotkeyPrompt.innerHTML = "Press [H] to view [H]otkeys";
hotkeyPrompt.className = "ss_hotkey_prompt";
hotkeyPrompt.onclick = function (event) {
staticscroll.showHideHotKeyDialog();
};
document.body.appendChild(hotkeyPrompt);
/*
staticscroll.debugLabel = document.createElement("DIV");
staticscroll.debugLabel.innerHTML = "DEBUGGING";
staticscroll.debugLabel.className = "ss_debug_label";
document.body.appendChild(staticscroll.debugLabel);
*/
staticscroll.processPages();
staticscroll.createUI();
ss_load.hide();
},
registerHotKeys: function() {
log("Registering HotKeys", 2);
document.onkeydown = function (event) {
if (staticscroll.hotKeysEnabled) {
var arrow = {pageDown: 34, pageUp: 33, left: 37, up: 38, right: 39, down: 40, plus: 107, minus: 109, space: 32, h: 72 };
if ((event.ctrlKey) || (event.altKey) || (event.metaKey)) {
return true;
}
switch(event.keyCode) {
case arrow.pageUp:
case arrow.left:
staticscroll.showPrevPage();
break;
case arrow.space:
staticscroll.startStopScroll();
break;
case arrow.pageDown:
case arrow.right:
staticscroll.showNextPage();
break;
case arrow.up:
staticscroll.scrollBackward();
break;
case arrow.down:
staticscroll.scrollForward();
break;
case arrow.plus:
staticscroll.increaseScrollSpeed();
break;
case arrow.minus:
staticscroll.decreaseScrollSpeed();
break;
case arrow.h:
staticscroll.showHideHotKeyDialog();
break
case 27:
if ((staticscroll.hotKeyDialog) && (staticscroll.hotKeyDialog.style.visibility === "visible")) {
staticscroll.showHideHotKeyDialog();
}
break
default:
return true;
}
} else {
if (event.keyCode === 27) {
staticscroll.showBugReport();
} else {
return true;
}
}
return false;
};
var mouseScroll = function(event) {
var delta = 0;
log("Scroll detected", 2);
if (!event) event = window.event;
// normalize the delta
if (event.wheelDelta) {
if ((!staticscroll.magicMouse) && (Math.abs(event.wheelDelta) >= 60)) {
delta = event.wheelDelta / 120;
} else {
//log("MagicMouse", 0);
staticscroll.magicMouse = true;
delta = event.wheelDelta;
}
} else if (event.detail) {
// W3C
delta = -event.detail;
}
log("Delta: " + delta, 2);
var count = 0;
if (staticscroll.magicMouse) {
staticscroll.scroll(delta);
} else if (delta < 0) {
while (count-- > delta) {
staticscroll.scrollForward();
};
} else {
while (count++ < delta) {
staticscroll.scrollBackward();
};
}
}
window.onmousewheel = mouseScroll;
document.documentElement.addEventListener("DOMMouseScroll", mouseScroll, false);
// TOUCH CONTROLS (see README.md for design overview)
(function(){
//////////////////////////////////////////////////////////////////////
// Scroll Metaphor functions
var hToY = function(h) {
return h + getTopPageOffset();
};
var yToH = function(y) {
var h = y - getTopPageOffset();
h = Math.max(0,h);
h = Math.min(h,getTopPageMaxHeight());
return h;
};
var getMinScroll = function() {
return hToY(0);
};
var getMaxScroll = function() {
return hToY(getTopPageMaxHeight());
};
var getScrollPos = function() {
return hToY(getTopPageHeight());
};
var setScrollPos = function(y) {
setTopPageHeight(yToH(y));
};
var scrollTop = function() {
setScrollPos(0);
};
var scrollBot = function() {
setScrollPos(getMaxScroll());
};
var getScrollState = function() {
var h = getTopPageHeight();
if (h == 0) {
return "TOP";
}
else if (h == getTopPageMaxHeight()) {
return "BOT";
}
return "MID";
};
//////////////////////////////////////////////////////////////////////
// Top Page Wrappers
var getTopPageOffset = function() {
return staticscroll.topPage.offsetTop;
};
var getTopPageHeight = function() {
return staticscroll.topPage.clientHeight;
};
var setTopPageHeight = function(h) {
staticscroll.topPage.style.height = h + "px";
staticscroll.topRightHider.style.height = h + "px";
};
var getTopPageMaxHeight = function() {
return staticscroll.getMaxHeight();
};
var pageForward = function() {
staticscroll.showNextPage();
};
var pageBack = function() {
staticscroll.showPrevPage();
};
//////////////////////////////////////////////////////////////////////
// The radius regions for snapping and grabbing.
var radius = 60;
var inTopRadius = function(x,y) {
return Math.abs(y - getMinScroll()) < radius;
};
var inBotRadius = function(x,y) {
return Math.abs(y - getMaxScroll()) < radius;
};
var inMidRadius = function(x,y) {
return Math.abs(y - getScrollPos()) < radius;
};
//////////////////////////////////////////////////////////////////////
// Scroll Anchor
// (An anchor connects our touch motion to the horizontal scroll guide)
var anchor = (function() {
var on = false;
var offset = 0; // distance between touch and scroll
// enable anchor exactly at Y
var set = function(y) {
offset = 0;
on = true;
};
// enable anchor relative to Y
var setWithOffset = function(y) {
offset = y - getScrollPos();
on = true;
};
// A predicate allows us to defer anchoring to another moment.
var predicate = null; // boolean function
var predSet = null; // which "set" function to use when predicate is met.
var setWhen = function(p) {
predicate = p;
predSet = set;
};
var setWithOffsetWhen = function(p) {
predicate = p;
predSet = setWithOffset;
};
// disable anchor
var clear = function() {
on = false;
predicate = null;
};
// Update the anchor position if enabled.
var scroll = function(y) {
// Enable if predicate is met.
if (predicate && predicate(y)) {
predSet(y);
predicate = null;
predSet = null;
}
// Update scroll position if enabled.
if (on) {
setScrollPos(y - offset);
}
};
return {
set: set,
setWithOffset: setWithOffset,
setWhen: setWhen,
setWithOffsetWhen: setWithOffsetWhen,
clear: clear,
scroll: scroll,
isOn: function() { return on },
};
})();
//////////////////////////////////////////////////////////////////////
// High level touch functions
var touchStart = function(x,y) {
var state = getScrollState();
var scrollY = getScrollPos();
if (state == "TOP") {
if (inTopRadius(x,y)) {
anchor.set(y);
}
else if (inBotRadius(x,y)) {
anchor.set(y);
pageBack();
}
}
else if (state == "BOT") {
if (inTopRadius(x,y)) {
anchor.set(y);
pageForward();
}
else if (inBotRadius(x,y)) {
anchor.set(y);
}
}
else if (state == "MID") {
anchor.setWithOffsetWhen(function(y) {
return inMidRadius(0,y);
});
}
anchor.scroll(y);
};
var touchMove = function(x,y) {
anchor.scroll(y);
};
var touchEnd = function(x,y) {
if (anchor.isOn()) {
if (inTopRadius(x,y)) {
scrollTop();
}
else if (inBotRadius(x,y)) {
scrollBot();
}
}
anchor.clear();
};
var touchCancel = function(x,y) {
touchEnd(x,y);
};
//////////////////////////////////////////////////////////////////////
// Low level touch functions
// (maps our functions to the proper mouse and touch events)
(function(){
var lastX, lastY;
var callWithXY = function(func,evt) {
var x,y;
if (evt.touches && evt.touches.length > 0) { // touch
x = evt.touches[0].pageX;
y = evt.touches[0].pageY;
// disable default touch controls to prevent
// content-dragging, etc.
evt.preventDefault();
}
else { // mouse
x = evt.pageX;
y = evt.pageY;
}
lastX = x;
lastY = y;
func(x,y);
};
var isTouching = false;
var start = function(evt) {
isTouching = true;
callWithXY(touchStart,evt);
};
var move = function(evt) {
if (isTouching) {
callWithXY(touchMove,evt);
}
};
var end = function(evt) {
isTouching = false;
touchEnd(lastX,lastY);
};
var cancel = function(evt) {
isTouching = false;
touchEnd(lastX,lastY);
};
// Only allow mouse touch events when shift key is pressed.
var mouseCanDrag = false;
document.addEventListener("keydown", function(evt) {
evt = evt || window.event;
if (evt.keyCode == 16) {
mouseCanDrag = true;
setCursor("n-resize");
}
});
document.addEventListener("keyup", function(evt) {
evt = evt || window.event;
if (evt.keyCode == 16) {
mouseCanDrag = false;
setCursor("auto");
}
});
var wrapMouseCallback = function(callback) {
return function(evt) {
if (mouseCanDrag) {
// only call event if we're allowing the mouse to drag.
callback(evt);
// prevent text-selecting.
evt.preventDefault();
}
else if (isTouching) {
// end our touch operation if needed.
end(evt);
}
};
};
// Add touch controls to the elements comprising the page.
var touchElements = [
"topPage", "bottomPage",
"topRightHider",
"topHider", "bottomHider", "leftHider", "rightHider",
"progressIndicator"];
var i,len,elm;
for (i=0, len=touchElements.length; i<len; i++) {
elm = staticscroll[touchElements[i]];
elm.addEventListener('touchstart', start);
elm.addEventListener('touchmove', move);
elm.addEventListener('touchend', end);
elm.addEventListener('touchcancel', cancel);
// emulate touch controls with mouse
elm.addEventListener('mousedown', wrapMouseCallback(start));
elm.addEventListener('mousemove', wrapMouseCallback(move));
elm.addEventListener('mouseup', wrapMouseCallback(end));
}
// Set the cursor over the page contents.
var setCursor = function(c) {
var i,len,elm;
for (i=0, len=touchElements.length; i<len; i++) {
elm = staticscroll[touchElements[i]];
elm.style.cursor = c;
}
};
})();
})();
window.onresize = function (event) {
staticscroll.doResize();
}
},
showHideHotKeyDialog: function() {
if (!staticscroll.hotKeyDialog) {
log("Creating hotkey dialog", 2);
staticscroll.hotKeyDialog = document.createElement("div");
staticscroll.innerHotKeyDialog = document.createElement("p");
staticscroll.hotKeyDialog.className = "ss_hotkey_container";
staticscroll.innerHotKeyDialog.className = "ss_hotkey_dialog";
staticscroll.hotKeyDialog.style.visibility = "hidden";
staticscroll.innerHotKeyDialog.innerHTML = "<table cellspacing='20'>"
+ "<tr><td align='right' width='240px'><b>[SPACE]</b></td><td>Start or Stop AutoScroll</td></tr>"
+ "<tr><td align='right' width='240px'><b>[+]/[-]</b></td><td>Increase / Decrease Scroll Speed</td></tr>"
+ "<tr><td align='right' width='240px'><b>[LEFT]/[PAGE UP]</b></td><td>Previous Page</td></tr>"
+ "<tr><td align='right' width='240px'><b>[RIGHT]/[PAGE DOWN]</b></td><td>Next Page</td></tr>"
+ "<tr><td align='right' width='240px'><b>[SHIFT+DRAG]</b></td><td>Move Scroll Line</td></tr>"
+ "<tr><td align='right' width='240px'><b>[H]</b></td><td>Show or Hide this Dialog</td></tr>"
+ "</table>";
staticscroll.innerHotKeyDialog.style.marginTop = (((window.innerHeight - 220) / 2) - 50) + "px";
staticscroll.innerHotKeyDialog.style.marginLeft = (((window.innerWidth - 580) / 2) - 15) + "px";
staticscroll.hotKeyDialog.onclick = function (event) {
staticscroll.showHideHotKeyDialog();
};
document.body.appendChild(staticscroll.hotKeyDialog);
document.body.appendChild(staticscroll.innerHotKeyDialog);
}
if (staticscroll.hotKeyDialog.style.visibility === "hidden") {
staticscroll.hotKeyDialog.style.visibility = "visible";
staticscroll.innerHotKeyDialog.style.visibility = "visible";
} else {
staticscroll.hotKeyDialog.style.visibility = "hidden";
staticscroll.innerHotKeyDialog.style.visibility = "hidden";
}
},
originalFS: null,
showHideSettingsDialog: function() {
log("Showing Settings Dialog", 2);
if (!staticscroll.settingsDialog) {
log("Creating settings dialog", 2);
staticscroll.settingsDialog = document.createElement("div");
staticscroll.innerSettingsDialog = document.createElement("p");
staticscroll.settingsDialog.className = "ss_settings_container";
staticscroll.innerSettingsDialog.className = "ss_settings_dialog";
staticscroll.settingsDialog.style.visibility = "hidden";
staticscroll.innerSettingsDialog.innerHTML = "<h2>Change Settings: </h2><table cellspacing='10'>"
+ "<tr><td><table class='ss_radioSettings'><tr><th colspan='2'>Font Size:</th></tr>"
+ "<tr><td>Small</td><td><input type='radio' name='fontSize' value='small' id='fs_small'></td></tr>"
+ "<tr><td>Default</td><td><input type='radio' name='fontSize' value='default' id='fs_default'></td></tr>"
+ "<tr><td>Large</td><td><input type='radio' name='fontSize' value='large' id='fs_large'></td></tr>"
+ "<tr><td>Largest</td><td><input type='radio' name='fontSize' value='largest' id='fs_largest'></td></tr>"
+ "</table></td><td><table class='ss_radioSettings'><tr><th colspan='2'>Color Scheme:</th></tr>"
+ "<tr><td>Default</td><td><input type='radio' name='colorScheme' value='default' id='cs_default'></td></tr>"
+ "<tr><td>Solar Day</td><td><input type='radio' name='colorScheme' value='Solar Day' id='cs_solar_day'></td></tr>"
+ "<tr><td>Solar Night</td><td><input type='radio' name='colorScheme' value='Solar Night' id='cs_solar_night'></td></tr>"
+ "<tr><td>Low Contrast</td><td><input type='radio' name='colorScheme' value='Low Contrast' id='cs_low_contrast'></td></tr>"
+ "</table></td></table>"
+ "<strong>Drag the following link to your bookmarks bar to save these settings:</strong> <br/>"
+ "<a id='ss_bookmarklet' onclick='alert(\"Drag the link to your bookmarks bar\"); return false;'"
+ "href='javascript:(function(){var resource = document.createElement(\"script\");"
+ "resource.src = \"" + ss_url("init.js") + "\"; document.documentElement.appendChild(resource);}());'>Read with MagicScroll</a> <br/>"
+ "<input type='button' value='Close Settings' class='ss_settingsClose' id='ss_cancelSettings'/>";
staticscroll.innerSettingsDialog.style.marginTop = (((window.innerHeight - 288) / 2) - 50) + "px";
staticscroll.innerSettingsDialog.style.marginLeft = (((window.innerWidth - 464) / 2) - 15) + "px";
staticscroll.settingsDialog.onclick = function (event) {
staticscroll.showHideSettingsDialog();
};
document.body.appendChild(staticscroll.settingsDialog);
document.body.appendChild(staticscroll.innerSettingsDialog);
document.getElementById("ss_cancelSettings").onclick = function(event) {
staticscroll.showHideSettingsDialog();
};
document.getElementById("ss_bookmarklet").href = "javascript:(function(){"
+ "window.ss_bookmarkletstate = " + JSON.stringify(ss_state) + "; "
+ "var resource = document.createElement(\"script\");"
+ "resource.src = \"" + ss_url("init.js") + "\"; document.documentElement.appendChild(resource);}());";
var saveSettings = function (event) {
staticscroll.saveSettings();
}
document.getElementById("fs_small").onclick = saveSettings;
document.getElementById("fs_default").onclick = saveSettings;
document.getElementById("fs_large").onclick = saveSettings;
document.getElementById("fs_largest").onclick = saveSettings;
document.getElementById("cs_default").onclick = saveSettings;
document.getElementById("cs_solar_day").onclick = saveSettings;
document.getElementById("cs_solar_night").onclick = saveSettings;
document.getElementById("cs_low_contrast").onclick = saveSettings;
staticscroll.settingsDialog.style.visibility = "hidden";
staticscroll.innerSettingsDialog.style.visibility = "hidden";
switch (staticscroll.fontSize) {
case 0: document.getElementById('fs_small').checked = true; break;
case 1: document.getElementById('fs_default').checked = true; break;
case 2: document.getElementById('fs_large').checked = true; break;
case 3: document.getElementById('fs_largest').checked = true; break;
}
switch (staticscroll.colorScheme) {
case 0: document.getElementById('cs_default').checked = true; break;
case 1: document.getElementById('cs_solar_day').checked = true; break;
case 2: document.getElementById('cs_solar_night').checked = true; break;
case 3: document.getElementById('cs_low_contrast').checked = true; break;
}
}
if (staticscroll.settingsDialog.style.visibility === "hidden") {
staticscroll.orignalFS = staticscroll.fontSize;
staticscroll.settingsDialog.style.visibility = "visible";
staticscroll.innerSettingsDialog.style.visibility = "visible";
} else {
staticscroll.settingsDialog.style.visibility = "hidden";
staticscroll.innerSettingsDialog.style.visibility = "hidden";
if (staticscroll.orignalFS != staticscroll.fontSize) {
staticscroll.doResize();
}
}
},
saveSettings: function() {
log("Saving Settings", 2);
if (document.getElementById('fs_small').checked) {
ss_savelocal({'ss_fs': 0});
staticscroll.fontSize = 0;
} else if (document.getElementById('fs_default').checked) {
ss_savelocal({'ss_fs': 1});
staticscroll.fontSize = 1;
} else if (document.getElementById('fs_large').checked) {
ss_savelocal({'ss_fs': 2});
staticscroll.fontSize = 2;
} else if (document.getElementById('fs_largest').checked) {
ss_savelocal({'ss_fs': 3});
staticscroll.fontSize = 3;
}
if (document.getElementById('cs_default').checked) {
ss_savelocal({'ss_cs': 0});
staticscroll.colorScheme = 0;
} else if (document.getElementById('cs_solar_day').checked) {
ss_savelocal({'ss_cs': 1});
staticscroll.colorScheme = 1;
} else if (document.getElementById('cs_solar_night').checked) {
ss_savelocal({'ss_cs': 2});
staticscroll.colorScheme = 2;
} else if (document.getElementById('cs_low_contrast').checked) {
ss_savelocal({'ss_cs': 3});
staticscroll.colorScheme = 3;
}
staticscroll.topPage.className = "ss_page fs_" + staticscroll.fontSize + " cs_" + staticscroll.colorScheme;
staticscroll.bottomPage.className = "ss_page fs_" + staticscroll.fontSize + " cs_" + staticscroll.colorScheme;
staticscroll.prepPage.className = "ss_page fs_" + staticscroll.fontSize + " cs_" + staticscroll.colorScheme;
document.body.className = "ss_body ss_body_cs_" + staticscroll.colorScheme;
if (staticscroll.colorScheme == 0) {
document.body.style.backgroundImage = "url(" + ss_url("images/skewed_print.png") + ")";
} else {
document.body.style.backgroundImage = "none";
}
},
loadFontSize: function(callback) {
ss_loadlocal("ss_fs", function(fetchedData){
if (fetchedData.ss_fs) {
callback(fetchedData.ss_fs);
} else {
callback(1);
}
});
},
loadColorScheme: function(callback) {
ss_loadlocal("ss_cs", function(fetchedData){
if (fetchedData.ss_cs) {
callback(fetchedData.ss_cs);
} else {
callback(0);
}
});
},
resizeTimer: 0,
doResize: function() {
log("Resizing", 2);
clearTimeout(staticscroll.resizeTimer);
function resize() {
staticscroll.bugReportDiv = null;
staticscroll.innerHotKeyDialog = null;
staticscroll.hotKeyDialog = null;
staticscroll.innerSettingsDialog = null;
staticscroll.settingsDialog = null;
staticscroll.goalPage = staticscroll.pages[staticscroll.currentPage - 1] || 0;
staticscroll.pages = [0];
staticscroll.lastPage = -1;
clearTimeout(staticscroll.processPageTimerId);
staticscroll.processLock = false;
staticscroll.currentPage = 0;
staticscroll.scrollInfo = [];
staticscroll.init();
}
staticscroll.resizeTimer = setTimeout(resize, 10);
},
updateProgressIndicator: function (currentCharCount) {
if (currentCharCount > 0) {
var progress = Math.round((currentCharCount * 10000) / staticscroll.article.length);
staticscroll.progressIndicator.innerHTML = (progress / 100) + "%";
} else {
staticscroll.progressIndicator.innerHTML = "0%";
}
},
scrollForward: function() {
var pageHeight = staticscroll.topPage.clientHeight;
if (staticscroll.scrollInfo[staticscroll.currentPage - 1]) {
var currentScrollInfo = staticscroll.scrollInfo[staticscroll.currentPage - 1];
var i;
for (i = 0; i < currentScrollInfo.length; i++) {
if (pageHeight <= currentScrollInfo[i][1]) {
break
}
}
if (i < currentScrollInfo.length - 1) {
staticscroll.scroll(Math.max(1, currentScrollInfo[i + 1][1] - pageHeight));
} else {
staticscroll.scroll(30);
}
}
},
scrollBackward: function() {
staticscroll.startScrollTime = 0;
var pageHeight = staticscroll.topPage.clientHeight;
if (pageHeight <= 0) {
if (staticscroll.currentPage > 1) {
staticscroll.showPrevPage();
staticscroll.topPage.style.height= staticscroll.getMaxHeight() + "px";
staticscroll.topRightHider.style.height = staticscroll.getMaxHeight() + "px";
}
return;
}
if (staticscroll.scrollInfo[staticscroll.currentPage - 1]) {
var currentScrollInfo = staticscroll.scrollInfo[staticscroll.currentPage - 1];
var i;
for (i = 0; i < currentScrollInfo.length - 1; i++) {
if (pageHeight <= currentScrollInfo[i][1]) {
break;
}
}
if (i < 1){
if (currentScrollInfo.length > 1) {
if (staticscroll.currentPage > 1) {
staticscroll.showPrevPage();
staticscroll.topPage.style.height= staticscroll.getMaxHeight() + "px";
staticscroll.topRightHider.style.height = staticscroll.getMaxHeight() + "px";
}
} else {
staticscroll.scroll(-30);
}
} else if (i< currentScrollInfo.length - 1) {
staticscroll.scroll(Math.min(-1, currentScrollInfo[i - 1][1] - pageHeight));
} else {
var delta = currentScrollInfo[i - 1][1] - pageHeight;
staticscroll.scroll(Math.min(-1, Math.max(delta,-30)));
}
}
},
scroll: function(distance) {
if (distance > 0) {
distance = Math.min(distance, 75);
} else {
distance = Math.max(distance, -75);
}
var goal = staticscroll.topPage.clientHeight + distance;
if (goal < 0) {
staticscroll.showPrevPage();
} else if (goal > staticscroll.getMaxHeight()) {
staticscroll.showNextPage();
} else {
staticscroll.topPage.style.height = goal + "px";
staticscroll.topRightHider.style.height = goal + "px";
}
},
showNextPage: function() {
staticscroll.getNextPage(function (pageText) {
staticscroll.bottomPage.innerHTML = staticscroll.topPage.innerHTML;
staticscroll.topPage.innerHTML = pageText;
staticscroll.topPage.style.height = "0px";
if (staticscroll.pages[staticscroll.currentPage - 1]) {
staticscroll.updateProgressIndicator(staticscroll.pages[staticscroll.currentPage - 1]);
}
else {
staticscroll.updateProgressIndicator(0);
}
})
},
showPrevPage: function(fromClick) {
if (staticscroll.topPage.clientHeight > 50) {
staticscroll.topPage.style.height = "0px";
} else if (staticscroll.currentPage > 1) {
staticscroll.getPrevPage(function (pageText) {
staticscroll.topPage.innerHTML = staticscroll.bottomPage.innerHTML;
staticscroll.bottomPage.innerHTML = pageText;
if (fromClick) {
staticscroll.topPage.style.height = "0px";
} else {
staticscroll.topPage.style.height = staticscroll.getMaxHeight() + "px";
}
if (staticscroll.pages[staticscroll.currentPage - 1]) {
staticscroll.updateProgressIndicator(staticscroll.pages[staticscroll.currentPage - 1]);
} else {
staticscroll.updateProgressIndicator(0);
}
})
}
},
getMaxHeight: function() {
return window.innerHeight - 80;
},
createUI: function() {
log("Creating UI 8", 2);
var nextButton = document.createElement("img");
nextButton.src = ss_url("images/next_1.png");
nextButton.className = "ss_nav_button ss_unselected";
var width = Math.round(Math.min(window.innerWidth - 60, Math.max(window.innerHeight * 0.618, 400) + 20));
var left = (((window.innerWidth - (width + 120)) / 4) - 24);
var top = ((window.innerHeight / 2) - 24) + "px";
nextButton.style.left = (window.innerWidth - ((left * 2) + 48))+ "px";
left = left + "px";
nextButton.style.paddingLeft = left;
nextButton.style.paddingRight = left;
nextButton.style.paddingTop = top;
nextButton.style.paddingBottom = top;
nextButton.onmouseover = function (event) {
nextButton.className = "ss_nav_button";
}
nextButton.onmouseout = function (event) {
nextButton.className = "ss_nav_button ss_unselected";
}
nextButton.onclick = function (event) {
staticscroll.showNextPage();
}
var prevButton = document.createElement("img");
prevButton.src = ss_url("images/previous_1.png");
prevButton.className = "ss_nav_button ss_unselected";
prevButton.style.paddingLeft = left;
prevButton.style.paddingRight = left;
prevButton.style.paddingTop = top;
prevButton.style.paddingBottom = top;
prevButton.onmouseover = function (event) {
prevButton.className = "ss_nav_button";
}
prevButton.onmouseout = function (event) {
prevButton.className = "ss_nav_button ss_unselected";
}
prevButton.onclick = function (event) {
staticscroll.showPrevPage(true);
}
staticscroll.updatePlayButton();
staticscroll.playButton.onclick = function (event) {
staticscroll.startStopScroll();
}
var fastButton = document.createElement("img");
fastButton.src = ss_url("images/plus_1.png");
fastButton.title = "Increase Scroll Speed";