
function TruncateDisplayTextWidth(container,widthMaximum,shortenerTextNode){
if(TruncationIsNeeded(container,"offsetWidth",widthMaximum)){
var suffixNode=PrepareTruncationTextSuffix(container,shortenerTextNode,"...");
var originalText=TruncateDisplayTextInternalEx(container,"offsetWidth",widthMaximum,shortenerTextNode);
var truncationStillNeeded=TruncationIsNeeded(container,"offsetWidth",widthMaximum);
return FinalizeTruncationSuffixTooltip(container,shortenerTextNode,originalText,truncationStillNeeded,suffixNode);}
else{
return null;}}
function TruncateDisplayTextHeight(container,heightMaximum,shortenerTextNode){
if(TruncationIsNeeded(container,"offsetHeight",heightMaximum)){
var suffixNode=PrepareTruncationTextSuffix(container,shortenerTextNode,"...");
var originalText=TruncateDisplayTextInternalEx(container,"offsetHeight",heightMaximum,shortenerTextNode);
var truncationStillNeeded=TruncationIsNeeded(container,"offsetHeight",heightMaximum);
return FinalizeTruncationSuffixTooltip(container,shortenerTextNode,originalText,truncationStillNeeded,suffixNode);}
else{
return null;}}
function TruncateDisplayTextWidthCustomized(container,widthMaximum,shortenerTextNode,truncationFunction,details){
if(TruncationIsNeeded(container,"offsetWidth",widthMaximum)){
return TruncateDisplayTextInternal(container,"offsetWidth",widthMaximum,shortenerTextNode,truncationFunction,details);}
else{
return null;}}
function TruncateDisplayTextHeightCustomized(container,heightMaximum,shortenerTextNode,truncationFunction,details){
if(TruncationIsNeeded(container,"offsetHeight",heightMaximum)){
return TruncateDisplayTextInternal(container,"offsetHeight",heightMaximum,shortenerTextNode,truncationFunction,details);}
else{
return null;}}
function TruncateDisplayTextWidthPrepared(container,widthMaximum,shortenerTextNode,preparationFunction,finalizationFunction,details){
if(TruncationIsNeeded(container,"offsetWidth",widthMaximum)){
details=preparationFunction(container,shortenerTextNode,details);
var originalText=TruncateDisplayTextInternalEx(container,"offsetWidth",widthMaximum,shortenerTextNode);
var truncationStillNeeded=TruncationIsNeeded(container,"offsetWidth",widthMaximum);
return finalizationFunction(container,shortenerTextNode,originalText,truncationStillNeeded,details);}
else{
return null;}}
function TruncateDisplayTextHeightPrepared(container,heightMaximum,shortenerTextNode,preparationFunction,finalizationFunction,details){
if(TruncationIsNeeded(container,"offsetHeight",heightMaximum)){
details=preparationFunction(container,shortenerTextNode,details);
var originalText=TruncateDisplayTextInternalEx(container,"offsetHeight",heightMaximum,shortenerTextNode);
var truncationStillNeeded=TruncationIsNeeded(container,"offsetHeight",heightMaximum);
return finalizationFunction(container,shortenerTextNode,originalText,truncationStillNeeded,details);}
else{
return null;}}
function AddTruncationSuffix(container,shortenerTextNode,originalText,details){
var suffix=details;
var textCurrentLength=shortenerTextNode.length;
var suffixLength=suffix.length;
if(textCurrentLength>suffixLength){
shortenerTextNode.replaceData(textCurrentLength-suffixLength,suffixLength,suffix);}
return container;}
function AddTruncationSuffixAndDisplayTextTooltip(container,shortenerTextNode,originalText,details){
var suffix=details;
var textCurrentLength=shortenerTextNode.length;
var shortenerParent=shortenerTextNode.parentNode;
var shortenerNeighbor=shortenerTextNode.nextSibling;
var wrapper=window.document.createElement("SPAN");
wrapper.title=originalText;
wrapper.appendChild(shortenerTextNode);
shortenerParent.insertBefore(wrapper,shortenerNeighbor);
var suffixLength=suffix.length;
if(textCurrentLength>suffixLength){
shortenerTextNode.replaceData(textCurrentLength-suffixLength,suffixLength,suffix);}
return wrapper;}
function AddDisplayTextTooltip(container,shortenerTextNode,originalText,details){
var suffixNode=details;
suffixNode.parentNode.removeChild(suffixNode);
var shortenerParent=shortenerTextNode.parentNode;
var shortenerNeighbor=shortenerTextNode.nextSibling;
var wrapper=window.document.createElement("SPAN");
wrapper.title=originalText;
wrapper.appendChild(shortenerTextNode);
wrapper.appendChild(suffixNode);
shortenerParent.insertBefore(wrapper,shortenerNeighbor);
return wrapper;}
function PrepareTruncationTextSuffix(container,shortenerTextNode,details){
var suffixTextNode=window.document.createTextNode(details);
shortenerTextNode.parentNode.insertBefore(suffixTextNode,shortenerTextNode.nextSibling);
return suffixTextNode;}
function RangedPrepareTruncationTextSuffix(container,firstShortenerTextNode,lastShortenerTextNode,details){
var suffixTextNode=window.document.createTextNode(details);
lastShortenerTextNode.parentNode.insertBefore(suffixTextNode,lastShortenerTextNode.nextSibling);
return suffixTextNode;}
function PrepareTruncationElementSuffix(container,shortenerTextNode,details){
var suffixElement=details;
shortenerTextNode.parentNode.insertBefore(suffixElement,shortenerTextNode.nextSibling);
return suffixElement;}
function RangedPrepareTruncationElementSuffix(container,firstShortenerTextNode,lastShortenerTextNode,details){
var suffixElement=details;
lastShortenerTextNode.parentNode.insertBefore(suffixElement,lastShortenerTextNode.nextSibling);
return suffixElement;}
function PrepareTruncationNoOp(container,shortenerTextNode,details){
return details;}
function FinalizeTruncationSuffixTooltip(container,shortenerTextNode,originalText,truncationStillNeeded,details){
var suffixNode=details;
if(originalText!==null){
var wrapper=AddDisplayTextTooltip(container,shortenerTextNode,originalText,suffixNode);
if(truncationStillNeeded){
suffixNode.parentNode.removeChild(suffixNode);}
return wrapper;}
else{
return null;}}
function RangedFinalizeTruncationSuffixTooltip(container,firstShortenerTextNode,lastShortenerTextNode,originalText,truncationStillNeeded,details){
var suffixNode=details;
if(originalText!==null){
suffixNode.parentNode.removeChild(suffixNode);
var shortenerParent=lastShortenerTextNode.parentNode;
var shortenerNeighbor=lastShortenerTextNode.nextSibling;
var wrapper=window.document.createElement("SPAN");
wrapper.title=originalText;
var nextCursor;
for(var shortenerCursor=firstShortenerTextNode;shortenerCursor!==shortenerNeighbor;shortenerCursor=nextCursor){
nextCursor=shortenerCursor.nextSibling;
wrapper.appendChild(shortenerCursor);}
wrapper.appendChild(suffixNode);
shortenerParent.insertBefore(wrapper,shortenerNeighbor);
if(truncationStillNeeded){
suffixNode.parentNode.removeChild(suffixNode);}
return wrapper;}
else{
return null;}}
function FinalizeTruncationSuffix(container,shortenerTextNode,originalText,truncationStillNeeded,details){
var suffixNode=details;
if(originalText!==null){
if(truncationStillNeeded){
suffixNode.parentNode.removeChild(suffixNode);}
return container;}
else{
return null;}}
function RangedFinalizeTruncationSuffix(container,firstShortenerTextNode,lastShortenerTextNode,originalText,truncationStillNeeded,details){
var suffixNode=details;
if(originalText!==null){
if(truncationStillNeeded){
suffixNode.parentNode.removeChild(suffixNode);}
return container;}
else{
return null;}}
function TruncationIsNeeded(container,dimensionProperty,dimensionMaximum){
var currentDimension=container[dimensionProperty];
return(currentDimension>dimensionMaximum);}
function TruncateDisplayTextInternal(container,dimensionProperty,dimensionMaximum,shortenerTextNode,truncationFunction,details){
var originalText=TruncateDisplayTextInternalEx(container,dimensionProperty,dimensionMaximum,shortenerTextNode);
if(originalText!==null){
return truncationFunction(container,shortenerTextNode,originalText,details);}
else{
return null;}}
function TruncateDisplayTextInternalEx(container,dimensionProperty,dimensionMaximum,shortenerTextNode){
var originalText=shortenerTextNode.data;
var originalTextLength=originalText.length;
if(originalTextLength===0){
return null;}
var textCurrentLength=originalTextLength;
var textLowLength=0;
var textHighLength=textCurrentLength;
while(true){
var currentDimension=container[dimensionProperty];
var dimensionDifference=currentDimension-dimensionMaximum;
if(dimensionDifference>0){
textHighLength=textCurrentLength;}
else{
textLowLength=textCurrentLength;}
var candidateTextLengthDifference;
if(textHighLength-textLowLength>1){
var dimensionDifferenceRatio=dimensionMaximum/currentDimension;
var candidateTextLength=Math.floor(textCurrentLength*dimensionDifferenceRatio);
candidateTextLengthDifference=textCurrentLength-candidateTextLength;
if(candidateTextLengthDifference===0){
if(dimensionDifferenceRatio>0){
candidateTextLength++;
candidateTextLengthDifference=-1;}
else{
candidateTextLength--;
candidateTextLengthDifference=1;}}
if(candidateTextLength>=textHighLength){
candidateTextLength=textHighLength-1;
candidateTextLengthDifference=textCurrentLength-candidateTextLength;}
else if(candidateTextLength<=textLowLength){
candidateTextLength=textLowLength+1;
candidateTextLengthDifference=textCurrentLength-candidateTextLength;}
if(candidateTextLengthDifference>0){
shortenerTextNode.deleteData(candidateTextLength,candidateTextLengthDifference);}
else{
shortenerTextNode.appendData(originalText.substr(textCurrentLength,-candidateTextLengthDifference));}
textCurrentLength=candidateTextLength;}
else{
if(textCurrentLength!==textLowLength){
candidateTextLengthDifference=textCurrentLength-textLowLength;
if(candidateTextLengthDifference>0){
shortenerTextNode.deleteData(textLowLength,candidateTextLengthDifference);}
else{
shortenerTextNode.appendData(originalText.substr(textCurrentLength,-candidateTextLengthDifference));}
textCurrentLength=textLowLength;}
break;}}
if(originalTextLength!==textCurrentLength){
return originalText;}
else{
return null;}}
function ComputeDisplayTextLineHeight(oneLineElement,twoLineElement,lineCount){
var oneLineElementHeight=oneLineElement.offsetHeight;
var twoLineElementHeight=twoLineElement.offsetHeight;
var lineHeight=twoLineElementHeight-oneLineElementHeight;
var fixedHeight=oneLineElementHeight-lineHeight;
return fixedHeight+(lineHeight*lineCount);}
function WordBreakDisplayTextWidth(container,widthMaximum,textNode){
var text=textNode.data;
var offsets=FindWordBreakOffsetsWidthInternal(container,widthMaximum,textNode);
if(offsets.length!==0){
var lastOffset=0;
var currentTextNode=textNode;
var textNodeParent=textNode.parentNode;
for(var offsetIndex=0;offsetIndex<offsets.length;offsetIndex++){
var offset=offsets[offsetIndex];
var difference=offset-lastOffset;
var newTextNode=currentTextNode.splitText(difference);
var nextNode=currentTextNode.nextSibling;
textNodeParent.insertBefore(window.document.createElement("WBR"),nextNode);
textNodeParent.insertBefore(newTextNode,nextNode);
currentTextNode=newTextNode;
lastOffset=offset;}}}
function FindWordBreakOffsetsWidthInternal(container,widthMaximum,textNode){
var wrapper=window.document.createElement("DIV");
var duplicateContainer=container.cloneNode(false);
var duplicateTextNode=window.document.createTextNode("");
duplicateContainer.appendChild(duplicateTextNode);
duplicateContainer.style.overflow="visible";
duplicateContainer.style.position="absolute";
duplicateContainer.style.left="-999px";
duplicateContainer.style.top="-999px";
duplicateContainer.style.display="block";
duplicateContainer.style.whiteSpace="nowrap";
duplicateContainer.style.width="auto";
duplicateContainer.style.wordWrap="normal";
container.parentNode.insertBefore(wrapper,container);
wrapper.appendChild(duplicateContainer);
var text=textNode.data;
var lastBreakIndex=0;
var offsets=[];
for(var breakIndex=text.indexOf(" ",lastBreakIndex);breakIndex!==-1;breakIndex=text.indexOf(" ",lastBreakIndex)){
var word=text.substring(lastBreakIndex,breakIndex);
AppendWordBreakOffsetsWidthInternal(duplicateContainer,widthMaximum,duplicateTextNode,word,lastBreakIndex,offsets);
lastBreakIndex=breakIndex+1;}
var lastWord=text.substr(lastBreakIndex);
AppendWordBreakOffsetsWidthInternal(duplicateContainer,widthMaximum,duplicateTextNode,lastWord,lastBreakIndex,offsets);
wrapper.parentNode.removeChild(wrapper);
return offsets;}
function AppendWordBreakOffsetsWidthInternal(container,widthMaximum,textNode,word,offsetAdjustment,offsets){
textNode.data=word;
for(var wordIndex=0;(TruncateDisplayTextInternalEx(container,"offsetWidth",widthMaximum,textNode)!==null);){
var breakThreshold=textNode.data.length;
offsets.push(breakThreshold+wordIndex+offsetAdjustment);
wordIndex+=breakThreshold;
textNode.data=word.substr(wordIndex);}}
function FitDisplayTextToBlock(container,widthMaximum,heightMaximum,textNode){
return FitDisplayTextToBlockPrepared(container,widthMaximum,heightMaximum,textNode,RangedPrepareTruncationTextSuffix,RangedFinalizeTruncationSuffixTooltip,"...");}
function FitDisplayTextToBlockPrepared(container,widthMaximum,heightMaximum,textNode,rangedPreparationFunction,rangedFinalizationFunction,details){
var originalText=textNode.data;
var offsets=FindWordBreakOffsetsWidthInternal(container,widthMaximum,textNode);
if(offsets.length!==0){
textNode.data="";
var lastOffset=0;
var currentTextNode=textNode;
var textNodeParent=textNode.parentNode;
for(var offsetIndex=0;offsetIndex<offsets.length;offsetIndex++){
var offset=offsets[offsetIndex];
currentTextNode.data=originalText.substring(lastOffset,offset);
if(TruncationIsNeeded(container,"offsetHeight",heightMaximum)){
return FitDisplayTextToBlockPreparedFitLastLineInternal(container,widthMaximum,heightMaximum,originalText,textNode,currentTextNode,textNodeParent,lastOffset,rangedPreparationFunction,rangedFinalizationFunction,details);}
var nextNode=currentTextNode.nextSibling;
textNodeParent.insertBefore(window.document.createElement("WBR"),nextNode);
var newTextNode=window.document.createTextNode("");
textNodeParent.insertBefore(newTextNode,nextNode);
currentTextNode=newTextNode;
lastOffset=offset;}
currentTextNode.data=originalText.substr(lastOffset);
if(TruncationIsNeeded(container,"offsetHeight",heightMaximum)){
return FitDisplayTextToBlockPreparedFitLastLineInternal(container,widthMaximum,heightMaximum,originalText,textNode,currentTextNode,textNodeParent,lastOffset,rangedPreparationFunction,rangedFinalizationFunction,details);}
else{
return null;}}
else{
var detailsShim={
"PreparationFunction":rangedPreparationFunction,
"FinalizationFunction":rangedFinalizationFunction,
"Details":details};
return TruncateDisplayTextHeightPrepared(container,heightMaximum,textNode,PrepareFromRangedFunctionInternal,FinalizeFromRangedFunctionInternal,detailsShim);}}
function FitDisplayTextToBlockPreparedFitLastLineInternal(container,widthMaximum,heightMaximum,originalText,textNode,currentTextNode,textNodeParent,lastOffset,rangedPreparationFunction,rangedFinalizationFunction,details){
details=rangedPreparationFunction(container,textNode,currentTextNode,details);
TruncateDisplayTextInternalEx(container,"offsetHeight",heightMaximum,currentTextNode);
if(currentTextNode.data.length===0){
var cursor=currentTextNode.previousSibling;
if(cursor!==null){
for(;cursor!==null;cursor=cursor.previousSibling){
if(cursor.nodeType===3){
break;}}
for(var eraser=cursor.nextSibling;eraser!==currentTextNode;eraser=cursor.nextSibling){
textNodeParent.removeChild(eraser);}
textNodeParent.removeChild(currentTextNode);
cursor.appendData(originalText.substr(lastOffset));
TruncateDisplayTextInternalEx(container,"offsetWidth",widthMaximum,cursor);
var truncationStillNeeded=TruncationIsNeeded(container,"offsetWidth",widthMaximum);
return rangedFinalizationFunction(container,textNode,cursor,originalText,truncationStillNeeded,details);}
else{
return rangedFinalizationFunction(container,textNode,textNode,originalText,false,details);}}
else{
return rangedFinalizationFunction(container,textNode,currentTextNode,originalText,false,details);}}
function PrepareFromRangedFunctionInternal(container,shortenerTextNode,details){
return{
"FinalizationFunction":details.FinalizationFunction,
"Details":details.PreparationFunction(container,shortenerTextNode,shortenerTextNode,details.Details)};}
function FinalizeFromRangedFunctionInternal(container,shortenerTextNode,originalText,truncationStillNeeded,details){
return details.FinalizationFunction(container,shortenerTextNode,shortenerTextNode,originalText,truncationStillNeeded,details.Details);}
function HyphenateDisplayText(textNode){
var text=textNode.data;
var lastBreakIndex=0;
var offsets=[];
for(var breakIndex=text.indexOf(" ",lastBreakIndex);breakIndex!==-1;breakIndex=text.indexOf(" ",lastBreakIndex)){
var word=text.substring(lastBreakIndex,breakIndex);
AppendWordHyphenationOffsetsInternal(word,lastBreakIndex,offsets);
lastBreakIndex=breakIndex+1;}
var lastWord=text.substr(lastBreakIndex);
AppendWordHyphenationOffsetsInternal(lastWord,lastBreakIndex,offsets);
if(offsets.length!==0){
for(var offsetIndex=0;offsetIndex<offsets.length;offsetIndex++){
var offset=offsets[offsetIndex];
textNode.insertData(offset+offsetIndex,"\u00AD");}}}
function AppendWordHyphenationOffsetsInternal(word,offsetAdjustment,offsets){
var hyphenationThreshold=12;
var breakCount=Math.floor((word.length-1)/hyphenationThreshold);
for(var breakIndex=1;breakIndex<=breakCount;breakIndex++){
offsets.push(hyphenationThreshold*breakIndex+offsetAdjustment);}}

