I'm using Americommerce and they use widgets for everything, I have a widget that shows a users recently viewed products, but when they haven't yet viewed anything the spot is just empty.
I'd like to display a message. The problem I'm having is detecting if the widget is empty. I tried wrapping the widget with a div(#cond)
but that didn't help, I tried using JavaScript to check to see if the class ul.side_carousel
existed and also if there were any contents in div#cond
. No matter what I do, I can't get it to work right.
The script below is the closest I've gotten. Upon a fresh visit to the site the div displays the 'No Items to Display' message from the script but then if I click on a product and then go back to the homepage the div is no longer empty, it is showing the recently viewed product (this is good!), but its also showing the 'No Items to Display' message (this is bad), I'm not sure why that's even showing up since the div is no longer null.
<div class="col-sm-2 side hidden-xs hidden-sm">
<h3>Recently Viewed:</h3>
<div id="cond">
<ac:widget id="CAROUSEL23626" type="Carousel" scrollby="4" displayorientation="Vertical" enablemergecode="True" categoryid="293" repeatabletype="RecentlyViewedItems" rotatorstartdate="10/23/2019" productlistid="9" displaycount="8">
<ac:visibilityarea id="dvControl">
##INCLUDESTYLESHEET[/store/inc/bxslider/jquery.bxslider.css]##
<ac:layoutarea id="Layout">
<ul class="side-carousel">$$GROUP$$</ul>
</ac:layoutarea>
<ac:layoutarea id="Group">
$$ITEM$$
</ac:layoutarea>
<ac:layoutarea id="Item">
<li>
<!--$$PRODUCTNAME$$-->
$$PHOTOWITHLINK$$
<div class="FeaturedItemsRating">$$OVERALLRATING$$</div>
<div class="saleprice">$$PRICE$$</div>
</li>
</ac:layoutarea>
<ac:layoutarea id="Script">
<script>
$(function () {
$("$$SELECTOR$$ ul").bxSlider({
minSlides: 4,
maxSlides: $$VISIBLESLIDES$$,
moveSlides: $$SCROLLBY$$,
mode: '$$ORIENTATION$$',
slideWidth: $$WIDTH$$,
slideMargin: 10
});
});
</script>
</ac:layoutarea>
##INCLUDESCRIPTBOTTOM[/store/inc/bxslider/jquery.bxslider.js]##
</ac:visibilityarea>
</ac:widget>
</div>
<script>
var bond_div = document.getElementById("CAROUSEL23626");
var cond_div = document.getElementById("cond");
if (bond_div === null) {
cond_div.innerHTML = "<H3>No Items to Display</H3>";
}
</script>
$$CAROUSEL23626$$
</div>