Commit dccccfc6 authored by Laurent Sittler's avatar Laurent Sittler ©
Browse files

fix: duplicate headers

parents 263d1644 99e475f8
Pipeline #1006 passed with stages
in 8 minutes
10.22.1
\ No newline at end of file
10
\ No newline at end of file
......@@ -2,6 +2,6 @@
const build = require('@microsoft/sp-build-web');
build.addSuppression(`Warning - tslint - src/extensions/tableOfContent/TableOfContentApplicationCustomizer.ts(82,27): error no-function-expression: Use arrow function instead of function expression`);
build.addSuppression(`Warning - tslint - src/extensions/tableOfContent/TableOfContentApplicationCustomizer.ts(89,27): error no-function-expression: Use arrow function instead of function expression`);
build.initialize(require('gulp'));
{
"name": "table-of-contents-for-share-point",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"main": "lib/index.js",
"engines": {
......
......@@ -20,6 +20,11 @@ export default class TableOfContentApplicationCustomizer extends BaseApplication
*/
private _initRender: boolean = false;
/**
* Header keys already saved
*/
private _keys: Array<string>;
/**
* SharePoint PlaceHolder area
*/
......@@ -46,6 +51,8 @@ export default class TableOfContentApplicationCustomizer extends BaseApplication
this.properties.tocHeaders = this.properties.tocHeaders.toUpperCase();
}
this._keys = new Array;
this.context.placeholderProvider.changedEvent.add(this, this.partialEvent);
this.context.application.navigatedEvent.add(this, this.partialEvent);
......@@ -147,11 +154,11 @@ export default class TableOfContentApplicationCustomizer extends BaseApplication
}
/* Add lastest header */
if (headers && index == headers.length - 1) {
if (parent['H2']) {
if (parent['H2'] && this._keys.indexOf(parent['H2'].key) < 0) {
root[0].links.push(parent['H2']);
} else if (parent['H3']) {
} else if (parent['H3'] && this._keys.indexOf(parent['H3'].key) < 0) {
root[0].links.push(parent['H3']);
} else if (parent['H4']) {
} else if (parent['H4'] && this._keys.indexOf(parent['H4'].key) < 0) {
root[0].links.push(parent['H4']);
}
}
......@@ -167,6 +174,7 @@ export default class TableOfContentApplicationCustomizer extends BaseApplication
*/
private sortHeaders(root: Object, parent: Array<Object>, headers: NodeListOf<HTMLElement>, index: number): any {
var node = { name: (headers[index].innerText), url: '#' + headers[index].id, key: headers[index].id, isExpanded: true, links: [] };
this._keys.push(headers[index].id);
switch (headers[index].tagName) {
case 'H2':
if (parent['H2']) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment