Created
January 19, 2017 13:27
-
-
Save salami-art/c84071eeb825e1d42234aca9a4d234bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates news card inner html | |
var postInnerHtml = function(post) { | |
content = ''; | |
content += '<div style="background:url('+post.image+') center center no-repeat transparent; background-size: cover;text-align:center" ><a href="'+post.url+'" title="'+post.linkTitle+'" target="_blank"> <h5 class="titolo-news" style="margin-top:5px;" ><img src="img/spacer.gif" class="youtubeIcon" /></a></div>'; | |
content += '<a href="'+post.url+'" title="'+post.title+'" target="_blank"> <h5 class="titolo-news" style="margin-top:5px;" >'+post.title+'</h5></a>'; | |
return content; | |
} | |
var createSliderItem = function(data, index) { | |
// Set as active slide if first | |
var activeClass = index == 0 ? ' active' : '' | |
// Initialize the slider item | |
var item = document.createElement('div'); | |
item.className = 'item' + activeClass; | |
// Wrap content | |
for (var i = data.length - 1; i >= 0; i--) { | |
var post = data[i] | |
var postItem = document.createElement('div'); | |
postItem.className = 'post-item col-sm-3'; | |
var itemContent = document.createElement('div'); | |
itemContent.className = 'news'; | |
// Add post data to wrapper | |
itemContent.innerHTML = postInnerHtml(post); | |
// Wrap things up | |
postItem.appendChild(itemContent); | |
item.appendChild(postItem); | |
} | |
// Add Indicator | |
var indicatorsContainer = document.getElementById('myCarouselPosts').querySelector('ol.carousel-indicators'); | |
var indicator = document.createElement('li'); | |
indicator.setAttribute('data-target', '#myCarouselPosts'); | |
indicator.setAttribute('data-slide-to', index) | |
indicator.className = activeClass | |
indicatorsContainer.appendChild(indicator); | |
return item; | |
} | |
var initSlider = function(data) { | |
var container = document.getElementById('resultsRecentPost'); | |
var posts = [], size = 4; | |
var content = ''; | |
// Split data in chunks of 4 | |
while (data.length > 0) | |
posts.push(data.splice(0, size)); | |
for (var i = 0 ; i < posts.length; i++) { | |
// append the Html | |
container.appendChild(createSliderItem(posts[i], i)); | |
} | |
$('#myCarouselPosts .carousel-control').show(); | |
} | |
$(document).ready(function(){ | |
window.bv_totalPosts = []; | |
$.when( | |
// Retrieve the data from API ( Blog Posts ) | |
$.getJSON( | |
'recent_posts.json.php', | |
function(data){ | |
// Normalize the data | |
data = data.posts.map(function(post) { | |
post.image = post.attachments[0].url; | |
post.title = post.title; | |
post.linkTitle = post.attachments[0].title; | |
return post; | |
}); | |
// Add to the main scope | |
window.bv_totalPosts = window.bv_totalPosts.concat(data); | |
} | |
), | |
// Retrieve the data from API ( Video Contents ) | |
$.getJSON( | |
'picture_images.json.php', | |
function(data){ | |
// Normalize the data | |
data = data.map(function(post) { | |
post.image = post.youtube_thumb_url; | |
post.title = post.name; | |
post.linkTitle = post.name; | |
return post; | |
}); | |
// Add to the main scope | |
window.bv_totalPosts = window.bv_totalPosts.concat(data); | |
} | |
) | |
).then(function() { | |
initSlider(window.bv_totalPosts); | |
}); | |
}); | |
$(document).on("click", "tr.result-tr", function () { | |
window.open($(this).find('a').attr('href'),'_blank'); | |
}); | |
$(document).on("click", ".carousel-control", function (e) { | |
e.preventDefault(); | |
}); | |
$(document).on("click", "tr.result-tr a", function (e) { | |
e.preventDefault(); | |
}); | |
$(document).on("mouseenter mouseleave", "tr.result-tr", function () { | |
$(this).toggleClass('hover'); | |
}); | |
$(window).resize(function () { | |
setCookie("wsize", $("body").height(), 1); | |
}); | |
$('.reload_form').click(function () { | |
location.reload(true); | |
}); | |
$( "a.more" ).on( "click", function(e) { | |
$(this).parent().parent().parent().css('overflow','initial').css('height','auto'); | |
e.preventDefault(); | |
$(this).parent().css('display','none'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment