forked from p12tic/cppreference-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandard_revisions.js
More file actions
1821 lines (1560 loc) · 64.1 KB
/
standard_revisions.js
File metadata and controls
1821 lines (1560 loc) · 64.1 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
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
/*
Copyright (C) 2013-2017 Povilas Kanapickas <povilas@radix.lt>
This file is part of cppreference.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
$(function() {
// Add console.log() if not present
if (!window.console)
window.console = {};
if (!window.console.log)
window.console.log = function() { };
var get_url_parameter = function(name) {
var url = decodeURIComponent(window.location.search.substring(1));
var params = url.split('&');
for (i = 0; i < params.length; i++) {
var param = params[i].split('=');
if (param[0] === name) {
return param[1] === undefined ? true : param[1];
}
}
return null;
};
var debug = false;
if (get_url_parameter('stdrev_debug') !== null)
debug = true;
// Returns true if the given arrays have the same length and equal elements
// at specific positions, false otherwise
function array_equal(a, b) {
var i = a.length;
if (i !== b.length) {
return false;
}
while (i--) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
};
// Given an array of numbers, sorts them, removes non-unique elements and
// returns the resulting array. The argument array is not modified.
function array_sort_unique(a) {
a = a.sort(function(x, y) { return x - y; });
var c = a[0];
var res = [c];
for (var i = 1; i < a.length; i++) {
if (a[i] !== c) {
res.push(a[i]);
c = a[i];
}
}
return res;
}
/// Exit if we are not in view mode
if (mw.config.get('wgAction') != 'view') {
return;
}
if (mw.config.get('wgNamespaceNumber') != 0) {
return;
}
/// Are we dealing with C or C++?
var is_cxx = (mw.config.get('wgTitle').indexOf('c/') != 0);
// Standard revision identification 'enums'. Thoughout the plugin it is
// assumed that the values are integers starting at zero and thus they can
// be used as an index in regular arrays.
var Rev_c = {
DIFF: 0,
FIRST: 1,
C89: 1,
C99: 2,
C11: 3,
LAST: 4
};
var Rev_cxx = {
DIFF: 0,
FIRST: 1,
CXX98: 1,
CXX03: 2,
CXX11: 3,
CXX14: 4,
CXX17: 5,
CXX20: 6,
LAST: 7,
};
var Rev;
if (is_cxx) {
Rev = Rev_cxx;
} else {
Rev = Rev_c;
}
/// Standard revision description strings
var desc_c = [
{ rev: Rev.DIFF, title: 'Diff' },
{ rev: Rev.C89, title: 'C89' },
{ rev: Rev.C99, title: 'C99' },
{ rev: Rev.C11, title: 'C11' },
];
var desc_cxx = [
{ rev: Rev.DIFF, title: 'Diff' },
{ rev: Rev.CXX03, title: 'C++98/03' },
{ rev: Rev.CXX11, title: 'C++11' },
{ rev: Rev.CXX14, title: 'C++14' },
{ rev: Rev.CXX17, title: 'C++17' },
{ rev: Rev.CXX20, title: 'C++20' },
];
var rev_css_classes_c = [
{ rev: Rev.C99, since: 't-since-c99', until: 't-until-c99' },
{ rev: Rev.C11, since: 't-since-c11', until: 't-until-c11' },
];
var rev_css_classes_cxx = [
{ rev: Rev.CXX03, since: 't-since-cxx03', until: 't-until-cxx03' },
{ rev: Rev.CXX11, since: 't-since-cxx11', until: 't-until-cxx11' },
{ rev: Rev.CXX14, since: 't-since-cxx14', until: 't-until-cxx14' },
{ rev: Rev.CXX17, since: 't-since-cxx17', until: 't-until-cxx17' },
{ rev: Rev.CXX20, since: 't-since-cxx20', until: 't-until-cxx20' },
];
var desc;
var rev_css_classes;
if (is_cxx) { // select either C or C++ version
desc = desc_cxx;
rev_css_classes = rev_css_classes_cxx;
} else {
desc = desc_c;
rev_css_classes = rev_css_classes_c;
}
/* This class stores information about what revisions a certain object
should be shown on. A number of convenience functions are provided.
*/
var VisibilityMap = function(revs) {
this.map = [];
// initialize the map to "not shown"
var i;
for (i = 0; i < Rev.LAST; i++) {
this.map.push(false);
}
if (typeof(revs) !== 'undefined') {
for (i = 0; i < revs.length; i++) {
this.map[revs[i]] = true;
}
}
}
// Checks the visibility on the given revision.
VisibilityMap.prototype.is_visible_on = function(rev) {
return this.map[rev];
}
// Checks whether all revisions are hidden in this visibility map
VisibilityMap.prototype.is_visible_on_none = function() {
for (var i = 0; i < Rev.LAST; i++) {
if (this.map[i] === true) {
return false;
}
}
return true;
}
// Checks whether all revisions are shown in this visibility map
VisibilityMap.prototype.is_visible_on_all = function() {
for (var i = 0; i < Rev.LAST; i++) {
if (this.map[i] === false) {
return false;
}
}
return true;
}
// Sets the visibility on the given revision to true.
VisibilityMap.prototype.add = function(rev) {
this.map[rev] = true;
}
// Sets the visibility on the given revision to true.
VisibilityMap.prototype.remove = function(rev) {
this.map[rev] = false;
}
/* Fills the visibility map with the given value. After the operation
map.is_visible_on(rev) == value for all valid revisions.
*/
VisibilityMap.prototype.fill = function(value) {
for (var i = 0; i < this.map.length; i++)
this.map[i] = value;
}
var visibility_fill = function(value) {
var ret = new VisibilityMap();
ret.fill(value);
return ret;
}
// Clones the visibility map
VisibilityMap.prototype.clone = function() {
var ret = new VisibilityMap();
ret.map = this.map.slice();
return ret;
}
// Checks whether two visibility maps are equal
VisibilityMap.prototype.equal = function(other) {
return array_equal(this.map, other.map);
}
/* Combines the map with another visibility map. The resulting map
indicates visibility on particular revision if both argument maps
indicated so. Returns this.
*/
VisibilityMap.prototype.combine_and = function(map) {
for (var i = 0; i < Rev.LAST; i++) {
this.map[i] = this.map[i] && map.map[i];
}
}
/* Combines the map with another visibility map. The resulting map
indicates visibility on particular revision if either argument maps
indicated so.
*/
VisibilityMap.prototype.combine_or = function(map) {
for (var i = 0; i < Rev.LAST; i++) {
this.map[i] = this.map[i] || map.map[i];
}
}
// Prints the contents to a string
VisibilityMap.prototype.debug_to_string = function() {
var out = '{ ';
for (var i = 0; i < this.map.length; i++) {
if (this.map[i]) {
out += 'T';
} else {
out += 'F';
}
}
out += ' }';
return out;
}
/* Given an jQuery object, inspects mark css classes and returns a
visibility map corresponding to these css classes. Rev.DIFF is not
included into the returned visibility map.
*/
function get_visibility_map(el) {
var map = new VisibilityMap();
for (var i = 0; i < rev_css_classes.length; i++) {
if (el.hasClass(rev_css_classes[i].since)) {
break;
}
}
if (i === rev_css_classes.length) {
map.add(Rev.FIRST);
i = 0;
}
for (; i < rev_css_classes.length; i++) {
if (el.hasClass(rev_css_classes[i].until)) {
break;
}
map.add(rev_css_classes[i].rev);
}
return map;
}
/** This class keeps track of objects that need to be shown or hidden for
specific standard revision.
*/
var ObjectTracker = function() {
this.all_objects = [];
// jQuery screws up restoring correct display property
this.all_display = [];
this.diff_ids = [];
this.curr_rev = Rev.DIFF;
// Maps revisions to object indexes within this.all_objects.
this.rev2id_map = [];
for (var i = 0; i < Rev.LAST; ++i) {
this.rev2id_map[i] = [];
}
}
/** Adds a jQuery object @a obj that should be shown only on specific
revisions identified by @a revs. @a orig_obj is used to compute the
display property that should be set to the object when the visibility
is restored.
*/
ObjectTracker.prototype.add_object = function(obj, orig_obj, visibility_map) {
var id = this.all_objects.length;
this.all_objects[id] = obj;
this.all_display[id] = orig_obj.css('display');
for (var rev = 0; rev < Rev.LAST; rev++) {
if (visibility_map.is_visible_on(rev)) {
this.rev2id_map[rev].push(id);
}
}
};
// Same as add_object except that obj is used to compute the display
// property. The object must be already attached to DOM.
ObjectTracker.prototype.add_diff_object = function(obj, visibility_map) {
this.add_object(obj, obj, visibility_map);
}
/* Changes the visibility of objects to what it should be at the given
revision rev.
*/
ObjectTracker.prototype.to_rev = function(rev) {
if (rev === this.curr_rev) {
return;
}
var visible_before = this.rev2id_map[this.curr_rev];
var visible_after = this.rev2id_map[rev];
var i, curr;
for (i = 0; i < visible_before.length; ++i) {
curr = visible_before[i];
if ($.inArray(curr, visible_after) === -1) {
this.all_objects[curr].css('display', 'none');
}
}
for (i = 0; i < visible_after.length; ++i) {
curr = visible_after[i];
if ($.inArray(curr, visible_before) === -1) {
this.all_objects[curr].css('display', this.all_display[curr]);
}
}
this.curr_rev = rev;
};
/* This class tracks object visibility throughout the section hierarchy.
For example, when section contents are not visible on a certain
revision, then related visual objects such as section title are hidden
too.
In the context of this class, visual objects can be of one of the
following four kinds: primary, secondary, heading, unknown and
container. A visual object is a certain DOM node in the tree. Section
boundaries and hierarchy has no relation to the DOM hierarchy.
Primary
Primary objects define the visibility of the whole section the objects
are in. If all primary and unknown objects are not visible, the whole
section is hidden. The reason why unknown objects affect the visibility
of sections is that we want to be conservative and if we can't
determine the kind of an object, better treat it as primary.
Primary objects do not contain other objects.
Secondary
Secondary objects don't affect the visibility of sections if there are
primary on unknown elements in it. If the section contains only
secondary elements, it is are hidden if all secondary elements are
hidden.
Secondary objects do not contain other objects.
Heading
Heading elements never affect the visibility of sections. All other
elements in the section are hidden, headings are hidden too.
Container
Container objects contain other visual objects and add some visual
"effect" such as padding, so that in order to hide the presence
of the contained objects completely, the container must be hidden too.
Unknown
Unknown objects are those objects for which any other kind was not
defined. They are treated the same way as primary objects.
Unknown objects do not contain other objects.
When all primary and unknown elements within a section are not visible
in certain revision, then all secondary elements are hidden too. The
process is repeated throughout entire section hierarchy.
The section hierarchy tree is built by specifying hierarchy level via
set_level() and adding elements via add_*() functions. Hierarchy levels
are identified by ascending integer numbers. Container objects are set
independently via enter_container() and exit_container() functions -
these functions effectively form a parallel hierarchy.
*/
var SectionContentsTracker = function() {
this.root_section = new SectionNode(null);
this.root_container = new ContainerNode(null, null);
this.curr_section = this.root_section;
this.curr_container = this.root_container;
};
var ObjectType = {
PRIMARY : 0,
SECONDARY : 1,
HEADING : 2,
UNKNOWN : 3,
SECTION : 4,
CONTAINER : 5
};
// internal classes for SectionContentsTracker
var ObjectNode = function(parent_section, parent_container, type, obj) {
this.parent_section = parent_section;
this.parent_container = parent_container;
this.level = parent_section.level + 1;
this.children = null;
this.obj = obj;
this.type = type;
this.visible = null;
};
// Creates a section node given a parent node. For root section parent
// should be null. The level of the created section is determined
// automatically from the level of the parent section.
var SectionNode = function(parent) {
this.parent_section = parent;
if (parent === null) {
this.level = 0;
} else {
this.level = this.parent_section.level + 1;
}
this.children = [];
this.obj = null;
this.type = ObjectType.SECTION;
this.visible = null;
};
// Creates a container node given a parent container and the jQuery object
// representing the object. For root container parent should be null.
var ContainerNode = function(parent, obj) {
this.parent_container = parent;
this.children = [];
this.obj = obj;
this.type = ObjectType.CONTAINER;
this.visible = null;
};
/* Walks the internal section hierarchy tree to the specified level. If
level is higher than current level, then new section nodes are created as
descendants of the current section node. If the current level is the
same, a new node is created.
Sections are portions of the html tree delimited by the heading
elements (<h1>, <h2>, etc.)
*/
SectionContentsTracker.prototype.set_level = function(level) {
if (level < 0) {
console.log("Level must be positive");
return;
}
while (this.curr_section.level >= level && this.curr_section.level > 0) {
this.curr_section = this.curr_section.parent_section;
}
while (this.curr_section.level < level) {
var new_section = new SectionNode(this.curr_section);
this.curr_section.children.push(new_section);
this.curr_section = new_section;
}
};
/* Adds an jQuery object to the current section and container. type is the
kind of the object and visible is the visibility map. Don't use this
method, use add_primary, add_secondary and add_unknown instead
*/
SectionContentsTracker.prototype.add_object = function(obj, type, visible) {
var new_node = new ObjectNode(this.curr_section, this.curr_container, type, obj);
new_node.visible = visible;
this.curr_section.children.push(new_node);
this.curr_container.children.push(new_node);
};
// Adds a primary object to the current section and container with the
// given visibility map.
SectionContentsTracker.prototype.add_primary = function(obj, visible) {
this.add_object(obj, ObjectType.PRIMARY, visible);
};
// Adds a secondary object to the current section and container
SectionContentsTracker.prototype.add_secondary = function(obj, visible) {
this.add_object(obj, ObjectType.SECONDARY, visible);
};
// Adds a heading object to the current section and container
SectionContentsTracker.prototype.add_heading = function(obj) {
this.add_object(obj, ObjectType.HEADING, null);
};
// Adds an unknown object to the current section and container
SectionContentsTracker.prototype.add_unknown = function(obj) {
this.add_object(obj, ObjectType.UNKNOWN, visibility_fill(true));
};
// Interprets a given object as a container and "enters" it. From this call
// until call to exit_container, all added objects are added as descendants
// of this container. Multiple containers may be nested.
SectionContentsTracker.prototype.enter_container = function(obj) {
var new_node = new ContainerNode(this.curr_container, obj);
this.curr_container.children.push(new_node);
this.curr_container = new_node;
};
SectionContentsTracker.prototype.exit_container = function() {
this.curr_container = this.curr_container.parent_container;
};
// Recursively evaluates visibility of a section object
SectionContentsTracker.prototype.eval_section_visibility = function(obj) {
var visible = new VisibilityMap();
var secondary_visible = new VisibilityMap();
var i, child;
var has_non_secondary = false;
for (i = 0; i < obj.children.length; i++) {
child = obj.children[i];
switch (child.type) {
case ObjectType.PRIMARY:
case ObjectType.UNKNOWN:
visible.combine_or(child.visible);
has_non_secondary = true;
break;
case ObjectType.SECONDARY:
secondary_visible.combine_or(child.visible);
break;
case ObjectType.HEADING:
break;
case ObjectType.SECTION:
visible.combine_or(this.eval_section_visibility(child));
has_non_secondary = true;
break;
}
}
if (has_non_secondary) {
// Apply the resolved visibility to secondary children elements, if any
for (i = 0; i < obj.children.length; i++) {
child = obj.children[i];
if (child.type === ObjectType.SECONDARY) {
child.visible = visible;
}
}
} else {
visible = secondary_visible;
}
// Apply the resolved visibility to heading children elements, if any
for (i = 0; i < obj.children.length; i++) {
child = obj.children[i];
if (child.type === ObjectType.HEADING) {
child.visible = visible;
}
}
obj.visible = visible;
return visible;
};
// Recursively evaluates visibility of container objects. Assumes that
// visibility of secondary objects is already set
SectionContentsTracker.prototype.eval_container_visibility = function(obj) {
var visible = new VisibilityMap();
for (var i = 0; i < obj.children.length; i++) {
var child = obj.children[i];
if (child.type === ObjectType.CONTAINER) {
visible.combine_or(this.eval_container_visibility(child));
} else {
visible.combine_or(child.visible);
}
}
obj.visible = visible;
return visible;
};
/* Checks if the object needs to be hidden in any revisions identified in
mask and if yes, performs the hide operation. visible_mask is a
visibility map. Returns the visibility of the object ANDed with the mask.
*/
SectionContentsTracker.prototype.perform_hide_obj = function(obj, tracker, visible_mask) {
var wanted_visible = obj.visible.clone();
wanted_visible.combine_and(visible_mask);
if (!wanted_visible.equal(visible_mask)) {
tracker.add_diff_object(obj.obj, wanted_visible);
return wanted_visible;
}
return visible_mask;
};
// Recursively evaluates the contents of a container and hides container,
// heading and secondary elements if needed. visible_mask identifies which
// revisions the object may be visible in certain revision (it may not be
// visible in case parent container is not visible).
SectionContentsTracker.prototype.perform_hide = function(obj, tracker, visible_mask) {
// handle visibility of the container
if (obj !== this.root_container) {
visible_mask = this.perform_hide_obj(obj, tracker, visible_mask);
}
// handle visibility of contents
for (var i = 0; i < obj.children.length; ++i) {
var child = obj.children[i];
switch (child.type) {
case ObjectType.CONTAINER:
this.perform_hide(child, tracker, visible_mask);
break;
case ObjectType.SECONDARY:
case ObjectType.HEADING:
this.perform_hide_obj(child, tracker, visible_mask);
break;
}
}
};
SectionContentsTracker.prototype.debug_obj_impl =
function(obj, desc, level) {
// note that obj.level only considers section hierarchy. When printing
// container hierarchy the depth level will be different and must be
// calculated explicitly
var indent = ' '.repeat(level);
var tag = '';
if (obj.obj !== null)
tag = obj.obj.prop("tagName");
return indent + desc + ' ' + tag + '\n';
};
SectionContentsTracker.prototype.debug_obj = function(obj, level) {
switch (obj.type) {
case ObjectType.PRIMARY:
return this.debug_obj_impl(obj, 'primary object', level);
case ObjectType.SECONDARY:
return this.debug_obj_impl(obj, 'secondary object', level);
case ObjectType.UNKNOWN:
return this.debug_obj_impl(obj, 'unknown object', level);
case ObjectType.HEADING:
return this.debug_obj_impl(obj, 'heading object', level);
}
return '';
};
SectionContentsTracker.prototype.debug_section_obj = function(obj, level) {
if (obj.type === ObjectType.SECTION) {
var out = this.debug_obj_impl(obj, 'section', level);
for (var i = 0; i < obj.children.length; ++i) {
out += this.debug_section_obj(obj.children[i], level+1);
}
return out;
}
return this.debug_obj(obj, level);
};
SectionContentsTracker.prototype.debug_container_obj = function(obj, level) {
if (obj.type === ObjectType.CONTAINER) {
var out = this.debug_obj_impl(obj, 'container', level);
for (var i = 0; i < obj.children.length; ++i) {
out += this.debug_container_obj(obj.children[i], level+1);
}
return out;
}
return this.debug_obj(obj, level);
};
SectionContentsTracker.prototype.debug_all = function() {
var out = 'Section hierarchy:\n\n';
out += this.debug_section_obj(this.root_section, 0);
out += '\nContainer hierarchy:\n\n';
out += this.debug_container_obj(this.root_container, 0);
return out;
};
SectionContentsTracker.prototype.run = function(tracker) {
// evaluate visibility of sections and containers
this.eval_section_visibility(this.root_section);
this.eval_container_visibility(this.root_container);
this.perform_hide(this.root_container, tracker, visibility_fill(true));
if (debug) {
alert(this.debug_all());
}
};
/* Used to aggregate a set of objects that need to be versioned. The set
may be created from objects only in certain part of the DOM tree, this
allows to perform independent versioning execution in different parts
of the page.
This is used for example to support inclusions of Template:member. It
almost always contains a separate set declaration and description lists
whose numbering needs to be versioned separately.
*/
var Scope = function(root) {
this.root = root;
};
/** Creates a new scope and initializes it with the objects gathered from
the given jQuery object. Returns the new scope.
*/
Scope.create_root = function(obj) {
var scope = new Scope(obj);
scope.nv = scope.root.find('.t-navbar');
scope.dcl_tables = scope.root.find('.t-dcl-begin');
scope.dcl_rev_tables = scope.dcl_tables.filter('.t-dcl-rev-begin');
scope.rev_tables = scope.root.find('.t-rev-begin');
scope.rev_inl_tables = scope.root.find('.t-rev-inl');
scope.list_items = scope.root.find('.t-li1');
scope.list_items.add(scope.root.find('.t-li2'));
scope.list_items.add(scope.root.find('.t-li3'));
return scope;
};
/** Given two scopes: parent scope and child scope, moves the elements
contained within jQuery object in parent_scope[prop] to
child_scope[prop] whenever they have child_scope.root as parent.
*/
Scope.split_scope = function(parent_scope, child_scope, prop) {
// get elements to move
var to_move = parent_scope[prop].filter(function() {
return $.contains(child_scope.root[0], this);
});
// remove elements from parent and add to child
parent_scope[prop] = parent_scope[prop].not(to_move);
child_scope[prop] = to_move;
};
/** Creates a new scope and initializes it with the objects from the given
parent scope that also have the given jQuery object obj as parent. The
filtered objects are removed from the parent scope. The function returns
the new scope.
*/
Scope.create_child = function(parent, obj) {
var scope = new Scope(obj);
Scope.split_scope(parent, scope, 'nv');
Scope.split_scope(parent, scope, 'dcl_tables');
Scope.split_scope(parent, scope, 'dcl_rev_tables');
Scope.split_scope(parent, scope, 'rev_tables');
Scope.split_scope(parent, scope, 'rev_inl_tables');
Scope.split_scope(parent, scope, 'list_items');
return scope;
};
var StandardRevisionPlugin = function() {
this.curr_rev = Rev.DIFF;
this.tracker = new ObjectTracker();
this.is_prepared = false;
};
/* Prepares the navbar for versioning using object tracker. As the navbar
contains many items and we might want to reflow the columns in the
future, instead of committing each item to the object tracker we make
as many copies of the original navbar as there needed, customize each
copy in-place and commit the results to the object tracker. This gives
us both performance and flexibility benefits.
*/
StandardRevisionPlugin.prototype.prepare_navbar = function(scope) {
var nv = scope.nv // main navbar
if (nv.length === 0) {
return; // no navbar
}
this.tracker.add_diff_object(nv, new VisibilityMap([Rev.DIFF]));
var self = this;
for (var rev = Rev.FIRST; rev < Rev.LAST; ++rev) {
// Create new navbar and insert it to the tracker
var rev_nv = nv.clone().hide().insertAfter(nv);
this.tracker.add_object(rev_nv, nv, new VisibilityMap([rev]));
// Get interesting elements
var nv_tables = rev_nv.find('.t-nv-begin');
var nv_tables_tb = nv_tables.children('tbody');
var el_h1 = nv_tables_tb.children('.t-nv-h1');
var el_h2 = nv_tables_tb.children('.t-nv-h2');
var el_col_tables = nv_tables_tb.children('.t-nv-col-table');
var el_nv = nv_tables_tb.children('.t-nv');
// Remove entries from the link tables that should not be visible
// for the revision in question
el_nv.each(function(){
// Get the link table
var link_tds = $(this).find('.t-nv-ln-table div');
var marks;
if (link_tds.length === 0) {
// bare nv template used. Check if we don't have a mark
// template by chance
marks = $(this).find('.t-mark-rev');
if (marks.length > 0) {
var visible = get_visibility_map(marks.first());
visible.add(Rev.DIFF);
if (!visible.is_visible_on(rev)) {
$(this).remove();
} else {
marks.remove(); // do not show marks in any case
}
}
return;
}
if (link_tds.length === 1) {
// The earliest standard (always visible)
return;
}
var titles = link_tds.first().children().children().first().children();
marks = link_tds.last().children().first().children();
// Delete the lines
if (self.delete_lines(titles, marks, rev)) {
$(this).remove();
}
});
// Remove all empty column tables
el_col_tables.each(function() {
if ($(this).find('.t-nv').length === 0) {
$(this).remove();
}
});
// Look for any headings that do not have items after them
el_h2.each(function() {
if ($(this).next().length === 0 ||
$(this).next().is('.t-nv-h2, .t-nv-h1')
) {
$(this).remove();
}
});
el_h1.each(function() {
if ($(this).next().length === 0 ||
$(this).next().is('.t-nv-h1')
) {
$(this).remove();
}
});
// TODO: perhaps it's worth to reflow the remaining columns
}
};
/* Handles inclusion of Template:rev_begin, Template:rev and
Template:rev_end.
We don't copy the contents of this templates around. We just add the
rows to the element tracker and show and hide them as needed. To hide
the frame on non-diff revisions, we have special treatment in
on_selection_change. Note, that in order for this to work, the revision
marks must not be touched.
The visibility map of whole table is stored as 'visible' data member
of the jquery element.
*/
StandardRevisionPlugin.prototype.prepare_rev = function(el) {
var rev_elems = el.children('tbody').children('.t-rev');
var self = this;
var table_visible = new VisibilityMap();
rev_elems.each(function() {
var visible = get_visibility_map($(this));
visible.add(Rev.DIFF);
table_visible.combine_or(visible);
self.tracker.add_diff_object($(this), visible);
});
el.data('visible', table_visible);
};
StandardRevisionPlugin.prototype.prepare_all_revs = function(scope) {
var self = this;
scope.rev_tables.each(function() {
self.prepare_rev($(this));
});
};
/** Handles inclusions of Template:rev_inl
*/
StandardRevisionPlugin.prototype.prepare_all_inl_revs = function(scope) {
var self = this;
scope.rev_inl_tables.each(function() {
self.tracker.add_diff_object($(this), new VisibilityMap([Rev.DIFF]));
var visible = get_visibility_map($(this));
var copy = $(this).children().first().clone().hide()
.insertAfter($(this));
self.tracker.add_object(copy, $(this), visible);
});
};
// Returns true if the given jQuery object defines a secondary visual object
StandardRevisionPlugin.prototype.is_secondary = function(el) {
if (el.is('p') ||
el.is('.t-rev-begin'))
{
return true;
}
return false;
};
// Returns true if the given jQuery object defines a heading visual object
StandardRevisionPlugin.prototype.is_heading = function(el) {
if (el.is('h2') ||
el.is('h3') ||
el.is('h5') ||
(el.is('tr') && el.has('td > h5').length) ||
el.is('.t-dsc-header'))
{
return true;
}
return false;
};
/* If the given jQuery object refers to a heading element, then returns
the section level for that heading. More "important" heading elements
have lower section levels, the lowest being 0. If the given jQuery
object does not refer to a heading, then the function returns -1.
*/
StandardRevisionPlugin.prototype.get_heading_level = function(el) {
if (el.is('h2'))
return 0;
if (el.is('h3'))
return 1;
if (el.is('h5'))
return 2;
if (el.is('tr') && el.has('td > h5').length)
return 2;
if (el.is('.t-dsc-header'))
return 3;
return -1;
}
/* If jQuery object el has a known section level, then we enter that
section level by exiting section nodes or creating new section nodes
and entering them as needed.
*/
StandardRevisionPlugin.prototype.set_level_if_needed = function(section_tracker, el) {
var level = this.get_heading_level(el);
if (level >= 0) {
section_tracker.set_level(level);
}
};
/* Handles the section hierarchy in a scope as defined by description
lists and their contents. Description lists are inclusions of
Template:dsc_* ('t-dsc-*' CSS classes).
See the documentation of SectionContentsTracker for more information.
Also prepares items in dsc lists
*/
StandardRevisionPlugin.prototype.prepare_sections_and_dscs = function(scope) {
var self = this;
var section_tracker = new SectionContentsTracker();
scope.root.children().each(function(){