Skip to Content

JavaScript File

URL: https://www.we-are-digital.co.uk/hs-fs/hub/20293962/hub_generated/template_assets/50308226881/1644250290564/DD_Theme/assets/js/balancetext.min.js
HTTP Status: 200 OK
MIME Type: application/javascript
Last Modified: Mon, 07 Feb 2022 16:11:32 GMT
Download Time: Less than a second
Cookies: None
Size: 9 KB
HTTP Headers:  25 headers
Links In:  1 pages
Links Out:  0 links
Images:  0 images
CSS:  0 files
JavaScript:  0 files
  
OK Issues: No issues found

1"use strict";!function(root,factory){"function"==typeof define&&define.amd?define([],factory):"object"==typeof module&&module.exports?module.exports=factory():root.balanceText=factory()}

2(this,(function(){var breakMatches,wsnwMatches,wsnwOffset,watching={sel:[],el:[]}

3,handlersInitialized=!1,polyfilled=!1;function noop(){}

4function forEach(elements,callback){Array.prototype.forEach.call(elements,callback)}

5function NextWS_params(){this.reset()}

6function isWhiteSpaceNoWrap(index){return wsnwMatches.some((function(range){return range.start<index&&index<range.end}

7))}

8function recursiveCalcNoWrapOffsetsForLine(el,includeTag){if(el.nodeType===el.ELEMENT_NODE)if("nowrap"===window.getComputedStyle(el).whiteSpace){var len=el.outerHTML.length;wsnwMatches.push({start:wsnwOffset,end:wsnwOffset+len}

9),wsnwOffset+=len}

10else forEach(el.childNodes,(function(child){recursiveCalcNoWrapOffsetsForLine(child,!0)}

11)),includeTag&&(wsnwOffset+=el.outerHTML.length-el.innerHTML.length);else el.nodeType===el.COMMENT_NODE?wsnwOffset+=el.length+7:el.nodeType===el.PROCESSING_INSTRUCTION_NODE?wsnwOffset+=el.length+2:wsnwOffset+=el.length}

12function calcNoWrapOffsetsForLine(el,oldWS,lineCharOffset){if(0===lineCharOffset)el.style.whiteSpace=oldWS,wsnwOffset=0,wsnwMatches=[],recursiveCalcNoWrapOffsetsForLine(el,!1),el.style.whiteSpace="nowrap";else{var newMatches=[];wsnwMatches.forEach((function(match){match.start>lineCharOffset&&newMatches.push({start:match.start-lineCharOffset,end:match.end-lineCharOffset}

13)}

14)),wsnwMatches=newMatches}

15}

16NextWS_params.prototype.reset=function(){this.index=0,this.width=0}

17;var style;function justify(el,txt,conWidth){var div,size,tmp,words,wordSpacing;return words=(txt=txt.trim()).split(" ").length,txt+=" ",words<2?txt:((tmp=document.createElement("span")).innerHTML=txt,el.appendChild(tmp),size=tmp.offsetWidth,tmp.parentNode.removeChild(tmp),wordSpacing=Math.floor((conWidth-size)/(words-1)),tmp.style.wordSpacing=wordSpacing+"px",tmp.setAttribute("data-owner","balance-text-justify").setAttribute("aria-hidden",!0),(div=document.createElement("div")).appendChild(tmp),div.innerHTML)}

18function isBreakChar(txt,index){var match,re=/([^\S\u00a0]|-|\u2014|\u2013|\u00ad)(?![^<]*>)/g;if(!breakMatches)for(breakMatches=[],match=re.exec(txt);null!==match;)isWhiteSpaceNoWrap(match.index)||breakMatches.push(match.index),match=re.exec(txt);return-1!==breakMatches.indexOf(index)}

19function isBreakOpportunity(txt,index){return 0===index||index===txt.length||isBreakChar(txt,index-1)&&!isBreakChar(txt,index)}

20function findBreakOpportunity(el,txt,conWidth,desWidth,dir,c,ret){var w;if(txt&&"string"==typeof txt)for(;;){for(;!isBreakOpportunity(txt,c);)c+=dir;if(el.innerHTML=txt.substr(0,c),w=el.offsetWidth,dir<0){if(w<=desWidth||w<=0||0===c)break}

21else if(desWidth<=w||conWidth<=w||c===txt.length)break;c+=dir}

22ret.index=c,ret.width=w}

23function getElementsList(elements){return elements?"string"==typeof elements?document.querySelectorAll(elements):elements.tagName&&elements.querySelectorAll?[elements]:elements:[]}

24function balanceText(elements){forEach(getElementsList(elements),(function(el){!function(el){var brs=el.querySelectorAll('br[data-owner="balance-text-hyphen"]');forEach(brs,(function(br){br.outerHTML=""}

25)),forEach(brs=el.querySelectorAll('br[data-owner="balance-text"]'),(function(br){br.outerHTML=" "}

26));var spans=el.querySelectorAll('span[data-owner="balance-text-softhyphen"]');if(spans.length>0&&forEach(spans,(function(span){var textNode=document.createTextNode("­");span.parentNode.insertBefore(textNode,span),span.parentNode.removeChild(span)}

27)),(spans=el.querySelectorAll('span[data-owner="balance-text-justify"]')).length>0){var txt="";forEach(spans,(function(span){txt+=span.textContent,span.parentNode.removeChild(span)}

28)),el.innerHTML=txt}

29}

30(el);var oldWS=el.style.whiteSpace,oldFloat=el.style.float,oldDisplay=el.style.display,oldPosition=el.style.position,oldLH=el.style.lineHeight;el.style.lineHeight="normal";var containerWidth=el.offsetWidth,containerHeight=el.offsetHeight;el.style.whiteSpace="nowrap",el.style.float="none",el.style.display="inline",el.style.position="static";var nowrapWidth=el.offsetWidth,nowrapHeight=el.offsetHeight,spaceWidth="pre-wrap"===oldWS?0:function(el,h){var dims,space,container=document.createElement("div");return container.style.display="block",container.style.position="absolute",container.style.bottom=0,container.style.right=0,container.style.width=0,container.style.height=0,container.style.margin=0,container.style.padding=0,container.style.visibility="hidden",container.style.overflow="hidden",(space=document.createElement("span")).style.fontSize="2000px",space.innerHTML="&nbsp;",container.appendChild(space),el.appendChild(container),dims=space.getBoundingClientRect(),container.parentNode.removeChild(container),h/(dims.height/dims.width)}

31(el,nowrapHeight);if(containerWidth>0&&nowrapWidth>containerWidth&&nowrapWidth<5e3){for(var desiredWidth,le,ge,splitIndex,isSoftHyphen,remainingText=el.innerHTML,newText="",lineText="",shouldJustify=function(el){return"justify"===(el.currentStyle||window.getComputedStyle(el,null)).textAlign}

32(el),remLines=Math.round(containerHeight/nowrapHeight),lineCharOffset=0;remLines>1;)breakMatches=null,calcNoWrapOffsetsForLine(el,oldWS,lineCharOffset),findBreakOpportunity(el,remainingText,containerWidth,desiredWidth=Math.round((nowrapWidth+spaceWidth)/remLines-spaceWidth),-1,Math.round((remainingText.length+1)/remLines)-1,le=new NextWS_params),ge=new NextWS_params,findBreakOpportunity(el,remainingText,containerWidth,desiredWidth,1,le.index,ge),le.reset(),findBreakOpportunity(el,remainingText,containerWidth,desiredWidth,-1,ge.index,le),splitIndex=0===le.index?ge.index:containerWidth<ge.width||le.index===ge.index||Math.abs(desiredWidth-le.width)<Math.abs(ge.width-desiredWidth)?le.index:ge.index,lineText=remainingText.substr(0,splitIndex).replace(/\s$/,""),(isSoftHyphen=Boolean(lineText.match(/\u00ad$/)))&&(lineText=lineText.replace(/\u00ad$/,'<span data-owner="balance-text-softhyphen">-</span>')),shouldJustify?newText+=justify(el,lineText,containerWidth):(newText+=lineText,newText+=isSoftHyphen||Boolean(lineText.match(/(-|\u2014|\u2013)$/))?'<br data-owner="balance-text-hyphen" aria-hidden="true" />':'<br data-owner="balance-text" aria-hidden="true" />'),remainingText=remainingText.substr(splitIndex),lineCharOffset=splitIndex,remLines--,el.innerHTML=remainingText,nowrapWidth=el.offsetWidth;el.innerHTML=shouldJustify?newText+justify(el,remainingText,containerWidth):newText+remainingText}

33el.style.whiteSpace=oldWS,el.style.float=oldFloat,el.style.display=oldDisplay,el.style.position=oldPosition,el.style.lineHeight=oldLH}

34))}

35function updateWatched(){var selectedElements=getElementsList(watching.sel.join(","));balanceText(Array.prototype.concat.apply(watching.el,selectedElements))}

36function initHandlers(){var fn,func,threshold,execAsap,timeout;handlersInitialized||(fn=updateWatched,"loading"!==document.readyState?fn():document.addEventListener?document.addEventListener("DOMContentLoaded",fn):document.attachEvent("onreadystatechange",(function(){"loading"!==document.readyState&&fn()}

37)),window.addEventListener("load",updateWatched),window.addEventListener("resize",(func=updateWatched,function(){var obj=this,args=arguments;function delayed(){execAsap||func.apply(obj,args),timeout=null}

38timeout?clearTimeout(timeout):execAsap&&func.apply(obj,args),timeout=setTimeout(delayed,threshold||100)}

39)),handlersInitialized=!0)}

40function publicInterface(elements,options){elements?options&&!0===options.watch?function(elements){"string"==typeof elements?watching.sel.push(elements):forEach(getElementsList(elements),(function(el){watching.el.push(el)}

...

</html>