US news — RT International

US news — RT International

len) throw new RangeError(“getRandom: more elements taken than available”); while (n–) { var x = Math.floor(Math.random() * len); result[n] = arr[x in taken ? taken[x] : x]; taken[x] = –len in taken ? taken[len] : len; } return result; }; var shuffle = function(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle… while (0 !== currentIndex) { // Pick a remaining element… randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; }; var appendHtml = function() { if (!items.length) { return; } var html = ‘

    ‘; for (var item in items) { html += ‘

  • ‘ + ” + (items[item].cover ? ‘]]>

‘ : ” )+ ‘

‘ + items[item].title + ‘

‘ + ” + ” + ” } html += ”; bestcrosslinks.innerHTML += html; }; var getData = function() { ajax(‘/widget/bestcrosslinks/json’, function (response) { if (response) { try { var docs = JSON.parse(response).docs; docs = shuffle(docs); items = docs.length >= countOnPage ? getRandom(docs, countOnPage) : docs; appendHtml(); } catch (e) {console.log(‘Error parse data: ‘, e);} } }) }; var init = function() { content = document.getElementsByClassName(“static-66_high-100”); side = document.getElementsByClassName(“static-33_high-100”); if (!content.length || !side.length) { return; } contentOffsetHeight = content[0].offsetHeight; sideOffsetHeight = side[0].offsetHeight; var res = contentOffsetHeight – sideOffsetHeight; if (res > 0) { countOnPage = Math.floor(res / 280); countOnPage = countOnPage 10 ? 10 : countOnPage; } getData(); }; document.addEventListener(“DOMContentLoaded”, function() { setTimeout(init, 2000); }); var moreButton = document.querySelector(‘.js-listing__more’); moreButton.addEventListener(‘click’, function () { ajax(‘/widget/bestcrosslinks/json’, function (response) { if (response) { try { var docs = JSON.parse(response).docs; docs = shuffle(docs); items = docs.length >= 3 ? getRandom(docs, 3) : docs; appendHtml(); } catch (e) {console.log(‘Error parse data: ‘, e);} } }) }); })(); isJqueryInit(function() { $(function () { var interval = setInterval(function () { var $links = $(‘#bestcrosslinks’).find(‘a.bestcrosslinks__link[href]’); if ($links.is(‘a’)) { clearInterval(interval); $links.on(‘click’, function (e) { e.preventDefault(); var link = $(this).attr(‘href’); ga(‘send’, ‘event’, ‘Popular_widget’, ‘Click’, link); setTimeout(function () { window.location.href = link; }, 300); }); return null; } return null; }, 300); }); });

Related Post

Be the first to comment

Leave a Reply

Your email address will not be published.


*