I’ve been out of scripting for a good time and thought to make a “quick” upgrade to this page…
http://www.solartiming.com/store--e-books-TMP.php
The original order of the books is shown when it loads.
For the category Newest, I made data-rev attributes so I could reverse sort them with the newest ones on top. This works.
Now, this seems to be “holding on” to the code, or I can’t find what I have to reset, so that clicking Show ALL books will show the original order again…
I’ve tried two methods that I can’t get to work …
(1) Using the same sort code, but with data-srt attribute that I added for that (see code)
(2) Using cloning of #ebooks div and replaceWith
The code when clicking the picker is …
$("ul#picker li").click(function() { // clicking cat picker
$("ul#picker li").removeClass("active"); // (remove li's class="active" if there is one)
var $cat = $(this).data("cat"); // get content of data-cat=""
$(this).addClass("active"); // add class="active" to newly chosen category
var $xtra = $("#picker li.active").data("cat"); // store cat so we can later hide $xtra-xtra
$("div[class$='-xtra']").hide(); // hide all '[cat]-extra' divs
$("hr").removeClass("hide"); // make all <hr> visible again
if ($cat==="ALL") { // Show ALL
$(".book").show();
$(".book").sort(function (a, b) { // sort all .book divs to original order [WIP]
var contentA =parseInt( $(a).data("srt"));
var contentB =parseInt( $(b).data("srt"));
}).appendTo("#ebooks");
$(".book").last().children("hr").addClass("hide"); // hide <hr> after last .book (if there is one)
return false; // STOP here
}
$(".book").show(); // show(reset) full lists
$(".book, .show").not("." + $cat).hide(); // hide all, except selected Cat divs
$("." + $xtra +'-xtra').show(); // show [cat]-xtra divs
$('.read-more').addClass('hide'); // close up any opened 'Read more' blocks
$('.read-more-show').removeClass('hide');
if ($cat==="New") { // if Newest was clicked
$("."+$cat).sort(function (a, b) { // reverse sort selected cat divs w help of data-rev="nr" (recent on top)
var contentA =parseInt( $(a).data("rev"));
var contentB =parseInt( $(b).data("rev"));
return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
}).appendTo("#ebooks");
};
$("."+$cat).last().children("hr").addClass("hide"); // hide <hr> after last .book (if there is one)
});
Thank You for looking!