Commit 0013161e authored by sarah's avatar sarah
Browse files

Merge branch 'master' of gitlab.constantvzw.org:osp/work.iselp50

parents 7ae024ad c4359ac7
(function createIndex () {
function setRealPageNumbers () {
let pages = document.querySelectorAll('.pagedjs_page'),
realPageCounter = 0;
const pageCounterResetPatt = /page (\d+)/;
// Set an extra data-attribute with the 'real' pagenumber
// Loop through all the pages.
for (let i = 0; i < pages.length; i++) {
const page = pages[i],
m = window.getComputedStyle(page).getPropertyValue('counter-reset').match(pageCounterResetPatt);
// Test through getComputedStyles whether there is a counter reset.
if (m && m.length) {
// Set js counter to that value
console.log('Page counter reset to:', m[1], 'on page', page.dataset.pageNumber);
realPageCounter = parseInt(m[1]);
}
// Increment js counter by one
realPageCounter++;
// Set it on the page.
page.dataset.realPageNumber = realPageCounter;
}
}
function triggerDownload (content, filename, mime) {
const a = document.createElement('a');
a.setAttribute('href', `data:${mime};charset=utf-8,${encodeURIComponent(content)}`);
......@@ -15,11 +39,11 @@
}
function getPageNum (el) {
if ('pageNumber' in el.dataset) {
return parseInt(el.dataset.pageNumber);
if ('realPageNumber' in el.dataset) {
return parseInt(el.dataset.realPageNumber);
}
else if (el.parentElement) {
return getPageNum(el.parentElement);
return getPageNum(el.realPageNumber);
}
}
......@@ -58,6 +82,7 @@
}
if (urlParameters.has('makeIndex')) {
setRealPageNumbers();
const index = createIndex(config);
triggerDownload(JSON.stringify(index), downloadName, 'application/json');
}
......
(function createIndex () {
function setRealPageNumbers () {
let pages = document.querySelectorAll('.pagedjs_page'),
realPageCounter = 0;
const pageCounterResetPatt = /page (\d+)/;
// Set an extra data-attribute with the 'real' pagenumber
// Loop through all the pages.
for (let i = 0; i < pages.length; i++) {
const page = pages[i],
m = window.getComputedStyle(page).getPropertyValue('counter-reset').match(pageCounterResetPatt);
// Test through getComputedStyles whether there is a counter reset.
if (m && m.length) {
// Set js counter to that value
console.log('Page counter reset to:', m[1], 'on page', page.dataset.pageNumber);
realPageCounter = parseInt(m[1]);
}
// Increment js counter by one
realPageCounter++;
// Set it on the page.
page.dataset.realPageNumber = realPageCounter;
}
}
function triggerDownload (content, filename, mime) {
const a = document.createElement('a');
a.setAttribute('href', `data:${mime};charset=utf-8,${encodeURIComponent(content)}`);
......@@ -15,11 +39,11 @@
}
function getPageNum (el) {
if ('pageNumber' in el.dataset) {
return parseInt(el.dataset.pageNumber);
if ('realPageNumber' in el.dataset) {
return parseInt(el.dataset.realPageNumber);
}
else if (el.parentElement) {
return getPageNum(el.parentElement);
return getPageNum(el.realPageNumber);
}
}
......@@ -58,6 +82,7 @@
if (urlParameters.has('makeToc')) {
const index = createToc(tocQueries);
setRealPageNumbers()
triggerDownload(JSON.stringify(index), downloadName, 'application/json');
}
}
......
(function () {
function setRealPageNumbers () {
let pages = document.querySelectorAll('.pagedjs_page'),
realPageCounter = 0;
const pageCounterResetPatt = /page (\d+)/;
// Set an extra data-attribute with the 'real' pagenumber
// Loop through all the pages.
for (let i = 0; i < pages.length; i++) {
const page = pages[i],
m = window.getComputedStyle(page).getPropertyValue('counter-reset').match(pageCounterResetPatt);
// Test through getComputedStyles whether there is a counter reset.
if (m && m.length) {
// Set js counter to that value
console.log(m[1])
realPageCounter = parseInt(m[1]);
}
// Increment js counter by one
realPageCounter++;
// Set it on the page.
page.dataset.realPageNumber = realPageCounter;
}
}
window.setRealPageNumbers = setRealPageNumbers;
})();
\ No newline at end of file
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