Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Support
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
pagedjs
pagedjs
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 154
    • Issues 154
    • List
    • Boards
    • Labels
    • Milestones
  • Merge Requests 12
    • Merge Requests 12
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Tools
  • pagedjspagedjs
  • Issues
  • #180

Closed
Open
Opened Mar 05, 2020 by Antonio Norman@antman3351
  • Report abuse
  • New issue
Report abuse New issue

Generated content string(<identifier>) uses last item without checking identifier

Hello,

I noticed when using more than one content:string(<identifier>) for the margins (e.g. @top-left and @top-right) on new pages, if it can't find an element in the page it will use last item it found regardless of the "identifier".

Actual result (@top-right) has the same content as (@top-left):

Actual_result

Expected result:

Expected_result

( I think that's how it's supposed to work 🤔 )

To fix the problem in the class StringSets I modified afterPageLayout function, so the pageLastString is an object with the identifier as the key.

afterPageLayout(fragment) {

	if ( this.pageLastString === undefined )
	{
		this.pageLastString = {};
	}

	// get the value of the previous last string
	// Removed, not needed
	// 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;
		// 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;
			// Index by identifier
			this.pageLastString[name] = selected[selected.length - 1].textContent;

			
			if (this.type === "first") {
				cssVar = selected[0].textContent;
			} 
			
			else if (this.type === "last") {
				cssVar = selected[selected.length - 1].textContent;
			} 
			
			else if (this.type === "start") {
			
				if (sel.parentElement.firstChild === sel) {
					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)}`);
	
		// if there is no new string on the page
		if (!fragment.hasAttribute("data-string")) {
			fragment.style.setProperty(`--pagedjs-string-${name}`, `"${this.pageLastString}"`);
		}	

	}
}
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
0
Labels
None
Assign labels
  • View project labels
Reference: tools/pagedjs#180