Subversion Repository Public Repository

wpbsav

Diff Revisions 45 vs 47 for /SagreraWP/wp-content/themes/bsav/js/gallery.js

Diff revisions: vs.
  @@ -15,6 +15,8 @@
15 15 */
16 16 Gallery.parentsGalleryId = "parentsGallery";
17 17
18 + Gallery.allButtonsActuacions = ["btnAereasGallery", "btnPuntosElevadosGallery", "btnPuentesGallery", "btnVideosGallery"];
19 +
18 20 /*
19 21 * @desc Al inicializarse la página se ejecuta automáticamente
20 22 */
  @@ -76,6 +78,11 @@
76 78 }
77 79 }
78 80
81 + for( var i = 0; i < Gallery.allButtonsActuacions.length; i++ )
82 + {
83 + Gallery.hideButton( Gallery.allButtonsActuacions[i] );
84 + }
85 +
79 86 if( _.has( Gallery.buttons , 'img' ) === true)
80 87 {
81 88 Gallery.displayButton( "btnImgsGallery" );
  @@ -105,7 +112,6 @@
105 112 {
106 113 Gallery.hideNavigation();
107 114 }
108 -
109 115 }
110 116
111 117 /*
  @@ -252,7 +258,6 @@
252 258 var html = "", i = 0;
253 259 for( obj in data )
254 260 {
255 -
256 261 title = Gallery.formatTitle( data[obj] );
257 262
258 263 if( data[obj].post_type === "videos" )
  @@ -276,7 +281,6 @@
276 281 }
277 282
278 283 html+="</div>";
279 -
280 284 i++;
281 285 }
282 286
  @@ -425,10 +429,27 @@
425 429 /*
426 430 * @desc Al pulsar en el botón imágenes
427 431 */
428 - $("#btnImgsGallery").on("click", function(e)
432 + $("#btnImgsGallery, #btnAereasGallery, #btnPuentesGallery, #btnPuntosElevadosGallery").on("click", function(e)
429 433 {
430 434 e.preventDefault();
431 435
436 + if( $(this).attr("id") === "btnPuentesGallery")
437 + {
438 + thisCarouselData = Gallery.arrayPonts;
439 + }
440 + else if( $(this).attr("id") === "btnPuntosElevadosGallery" )
441 + {
442 + thisCarouselData = Gallery.arrayElevats;
443 + }
444 + else if( $(this).attr("id") === "btnAereasGallery" )
445 + {
446 + thisCarouselData = Gallery.arrayAereas;
447 + }
448 + else if( $(this).attr("id") === "btnImgsGallery" )
449 + {
450 + thisCarouselData = Gallery.imagesCommons;
451 + }
452 +
432 453 Gallery.hideVideos();
433 454
434 455 Gallery.displayCarousel();
  @@ -438,19 +459,38 @@
438 459 $("#navigationGallery label").removeClass("btn-bsav");
439 460 $(this).addClass("btn-bsav");
440 461
441 - for(var i=0 ; i< Gallery.imagesCommons.length ; i++)
462 + console.log( thisCarouselData)
463 +
464 + if( $(this).attr("id") === "btnImgsGallery" )
442 465 {
443 - if( Gallery.imagesCommons[i].desc )
466 + for(var i=0 ; i< thisCarouselData.length ; i++)
444 467 {
445 - $('<div class="item"><center><img src="'+Gallery.imagesCommons[i].img+'"><br><div class="carousel-caption"><strong><h5 style="font-weight: bold;">'+Gallery.imagesCommons[i].title+'</h5></strong><p style="font-size: 14px">'+Gallery.imagesCommons[i].desc+'</p></div></center></div>').appendTo('.carousel-inner');
468 + if( thisCarouselData[i].desc )
469 + {
470 + $('<div class="item"><center><img src="'+thisCarouselData[i].img+'"><br><div class="carousel-caption"><h5 style="font-weight: bold;">'+thisCarouselData[i].title+'</h5><p style="font-size: 14px">'+thisCarouselData[i].desc+'</p></div></center></div>').appendTo('.carousel-inner');
471 + }
472 + else
473 + {
474 + $('<div class="item"><center><img src="'+thisCarouselData[i].img+'"><div class="carousel-caption"><h5 style="font-weight: bold;">'+thisCarouselData[i].title+'</h5></div></center></div>').appendTo('.carousel-inner');
475 + }
446 476 }
447 - else
477 + }
478 + else
479 + {
480 + for(var i=0 ; i< thisCarouselData.length ; i++)
448 481 {
449 - $('<div class="item"><center><img src="'+Gallery.imagesCommons[i].img+'"><div class="carousel-caption"><h4>'+Gallery.imagesCommons[i].title+'</h4></div></center></div>').appendTo('.carousel-inner');
482 + if( thisCarouselData[i].desc.value )
483 + {
484 + $('<div class="item"><center><img src="'+thisCarouselData[i].img.value+'"><br><div class="carousel-caption"><h5 style="font-weight: bold;">'+thisCarouselData[i].title.value+'</h5><p style="font-size: 14px">'+thisCarouselData[i].desc.value+'</p></div></center></div>').appendTo('.carousel-inner');
485 + }
486 + else
487 + {
488 + $('<div class="item"><center><img src="'+thisCarouselData[i].img.value+'"><div class="carousel-caption"><h5 style="font-weight: bold;">'+thisCarouselData[i].title.value+'</h5></div></center></div>').appendTo('.carousel-inner');
489 + }
450 490 }
451 491 }
452 492
453 - Gallery.displayControls(Gallery.imagesCommons);
493 + Gallery.displayControls(thisCarouselData);
454 494
455 495 $('.item').first().addClass('active');
456 496
  @@ -478,9 +518,10 @@
478 518 {
479 519 if( _.has( data[obj] , 'img' ) )
480 520 {
521 +
481 522 Gallery.imagesCommons.push({
482 523 id: obj,
483 - date: data[obj].date.value,
524 + date: _.has( data[obj] , 'date' ) === true ? data[obj].date.value : null,
484 525 desc: _.has( data[obj] , 'desc' ) === true ? data[obj].desc.value : null,
485 526 img: _.has( data[obj] , 'img' ) === true ? data[obj].img.value : null,
486 527 title: _.has( data[obj] , 'title' ) === true ? data[obj].title.value : null
  @@ -568,20 +609,104 @@
568 609 */
569 610 $('area').click(function(e)
570 611 {
612 + Gallery.showPreloader( "h2", "Espere..." );
571 613 e.preventDefault();
614 + var language = $( "#qtranslate-chooser" ).find( '.dropdown-toggle li' ).context.URL.split( '/' );
615 + Gallery.language = language[4];
572 616 var data = {
573 617 action: 'actuacions',
574 618 type: $(this).data("type"),
575 - title: $(this).data("title")
619 + title: $(this).data("title"),
620 + language: Gallery.language
576 621 };
577 622
578 623 $.get( galleryAjax.url, data, function( response )
579 624 {
580 - console.log(response)
625 + if( typeof response === "object" )
626 + {
627 + if( response.success === true )
628 + {
629 + Gallery.updateParentTitle( response.data.parent );
630 + var explodedType = data.type.split("-")[0];
631 + var grouped = _.groupBy(response.data.childrens, 'post_type');
632 + Gallery.generateButtonsActuacions( grouped, explodedType );
633 + Gallery.generateChildrens( grouped["aereas-"+explodedType] );
634 + Gallery.arrayAereas = grouped["aereas-"+explodedType];
635 + Gallery.arrayPonts = grouped["ponts-"+explodedType];
636 + Gallery.arrayElevats = grouped["elevats-"+explodedType];
637 + Gallery.arrayVideos = _.has( grouped , 'videos-'+explodedType ) === true ? grouped["videos-"+explodedType] : [];
638 + }
639 + Gallery.hidePreloader();
640 + }
581 641 });
582 642 });
583 643
584 644 /*
645 + * @desc Genera los botones imágenes, vídeos
646 + * @param Data - array de objetos
647 + * @param Type - sagrera - sandreu
648 + */
649 + Gallery.generateButtonsActuacions = function( buttons, type )
650 + {
651 + Gallery.buttonsActuacions = {};
652 + Gallery.buttonsActuacions.total = 0;
653 +
654 + for( obj in buttons )
655 + {
656 + if( obj == 'aereas-' + type )
657 + {
658 + Gallery.buttonsActuacions.aereas = "btnAereasGallery";
659 + }
660 + if( obj == 'elevats-' + type )
661 + {
662 + Gallery.buttonsActuacions.elevats = "btnPuntosElevadosGallery";
663 + }
664 + if( obj == 'ponts-' + type )
665 + {
666 + Gallery.buttonsActuacions.ponts = "btnPuentesGallery";
667 + }
668 + if( obj == 'videos-' + type )
669 + {
670 + Gallery.buttonsActuacions.videos = "btnVideosGallery";
671 + }
672 + }
673 +
674 + for( var i = 0; i < Gallery.allButtonsActuacions.length; i++ )
675 + {
676 + Gallery.hideButton( Gallery.allButtonsActuacions[i] );
677 + }
678 +
679 + for( key in Gallery.buttonsActuacions )
680 + {
681 + if( Gallery.buttonsActuacions[key] != 0 )
682 + {
683 + Gallery.displayButton( String(Gallery.buttonsActuacions[key]) );
684 + Gallery.buttonsActuacions.total++;
685 + }
686 + }
687 +
688 + $("#btnImgsGallery").hide();
689 + if( Gallery.buttonsActuacions.total > 1 )
690 + {
691 + Gallery.displayNavigation();
692 + $("#btnAereasGallery").removeClass("btn-default").addClass("btn-bsav");
693 + }
694 + else
695 + {
696 + Gallery.hideNavigation();
697 + }
698 +
699 + if( type === "sagrera" )
700 + {
701 + $("#mapa2").hide();
702 + }
703 + else
704 + {
705 + $("#mapa3").hide();
706 + }
707 + }
708 +
709 + /*
585 710 * @desc Al seleccionar una opción del desplegable
586 711 */
587 712 $("#dd_gallery li a").click(function()