Remove scripts from the topic header

Jan 17, 2012 at 3:55 PM

Hello,

I'm looking for a way to remove the header scripts ("Collapse All," "Code All") from Sandcastle-generated topics.

Photobucket

So far, I have accomplished part of this objective by deleting the "CheckboxMenu.js file" (which removes the "Code All" drop-down) from the Flare project (which we use to generate structured WebHelp from the Sandcastle output), and by manually removing the remaining content from the topic xml. This is an acceptable Plan B, but I have over 150 topics in my project, so Plan B would require a few hours worth of work I'd like to avoid if possible.

Is there a way to remove these scripts automatically from all topics in the output?

Thanks,

Todd

Editor
Jan 17, 2012 at 4:58 PM

Your best bet is probably to make a copy of the presentation style as a backup and modify the XSL transformations to get rid of the unwanted elements.  That way, when you build the help, the elements are not added to the output at all.

Eric

 

Jan 17, 2012 at 5:15 PM

Hello Todd,

One way is to create a custom Sandcastle component which will run after the transformation component.

Now, the header is structure as follows

<div id="header">
  <table id="topTable" cellspacing="0" cellpadding="0">
    <tr>
      <td>
        <span onclick="ExpandCollapseAll(toggleAllImage)" style="cursor:default;" onkeypress="ExpandCollapseAll_CheckKey(toggleAllImage, event)" tabindex="0">
          <img ID="toggleAllImage" class="toggleAll" src="../icons/collapse_all.gif" />&nbsp;<label id="collapseAllLabel" for="toggleAllImage" style="display: none;">Collapse All</label><label id="expandAllLabel" for="toggleAllImage" style="display: none;">Expand All</label>&nbsp;</span>
        <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
        <span id="devlangsDropdown" class="filter" tabindex="0">
          <img id="devlangsDropdownImage" src="../icons/dropdown.gif" />&nbsp;<label id="devlangsMenuAllLabel" for="devlangsDropdownImage" style="display: none;"><nobr>Code: All&nbsp;</nobr></label><label id="devlangsMenuMultipleLabel" for="devlangsDropdownImage" style="display: none;"><nobr>Code: Multiple&nbsp;</nobr></label><label id="devlangsMenuCSharpLabel" for="devlangsDropdownImage" style="display: none;"><nobr>Code: C#&nbsp;</nobr></label><label id="devlangsMenuVisualBasicLabel" for="devlangsDropdownImage" style="display: none;"><nobr>Code: Visual Basic&nbsp;</nobr></label><label id="devlangsMenuManagedCPlusPlusLabel" for="devlangsDropdownImage" style="display: none;"><nobr>Code: Visual C++&nbsp;</nobr></label></span>
      </td>
    </tr>
  </table>
  <div id="devlangsMenu">
    <input id="CSharpCheckbox" type="checkbox" data="CSharp,cs,'persist'" value="on" onClick="SetLanguage(this)" />
    <label class="checkboxLabel" for="CSharpCheckbox">C#</label>
    <br />
    <input id="VisualBasicCheckbox" type="checkbox" data="VisualBasic,vb,'persist'" value="on" onClick="SetLanguage(this)" />
    <label class="checkboxLabel" for="VisualBasicCheckbox">Visual Basic</label>
    <br />
    <input id="ManagedCPlusPlusCheckbox" type="checkbox" data="ManagedCPlusPlus,cpp,'persist'" value="on" onClick="SetLanguage(this)" />
    <label class="checkboxLabel" for="ManagedCPlusPlusCheckbox">Visual C++</label>
    <br />
  </div>
  <table id="bottomTable" cellpadding="0" cellspacing="0">
    <tr id="headerTableRow1">
      <td align="left">
        <span id="runningHeaderText">Sandcastle Helpers: Test Hierarchical Toc</span>
      </td>
    </tr>
    <tr id="headerTableRow2">
      <td align="left">
        <span id="nsrTitle">Company.Supports.Sales.Games Namespace</span>
      </td>
    </tr>
    <tr id="headerTableRow3">
      <td align="left"></td>
    </tr>
  </table>
  <table id="gradientTable">
    <tr>
      <td class="nsrBottom" background="../icons/gradient.gif" />
    </tr>
  </table>
</div>

You can remove the header table with the id = "topTable" or just the cell. This is what I do to remove the feedback,
if the user sets it to none in my build tool. The code used is similar to:

void RemoveFeedback(XPathNavigator docNavigator)
{
	if (!_hasFeedback)
	{
		XPathNavigator headerDiv = docNavigator.SelectSingleNode(_headDivSelector);
		if (headerDiv == null)
		{
			return;
		}
		if (_feedbackRowSelector == null)
		{
			_feedbackRowSelector = XPathExpression.Compile(
				"//table[@id='bottomTable']/tr[@id='headerTableRow3']/td");
		}
		XPathNavigator feedbackRow = docNavigator.SelectSingleNode(
			_feedbackRowSelector);
		if (feedbackRow == null)
		{
			return;
		}
		if (_feedbackSpanSelector == null)
		{
			_feedbackSpanSelector = XPathExpression.Compile(
				"//include[@item='feedbackHeader']");
		}
		XPathNavigator feedbackSpan = feedbackRow.SelectSingleNode(
			_feedbackSpanSelector);
		if (feedbackSpan != null)
		{
			feedbackSpan.DeleteSelf();
		}
	}
}

The _headDivSelector is defined as

_headDivSelector = XPathExpression.Compile("//div[@id='header']");

and the docNavigator = document.CreateNavigator();

I use the XPath because I do several other operations in the component where this is used, but you do not have to use it.

Best regards,
Paul 

Jan 17, 2012 at 6:03 PM

Thanks for the quick replies. It sounds like these recommendations will allow me to accomplish what I'm trying to do.

Jan 17, 2012 at 7:34 PM
EWoodruff wrote:

Your best bet is probably to make a copy of the presentation style as a backup and modify the XSL transformations to get rid of the unwanted elements.  That way, when you build the help, the elements are not added to the output at all.

Eric

 

Eric, with regard to this, what specific XSL transformations would I want to target? I tried removing code from the Presentation file in bits, then adding it back, to see which parts corresponded to the content I want to remove, but I wasn't able to find the right code. Any help with this would be appreciated.

Thanks.

Editor
Jan 17, 2012 at 11:24 PM

Pretty much all of the literal text is stored in the resource files in the .\Content folder.  The best way to locate something is to search those for the text and then search the XSL files for the item names.  So, in this example, if you search the content files for "Collapse All", you'll find it in reference_content.xml in the collapseAll item.  Searching the XSL files for "collapseAll" leads you to the bodyHeaderTopTable template in the the htmlBody.xsl file.  You'll see that it renders the "Collapse All" link. the "Code" dropdown, and a few other elements.

Eric

 

Jan 18, 2012 at 7:57 PM
Edited Jan 18, 2012 at 8:01 PM

Eric,

Thank you - following this lead, I found the correct code. I was able to remove the "Collapse All" link from the header table.

 

<span onclick="ExpandCollapseAll(toggleAllImage)" style="cursor:default;" onkeypress="ExpandCollapseAll_CheckKey(toggleAllImage, event)" tabindex="0">
            <img ID="toggleAllImage" class="toggleAll">
              <includeAttribute name="src" item="iconPath">
                <parameter>collapse_all.gif</parameter>
              </includeAttribute>
            </img>
            <xsl:text>&#xa0;</xsl:text>
            <label id="collapseAllLabel" for="toggleAllImage" style="display: none;">
              <include item="collapseAll"/>
            </label>
            <label id="expandAllLabel" for="toggleAllImage" style="display: none;">
              <include item="expandAll"/>
            </label>
            <xsl:text>&#160;</xsl:text>
          </span>

 

However, when I remove the code for DevLangs (to remove the "CodeAll" dropdown), I encounter a script error when I view the resulting CHM:

Code:

 

          <xsl:if test="boolean($showDevlangsFilter)">
            <xsl:call-template name="devlangsDropdown"/>
          </xsl:if>

 

Error:

 Photobucket

What is the correlation between attachEvent and the code I am removing? How can I remove the "CodeAll" dropdown without causing script errors?

I appreciate your help with this.

Todd

Jan 18, 2012 at 8:26 PM

Eric,

Disregard the previous post. There was a bit of code I neglected to remove. Having removed it, I no longer encounter script errors in the CHM output. Once again, thanks for your assistance with this. It saved me a lot of time.

Todd