Eureka! While I was hoping for a JavaScript answer to completely solve this problem (and would still appreciate one if possible) I did find a solution and wanted to share it so that others may benefit.
There were two issues in this problem: attaching click events to the itemHeader class elements and getting the hideableItem class elements to hide after the partial page update. The following is what had to be changed to correct the issues.
• I had to do away with $(document).ready event statements wrapping the two functions and name them.
• Use the on() method to attach a handler to the click event.
• Within the page calling the partial update I had to modify the Ajax.ActionLink method by adding an additional property, OnSuccess, to the AjaxOptions list. OnSuccess calls the javascript function hidingItems when the partial page update is successfully completed.
Here is the code with the corrections.
Sliding.js
Code:
// Event handler attachment that attachs the showItem handler to the click event.
$(document).on('click', '.itemHeader', showItem);
// Causes the previously unhidden hideableItem to hide and shows the current clicked item
// thereby providing the accordion effect.
function showItem() {
// Get the parent of the item that was previously clicked.
var priorSelectedParent = $('.itemHeaderSelected').parent().attr('id');
$('#' + priorSelectedParent + ' .hideableItem').slideUp('slow');
$('#' + priorSelectedParent + ' .itemHeaderSelected').addClass('itemHeader');
$('#' + priorSelectedParent + ' .itemHeader').removeClass('itemHeaderSelected');
// Get the parent of the item that was clicked.
var headerParent = $(this).parent().attr('id');
$('#' + headerParent + ' .hideableItem').slideDown('slow');
$('#' + headerParent + ' .itemHeader').addClass('itemHeaderSelected cornersRoundSmall');
$('#' + headerParent + ' .itemHeaderSelected').removeClass('itemHeader');
}
// On pages that utilize the accordion effect this causes the div class openingHeader
// to open after the page loads.
function hidingItems() {
$('.hideableItem').hide();
// Needed to add a slight time delay before triggering the click event.
setTimeout(function () {
// Select the 'Summary' section be open after the page loads.
$('.openingHeader').trigger('click');
}, 10);
}
Index.aspx
Code:
<li class="selectionItem"><%= Ajax.ActionLink("Background","Background",
new AjaxOptions{UpdateTargetId="columnContent", OnSuccess="hidingItems"}) %></li>
Thank you to all of you who took your time looking into this problem for me.
Ken