Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- //Calls getOddNewImages every 10sec and updates every even/odd image based on isOdd
- var isOdd = false;
- setInterval(function () {
- isOdd = getOddNewImages(isOdd);
- }, 10000);
- getOddNewImages(); //hva gjor denne?
- });
- function getOddNewImages(isOdd) {
- var documentHeight = $(document).height();
- $.get('{event-url}')
- .done(function (data) {
- if (data < 1) return;
- //Randomize order of json
- fisherYatesShuffle(data);
- //Get all image tags
- var imgLst = $('img').map(function () { return this.src; }).get();
- if (imgLst < 1) {
- //Create new grid of images
- imgLst = createImageGrid(data.length);
- }
- var imagesData = JSON.parse(data);
- var cImageNo = 0;
- for (var i = 0; i < imgLst.length; i++) {
- if (!isOdd && i % 2 != 0) {continue;} //if even and current index is odd
- if (isOdd && i % 2 == 0) {continue;} //if odd and current index is even
- //update image
- imgLst[0].Attr("src", imgLst[cImageNo]);
- cImageNo++;
- };
- });
- //I didnt decode this, probably important?
- setTimeout(function () {
- var imageWrapperHeight = $('#image-wrapper').height();
- if (documentHeight < imageWrapperHeight) {
- remove_last_image();
- }
- }, 500);
- return !isOdd;
- }
- function createImageGrid(totImages) {
- //Logikk for å lage riktig grid basert på
- for (i = 0; i < imagesData.images.length; i++) {
- var imageWrapperHeight = $('#image-wrapper').height();
- if (documentHeight >= (imageWrapperHeight)) {
- $('#appending_images').append("<li><img src=''></li>");
- }
- }
- return $('img').map(function () { return this.src; }).get();
- }
- function fisherYatesShuffle(sourceArray) {
- for (let n = 0; n < sourceArray.length - 1; n++) {
- var k = n + Math.floor(Math.random() * (sourceArray.length - n));
- var temp = sourceArray[k];
- sourceArray[k] = sourceArray[n];
- sourceArray[n] = temp;
- }
- }
- function remove_last_image() {
- $('#appending_images li > img:last').css('display', 'none');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement