work on homepage

This commit is contained in:
2019-06-09 19:55:23 +02:00
parent 647e333a16
commit 027ad5511c
17 changed files with 396 additions and 381 deletions

View File

@@ -203,12 +203,6 @@
$(".home-wrapper-small").each(function () {
// var rn = randomNumbers()
// for (let i = 0; i < rn.length; i++) {
// var j = rn[i] +1
// $(this).children("article:nth-child(" + j + ")").addClass("random")
// }
// addRandomClass($(this))
$(this).addRandomClasses()
})
@@ -242,14 +236,25 @@
nextelem = target
}
// var offset = ($(nextelem).offset().left) - desktophomemargin
var offset = ($(nextelem).position().left)
//if loadmore is the next, do not scroll, but load
if ($(nextelem).attr("class") == "misha_loadmore") {
loadmore()
return target
} else {
//from the third wrap modify the offset
var wNum = parseInt($(nextelem).attr("class").split(" ")[1].split("-")[2])
if (wNum > 3) {
offset = offset - desktophomemargin
}
}
console.log("scrolling to: " + nextelem.attr("class") + " - offset: " + offset)
$('html, body').stop().animate({ scrollLeft: offset }, 800);
$('html, body, .wrapper').stop().animate({ scrollLeft: offset }, 800);
return nextelem;
}
//extractDelta(e): extract the scroll length from an event
//extractDelta(e): extract the scroll direction and length from an event
function extractDelta(e) {
if (e.wheelDelta) {
return e.wheelDelta;
@@ -268,11 +273,12 @@
}
}
var currElem = $('article:first-child')
const selector = 'main>#content>div'
var currElem = $(selector + ':first-child')
//checking the current scroll location for refresh:
if (isHome & !isMobile) {
var selector = 'main>#content>div'
var articleWidth = $(selector + ':first-child')[0].getBoundingClientRect().width
var currscroll = $('html').scrollLeft()
var scrollnr = Math.floor(currscroll / articleWidth) + 1
@@ -333,8 +339,83 @@
currElem = homeScroll(currElem, "next")
})
/* ----------------------------- loadmore click ----------------------------- */
$('.misha_loadmore').click(function (e) {
e.preventDefault()
loadmore($(this))
});
var noMoreAjax = false
function loadmore(element){
if (noMoreAjax) {
console.log("no more ajax")
return false
}
// var button = $(this),
var button = element || $('.misha_loadmore'),
data = {
'action': 'loadmore',
'query': misha_loadmore_params.posts, // that's how we get params from wp_localize_script() function
'page': misha_loadmore_params.current_page
};
button.trigger("moreload-start")
$.ajax({ // you can also use $.post here
url: misha_loadmore_params.ajaxurl, // AJAX handler
data: data,
type: 'POST',
beforeSend: function (xhr) {
button.html('<p>Betöltés...</p>'); // change the button text, you can also add a preloader image
},
success: function (data) {
if (data) {
if (data.length < 100) {
button.children().remove(); // if last page, remove the button
noMoreAjax = true
return false
}
button.html('<a>Mutass többet</a>').before(data); // insert new posts
misha_loadmore_params.current_page++;
button.trigger("moreload-finish")
console.log(data.length)
// you can also fire the "post-load" event here if you use a plugin that requires it
// $( document.body ).trigger( 'post-load' );
} else {
button.children().remove(); // if no data, remove the button as well
noMoreAjax = true
console.log("no data")
}
}
});
}
/* ------------------------------ hover on home ----------------------------- */
//hover on big articles
$(".home-big h2>a").hover(function () {
let cc = $(this)
//make width more
cc.parents("article").addClass("hovered")
//change bg
// $(this).parents('article').animate({})
//animate metadata
//show excerpt
}, function () {
let cc = $(this)
//width back to normal
cc.parents("article").removeClass("hovered")
})
//hover on small articles
function showTitle(th) {
$(th).children("h2").show()
$(th).children(".metadata").addClass("vis")
@@ -358,6 +439,7 @@
}
}, '.home-small');
//touch on small articles
$(document).on({
'touchend': function (e) {
e.preventDefault()