John, I made the changes you suggested to the script to get the accordions to stay open. I also externalized the script, following your suggestions. I did make a change in the script, because it was not working in the IE9 emulation. I incorporated the change you had suggested earlier to get it to work in IE9. I then retested to make sure I wasn't messing something else up.
OK, here are the results, with your changes to the script and an externalized script:
- Desktop: accordions open and stay open when I move from page to page in the following browsers: Chrome, Opera 43, Firefox, Safari, IE11, IE10, IE9. Nothing works in IE8.
- iPad: accordions open and stay open when I move from page to page in Opera Mini. In all other browsers (Safari, Chrome, and Firefox), the accordions open correctly, but they do not stay open when I move from page to page.
Is there an EASY fix for the failure of the iPad browsers to keep the accordions open from page to page? If not, perhaps I should abandon the idea? What do you think?
I discovered two additional problems.
- For Internet Explorer (always the problem child), when I open a page initially and also when I move from page to page, the text on the accordion buttons does something quite odd. For one split second the text appears with a larger font, then shrinks back to the proper size. This has nothing to do with the externalization of the script or with the latest changes you suggested to make the accordions persist. I noticed it yesterday before I had made any of these changes. This little glitch was not present in the demo page. It cropped up when I incorporate the demo page navigation into my aside left server side include. So, it was something I did wrong when I made that transition. I have no clue as to whether this is easily fixable. It's not a huge issue, so maybe I should just ignore it? What do you think?
- Dreamweaver gives me three irate errors for the externalized Javascript file. I did not get these errors on the aside left server side include before externalizing the script. I enclose a screen capture of the errors
.

