1if (!imageBasePathGallery) var imageBasePathGallery = 'img/'; 2if (!GALLERY_DATA_URL) var GALLERY_DATA_URL = "http://monte.mpa-dev.de/de/time-out-gallery/?tx_mpmontetimeout_gallery%5Baction%5D=ajaxGetGalleryData"; 3// image = imageId 4// type = like, fb, pi, in, tw, gp, tu, wa 5//var GALLERY_LIKE_URL = "http://monte.mpa-dev.de/de/time-out-gallery/?tx_mpmontetimeout_gallery%5Baction%5D=ajaxGalleryCount&tx_mpmontetimeout_gallery[image]=&tx_mpmontetimeout_gallery[type]="; 6if(!GALLERY_LIKE_URL) var GALLERY_LIKE_URL = "http://monte.mpa-dev.de/de/time-out-gallery/?tx_mpmontetimeout_gallery%5Baction%5D=ajaxGalleryCount&"; 7// when set, autoload detail view 8if(!timeoutImageId) var timeoutImageId;// = 129; 9 10if (!galleryLanguageStrings) var galleryLanguageStrings = { 11 'newest_button': 'Newest', 12 'most_liked_button': 'Most liked', 13 'winners_button': 'Winners', 14 'all_button': 'All', 15 'gallery_page_text_pre': 'Page', 16 'gallery_page_text_middle': 'of', 17 'num_likes': 'likes', 18 'winner_daily_title': 'The winner of the day', 19 'winner_weekly_title': 'Winner of the week', 20 'winner_grand_prize': 'Winner of the Prize' 21}; 22 23 24if (!galleryImages) var galleryImages = []; 25var galleryImagesSorted = []; 26var galleryImageIndex = 0; 27var currentPage = 0; 28var numberPages = 0; 29var teaserImagesPerpage = 15; 30var wasGalleryMobile = undefined; 31 32var gallery_states = { 33 GALLERY_NEWEST : 'state-gallery-newest',
34 GALLERY_MOST_LIKED : 'state-gallery-most-liked', 35 GALLERY_WINNERS : 'state-gallery-winners', 36 GALLERY_ALL : 'state-gallery-all', 37 PICTURE : 'state-picture' 38}; 39var previousGalleryState = gallery_states.GALLERY_NEWEST; 40var currentGalleryState = previousGalleryState; 41 42function initialiseGallery() { 43 initialiseGalleryButtons(); 44 initialiseNextAndPreviousButtons(); 45 initialisePictureNextAndPreviousButtons(); 46 initialiseReturnToGalleryButton(); 47 initialiseTeaserImages(); 48 initialiseLikeButtons(); 49 initialiseGallerySocialButtons(); 50 initialiseLanguageStringsGallery(); 51 52 goToStateGallery(gallery_states.GALLERY_NEWEST); 53 setButtonActive($('#newest-button')); 54 55 //sortImagesByNewest(); 56 onWindowResizeGallery(); 57 refreshGalleryData(); 58 59 window.addEventListener('resize', onWindowResizeGallery, true); 60 61 // listen from instructions from the create and win module to refresh the gallery data 62 $(document).on("timeoutUpdateGallery", refreshGalleryData); 63} 64var languageName = $('html').attr('lang'); 65 66function initialiseLanguageStringsGallery() { 67 $('#newest-button').html(galleryLanguageStrings['newest_button']); 68 $('#most-liked-button').html(galleryLanguageStrings['most_liked_button']); 69 $('#winners-button').html(galleryLanguageStrings['winners_button']); 70 $('#all-button').html(galleryLanguageStrings['all_button']); 71} 72 73function refreshGalleryData() { 74 $.ajax({ 75 dataType: "json", 76 url: GALLERY_DATA_URL, 77 success: onGalleryDataReceived 78 }); 79 80 $('#gallery-spinner')[0].style.display = 'block'; 81} 82 83function onGalleryDataReceived(data) { 84 $('#gallery-spinner')[0].style.display = 'none'; 85 socialUrls = data.socialUrls; 86 galleryImages = data.galleryImages; 87 88 89 90 91 // if we have been asked to display a gallery image, display it, otherwise show newest photos 92 if (timeoutImageId >= 0) { 93 $('#page_11').addClass('in'); 94 scrollTo('page_11'); 95 //sortImagesByNewest(); 96 onNewestClicked(); 97 setButtonActive($('#newest-button')); 98 var posInArray = findWithAttr(galleryImagesSorted, 'id', timeoutImageId); 99 goToPictureState(posInArray); 100 timeoutImageId = undefined; 101 } else { 102 onNewestClicked(); 103 setButtonActive($('#newest-button')); 104 } 105} 106 107function initialiseGallerySocialButtons() { 108 $('#facebook_gallery').click(function(){ 109 onSocialButtonClicked('fb') 110 }); 111 $('#twitter_gallery').click(function(){ 112 onSocialButtonClicked('tw') 113 }); 114 $('#pinterest_gallery').click(function(){ 115 onSocialButtonClicked('pi') 116 }); 117 $('#instagram_gallery').click(function(){ 118 onSocialButtonClicked('in') 119 }); 120 $('#whatsapp_gallery').click(function(){ 121 onSocialButtonClicked('wa') 122 }); 123} 124 125function onSocialButtonClicked(type) { 126 var imageId = galleryImagesSorted[galleryImageIndex].id; 127 if(type == 'wa') { 128 window.location = socialUrls[imageId][type]; 129 } else { 130 window.open(socialUrls[imageId][type],'_system'); 131 } 132 133 134 likeImage(imageId, type); 135 var posInArray = findWithAttr(galleryImages, 'id', imageId); 136 // remember that it has been liked 137 galleryImages[posInArray].counts[type]++; 138 139 // also update the object in the sorted array 140 galleryImagesSorted[galleryImageIndex] = galleryImages[posInArray]; 141 setSocialShareCounts(); 142} 143 144function onWindowResizeGallery() { 145 //console.log('onResize'); 146 updateWidthOfFrameGallery(); 147 setIsMobile(); 148 149 if (currentGalleryState == gallery_states.PICTURE) { 150 restoreImage(); 151 } 152 153 //if (wasGalleryMobile !== isMobile()) { 154 // update the UI for mobile mode 155 updateGalleryValues(); 156 updateGalleryNavigation(); 157 displayTeaserImages(); 158 //} 159 160 wasGalleryMobile = isMobile(); 161} 162 163function updateGalleryValues() { 164 if (isMobile()) { 165 teaserImagesPerpage = 8; 166 } else if (isTablet()) { 167 teaserImagesPerpage = 9; 168 } else if (isLargeDesktop()) { 169 teaserImagesPerpage = 15; 170 } else { 171 teaserImagesPerpage = 12; 172 } 173 //console.log(teaserImagesPerpage); 174 numberPages = Math.ceil(galleryImagesSorted.length / teaserImagesPerpage); 175} 176 177function initialiseReturnToGalleryButton() { 178 $('#back-to-gallery').click(goToPreviousStateGallery); 179} 180 181function initialiseLikeButtons(){ 182 $('.like-image').click(function(event) { 183 var posInSortedArray = $(event.target.parentNode.parentNode).find('.teaser-image')[0].value;
184 onLikeClicked(posInSortedArray, event.target); 185 }); 186 187 $('.picture-like-image').click(function(event) { 188 onLikeClicked(galleryImageIndex, event.target); 189 }); 190} 191 192function onLikeClicked(posInSortedArray, likeImageElement) { 193 var posInArray = findWithAttr(galleryImages, 'id', galleryImagesSorted[posInSortedArray].id); 194 195 // if not already liked 196 if (galleryImages[posInArray].alreadyLiked !== true) { 197 likeImageElement.src = imageBasePathGallery+'like_clicked.png'; 198 199 // remember that it has been liked 200 galleryImages[posInArray].alreadyLiked = true; 201 galleryImages[posInArray].counts.like++; 202 203 updateLikeButton(likeImageElement, posInArray); 204 205 // also update the object in the sorted array 206 galleryImagesSorted[posInSortedArray] = galleryImages[posInArray]; 207 208 // send a request to server 209 likeImage(galleryImages[posInArray].id, 'like'); 210 } 211} 212 213function updateLikeButton(likeImageElement, posInArray) { 214 if (galleryImages[posInArray].alreadyLiked == true) { 215 likeImageElement.src = imageBasePathGallery+'like_clicked.png'; 216 217 } else { 218 likeImageElement.src = imageBasePathGallery+'like.png'; 219 } 220 updateLikeText($(likeImageElement.parentNode).find('.num-likes'), galleryImages[posInArray].counts.like); 221} 222 223function initialiseGalleryButtons() { 224 $('#newest-button').click(onNewestClicked); 225 $('#most-liked-button').click(onMostLikedClicked); 226 $('#winners-button').click(onWinnersClicked); 227 $('#all-button').click(onAllClicked); 228} 229 230function onNewestClicked() { 231 goToStateGallery(gallery_states.GALLERY_NEWEST); 232 setButtonActive(this); 233 sortImagesByNewest(); 234 currentPage = 0; 235 updateGalleryNavigation(); 236 displayTeaserImages(); 237} 238 239function onMostLikedClicked() { 240 goToStateGallery(gallery_states.GALLERY_MOST_LIKED); 241 setButtonActive(this); 242 sortImagesByMostLiked(); 243 currentPage = 0; 244 updateGalleryNavigation(); 245 displayTeaserImages(); 246} 247 248function onWinnersClicked() { 249 goToStateGallery(gallery_states.GALLERY_WINNERS); 250 setButtonActive(this); 251 sortImagesByWinners(); 252 currentPage = 0; 253 updateGalleryNavigation(); 254 displayTeaserImages(); 255} 256 257function onAllClicked() { 258 goToStateGallery(gallery_states.GALLERY_ALL); 259 setButtonActive(this); 260 sortImagesByAll(); 261 currentPage = 0; 262 updateGalleryNavigation(); 263 displayTeaserImages(); 264} 265 266function setButtonActive(button){ 267 var buttons = $('.gallery-button.active'); 268 //console.log(buttons); 269 for (var i = 0; i < buttons.length; i++) { 270 $(buttons[i]).removeClass('active'); 271 } 272 273 $(button).addClass('active'); 274} 275 276function sortImagesByNewest() { 277 galleryImagesSorted = sortByKey(cloneObject(galleryImages), 'crdate', true); 278} 279function sortImagesByMostLiked() { 280 galleryImagesSorted = cloneObject(galleryImages); 281 galleryImagesSorted.sort(function (a, b) { 282 var property = 'counts.like'; 283 return getPropertyByPath(b, property) - getPropertyByPath(a, property); 284 }); 285} 286function sortImagesByWinners() { 287 galleryImagesSorted = []; 288 for (var i = 0; i < galleryImages.length; i++) { 289 if (galleryImages[i].winner !== '') { 290 galleryImagesSorted.push(cloneObject(galleryImages[i])); 291 } 292 } 293} 294function sortImagesByAll() { 295 galleryImagesSorted = sortByKey(cloneObject(galleryImages), 'crdate'); 296} 297 298function updateGalleryNavigation() { 299 updateGalleryValues(); 300 301 if (currentPage >= numberPages-1) { 302 currentPage = numberPages-1; 303 $('#gallery-next-arrow')[0].style.visibility = 'hidden'; 304 } else { 305 $('#gallery-next-arrow')[0].style.visibility = 'visible'; 306 } 307 if (currentPage <= 0) { 308 currentPage = 0; 309 $('#gallery-previous-arrow')[0].style.visibility = 'hidden'; 310 } else { 311 $('#gallery-previous-arrow')[0].style.visibility = 'visible'; 312 } 313 314 updatePagesNavigationText(); 315} 316 317function updatePictureNavigation() { 318 if (galleryImageIndex <= 0) { 319 galleryImageIndex = 0; 320 $('#gallery-picture-previous-arrow')[0].style.visibility = 'hidden'; 321 } else { 322 $('#gallery-picture-previous-arrow')[0].style.visibility = 'visible'; 323 } 324 if (galleryImageIndex >= galleryImagesSorted.length-1) { 325 galleryImageIndex = galleryImagesSorted.length-1; 326 $('#gallery-picture-next-arrow')[0].style.visibility = 'hidden'; 327 } else { 328 $('#gallery-picture-next-arrow')[0].style.visibility = 'visible'; 329 } 330} 331 332function updatePagesNavigationText() { 333 $('#gallery-page-text')[0].textContent = galleryLanguageStrings['gallery_page_text_pre'] + ' '+(currentPage+1)+' '+galleryLanguageStrings['gallery_page_text_middle']+' '+numberPages; 334} 335 336function initialiseNextAndPreviousButtons() { 337 $(document.getElementById("gallery-next-arrow")).on('click', function() { 338 currentPage++; 339 updateGalleryNavigation(); 340 displayTeaserImages(); 341 }); 342 $(document.getElementById("gallery-previous-arrow")).on('click', function() { 343 currentPage--; 344 updateGalleryNavigation(); 345 displayTeaserImages(); 346 }); 347} 348 349function initialisePictureNextAndPreviousButtons() { 350 $(document.getElementById("gallery-picture-next-arrow")).on('click', function() { 351 galleryImageIndex++; 352 updatePictureNavigation(); 353 setLikeText(); 354 restoreImage(); 355 }); 356 $(document.getElementById("gallery-picture-previous-arrow")).on('click', function() { 357 galleryImageIndex--; 358 updatePictureNavigation(); 359 setLikeText(); 360 restoreImage(); 361 }); 362} 363 364function goToStateGallery(newState) { 365 previousGalleryState = currentGalleryState; 366 //console.log(previousGalleryState); 367 currentGalleryState = newState; 368 //console.log(previousGalleryState); 369 var timeOutGalleryContainer = $('#timeOutGalleryContainer')[0]; 370 $.each( gallery_states, function( key, value ) { 371 $(timeOutGalleryContainer).removeClass(value); 372 }); 373 $(timeOutGalleryContainer).addClass(currentGalleryState); 374} 375 376function goToPreviousStateGallery() { 377 goToStateGallery(previousGalleryState); 378 displayTeaserImages(); 379} 380 381function goToPictureState(newGalleryImageIndex) { 382 //console.log(newGalleryImageIndex); 383 galleryImageIndex = newGalleryImageIndex; 384 goToStateGallery(gallery_states.PICTURE); 385 updatePictureNavigation(); 386 updateWidthOfFrameGallery(); 387 restoreImage(); 388 setLikeText(); 389 setSocialShareCounts(); 390} 391 392function setSocialShareCounts() { 393 $('#facebook_gallery_count').html(galleryImagesSorted[galleryImageIndex].counts.fb); 394 $('#twitter_gallery_count').html(galleryImagesSorted[galleryImageIndex].counts.tw); 395 $('#pinterest_gallery_count').html(galleryImagesSorted[galleryImageIndex].counts.pi);
396 $('#instagram_gallery_count').html(galleryImagesSorted[galleryImageIndex].counts.in); 397 $('#whatsapp_gallery_count').html(galleryImagesSorted[galleryImageIndex].counts.wa); 398} 399 400function setLikeText() { 401 var numLiked = $('.num-likes'); 402 updateLikeText(numLiked, galleryImagesSorted[galleryImageIndex].counts.like); 403} 404 405function updateLikeText(jQueryElement, newLikes) { 406 jQueryElement.html(newLikes+' '+ galleryLanguageStrings['num_likes']); 407 jQueryElement[0].style.visibility = 'visible'; 408} 409 410function initialiseTeaserImages() { 411 var teaserElements = $('.teaser-image'); 412 413 for (var i = 0; i < teaserElements.length; i++) { 414 $(teaserElements[i]).click(function(event) { 415 goToPictureState(event.target.value); 416 }) 417 } 418} 419 420function displayTeaserImages() { 421 var teaserElements = $('.teaser-image'); 422 423 for (var i = 0; i < teaserElements.length; i++) { 424 var currentGalleryIndex = currentPage*teaserImagesPerpage+i; 425 var teaserImageContainer = $(teaserElements[i].parentNode); 426 if (currentGalleryIndex < galleryImagesSorted.length) { 427 teaserElements[i].src = galleryImagesSorted[currentGalleryIndex].teaserImage; 428 teaserElements[i].style.visibility = 'visible'; 429 teaserElements[i].parentNode.style.visibility = 'visible'; 430 var numLiked = teaserImageContainer.find('.num-likes'); 431 updateLikeText(numLiked, galleryImagesSorted[currentPage*teaserImagesPerpage+i].counts.like); 432 433 434 if (galleryImagesSorted[currentPage*teaserImagesPerpage+i].winner == 'grand_prize') { 435 teaserImageContainer.addClass('grand_prize'); 436 teaserImageContainer.attr('title', galleryLanguageStrings['winner_grand_prize_title']); 437 teaserImageContainer.removeClass('weekly'); 438 teaserImageContainer.removeClass('daily'); 439 } else if (galleryImagesSorted[currentPage*teaserImagesPerpage+i].winner == 'weekly') { 440 teaserImageContainer.addClass('weekly'); 441 teaserImageContainer.attr('title', galleryLanguageStrings['winner_weekly_title']); 442 teaserImageContainer.removeClass('daily'); 443 teaserImageContainer.removeClass('grand_prize'); 444 } else if (galleryImagesSorted[currentPage*teaserImagesPerpage+i].winner == 'daily') { 445 teaserImageContainer.addClass('daily'); 446 teaserImageContainer.attr('title', galleryLanguageStrings['winner_daily_title']); 447 teaserImageContainer.removeClass('weekly'); 448 teaserImageContainer.removeClass('grand_prize'); 449 } else { 450 teaserImageContainer.removeClass('weekly'); 451 teaserImageContainer.removeClass('daily'); 452 teaserImageContainer.removeClass('grand_prize'); 453 teaserImageContainer.attr('title', ''); 454 } 455 456 $(teaserElements[i].parentNode).find('.like-image')[0].style.visibility = 'visible'; 457 if (galleryImagesSorted[currentPage*teaserImagesPerpage+i].alreadyLiked == true) { 458 $(teaserElements[i].parentNode).find('.like-image')[0].src=imageBasePathGallery+'like_clicked.png' 459 } else { 460 $(teaserElements[i].parentNode).find('.like-image')[0].src=imageBasePathGallery+'like.png' 461 } 462 } else { 463 teaserImageContainer.removeClass('weekly'); 464 teaserImageContainer.removeClass('daily'); 465 teaserImageContainer.removeClass('grand_prize'); 466 teaserElements[i].src = imageBasePathGallery+'670x440.png'; 467 teaserElements[i].style.visibility = 'hidden'; 468 teaserElements[i].parentNode.style.visibility = 'hidden'; 469 teaserImageContainer.find('.like-image')[0].style.visibility = 'hidden'; 470 teaserImageContainer.find('.num-likes')[0].style.visibility = 'hidden'; 471 } 472 473 teaserElements[i].value = currentGalleryIndex; 474 } 475} 476 477 478function restoreImage() { 479 var gifContainer = document.getElementById("gif-container-gallery"); 480 removeAllGifs(gifContainer); 481 482 var likeImageElement = $('.picture-like-image')[0]; 483 var posInArray = findWithAttr(galleryImages, 'id', galleryImagesSorted[galleryImageIndex].id); 484 updateLikeButton(likeImageElement, posInArray); 485 setSocialShareCounts(); 486 setCreatorName(); 487 setCreationDate(); 488 489 var imageToRestore = galleryImagesSorted[galleryImageIndex].image; 490 var backgroundImage = $('#picture-container').find('.background-image')[0]; 491 setBackgroundImage(backgroundImage, imageToRestore.backgroundImage); 492 backgroundImage.setAttribute('data-scale', imageToRestore.scale); 493 //setElementTransform(backgroundImage, undefined, undefined, imageToRestore.deg, imageToRestore.scale, widthOfFrameGallery);
494 setBackgroundImageTransform(backgroundImage, imageToRestore.deg, imageToRestore.scale); 495 var gifs = imageToRestore.gifs; 496 497 for (var i = 0; i < gifs.length; i++) { 498 restoreGif(gifs[i]); 499 } 500 501} 502 503function setCreatorName () { 504 if(languageName =='de'){ 505 $('#gallery-creator-name').html(galleryImagesSorted[galleryImageIndex].firstName); 506 }else{ 507 $('#gallery-creator-name').html(galleryImagesSorted[galleryImageIndex].firstName + ' ' + galleryImagesSorted[galleryImageIndex].lastName); 508 } 509} 510 511function setCreationDate () { 512 var date = new Date(galleryImagesSorted[galleryImageIndex].crdate * 1000); 513 console.log(date); 514 $('#gallery-creation-date').html(date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear()); 515} 516 517function createGifElementGallery(id, gifContainer) { 518 var gif = document.createElement('div'); 519 gif.id=id; 520 var img = document.createElement('img'); 521 $(img).addClass('image'); 522 gif.appendChild(img); 523 gifContainer.appendChild(gif); 524 return gif; 525} 526 527function restoreGif(gif) { 528 var gifContainer = document.getElementById("gif-container-gallery"); 529 530 var newGif = createGifElementGallery('gifOnPic', gifContainer); 531 $(newGif).addClass("gif-on-pic"); 532 newGif.style.zIndex = gif.zindex; 533 534 setElementWidthHeight(newGif, gif.width, gif.height, true, widthOfFrameGallery); 535 536 setElementTransform(newGif, gif.x, gif.y, gif.deg, undefined, widthOfFrameGallery); 537 setElementScale(newGif, gif.scale); 538 539 $(newGif).find('.image')[0].src=gif.src; 540 541} 542 543function sortByKey(array, key, reverse) { 544 return array.sort(function(a, b) { 545 var x = a[key]; var y = b[key]; 546 return reverse ? ((x > y) ? -1 : ((x < y) ? 1 : 0)) : ((x < y) ? -1 : ((x > y) ? 1 : 0)); 547 }); 548} 549 550function cloneObject(object) { 551 return JSON.parse(JSON.stringify(object)); 552} 553function getPropertyByPath(obj, path) { 554 return path.split('.').reduce(function (val, key) { return val[key]; }, obj); 555} 556function findWithAttr(array, attr, value) { 557 for(var i = 0; i < array.length; i += 1) { 558 if(array[i][attr] === value) { 559 return i; 560 } 561 } 562} 563 564function likeImage(id, type) { 565 $.ajax({ 566 url: GALLERY_LIKE_URL+'tx_mpmontetimeout_gallery[image]='+id+'&tx_mpmontetimeout_gallery[type]='+type, 567 type: 'GET', 568 dataType: 'json' 569 }); 570}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.