Created
August 12, 2013 20:22
-
-
Save ainth/6214775 to your computer and use it in GitHub Desktop.
Trying to figure out a break before strategy for ftcolumnflow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _addFlowedElement(element, index) { | |
var originalPadding, existingPadding, totalElementHeight, | |
desiredElementHeight, newPadding, overflow, loopCount, | |
nextElement = element.nextSibling, | |
prevElement = element.previousSibling; | |
// Check if it's necessary to sanitize elements to conform to the baseline grid | |
if (config.standardiseLineHeight) { | |
originalPadding = parseInt(element.getAttribute('data-cf-original-padding'), 10) || null; | |
existingPadding = parseInt(window.getComputedStyle(element).getPropertyValue('padding-bottom'), 10); | |
if (null === originalPadding) { | |
originalPadding = existingPadding; | |
element.setAttribute('data-cf-original-padding', originalPadding); | |
} else { | |
existingPadding = originalPadding; | |
} | |
// Return the element to its original padding | |
if (originalPadding !== existingPadding) { | |
element.style.paddingBottom = originalPadding + 'px'; | |
} | |
totalElementHeight = nextElement ? (nextElement.offsetTop - element.offsetTop) : element.offsetHeight; | |
desiredElementHeight = _roundUpToGrid(totalElementHeight); | |
newPadding = desiredElementHeight - totalElementHeight + existingPadding; | |
if (newPadding !== existingPadding) { | |
element.style.paddingBottom = newPadding + 'px'; | |
} | |
} | |
// ========= | |
// Begin wild experiment | |
var forceBreak = element.classList.contains(forcebreakClassName); | |
if (prevElement && forceBreak) { | |
while (prevElement.offsetBottom >= totalColumnHeight) { | |
overflow = (prevElement.offsetBottom > totalColumnHeight); | |
_wrapColumn(index-1, overflow); | |
} | |
_wrapColumn(index-1, false); | |
} | |
//End wild experiment | |
// ========= | |
element.offsetBottom = element.offsetTop + element.offsetHeight; | |
// TODO:GC: Remove this loop-protection check | |
loopCount = 0; | |
while ((element.offsetBottom >= totalColumnHeight || (nextElement && nextElement.offsetTop >= totalColumnHeight)) && (loopCount++ < 30)) { | |
overflow = (element.offsetBottom > totalColumnHeight); | |
_wrapColumn(index, overflow); | |
} | |
// TODO:GC: Remove this loop-protection check | |
if (loopCount >= 30) console.error('FTColumnflow: Caught and destroyed a loop when wrapping columns for element', element.outerHTML.substr(0, 200) + '...'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment