This repository has been archived by the owner on Nov 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorg-info-src.js
2341 lines (2150 loc) · 76.8 KB
/
org-info-src.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
/**
* @file
* org-info.js
*
* Version: 0.1.7.2
*
* @author Sebastian Rose, Hannover, Germany - sebastian_rose at gmx dot de
*
*
* This software is subject to the GNU General Public Licens version 3:
* see: http://www.gnu.org/licenses/
*
* Requirements:
*
* Org-mode >= 6.12a
*
* Org-mode > 6.23 (commit a68eb4b1e64cbe6e495fdd2c1eaf8ae597bf8602):
* You'll need at least org-info.js v.0.1.0.1
*
* Usage:
*
* Include this scipt into the Header of your HTML-exported org files by
* customizing the variable org-export-html-style (TODO: add file local export
* Options here).
* You will also need this here somewhere in the HTML-page:
*
* <script type="text/javascript" language="JavaScript" src="org-info.js"></script>
* <script type="text/javascript" language="JavaScript">
* <![CDATA[ // comment around this one
* org_html_manager.set("LOCAL_TOC", "1");
* org_html_manager.set("VIEW", "info");
* org_html_manager.set("VIEW_BUTTONS", "true");
* org_html_manager.set("LINK_UP", "http://full/path/to/index/of/this/directory.html");
* org_html_manager.set("LINK_HOME", "http://full/path/to/homepage.html");
* org_html_manager.set("MOUSE_HINT", "underline"); // or a color like '#eeeeee'
* org_html_manager.setup ();
* ]]> // comment around this one
* </script>
*
*
* The script is now roughly devided in sections by form-feeds. Editors can
* move section wise using the common emacs commands for this purpos ('C-x ]'
* and 'C-x ]').
*
* The sections are:
* 1. This comment block.
* 2. Everything around =OrgNodes=.
* 3. =org_html_manager= constructor and setup.
* 4. =org_html_manager= folding and view related stuff.
* 5. =org_html_manager= history related methods.
* 6. =org_html_manager= minibuffer handling.
* 7. =org_html_manager= user input.
* 8. =org_html_manager= search functonality.
* 9. =org_html_manager= misc.
* 10. Global functions.
*/
/**
* Creates a new OrgNode.
* An OrgOutline stores some refs to its assoziated node in the document tree
* along with some additional properties.
*/
function OrgNode ( _div, _heading, _link, _depth, _parent, _base_id, _toc_anchor)
{
var t = this;
t.DIV = _div;
t.BASE_ID = _base_id; // The suffix that's common to the heading and the diffs.
t.IDX = -1; // The index in OrgHtmlManager::SECS[]
t.HEADING = _heading;
t.L = _link;
t.HAS_HIGHLIGHT = false; // Node highlighted (search)
t.PARENT = _parent;
t.DIRTY = false; // Node is dirty, when children get
// folded seperatly.
t.STATE = OrgNode.STATE_FOLDED;
t.TOC = _toc_anchor;
t.DEPTH = _depth; // The Rootelement will have
// the depth 0. All other
// Nodes get the depth from
// their h-level (h1, h2...)
t.FOLDER = null;
t.CHILDREN = new Array();
t.NAV = ""; // The info navigation
t.BUTTONS = null;
if(null != t.PARENT) {
t.PARENT.addChild(this);
t.hide();
}
var folder = document.getElementById("text-"+t.BASE_ID);
if(null == folder && _base_id) {
var fid = _base_id.substring(4);
folder = document.getElementById("text-"+fid); // try old schema
}
if(null != folder)
t.FOLDER = folder;
t.isTargetFor = new Object();
t.isTargetFor['#' + t.BASE_ID] = 2;
OrgNode.findTargetsIn(t.isTargetFor, t.HEADING, 1); // 1 == prefere this one as section link.
OrgNode.findTargetsIn(t.isTargetFor, t.FOLDER, 3);
}
// static variables
OrgNode.STATE_FOLDED = 0;
OrgNode.STATE_HEADLINES = 1;
OrgNode.STATE_UNFOLDED = 2;
//
// static functions
//
OrgNode.findTargetsIn = function(safe, container, priority)
{
if(container) {
var a = container.getElementsByTagName("a");
if(a) {
for(var i=0;i<a.length;++i) {
var n = a[i].getAttribute('id');
if(n) safe['#' + n] = priority;
else {
n = a[i].getAttribute('name');
if(n) safe['#' + n] = priority;
}}}}};
OrgNode.hideElement = function (e)
{
if(e && e['style']) { // test for e['style'] is just quick fix for error elsewhere (fixed toc and title)
e.style.display = 'none';
e.style.visibility = 'hidden';
}
};
OrgNode.showElement = function (e)
{
if(e && e['style']) {
e.style.display = 'block';
e.style.visibility = 'visible';
}
};
OrgNode.unhideElement = function (e)
{
e.style.display="";
e.style.visibility="";
};
OrgNode.isHidden = function(e)
{
if(e.style.display=='none' || e.style.visibility=='hidden')
return true;
return false;
};
OrgNode.toggleElement = function (e)
{
if(e.style.display == 'none') {
e.style.display = 'block';
e.style.visibility = 'visible';
} else {
e.style.display = 'none';
e.style.visibility = 'hidden';
}
};
/**
* Find the OrgNode containing a DOM-text-node.
* @param dom The text node.
* @param org The OrgNode containing the OrgNode in question.
*/
OrgNode.textNodeToIdx = function (dom, org)
{
while(dom.nodeType != 1 /* IE has no Node.ELEMENT_NODE... */
|| -1 == dom.attributes["id"].value.indexOf("outline-container-")) {
dom = dom.parentNode;
}
var base_id = dom.attributes["id"].value.substr(18);
return OrgNode.idxForBaseId(base_id, org);
};
/**
* Find an OrgNode with base_id inside an OrgNode and return it's idx.
* @param base The base_id.
* @param org The OrgNode.
*/
OrgNode.idxForBaseId = function(base, org)
{
if(org.BASE_ID == base) return org;
for(var i = 0; i < org.CHILDREN.length; ++i) {
var o = OrgNode.idxForBaseId(idx, org.CHILDREN[i]);
if(null != o) return o;
}
return null;
};
//
// member functions
//
OrgNode.prototype.addChild = function (child)
{
this.CHILDREN.push(child);
return this.PARENT;
};
//
// OrgNode methods for paging (info mode)
//
OrgNode.prototype.hide = function ()
{
OrgNode.hideElement(this.DIV);
if(this.PARENT)
this.PARENT.hide();
};
OrgNode.prototype.show = function ()
{
OrgNode.showElement(this.DIV);
if(this.DEPTH > 2)
this.PARENT.show();
};
OrgNode.prototype.showAllChildren = function ()
{
for(var i=0;i<this.CHILDREN.length;++i) { this.CHILDREN[i].showAllChildren(); }
this.show();
};
OrgNode.prototype.hideAllChildren = function ()
{
for(var i=0;i<this.CHILDREN.length;++i) { this.CHILDREN[i].hideAllChildren(); }
this.hide();
};
/**
* Set class for links to current page to current and visited pages to visited_after_load
* Note: visited pages will be reset after reload!
*/
OrgNode.prototype.setLinkClass = function (on)
{
if(this.TOC) {
if(on) this.TOC.className = "current";
else this.TOC.className = "visited_after_load";
}
}
//
// OrgNode methods for folding
//
/**
* This one is called onclick() to toggle the folding state of the node.
* This one sets its parent dirty, since node is folded individually. Hence the
* next folding of parent has to collapse all.
* @param show_childrens_folders Boolean. This is only used for the special way
* of toggling of the ROOT element. If true, prevents this OrgNode from showing
* the folder.
*/
OrgNode.prototype.fold = function (hide_folder)
{
if(this.PARENT)
this.PARENT.DIRTY = true;
if(this.DIRTY) {
this.DIRTY = false;
this.STATE = OrgNode.STATE_UNFOLDED; // so next state is FOLDED. See below.
}
if(null != this.FOLDER) {
if(this.STATE == OrgNode.STATE_FOLDED) {
// I was folded but one could click on me. So now show Headlines
// recursive.
if(this.CHILDREN.length) {
this.STATE = OrgNode.STATE_HEADLINES;
OrgNode.hideElement(this.FOLDER);
for(var i=0;i<this.CHILDREN.length;++i) { this.CHILDREN[i].setState(OrgNode.STATE_HEADLINES); }
} else if (! hide_folder) {
// without children jump to unfolded state:
this.STATE = OrgNode.STATE_UNFOLDED;
OrgNode.showElement(this.FOLDER);
}
}
else if(this.STATE == OrgNode.STATE_HEADLINES) {
// show all content recursive
this.STATE = OrgNode.STATE_UNFOLDED;
OrgNode.showElement(this.FOLDER);
for(var i=0;i<this.CHILDREN.length;++i) { this.CHILDREN[i].setState(OrgNode.STATE_UNFOLDED); }
}
else {
// collapse. Show only own headline
this.STATE = OrgNode.STATE_FOLDED;
OrgNode.hideElement(this.FOLDER);
for(var i=0;i<this.CHILDREN.length;++i) { this.CHILDREN[i].setState(OrgNode.STATE_FOLDED); }
}
}
};
/**
* Recursive state switching. This functions folds children of activated
* parents. The states have a slightly different meaning here. Here the
* surrounding div (outline-container-id) gets hidden too.
* Maybe add OrgNode.STATE_HIDDEN with same value?
*/
OrgNode.prototype.setState = function (state)
{
var t = this;
for(var i=0;i<t.CHILDREN.length;++i) {
t.CHILDREN[i].setState(state);
}
switch (state)
{
case OrgNode.STATE_FOLDED:
OrgNode.hideElement(t.FOLDER);
OrgNode.hideElement(t.DIV);
break;
case OrgNode.STATE_HEADLINES:
OrgNode.hideElement(t.FOLDER);
OrgNode.showElement(t.DIV);
break;
default:
OrgNode.showElement(t.FOLDER);
OrgNode.showElement(t.DIV);
}
t.STATE = state;
};
/**
* OrgManager manages OrgNodes.
* We don't create anything in the constructor, since the document is not loaded
* yet.
*/
var org_html_manager = {
// Option
MOUSE_HINT: 0, // Highlight heading under mouse?
BODY:null, // The container all the contents live in.
PLAIN_VIEW: 0, // We're in plain view mode. On startup:= overview
CONTENT_VIEW: 1, // plain view show structure
ALL_VIEW: 2, // plain view show all
INFO_VIEW: 3, // We're in info view mode
SLIDE_VIEW: 4, // Slidemode.
VIEW: this.CONTENT_VIEW, // Default view mode (s. setup())
LOCAL_TOC: false, // Create sub indexes (s. setup()): "0", "1" "above", "below" (==1, default)
LINK_HOME: 0, // Link to this.LINK_HOME?
LINK_UP: 0, // Link to this.LINK_UP?
LINKS: "", // Prepare the links for later use (see setup),
RUN_MAX: 1200, // Max attempts to scan (results in ~2 minutes)
RUN_INTERVAL: 100, // Interval of scans in milliseconds.
HIDE_TOC: false, // Hide the table of contents.
TOC_DEPTH: 0, // Level to cut the table of contents. No cutting if 0.
STARTUP_MESSAGE: 0, // Show info at startup?
POSTAMBLE: null, // cache the 'postamble' element.
// Private
BASE_URL: document.URL, // URL without '#sec-x.y.z'
// BASE_URL_QUESTIONS: "https://github.com/tarjeiba/promo/issues/new",
BASE_URL_QUESTIONS: null,
Q_PARAM: "", // A query param like `?VIEW=content'
ROOT: null, // Root element or our OrgNode tree
NODE: null, // The current node
TITLE: null, // Save the title for hide/show
INNER_TITLE: false, // The cloned title in sec-1.
LOAD_CHECK: null, // Saves the setTimeout()'s value
WINDOW: null, // A div to display info view mode
SECS: new Array(), // The OrgNode tree
REGEX: /(#)(.*$)/, // identify a section link in toc
SID_REGEX: /(^#)(sec-\d+([._]\d+)*$)/, // identify a plain section ID
UNTAG_REGEX: /<[^>]+>/i, // Remove HTML tags
ORGTAG_REGEX: /^(.*)<span\s+class=[\'\"]tag[\'\"]>(<span[^>]+>[^<]+<\/span>)+<\/span>/i, // Remove Org tags
TRIMMER: /^(\s*)([^\s].*)(\s*)$/, // Trim
// FNREF_REGEX: /(fnr\.*)/, // Footnote ref FIXME: not in use!?!
TOC: null, // toc.
RUNS: 0, // Count the scan runs.
HISTORY: new Array(50), // Save navigation history.
HIST_INDEX: 0,
SKIP_HISTORY: false, // popHistory() set's this to true.
FIXED_TOC: false, // Leave toc alone if position=[fixed|absolute]?
// Commands:
CONSOLE: null, // The div containing the minibuffer.
CONSOLE_INPUT: null,
CONSOLE_LABEL: null,
CONSOLE_OFFSET: "50px",
OCCUR: "", // The search string.
SEARCH_REGEX: "",
SEARCH_HL_REGEX: new RegExp('(<span class="org-info-js_search-highlight">)([^<]*?)(<\/span>)', "gi"),
MESSAGING: 0, // Is there a message in the console?
MESSAGING_INPLACE: 1,
MESSAGING_TOP: 2,
// show help:
HELPING: false,
SYNTAXING: false,
// console in read mode?
READING: false,
// if yes, which command caused the readmode?
READ_COMMAND: "",
// numerical commands are internal commands.
READ_COMMAND_NULL: "_0",
READ_COMMAND_HTML_LINK: "_1",
READ_COMMAND_ORG_LINK: "_2",
READ_COMMAND_PLAIN_URL_LINK: "_03",
LAST_VIEW_MODE:0,
TAB_INDEX: 1000, // Users could have defined tabindexes!
SEARCH_HIGHLIGHT_ON: false,
TAGS: {}, // Tags: {tag:[index,index2...],tag2:[index1,index2...]}
SORTED_TAGS: new Array(), // Sorted tags
TAGS_INDEX: null, // Caches the tags-index screen
CLICK_TIMEOUT: null, // Mousehandling
SECNUM_MAP: {}, // Map section numbers to OrgNodes
TOC_LINK: null, // Last link used in TOC
HOOKS: { run_hooks: false, // Hoooks. run_hooks is false until onReady() is run.
onShowSection: [],
onReady: [] },
/**
* Setup the OrgHtmlManager for scanning.
* Here the timeout func gets set, that tells the wakes up org_html_mager
* for the next attempt to scan the document.
* All user setable config vars (the documented ones) are checked and adjusted
* to a legal value.
*/
setup: function ()
{
var t = this;
if(window['orgInfoHooks']) {
for(var i in orgInfoHooks) {
t.HOOKS[i] = orgInfoHooks[i];
}
t.HOOKS['run_hooks'] = false;
}
if(location.search) { // enable overwriting of settings
var sets = location.search.substring(1).split('&');
for(var i = 0; i < sets.length; ++i) {
var pos = sets[i].indexOf('=');
if(-1 != pos) {
var v = sets[i].substring(pos+1);
var k = sets[i].substring(0, pos);
switch(k) {
// Explicitely allow overwrites.
// Fall through:
case 'TOC':
case 'TOC_DEPTH':
case 'MOUSE_HINT':
case 'HJELP':
case 'VIEW':
case 'HIDE_TOC':
case 'LOCAL_TOC':
case 'OCCUR':
t.set(k, decodeURIComponent(v));
break;
default: break;
}
}
}
}
t.VIEW = t.VIEW ? t.VIEW : t.PLAIN_VIEW;
t.VIEW_BUTTONS = (t.VIEW_BUTTONS && t.VIEW_BUTTONS != "0") ? true : false;
t.STARTUP_MESSAGE = (t.STARTUP_MESSAGE && t.STARTUP_MESSAGE != "0") ? true : false;
t.LOCAL_TOC = (t.LOCAL_TOC && t.LOCAL_TOC != "0") ? t.LOCAL_TOC : false;
t.HIDE_TOC = (t.TOC && t.TOC != "0") ? false : true;
t.INNER_TITLE = (t.INNER_TITLE && t.INNER_TITLE != "title_above") ? false : true;
if(t.FIXED_TOC && t.FIXED_TOC != "0") {
t.FIXED_TOC = true;
t.HIDE_TOC = false;
}
else t.FIXED_TOC = false;
t.LINKS +=
((t.LINK_UP && t.LINK_UP != document.URL) ? '<a href="'+t.LINK_UP+'">Up</a> / ' : "") +
((t.LINK_HOME && t.LINK_HOME != document.URL) ? '<a href="'+t.LINK_HOME+'">HOME</a> / ' : "") +
'<a href="javascript:org_html_manager.showHelp();">HJELP</a> / ';
t.LOAD_CHECK = window.setTimeout("OrgHtmlManagerLoadCheck()", 50);
},
trim: function(s)
{
var r = this.TRIMMER.exec(s);
return RegExp.$2;
},
removeTags: function (s)
{
if(s) {
while(s.match(this.UNTAG_REGEX)) {
s = s.substr(0, s.indexOf('<')) + s.substr(s.indexOf('>') + 1);
}}
return s;
},
/**
* Remove tags from headline's inner HTML.
* @param s The headline's inner HTML.
* @return @c s with all tags stripped.
*/
removeOrgTags: function (s)
{
if(s.match(this.ORGTAG_REGEX)) {
var matches = this.ORGTAG_REGEX.exec(s);
return matches[1];
}
return s;
},
init: function ()
{
var t = this;
t.RUNS++;
t.BODY = document.getElementById("content");
if(null == t.BODY) {
if(5 > t.RUNS) {
t.LOAD_CHECK = window.setTimeout("OrgHtmlManagerLoadCheck()", t.RUN_INTERVAL);
return;
} else { // be backward compatible
t.BODY = document.getElementsByTagName("body")[0];
}}
t.PREA = document.getElementById("preamble");
t.POST = document.getElementById("postamble");
if(null == t.PREA) {
t.PREA = t.BODY;
}
if(null == t.POST) {
t.POST = t.BODY;
}
if(! t.WINDOW) {
t.WINDOW = document.createElement("div");
t.WINDOW.style.marginBottom = "40px";
t.WINDOW.id = "org-info-js-window";
}
var theIndex = document.getElementById('table-of-contents');
if(! t.initFromTOC()) {
if( t.RUNS < t.RUN_MAX ) {
t.LOAD_CHECK = window.setTimeout("OrgHtmlManagerLoadCheck()", t.RUN_INTERVAL);
return;
}
// CANCELED: warn if not scanned_all ??
}
var start_section = 0;
var start_section_explicit = false;
if("" != location.hash) {
t.BASE_URL = t.BASE_URL.substring(0, t.BASE_URL.indexOf('#'));
// Search for the start section:
for(var i=0;i<t.SECS.length;++i) {
if(t.SECS[i].isTargetFor[location.hash]) {
start_section = i;
start_section_explicit = 1;
break;
}
}
}
if("" != location.search) {
t.Q_PARAM = t.BASE_URL.substring(t.BASE_URL.indexOf('?'));
t.BASE_URL = t.BASE_URL.substring(0, t.BASE_URL.indexOf('?'));
}
t.convertLinks(); // adjust internal links. BASE_URL has to be stripped.
var pa=document.getElementById('postamble');
if(pa) t.POSTAMBLE=pa;
// Temporary FIX for missing P element if skip:nil
var b = t.BODY;
var n = b.firstChild;
if(3 == n.nodeType) { // IE has no ....
var neu = n.cloneNode(true);
var p = document.createElement("p");
p.id = "text-before-first-headline";
p.appendChild(neu);
b.replaceChild(p, n);
}
// END OF temporary FIX.
t.CONSOLE = document.createElement("div");
t.CONSOLE.innerHTML = '<form action="" style="margin:0px;padding:0px;" onsubmit="org_html_manager.evalReadCommand(); return false;">'
+'<table id="org-info-js_console" style="width:100%;margin:0px 0px 0px 0px;border-style:none;" cellpadding="0" cellspacing="0" summary="minibuffer">'
+'<tbody><tr><td id="org-info-js_console-icon" style="padding:0px 0px 0px 0px;border-style:none;"> </td><td style="width:100%;vertical-align:middle;padding:0px 0px 0px 0px;border-style:none;">'
+'<table style="width:100%;margin:0px 0px 0px 0px;border-style:none;" cellpadding="0" cellspacing="2">'
+'<tbody><tr><td id="org-info-js_console-label" style="white-space:nowrap;padding:0px 0px 0px 0px;border-style:none;"></td></tr>'
+'<tr><td style="width:100%;vertical-align:middle;padding:0px 0px 0px 0px;border-style:none;">'
+'<input type="text" id="org-info-js_console-input" onkeydown="org_html_manager.getKey();"'
+' onclick="this.select();" maxlength="150" style="width:100%;padding:0px;margin:0px 0px 0px 0px;border-style:none;"'
+' value=""/></td></tr></tbody></table></td><td style="padding:0px 0px 0px 0px;border-style:none;"> </td></tr></tbody></table>'
+'</form>';
t.CONSOLE.style.position = 'relative';
t.CONSOLE.style.marginTop = "-" + t.CONSOLE_OFFSET;
t.CONSOLE.style.top = "-" + t.CONSOLE_OFFSET;
t.CONSOLE.style.left = '0px';
t.CONSOLE.style.width = '100%';
t.CONSOLE.style.height = '40px';
t.CONSOLE.style.overflow = 'hidden';
t.CONSOLE.style.verticalAlign = 'middle';
t.CONSOLE.style.zIndex = '9';
t.CONSOLE.style.border = "1px solid #cccccc";
t.CONSOLE.id = 'org-info-js_console-container';
t.BODY.insertBefore(t.CONSOLE, t.BODY.firstChild);
t.MESSAGING = false;
t.CONSOLE_LABEL = document.getElementById("org-info-js_console-label");
t.CONSOLE_INPUT = document.getElementById("org-info-js_console-input");
document.onkeypress=OrgHtmlManagerKeyEvent;
if(t.VIEW == t.INFO_VIEW) {
t.infoView(start_section);
t.showSection(start_section);
// For Opera 10 - want to see the title and buttons on (re-)load.
window.setTimeout(function(){window.scrollTo(0, 0);}, 100);
}
else if(t.VIEW == t.SLIDE_VIEW) {
t.slideView(start_section);
t.showSection(start_section);
}
else {
var v = t.VIEW; // will be changed in t.plainView()!
t.plainView(start_section, 1);
t.ROOT.DIRTY = true;
t.ROOT_STATE = OrgNode.STATE_UNFOLDED;
t.toggleGlobaly();
if(v > t.PLAIN_VIEW)
t.toggleGlobaly();
if (v == t.ALL_VIEW)
t.toggleGlobaly();
if(start_section_explicit) // Unfold the requested section
t.showSection(start_section);
}
if("" != t.OCCUR) {
t.CONSOLE_INPUT.value = t.OCCUR;
t.READ_COMMAND = 'o';
t.evalReadCommand();
}
if(t.STARTUP_MESSAGE) {
t.warn("Denne siden bruker org-info.js. Trykk `?' for mer informasjon.", true);
}
t.HOOKS.run_hooks = true; // Unblock all hooks.
t.runHooks('onReady', this.NODE);
},
initFromTOC: function ()
{
var t = this;
// scan the document for sections. We do it by scanning the toc,
// so we do what is customized for orgmode (depth of sections in toc).
if(t.RUNS == 1 || ! t.ROOT) {
var toc = document.getElementById("table-of-contents");
if(null != toc) {
var heading = null;
var i = 0;
for(i;heading == null && i < 7;++i)
heading = toc.getElementsByTagName("h"+i)[0];
heading.onclick = function() {org_html_manager.fold(0);};
heading.style.cursor = "pointer";
if(t.MOUSE_HINT) {
heading.onmouseover = function(){org_html_manager.highlightHeadline(0);};
heading.onmouseout = function(){org_html_manager.unhighlightHeadline(0);};
}
if(t.FIXED_TOC) {
heading.setAttribute('onclick', 'org_html_manager.toggleGlobaly();');
t.ROOT = new OrgNode( null,
t.BODY.getElementsByTagName("h1")[0],
'javascript:org_html_manager.navigateTo(0);',
0,
null ); // the root node
t.TOC = new OrgNode( toc,
heading,
'javascript:org_html_manager.navigateTo(0);',
i,
null ); // the root node
t.NODE = t.ROOT;
}
else {
t.ROOT = new OrgNode( null,
t.BODY.getElementsByTagName("h1")[0],
'javascript:org_html_manager.navigateTo(0);',
0,
null ); // the root node
if(t.HIDE_TOC) {
t.TOC = new OrgNode( toc,
"",
'javascript:org_html_manager.navigateTo(0);',
i,
null );
t.NODE = t.ROOT;
OrgNode.hideElement(toc);
}
else {
t.TOC = new OrgNode( toc,
heading,
'javascript:org_html_manager.navigateTo(0);',
i,
t.ROOT ); // the root node
t.TOC.IDX = 0;
t.NODE = t.TOC;
t.SECS.push(t.TOC);
}
}
if(t.TOC) t.TOC.FOLDER = document.getElementById("text-table-of-contents");
}
else
return false;
}
var theIndex = t.TOC.FOLDER.getElementsByTagName("ul")[0]; // toc
// Could we scan the document all the way down?
// Return false if not.
if(! t.ulToOutlines(theIndex))
return false;
var fn = document.getElementById('footnotes');
if(fn) {
var fnheading = null;
var c = fn.childNodes;
for(var i=0;i<c.length;++i) {
if("footnotes"== c[i].className) {
fnheading=c[i];
break;}}
var sec = t.SECS.length;
fnheading.onclick = function() {org_html_manager.fold("" + sec);};
fnheading.style.cursor = "pointer";
if(t.MOUSE_HINT) {
fnheading.onmouseover = function() {org_html_manager.highlightHeadline("" + sec);};
fnheading.onmouseout = function() {org_html_manager.unhighlightHeadline("" + sec);};
}
var link = 'javascript:org_html_manager.navigateTo(' + sec + ')';
var fnsec= new OrgNode ( fn, fnheading, link, 1, t.ROOT, "footnotes");
t.SECS.push(fnsec);
}
if(t.TOC_DEPTH) {
t.cutToc(theIndex, 1);
}
// Move the title into the first visible section.
// TODO: show title above everything if FIXED_TOC !!!
t.TITLE = document.getElementsByClassName("title")[0];
if(t.INNER_TITLE && !t.FIXED_TOC && t.VIEW != t.SLIDE_VIEW) {
t.INNER_TITLE = t.TITLE.cloneNode(true);
/* TODO: this is still based on wrong behaviour of browsers (same id for two elements)
* But this here does not work:
* t.INNER_TITLE.style = t.TITLE.style;
* t.INNER_TITLE.id = "org-info-js-inner-title";
*/
t.SECS[0].DIV.insertBefore(t.INNER_TITLE, t.SECS[0].DIV.firstChild);
OrgNode.hideElement(t.TITLE);
}
// Create all the navigation links:
t.build();
t.NODE = t.SECS[0];
t.BODY.insertBefore(t.WINDOW, t.NODE.DIV);
return true;
},
/**
* Used by OrgHtmlManager::initFromToc
*/
ulToOutlines: function (ul)
{
if(ul.hasChildNodes() && ! ul.scanned_for_org) {
for(var i=0; i<ul.childNodes.length; ++i) {
if(false == this.liToOutlines(ul.childNodes[i])) {
return false;
}
}
ul.scanned_for_org = 1;
}
return true;
},
/**
* Used by OrgHtmlManager::initFromToc
*/
liToOutlines: function (li)
{
if(! li.scanned_for_org) {
for(var i=0; i<li.childNodes.length; ++i) {
var c = li.childNodes[i];
switch (c.nodeName) {
case "A":
var newHref = this.mkNodeFromHref(c);
if(false == newHref) {
return false;
}
else {
c.href = newHref;
c.tabIndex = this.TAB_INDEX;
c.onfocus=function(){org_html_manager.TOC_LINK=this;void 0;};
if(null==this.TOC_LINK) this.TOC_LINK=c;
this.TAB_INDEX++;
}
break;
case "UL":
return this.ulToOutlines(c);
break;
}
}
li.scanned_for_org = 1;
}
return true;
},
/**
* Used by OrgHtmlManager::initFromToc
*/
cutToc: function (ul, cur_depth)
{
cur_depth++;
if(ul.hasChildNodes()) {
for(var i=0; i < ul.childNodes.length; ++i) {
var li = ul.childNodes[i];
for(var j=0; j < li.childNodes.length; ++j) {
var c = li.childNodes[j];
if(c.nodeName == "UL") {
if(cur_depth > this.TOC_DEPTH)
li.removeChild(c);
else
this.cutToc(c, cur_depth); }}}}
},
/**
* Used by OrgHtmlManager::liToOutlines
* @param anchor <a...> element in the TOC, that links to a section.
*/
mkNodeFromHref: function (anchor)
{
s = anchor.href;
if(s.match(this.REGEX)) {
var matches = this.REGEX.exec(s);
var id = matches[2];
var h = document.getElementById(id);
// This heading could be null, if the document is not yet entirely loaded.
// So we stop scanning and set the timeout func in caller.
// We could even count the <ul> and <li> elements above to speed up the next
// scan.
if(null == h) {
return(false);
}
var div = h.parentNode;
var sec = this.SECS.length;
var depth = div.className.substr(8);
h.onclick = function() {org_html_manager.fold("" + sec);};
h.style.cursor = "pointer";
if(this.MOUSE_HINT) {
h.onmouseover = function() {org_html_manager.highlightHeadline("" + sec);};
h.onmouseout = function() {org_html_manager.unhighlightHeadline("" + sec);};
}
var link = 'javascript:org_html_manager.navigateTo(' + sec + ')';
if(depth > this.NODE.DEPTH) {
this.NODE = new OrgNode ( div, h, link, depth, this.NODE, id, anchor);
}
else if (depth == 2) {
this.NODE = new OrgNode ( div, h, link, depth, this.ROOT, id, anchor);
}
else {
var p = this.NODE;
while(p.DEPTH > depth) p = p.PARENT;
this.NODE = new OrgNode ( div, h, link, depth, p.PARENT, id, anchor);
}
this.SECS.push(this.NODE);
// Prepare the tags-index:
var spans = h.getElementsByTagName("span");
if(spans) {
for(var i = 0; i < spans.length; ++i) {
if(spans[i].className == "tag") {
var tags = spans[i].innerHTML.split(" ");
for(var j = 0; j < tags.length; ++j) {
var t = this.removeTags(tags[j]);
if(! this.TAGS[t]) {
this.TAGS[t] = new Array();
this.SORTED_TAGS.push(t);
}
this.TAGS[t].push(sec);
}
}
else if(spans[i].className.match(this.SECNUM_REGEX)) {
this.SECNUM_MAP[this.trim(spans[i].innerHTML)] = this.NODE;
}
}
}
this.NODE.hide();
return (link);
}
// return the link as it was, if no section link:
return (s);
},
/**
* Creates all the navigation links for this.SECS.
* This is called from initFromStructure() and initFromToc() as well.
*
* @todo Apply style classes to the generated links.
*/
build: function ()
{
var index_name = this.TITLE.innerHTML;
var min_subindex_sec = 0;
for(var i = 0; i < this.SECS.length; ++i)
{
this.SECS[i].IDX = i;
var html = '<table class="org-info-js_info-navigation" width="100%" border="0" style="border-bottom:1px solid black;">'
+'<tr><td colspan="3" style="text-align:left;border-style:none;vertical-align:bottom;">'
+'<span style="float:left;display:inline;text-align:left;">'
+'Topp: <a accesskey="t" href="javascript:org_html_manager.navigateTo(0);">'+index_name+'</a></span>'
+'<span style="float:right;display:inline;text-align:right;font-size:70%;">'
+ this.LINKS
+'<a accesskey="m" href="javascript:org_html_manager.toggleView('+i+');">endre visning</a></span>'
+'</td></tr><tr><td style="text-align:left;border-style:none;vertical-align:bottom;width:22%">';
if(i>0)
html += '<a accesskey="p" href="'+this.SECS[i-1].L
+'" title="Gå til: '+this.removeTags(this.SECS[i-1].HEADING.innerHTML)+'">Forrige</a> | ';
else
html += 'Forrige | ';
if(i < this.SECS.length - 1)
html += '<a accesskey="n" href="'+this.SECS[i+1].L
+'" title="Gå til: '+this.removeTags(this.SECS[i+1].HEADING.innerHTML)+'">Neste</a>';
else
html += 'Neste';
html += '</td><td style="text-align:center;vertical-align:bottom;border-style:none;width:56%;">';
if(i>0 && this.SECS[i].PARENT.PARENT) // != this.ROOT)
html += '<a href="'+this.SECS[i].PARENT.L
+'" title="Gå til: '+this.removeTags(this.SECS[i].PARENT.HEADING.innerHTML)+'">'
+'<span>'
+this.SECS[i].PARENT.HEADING.innerHTML+'</span></a>';
else
html += '<span>'+this.SECS[i].HEADING.innerHTML+'</span>';
// Right:
html += '</td><td style="text-align:right;vertical-align:bottom;border-style:none;width:22%">';
html += (i + 1) +'</td></tr></table>';
// buttons:
this.SECS[i].BUTTONS = document.createElement("div");
this.SECS[i].BUTTONS.innerHTML = '<div class="org-info-js_header-navigation" style="display:inline;float:right;text-align:right;font-size:70%;font-weight:normal;">'
+ this.LINKS
+ '<a accesskey="m" href="javascript:org_html_manager.toggleView('+i+');">endre visning</a></div>';
if(this.SECS[i].FOLDER)
// this.SECS[i].HEADING.appendChild(this.SECS[i].BUTTONS);
this.SECS[i].DIV.insertBefore(this.SECS[i].BUTTONS, this.SECS[i].HEADING); //div.firstChild.nextSibling);
else if(this.SECS[i].DIV.hasChildNodes()) {
this.SECS[i].DIV.insertBefore(this.SECS[i].BUTTONS, this.SECS[i].DIV.firstChild);
}
if(!this.VIEW_BUTTONS) OrgNode.hideElement(this.SECS[i].BUTTONS);
this.SECS[i].NAV = html;
// subindex for sections containing subsections:
if(0 < this.SECS[i].CHILDREN.length && this.LOCAL_TOC)
{
var navi2 = document.createElement("div");
navi2.className="org-info-js_local-toc";
html = 'Innhold:<br /><ul>';
for(var k=0; k < this.SECS[i].CHILDREN.length; ++k) {
html += '<li><a href="'
+this.SECS[i].CHILDREN[k].L+'">'
+this.removeTags(this.removeOrgTags(this.SECS[i].CHILDREN[k].HEADING.innerHTML))+'</a></li>';
}
html += '</ul>';
navi2.innerHTML = html;
if("above" == this.LOCAL_TOC) {
if(this.SECS[i].FOLDER)
this.SECS[i].FOLDER.insertBefore(navi2, this.SECS[i].FOLDER.firstChild);
else
this.SECS[i].DIV.insertBefore(
navi2, this.SECS[i].DIV.getElementsByTagName("h"+this.SECS[i].DEPTH)[0].nextSibling);
} else {
if(this.SECS[i].FOLDER)
this.SECS[i].FOLDER.appendChild(navi2);
else
this.SECS[i].DIV.appendChild(navi2);
}
}
}
// Setup the Tags for sorted output:
this.SORTED_TAGS.sort();
},
/**