4

I am using Javascript to display headers on a SharePoint site, according to a column that I have specified HTML in. Here is the HTML.

<DIV style ='text-align:center; font-weight:bold; font-size: 20px;'>◆</DIV>

The problem is that the script, while rendering the HTML properly within the page, does not do the same for header. It works 90% of the way, but instead of displaying the unicode "◆", it renders "â".

I've already tried modifying the Javascript to try to account for the unicode \u25c6, but I'm failing miserably. Can anyone help me out or provide me some clues as to why this is happening?

Here is the Javascript.

<script type="text/javascript">
// Find all Web Parts in the page
var listWP = [],
    calWP = [],
    divs = document.getElementById("MSO_ContentTable").getElementsByTagName("div");
var count=divs.length;
for (i=0;i<count;i++) {
    try {
        if (divs[i].id.indexOf("WebPartWPQ")==0){
            if (divs[i].innerHTML.indexOf("ViewDefault_CalendarView")>=0) {
                // Calendars
                calWP.push(divs[i].id);
            } else {
                // Other Web Parts
                listWP.push(divs[i].id);
            }
        }
    }
    catch(e){}
}
function TextToHTML(NodeSet, HTMLregexp) {
    var CellContent = "";
    var i=0;
    while (i < NodeSet.length){
        try {
            CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
            if (HTMLregexp.test(CellContent)) {
                NodeSet[i].innerHTML = CellContent;
            }
        }
        catch(err){}
        i=i+1;
    }
}

var regexpA = new RegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
var WP = new Object;

function UpdateWP() {
    if (calWP.length>0){
        for (i=0;i<calWP.length;i++) {
            WP=document.getElementById(calWP[i]);
            if (WP.innerHTML.indexOf("&lt\;")>=0) {
                TextToHTML(WP.getElementsByTagName ("a"),regexpA);
            }
        }
    }
    if (listWP.length>0){
        for (i=0;i<listWP.length;i++) {
            WP=document.getElementById(listWP[i]);
            if (WP.innerHTML.indexOf("&lt\;")>=0) {
                TextToHTML(WP.getElementsByTagName ("td"),regexpTD);
            }
        }
    }
    // Check every 200000000 ms, forever
    setTimeout("UpdateWP()",200000000);
}
UpdateWP();
function HeaderToHTML(){
    var headers=document.getElementById("MSO_ContentTable").getElementsByTagName("li");
    var regexpTR1 = new RegExp("FilterValue1=([\\S\\s]*)'\\)");
    var regexpTR2 = new RegExp("FilterValue2=([\\S\\s]*)'\\)");

    for (i=0;i<headers.length;i++) {
        try{
            var sp=headers[i].getElementsByTagName("span");
            for (j=0;j<sp.length;j++) {
                var test = sp[j].innerText || sp[j].textContent || " ";
                //var test = sp[j].innerText;
                if (test.indexOf("...")>0) {
                    //alert(test);
                    //var value = regexpTR1.exec(headers[i].innerHTML)[1];
                    var inner = headers[i].innerHTML;
                    var value = (inner.indexOf("FilterValue2")>0) ? regexpTR2.exec(headers[i].innerHTML) [1] : regexpTR1.exec(headers[i].innerHTML)[1];
                    //alert(value);
                    //alert(value.replace(/\\u00/g,"\%"));
                    value=value.replace(/\\u00/g,"%");
                    sp[j].innerHTML=unescape(unescape(value)).replace(/8_/," ");
                } 
            }
        }catch(e){}
    }
}
setInterval(function(){HeaderToHTML();},100);
</script>
3
  • Could you try using this instead : &diams;? Commented Jan 4, 2013 at 18:46
  • 1
    You need to provide more information. The JavaScript code posted does not do anything to the div element in the question, and you have not specified what you mean by “columns” and “headers” (such concepts do not make sense when the only HTML element mentioned is div). Commented Jan 4, 2013 at 20:33
  • Thanks for the assist. Actually, it does recognize <div> and <span>. It's on a SharePoint site, so adding to this to a CEWP allows the text to render as HTML; that's what I meant by columns and their headers. The only thing that doesn't work is the unicode that I specified. It renders in the SharePoint column filter headers as that special character. Commented Jan 10, 2013 at 14:55

2 Answers 2

1

I would suggest using the html dex/dec for the symbols.
that is,

&#x25C6; = ◆
&#9670; = ◆

Wikipedia has a nice list of them broken into categories here.
I found the black diamond you're trying to write here

Sign up to request clarification or add additional context in comments.

1 Comment

I actually already tried rendering them using hexa/dec, and it doesn't work. I guess the problem is I don't know where to stick the code in the Javascript posted above to direct it to look for and render the unicode.
1

I think a solution could be to render your character in its encoding and let browser know about it via:

<meta http-equiv="Content-Type" content="text/html; charset="...">

For example, if you are using UTF-8:

<meta http-equiv="Content-Type" content="text/html; charset="UTF-8">

1 Comment

This might be an idea. Again, where would I stick this code? After the script open command?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.