AAron nAAs

All MindsharpBlogs

AAron's SharePoint notepad

My Links

Archives

Blog Stats

My Sites

Monday, March 31, 2008 #

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 @ 10:48 PM | Feedback (3)