cjs.js
//add default classes and collapsed state to paragraphs and headings
add default classes and collapsed state to paragraphs and headings
add default classes and collapsed state to paragraphs and headings
function apply_default_classes_and_state(editorContentNodes){
		applyLayout(getLayout(), editorContentNodes);
		for (const editorContentNode of editorContentNodes) {
			const childNodes = editorContentNode.querySelectorAll(':scope > *');
			let largestFoundHeader = null;
			let lastFoundHeader = null;
			for (const child of childNodes) {
				const headerNumber = getHeaderNumber(child);
				if (largestFoundHeader !== null) {
					if (!headerNumber && !child.classList.contains('labelTxtMatchedSection')) {
						apply_defaultCollapsedState(child);
						console.log('CJS (applydefaultclassesandstate) | applied default colllapsed state to child:', child);
					}else if (largestFoundHeader < headerNumber && !child.classList.contains('labelTxtMatchedSection')){
						apply_defaultCollapsedState(child);
						console.log('CJS (applydefaultclassesandstate) | applied default colllapsed state to child:', child);
						let headerTxt = child.textContent;
						if (headerTxt == labeltxt) {
							$(child).show().addClass('labelTxtMatchedSection');
							showSection(child);
						}
					}
				}
				if (headerNumber) {
					lastFoundHeader = headerNumber;
					apply_h_classes(child);
					let headerTxt = child.textContent;
					if (headerTxt == labeltxt) {
						$(child).show().addClass('labelTxtMatchedSection');
						showSection(child);
					}
					if (largestFoundHeader === null || largestFoundHeader > headerNumber) {
						largestFoundHeader = headerNumber;
					}
				}
			}
		}
	}
function apply_default_classes_and_state ( editorContentNodes ) { applyLayout ( getLayout ( ) , editorContentNodes ) ; for ( const editorContentNode of editorContentNodes ) { const childNodes = editorContentNode . querySelectorAll ( ':scope > *' ) ; let largestFoundHeader = null ; let lastFoundHeader = null ; for ( const child of childNodes ) { const headerNumber = getHeaderNumber ( child ) ; if ( largestFoundHeader !== null ) { if ( ! headerNumber && ! child . classList . contains ( 'labelTxtMatchedSection' ) ) { apply_defaultCollapsedState ( child ) ; console . log ( 'CJS (applydefaultclassesandstate) | applied default colllapsed state to child:' , child ) ; } else if ( largestFoundHeader < headerNumber && ! child . classList . contains ( 'labelTxtMatchedSection' ) ) { apply_defaultCollapsedState ( child ) ; console . log ( 'CJS (applydefaultclassesandstate) | applied default colllapsed state to child:' , child ) ; let headerTxt = child . textContent ; if ( headerTxt == labeltxt ) { $ ( child ) . show ( ) . addClass ( 'labelTxtMatchedSection' ) ; showSection ( child ) ; } } } if ( headerNumber ) { lastFoundHeader = headerNumber ; apply_h_classes ( child ) ; let headerTxt = child . textContent ; if ( headerTxt == labeltxt ) { $ ( child ) . show ( ) . addClass ( 'labelTxtMatchedSection' ) ; showSection ( child ) ; } if ( largestFoundHeader === null || largestFoundHeader > headerNumber ) { largestFoundHeader = headerNumber ; } } } } }
add default classes and collapsed state to paragraphs and headings
add default classes and collapsed state to paragraphs and headings
// Don't use editorContentNode.childNodes as these include text nodes // Don't collapse any text located before the first header is encountered //  or anything that has the class labelTxtMatchedSection // Do collapse any text which is either // - not a header (located after a header) // - a header which is smaller that any previous encountered headers //if its not a header //if its a subheader, apply the default collapsed state //if labeltxt matches the text of this header, show it and it's contents. //else apply default collapsed state //show its contents //if its a header, save its number to last found header, apply h classes, check if it matches the label text, check if its the largest header. // h1 is larger than h2