Skip to content

Commit 998934f

Browse files
committed
Add a <cxx-figure> element analogous to <cxx-table>.
Also made tables renumber themselves when they're added or removed from the document. This isn't as efficient as it could be, but I can optimize that later.
1 parent 18c8794 commit 998934f

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

figure.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!-- Copyright 2014 Google Inc. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
-->
15+
16+
<!--
17+
Uses the HTML <figure> content model, but automatically adds a number to
18+
the <figcaption>.
19+
-->
20+
<polymer-element name="cxx-figure" constructor="CxxFigureElement">
21+
<template>
22+
<style>
23+
:host { margin-left: auto; margin-right: auto; }
24+
figcaption { white-space: nowrap; text-align: center; }
25+
/* @polyfill figcaption figcaption */
26+
::content figcaption { display: inline; }
27+
28+
</style>
29+
<figure>
30+
<figcaption>Figure {{figure_num}} — <wbr><content select="figcaption"></content></figcaption>
31+
<content></content>
32+
</figure>
33+
</template>
34+
<script>
35+
(function() {
36+
function renumberFigures() {
37+
document.querySelectorAll('cxx-figure').array().forEach(function(figure, index) {
38+
figure.figure_num = index + 1;
39+
});
40+
}
41+
Polymer('cxx-figure', {
42+
attached: renumberFigures,
43+
detached: renumberFigures,
44+
});
45+
})();
46+
</script>
47+
</polymer-element>

framework.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<link rel="import" href="section.html"/>
2323
<link rel="import" href="clause.html"/>
2424
<link rel="import" href="table.html"/>
25+
<link rel="import" href="figure.html"/>
2526
<link rel="import" href="definition-section.html"/>
2627
<link rel="import" href="toc.html"/>
2728
<link rel="import" href="ref.html"/>

ref.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
><template if="{{in_elem.index}}">{{in_elem.name}} &#xa7;{{in_elem.index[to]}}</template
3232
><template if="{{!in}}"><a href="#{{to}}"
3333
><template if="{{to_elem.sec_num}}">{{to_elem.sec_num}}</template
34-
><template if="{{to_elem.table_num}}">Table {{to_elem.table_num}}</template></a></template
34+
><template if="{{to_elem.table_num}}">Table {{to_elem.table_num}}</template
35+
><template if="{{to_elem.figure_num}}">Figure {{to_elem.figure_num}}</template></a></template
3536
></template
3637
><template if="{{insynopsis}}">// <i><template bind="" ref="target_num"></template>, {{to_elem.title_element.textContent}}</i></template
3738
><template if="{{!insynopsis}}"><template bind="" ref="target_num"></template></template

ref.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ limitations under the License.
4343
this.async(function() {
4444
// Async makes sure the to_elem is upgraded.
4545
if (!(this.to_elem instanceof CxxSectionElement ||
46-
this.to_elem instanceof CxxTableElement)) {
46+
this.to_elem instanceof CxxTableElement ||
47+
this.to_elem instanceof CxxFigureElement)) {
4748
console.error("Reference from", this,
48-
"refers to non-section, non-table element",
49+
"refers to non-section, non-table, non-figure element",
4950
this.to_elem);
5051
}
5152
});

table.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
</template>
4141
<script>
4242
(function() {
43-
var next_table_num = 1;
43+
function renumberTables() {
44+
document.querySelectorAll('[is=cxx-table]').array().forEach(function(table, index) {
45+
table.table_num = index + 1;
46+
});
47+
}
4448
Polymer('cxx-table', {
45-
created: function() {
46-
this.table_num = next_table_num++;
47-
}
49+
attached: renumberTables,
50+
detached: renumberTables,
4851
});
4952
})();
5053
</script>

0 commit comments

Comments
 (0)