Arie/John: I seem to have added to the confusion about the server side include issue by not explaining clearly. I will give it a try. It's difficult, because all you see is the code for each page AFTER the server sides includes have been included.
- I made the left hand navigation panel a server side include to make changes to the navigation quick and easy. I made this decision based on advice I got on this forum some years ago, when I adopted the server side include approach for another web site. This approach seems to be working fine, so I would be highly reluctant to change it.
- When I initially incorporated the new accordion navigation panel, I grabbed all the style stuff and stuffed it into my external style sheet, applying it to all views (mobile, tablet, desktop). I left the html stuff (the lists of URLs, etc), plus the accordion script in the server side include file. I tested it out (as reported earlier), and everything seemed to work (with the exceptions noted earlier, plus the nonpersisting accordion panels.
- The next step, which I accomplished this morning, was to incorporate John's suggestion to keep the accordions open from page to page. I made that change in the script (still in the server side include) and tested it out.
- The final step (also this morning) was to externalize the script by following John's suggestion to create a js file and put in a script reference in the server side include. I tested that out. The results are reported above. One of the problems (the strange behavior of the button text in IE) appears unrelated to externalizing the script. However, the other problem (the three nasty error messages) only appeared on the externalized script.
At this point, the remaining problems do not seem to be fatal, although I worry about those nasty, little error messages on the js file. I would like to fix every problem, but not if fixing them would potentially mess up something else that is working at the moment.
As always, I am very, very grateful for all of the time you have taken to help me. You have been very patient. If there is an easy fix to the problems that remain, please let me know. If you think that the problems are trivial and/or not easily fixable, let me know.
Thanks again, ellen
Here is the code for the external script file:
Code:
(function(){
var accs = document.querySelectorAll('.accordion, .accordionSecond'),
storagename = 'accordionpersiting_73561',
persisted = localStorage.getItem(storagename),
persisting = {}, i = accs.length;
if(persisted){
var p = persisted.split('.'), l = p.length;
while(--l > -1){
persisting[p[l]] = true;
}
}
while (--i > -1) {
accs[i].setAttribute('data-index', i);
accs[i].onclick = function() {
this.className = /\bactive\b/.test(this.className)? this.className.replace(/\bactive\b/, '') : this.className? this.className + ' active' : 'active';
persisting[this.getAttribute('data-index')] = /\bactive\b/.test(this.className);
var panel = this.nextElementSibling;
if (panel.style.maxHeight){
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
}
if(persisting[i]){
accs[i].onclick.apply(accs[i]);
}
}
window.addEventListener('unload', function(){
var pa = [];
for(var p in persisting){
if(persisting.hasOwnProperty(p) && persisting[p]){
pa.push(p);
}
}
localStorage.setItem(storagename, pa.join('.'));
}, false);
})()
;
Here is the html for the aside left server side include:
HTML Code:
<aside class="asideLeft">
<script type="text/javascript">
// Google Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use
//Enter domain of site to search.
var domainroot="www.wildadirondacks.org"
function Gsitesearch(curobj){
curobj.q.value="site:"+domainroot+" "+curobj.qfront.value
}
</script>
<section class="searchSection">
<form action="http://www.google.com/search" method="get" onSubmit="Gsitesearch(this)">
<input name="q" type="hidden" />
<input name="qfront" type="text" style="width: 70%">*
<input type="submit" value="" style="border-style: none; background: url('images/Search-Icon-1.png') no-repeat; width: 24px; height: 20px">
</form>
</section>
<div class="noexpandFirst">
<a href="index.html" title="Forever Wild"><strong>HOME: FOREVER WILD</strong></a></div>
<div class="noexpandSecond">
<a href="adirondack-geology.html" title="Adirondack Geology">Adirondack Geology
</a></div>
<div class="noexpandSecond">
<a href="adirondack-wilderness.html" title="Adirondack Wilderness">Wilderness</a></div>
<div class="noexpandSecond">
<a href="forever-wild-the-adirondack-park.html" title="The Adirondack Park">The Adirondack Park</a>
</div>
<button class="accordion"><strong>TRAILS</strong></button>
<div class="panel">
<ul>
<li><a href="adirondack-trails.html" title="Adirondack Trails">Adirondack Trails</a>
</li>
<li><a href="barnum-brook-interpretive-trail.html">Barnum Brook Trail (VIC)</a> </li>
<li><a href="boreal-life-interpretive-trail.html">Boreal Life Trail (VIC)</a> </li>
<li><a href="heron-marsh-interpretive-trail.html">Heron Marsh Trail (VIC)
</a></li>
<li><a href="jenkins-mountain-trail.html">Jenkins Mountain Trail (VIC)
</a></li>
<li><a href="loggers-loop-trail.html">Logger’s Loop Trail (VIC)
</a></li>
<li><a href="woods-and-waters-trail.html">Woods & Waters Trail (VIC)</a></li>
<li><a href="black-pond-trail.html">Black Pond Trail (VIC)</a></li>
<li><a href="long-pond-trail.html">Long Pond Trail (VIC)</a></li>
<li><a href="bobcat-trail.html">Bobcat Trail (VIC)</a></li>
<li><a href="silvi-trail.html">Silvi Trail (VIC)</a></li>
<li><a href="easy-street-trail.html">Easy Street Trail (VIC)</a></li>
<li><a href="fox-run-trail.html">Fox Run Trail (VIC)</a></li>
<li><a href="skidder-trail.html">Skidder Trail (VIC)</a></li>
<li><a href="esker-trail.html">Esker Trail (VIC)</a></li>
<li>Bloomingdale Bog Trail (Bloomingdale)</li>
<li>Henry’s Woods Trail (Lake Placid)</li>
<li>John Brown Farm Trails (Lake Placid)</li>
<li>Heaven Hill Trails (Lake Placid)</li>
<li>Penninsula Trails (Lake Placid)</li>
</ul>
</div>
<div class="noexpandFirst"> <a href="adirondack-habitats.html" title="Adirondack Habitats"><strong>HABITATS</strong></a></div>
<div class="noexpandSecond"> <a href="adirondack-wetlands.html" title="Adirondack Wetlands">Adirondack Wetlands</a></div>
<div class="noexpandSecond"> <a href="adirondack-mixed-wood-forest.html" title="Adirondack Mixed Wood Forest">Mixed Wood Forest</a></div>
<div class="noexpandSecond"> <a href="adirondack-northern-hardwood-forest.html" title="Adirondack Northern Hardwood Forest">Northern Hardwood Forest</a></div>
<div class="noexpandSecond"> <a href="adirondack-forest-succession.html" title="Adirondack Forest Succession">Forest Succession</a></div>
<div class="noexpandFirst"> <a href="adirondack-plants.html" title="Adirondack Plant Life"><strong>PLANTS</strong></a></div>
<button class="accordionSecond">Trees</button>
<div class="panel">
<ul>
<li><a href="adirondack-trees.html">Adirondack Trees</a></li>
<li><a href="trees-of-the-adirondacks-american-beech-fagus-grandifolia.html">American Beech (<em>Fagus grandifolia</em>)</a></li>
<li><a href="trees-of-the-adirondacks-balsam-fir-abies-balsamea.html">Balsam Fir (<em>Abies balsamea</em>)</a></li>
<li><a href="trees-of-the-adirondacks-bigtooth-aspen-populus-grandidentata.html">Bigtooth Aspen (<em>Populus</em> <em>grandidentata</em>)</a></li>
<li><a href="trees-of-the-adirondacks-black-cherry-prunus-serotina.html">Black Cherry (<em>Prunus serotina</em>)</a></li>
<li><a href="trees-of-the-adirondacks-black-spruce-picea-mariana.html">Black Spruce (<em>Picea mariana</em>)</a></li>
<li><a href="trees-of-the-adirondacks-eastern-hemlock-tsuga-canadensis.html">Eastern Hemlock (<em>Tsuga canadensis</em>)</a></li>
<li><a href="trees-of-the-adirondacks-eastern-white-pine-pinus-strobus.html">Eastern White Pine (<em>Pinus strobus</em>)</a></li>
<li><a href="trees-of-the-adirondacks-paper-birch-betula-papyrifera.html">Paper Birch (<em>Betula papyrifera </em>var.<em>papyrifera</em>)</a></li>
<li><a href="trees-of-the-adirondacks-red-maple-acer-rubrum.html">Red Maple (<em>Acer rubrum</em>)</a></li>
<li><a href="trees-of-the-adirondacks-red-spruce-picea-rubens.html">Red Spruce (<em>Picea rubens</em>)</a></li>
<li><a href="trees-of-the-adirondacks-striped-maple-acer-pensylvanicum.html">Striped Maple (<em>Acer pensylvanicum</em>)</a></li>
<li><a href="trees-of-the-adirondacks-sugar-maple-acer-saccharum-Marshall.html">Sugar Maple (<em>Acer saccharum</em>)</a></li>
<li><a href="trees-of-the-adirondacks-tamarack-larix-laricina.html">Tamarack (<em>Larix laricina</em>)</a></li>
<li><a href="trees-of-the-adirondacks-yellow-birch-betula-alleghaniensis.html">Yellow Birch (<em>Betula alleghaniensis</em>)</a></li>
<li><a href="adirondack-tree-list.html">Adirondack Tree List</a></li>
</ul>
</div>
<button class="accordionSecond">Shrubs</button>
<div class="panel">
<ul>
<li><a href="adirondack-shrubs.html">Adirondack Shrubs</a></li>
<li><a href="adirondack-shrubs-bog-laurel-kalmia-polifolia.html">Bog Laurel (<em>Kalmia polifolia</em>)</a></li>
<li><a href="adirondack-shrubs-bog-rosemary-andromeda-polifolia.html">Bog Rosemary (<em>Andromeda polifoli</em>a)</a></li>
<li><a href="adirondack-shrubs-northern-wild-raisin-viburnum-nudum-l-var-cassinoides.html">Northern Wild Raisin (<em>Viburnum nudum</em>*var*<em>cassinoides</em>)</a></li>
<li><a href="adirondack-shrubs-red-elderberry-sambucus-racemosa-l-var-racemosa.html">Red Elderberry*(<em>Sambucus racemosa</em>)</a></li>
<li><a href="adirondack-shrubs-white-meadowsweet-spiraea-alba-var-latifolia.html">White Meadowsweet*(<em>Spiraea alba</em>*var*<em>latifolia</em>)</a></li>
</ul>
</div>
<div class="noexpandSecond"><a href="adirondack-wildflowers.html" title="Adirondack Wildflowers">Wildflowers</a></div>
<div class="noexpandSecond"><a href="adirondack-mosses.html" title="Adirondack Moss">Moss</a></div>
<div class="noexpandSecond"><a href="adirondack-ferns.html" title="Adirondack Ferns">Ferns</a></div>
<div class="noexpandFirst">
<a href="adirondack-wildlife.html" title="Adirondack Wildlife"><strong>WILDLIFE</strong></a></div>
<div class="noexpandFirst">
<a href="adirondack-fungi.html" title="Adirondack Fungi"><strong>FUNGI</strong></a></div>
<script src="/wildadirondacksaccordion.js"></script>
<!-- end .asideLeft -->
</aside>
Bookmarks