Commit 9680252a authored by julien's avatar julien

closes #180

parent 5e1eea4f
Pipeline #420 passed with stage
in 3 minutes and 19 seconds
This diff is collapsed.
......@@ -157,4 +157,41 @@ describe("string-start", async () => {
expect(text).toEqual("\"ggg\"");
});
});
describe("string-multiple", async () => {
let page;
let rendered;
beforeAll(async () => {
page = await loadPage("string/string-multiple.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
it("should set the running header as nothing on the first page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"aaa\"");
});
it("should set the running header as nothing on the first page", async () => {
let text = await page.$eval("#page-2", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabetbis"));
expect(text).toEqual("\"1111\"");
});
it("should set the running header as \"fff\" on the third page", async () => {
let text = await page.$eval("#page-9", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabet"));
expect(text).toEqual("\"bbb\"");
});
it("should set the running header as \"fff\" on the third page", async () => {
let text = await page.$eval("#page-9", (r) =>
window.getComputedStyle(r).getPropertyValue("--pagedjs-string-alphabetbis"));
expect(text).toEqual("\"2222\"");
});
});
\ No newline at end of file
......@@ -55,19 +55,30 @@ class StringSets extends Handler {
afterPageLayout(fragment) {
if ( this.pageLastString === undefined )
{
this.pageLastString = {};
}
// get the value of the previous last string
let previousPageLastString = this.pageLastString;
for (let name of Object.keys(this.stringSetSelectors)) {
let set = this.stringSetSelectors[name];
let selected = fragment.querySelectorAll(set.selector);
let cssVar = previousPageLastString;
selected.forEach((sel) => {
// let cssVar = previousPageLastString;
// Get the last found string for the current identifier
let cssVar = ( name in this.pageLastString ) ? this.pageLastString[name] : '';
selected.forEach((sel) => {
// push each content into the array to define in the variable the first and the last element of the page.
this.pageLastString = selected[selected.length - 1].textContent;
//this.pageLastString = selected[selected.length - 1].textContent;
// Index by identifier
this.pageLastString[name] = selected[selected.length - 1].textContent;
if (this.type === "first") {
cssVar = selected[0].textContent;
......@@ -83,19 +94,19 @@ class StringSets extends Handler {
cssVar = sel.textContent;
}
}
else if (this.type === "first-except") {
cssVar = "";
}
else {
cssVar = selected[0].textContent;
}
});
fragment.setAttribute("data-string", `string-type-${this.type}-${name}`);
// fragment.style.setProperty(`--pagedjs-string-${name}`, `"${cssVar.replace(/\\([\s\S])|(["|'])/g, "\\$1$2")}"`);
fragment.style.setProperty(`--pagedjs-string-${name}`, `"${cleanPseudoContent(cssVar)}`);
......@@ -103,10 +114,10 @@ class StringSets extends Handler {
if (!fragment.hasAttribute("data-string")) {
fragment.style.setProperty(`--pagedjs-string-${name}`, `"${this.pageLastString}"`);
}
}
}
}
......
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