AAron nAAs

All MindsharpBlogs

AAron's SharePoint notepad

My Links

Archives

Blog Stats

My Sites

Mystery JS Code

Can you guess what this Javascript code does and why? (I didn't even remove my comments)

I wrote this interesting bit of Javascript for my MOSS portal site out of necessity. If someone figures out why I'm using this, we could discuss the alternatives :-) Todd isn't allowed to guess because he knows !

function PageViewerWPVisibility(show) {

  // Open the PageViewerWP if found

  if (window != top) {

    // If in edit mode, leave alone

    var versionLink = window.parent.document.getElementById('pvi1_anchor');

    if (versionLink != null) {

      return;

    }

    // Find this iframe

    // iframesrc = "/sites/Somesite/Pages/Somepage.aspx"

    // windowsrc = "http://hostname/sites/Somesite/Pages/Somepage.aspx"

    var iframes = window.parent.document.getElementsByTagName('iframe');

    var windowsrc = window.location.href.toLowerCase();

    var iframe = null;

    for (var i=0; i<iframes.length; i++) {

      var iframesrc = iframes[i].src.toLowerCase();

      var pos = windowsrc.indexOf(iframesrc);

      if (pos == (windowsrc.length - iframesrc.length)) {

        iframe = iframes[i];

        break;

      }

    }

    if (iframe == null) { return; }

 

    // Example: MSOPageViewerWebPart_WebPartWPQ13

    var iframeid = iframe.parentNode.id;

    var wpqNumPos = iframeid.indexOf("WebPartWPQ") + 10;

    var wpqNum = parseInt(iframeid.substr(wpqNumPos));

    var zonecell = window.parent.document.getElementById("MSOZoneCell_WebPartWPQ"+wpqNum);

    if (show) {

      // Show hidden cell and remove "(Hidden)" text.

      zonecell.childNodes[0].style.display = "inline";

      var titlenode = window.parent.document.getElementById("WebPartTitleWPQ"+wpqNum);

      if (titlenode.innerHTML) {

        titlenode.innerHTML = titlenode.innerHTML.replace(/[\s\u202C\u202D]*\(Hidden\)[\s\u202C\u202D]*/gm, "");

        titlenode.title = titlenode.title.replace(/\s*\(Hidden\)\s*/g, "");

      }

    }

    else {

      // Ensure cell is hidden.

      zonecell.style.display = "none";

      zonecell.parentNode.style.display = "none";

    }

  }

}

 

posted on Monday, March 31, 2008 10:48 PM

Feedback

# re: Mystery JS Code 4/18/2008 1:38 PM AAron nAAs

Interesting that no-one has attempted a guess. I'm using it in a page that displays inside a Page Viewer Web Part. Who sees the value of using this (and when)?

# re: Mystery JS Code 6/10/2008 5:06 PM Otto

Are comments disabled?

# re: Mystery JS Code 6/10/2008 5:08 PM Otto

I see they are not.
Please post a screenshot so I can see if this real rocket science high end javascript bit does any good (it toggles the visibility of either the web part or of the title bar of the web part, I would guess).

Title  
Name  
Url
CAPTCHA
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments