some bugs, started working on search-results

This commit is contained in:
infeeeee
2019-08-01 20:47:57 +02:00
parent 7ea5c5d1e8
commit 02e6844883
6 changed files with 395 additions and 296 deletions

View File

@@ -87,12 +87,18 @@
//isArchive
const isArchive = bodyHasClass('archive', 'category-esemeny')
//isSearch
const isSearch = bodyHasClass('search-results')
//isEsemeny
const isEsemeny = bodyHasClass('category-esemeny')
//isSingle
const isSingle = bodyHasClass('single')
var isMasonryPage = isArchive || isHome || isSearch
/* ========================================================================== */
@@ -205,7 +211,7 @@
if (!isMobile) {
if (isHome || isArchive) {
if (isMasonryPage) {
//no overflowY
$('html').css({ overflowY: "hidden" })
@@ -216,8 +222,8 @@
//wrapping for big-small difference
if (isHome) {
$('.hbox:first-child').wrap('<div class="home-wrapper-big home-wrapper-1"></div>').addClass("home-big")
$('.hbox:nth-child(2)').wrap('<div class="home-wrapper-big home-wrapper-2"></div>').addClass("home-big")
$('.hbox:first-child').wrap('<div class="home_wrapper-big home_wrapper-1"></div>').addClass("home-big")
$('.hbox:nth-child(2)').wrap('<div class="home_wrapper-big home_wrapper-2"></div>').addClass("home-big")
wrapArticles = $(".hbox").length - 2
}
@@ -252,19 +258,19 @@
j = i + 3
}
var k = i + 1
$(".home-thumbnail-small-" + k).wrapAll('<div class="home-wrapper-small home-wrapper-' + j + '"></div>')
$(".home-thumbnail-small-" + k).wrapAll('<div class="home_wrapper-small home_wrapper-' + j + '"></div>')
if (i == 0) {
$(".home-wrapper-" + j).addClass("home-wrapper-s1")
$(".home_wrapper-" + j).addClass("home_wrapper-s1")
}
}
//add bottom scrollbar to div on bottom:
if (bottomScrollHeight > 0) {
$(".home-wrapper-big .metadata").css({ bottom: bottomScrollHeight })
$(".home_wrapper-big .metadata").css({ bottom: bottomScrollHeight })
} else {
$(".home-wrapper-big .metadata").addClass("noBottomScrollbar")
$(".home_wrapper-big .metadata").addClass("noBottomScrollbar")
}
}//isHome || isArchive end
}//isMasonryPage end
}// !isMobile end
//returns three random numebers 0-5
@@ -316,7 +322,7 @@
})(jQuery);
$(".home-wrapper-small").each(function () {
$(".home_wrapper-small").each(function () {
$(this).addRandomClasses()
})
@@ -324,7 +330,7 @@
/* ----------------------------- Snap on mobile ----------------------------- */
// if (isMobile) {
// if (isHome || isArchive) {
// if (isMasonryPage) {
// $("article.post").SnapScroll({
// animateDuration: 400
// });
@@ -340,7 +346,11 @@
/* ---------------------------- Scroll on desktop --------------------------- */
//scroll to the next or prev article
/**
* scroll to next or previous section
* @param {jQuery} target put here currElem
* @param {String} direction "next" of "prev"
*/
function homeScroll(target, direction) {
// console.log(target.attr('class'))
var nextelem;
@@ -370,7 +380,14 @@
}
}
console.log("scrolling to: " + nextelem.attr("class") + " - offset: " + offset)
$('html, body, .wrapper').stop().animate({ scrollLeft: offset }, 800);
$('html, body, .wrapper').stop().animate({ scrollLeft: offset }, 800, function () {
//hide the left arrow if on start
if (nextelem.hasClass("home_wrapper-1")) {
$(".header-scroll-left").hide()
} else {
$(".header-scroll-left").show()
}
});
return nextelem;
}
@@ -399,7 +416,7 @@
//checking the current scroll location for refresh:
if (!isMobile) {
if (isHome || isArchive) {
if (isMasonryPage) {
const homeDivWidths = []
const homeFullWidths = []
homeDivWidths[0] = 0
@@ -414,8 +431,8 @@
}
homeFullWidths[i] = homeDivWidths[i] + prev
}
console.log(homeDivWidths)
console.log(homeFullWidths)
// console.log(homeDivWidths)
// console.log(homeFullWidths)
var currscroll = $('html').scrollLeft()
@@ -424,11 +441,18 @@
});
var scrollnr = homeFullWidths.indexOf(closest) + 1
console.log("currscroll", currscroll, "scrollnr", scrollnr, "closest", closest)
currElem = $(selector + ':nth-child(' + scrollnr + ')')
if (currElem.hasClass("home_wrapper-1")) {
$(".header-scroll-left").hide()
}
// console.log("currscroll", currscroll, "scrollnr", scrollnr, "closest", closest)
console.log("start location: " + currElem.attr("class"))
}
}
@@ -436,7 +460,7 @@
$(window).on('wheel DOMMouseScroll', function (e) {
//e.preventDefault();
if (!isMobile) {
if (isHome || isArchive) {
if (isMasonryPage) {
if (scrolltimer) {
return false;
}
@@ -477,7 +501,7 @@
return
} else {
if (!isMobile) {
if (isHome || isArchive) {
if (isMasonryPage) {
if (!$('.search-bar *').is(':focus')) {
// console.log("keydown!")
kd = true
@@ -509,7 +533,7 @@
//check for keyup for disabling counter
$('html *:not(input)').keyup(function (event) {
if (!isMobile) {
if (isHome || isArchive) {
if (isMasonryPage) {
if (!$('.search-bar *').is(':focus')) {
kd = false
}
@@ -532,8 +556,8 @@
var wrapnum = articleWrapCounter + 2
$("#content>article")
.addClass("home-small home-thumbnail-small-" + articleWrapCounter)
.wrapAll('<div class="home-wrapper-small home-wrapper-' + wrapnum + '"></div>')
$(".home-wrapper-" + wrapnum).addRandomClasses()
.wrapAll('<div class="home_wrapper-small home_wrapper-' + wrapnum + '"></div>')
$(".home_wrapper-" + wrapnum).addRandomClasses()
//Scroll to new element
currElem = homeScroll(currElem, "next")
@@ -653,9 +677,13 @@
})
/**
* finds a name of a class, from the first element
* @param {Array} classlist the list of classes to search from as an array
* @param {String} startString the string to search for
* @param {String} sep the separator that separates the startString from the rest of the classname
*/
function findClassByStart(classlist, startString, sep = "-") {
//finds a name of a class, from the first elemnt
var fullstring
for (let i = 0; i < classlist.length; i++) {
let curr = classlist[i].split(sep)