historia-de-zainab/js/main.js

187 lines
5.2 KiB
JavaScript
Raw Normal View History

2017-09-26 11:17:09 +02:00
viewStatus= "story" /* data story */
2017-09-26 13:35:51 +02:00
pagesLoaded= 0
2017-11-08 13:08:21 +01:00
totalPages=8;
window.onresize = function(){ location.reload(); }
2017-09-25 14:03:53 +02:00
window.onload = function() {
width = 1000,
height = 1000;
2017-11-08 13:08:21 +01:00
loadData();
2017-09-25 14:03:53 +02:00
$('#pagepiling').pagepiling({
menu: null,
2017-09-29 11:53:26 +02:00
anchors: ["portada","page1","page2","page3","page4","page5","page6","page7"],
2017-09-25 14:03:53 +02:00
direction: 'horizontal',
verticalCentered: true,
scrollingSpeed: 800,
easing: 'swing',
2017-09-29 11:53:26 +02:00
normalScrollElements:'div',
2017-09-25 14:03:53 +02:00
afterLoad: function(anchorLink, index){
//using index
2017-09-29 11:53:26 +02:00
index-=1;
console.log(index)
if(index<=0){
$('#timeline').fadeOut();
}else{
$('#timeline').fadeIn();
}
2017-09-25 14:03:53 +02:00
$('.btn-navigation.active').removeClass('active')
$('#nav-btn-page'+index + " a").addClass('active')
}
2017-11-08 13:08:21 +01:00
}); //turnEventsOn();
2017-11-07 11:14:07 +01:00
2017-11-08 13:08:21 +01:00
}
2017-11-07 11:14:07 +01:00
2017-11-08 13:08:21 +01:00
function loadData(){
$.getJSON( "data/textos.json", function( data ) {
n_projects=Object.keys(data).length;
paginasData=data;
console.log("astas")
loadPageTemplates()
}).fail(function() {
console.log( "error" );
})
}
2017-11-07 11:14:07 +01:00
2017-11-08 13:08:21 +01:00
sufix="desk"
n_projects=7;
function renderPage(pageNumber ){
//$("body").fadeOut();
console.log(pageNumber)
//$("body").empty();
if(pageNumber==0){
my.utils().renderExtTemplate({ name: 'portada_'+sufix, selector: 'body', data: {} })
}
else if(pageNumber==6){
var mdata=paginasData[pageNumber-1]
my.utils().renderExtTemplate({ name: 'page6_'+sufix, selector: '#page-'+pageNumber, index : pageNumber, data: mdata })
}
else{
var mdata=paginasData[pageNumber-1]
my.utils().renderExtTemplate({ name: 'page_'+sufix, selector: '#page-'+pageNumber, index : pageNumber, data: mdata })
}
2017-09-25 14:03:53 +02:00
}
2017-11-08 13:08:21 +01:00
2017-09-25 14:03:53 +02:00
function loadPageTemplates(){
2017-11-08 13:08:21 +01:00
my.utils().renderExtTemplate({ name: 'portada_'+sufix, selector: '#portada', data: {}, index : 0 })
/*$('#portada').load("templates/portada.html",function(){
2017-09-29 22:11:44 +02:00
loadModalEvent(0);
2017-11-08 13:08:21 +01:00
})*/
2017-09-25 15:15:33 +02:00
2017-11-08 13:08:21 +01:00
for (var i=1; i<= totalPages-1; i++){
/*(function (n) {
2017-09-26 13:35:51 +02:00
$('#page-'+n).load("templates/page"+n+".html",function(){
counterLoading();
loadModalEvent(n);
})
2017-11-08 13:08:21 +01:00
})(i)*/
renderPage(i)
2017-09-26 13:35:51 +02:00
}
//turnEventsOn();
2017-09-26 11:17:09 +02:00
}
2017-09-26 13:35:51 +02:00
function loadModalEvent(j){
2017-09-29 22:11:44 +02:00
//console.log(j)
2017-09-26 11:17:09 +02:00
var modal = new jBox('Modal', {
2017-09-26 13:35:51 +02:00
attach: '#map-btn-page-'+j,
content: $('#map-page-'+j),
2017-09-26 11:17:09 +02:00
closeButton: 'box'
});
2017-11-08 13:08:21 +01:00
console.log(j)
2017-09-29 20:30:37 +02:00
var modal2=
new jBox('Modal', {
width: '60%',
height: '80%',
attach: '#referencias-page-btn-'+j,
2017-11-08 13:08:21 +01:00
//content: $('#referencias-page-'+j),
ajax: {
url: 'referencias/page'+j+".html",
reload: 'strict'
},
2017-09-29 20:30:37 +02:00
closeButton: 'box'
});
2017-09-26 11:17:09 +02:00
}
function counterLoading(){
2017-09-26 13:35:51 +02:00
pagesLoaded++;
2017-11-08 13:08:21 +01:00
$('.verstory-btn').hide();
2017-09-26 13:35:51 +02:00
if(pagesLoaded >= totalPages){
2017-09-29 22:11:44 +02:00
var ssize=$( window ).height();
var bottomSize=$( "#timeline" ).height();
$('.story-content').css("height",ssize-bottomSize+'px')
2017-09-29 22:22:47 +02:00
$('.data-content').css("height",ssize-bottomSize+'px')
2017-09-26 13:35:51 +02:00
//Todas las plantillas cargadas
2017-11-08 13:08:21 +01:00
$('.extra-btn-container').on("click",'.switchMode', function(e){
2017-09-29 13:52:12 +02:00
if(viewStatus=="story")
{
viewStatus="data"
}
2017-09-26 11:17:09 +02:00
else{
viewStatus="story"
}
if(viewStatus=="story"){
2017-09-27 13:00:50 +02:00
$('.story-content, .menu-story-content').show();
$('.data-content, .menu-data-content').hide();
2017-11-08 13:08:21 +01:00
$('.verstory-btn').hide();
$('.vergrafico-btn').show();
2017-09-27 13:00:50 +02:00
//$('.menu-content .switchMode').empty().html("ver datos")
2017-09-26 11:17:09 +02:00
}
else{
2017-09-27 13:00:50 +02:00
$('.story-content, .menu-story-content').hide();
$('.data-content, .menu-data-content').show();
2017-11-08 13:08:21 +01:00
$('.vergrafico-btn').hide();
$('.verstory-btn').show();
2017-09-27 13:00:50 +02:00
//$('.menu-content .switchMode').empty().html("ver historia")
2017-09-26 11:17:09 +02:00
}
})
2017-09-29 13:52:12 +02:00
$('#page-6').on("click",'.carousel-btn a', function(e){
$('.carousel-btn a.active').removeClass("active")
$(this).addClass("active")
});
2017-09-26 11:17:09 +02:00
}
2017-09-25 14:03:53 +02:00
}
function turnEventsOn(){
2017-09-25 15:15:33 +02:00
/*$('#timeline').on("click",'.btn-navigation', function(e){
2017-09-25 14:03:53 +02:00
$('.btn-navigation.active').removeClass('active')
$(this).addClass('active')
2017-09-25 15:15:33 +02:00
})*/
2017-09-26 11:17:09 +02:00
}
2017-11-08 13:08:21 +01:00
var my = my || {};
my.utils = (function() {
var getPath = function(name) {
return 'templates/' + name + '.tmpl.html';
},
renderExtTemplate = function(item) {
var file = getPath( item.name );
$.when($.get(file))
.done(function(tmplData) {
n_projects--;
var tmpl= $.templates( tmplData );
var rendered=tmpl.render(item.data)
$(item.selector).append(rendered);
//setCardSizes();
afterLoading(item.index);
});
};
return {
getPath: getPath,
renderExtTemplate: renderExtTemplate
};
});
function afterLoading(i){
//$("body").fadeIn();
//reloadEvents();
if(i>0)loadModalEvent(i)
counterLoading();
}