historia-de-zainab/js/main-mvl.js

156 lines
4 KiB
JavaScript
Raw Normal View History

2017-11-06 12:53:02 +01:00
viewStatus= "story" /* data story */
pagesLoaded= 0
totalPages=7;
currentPage=0;
2017-11-08 13:08:21 +01:00
mode="desktop"
sufix="desk"
2017-11-08 13:10:52 +01:00
//window.onresize = function(){ location.reload(); }
2017-11-06 12:53:02 +01:00
window.onload = function() {
2017-11-08 13:08:21 +01:00
wwidth=$( window ).width();
if(wwidth<900) {
mode="mobile"
sufix="mob"
}
2017-11-06 12:53:02 +01:00
loadData()
/**** mobile ****/
}
function reloadEvents(){
$('a[href^="#"].link-menu').on('click',function (e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);
2017-11-07 11:14:07 +01:00
//$('.link-menu.active').removeClass("active")
//$(this).addClass("active")
2017-11-06 12:53:02 +01:00
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing', function () {
window.location.hash = target;
});
});
$('.next').on('click',function (e) {
renderPage(++currentPage)
});
$('.prev').on('click',function (e) {
renderPage(--currentPage)
});
2017-11-07 11:14:07 +01:00
$('#page-6').on("click",'.carousel-btn a', function(e){
$('.carousel-btn a.active').removeClass("active")
$(this).addClass("active")
});
2017-11-08 13:08:21 +01:00
2017-11-07 11:14:07 +01:00
Waypoint.destroyAll()
var waypoints = $('#story, #mapa, #datos').waypoint({
handler: function(direction) {
console.log(direction)
if(direction=="down")
enableMenuElement(this.element.id)
},
offset: '11%'
})
var waypoints = $('#story, #mapa, #datos').waypoint({
handler: function(direction) {
console.log(direction)
if(direction=="up")
enableMenuElement(this.element.id)
},
offset: '-11%'
})
2017-11-08 13:08:21 +01:00
var modal2=
new jBox('Modal', {
width: '90%',
height: '90%',
attach: '#referencias-page-btn-'+currentPage,
//content: $('#referencias-page-'+j),
ajax: {
url: 'referencias/page'+currentPage+".html",
reload: 'strict'
},
closeButton: 'box'
});
2017-11-07 11:14:07 +01:00
/* var waypoints = $('#mapa').waypoint({
handler: function(direction) {
enableMenuElement(this.element.id)
}
})
var waypoints = $('#datos').waypoint({
handler: function(direction) {
enableMenuElement(this.element.id)
}
})*/
}
function enableMenuElement(idElement){
console.log(idElement)
$('.link-menu.active').removeClass("active")
var menu_el=$('a[href^="#'+idElement+'"].link-menu')
$(menu_el).addClass("active")
2017-11-06 12:53:02 +01:00
}
function loadData(){
$.getJSON( "data/textos.json", function( data ) {
n_projects=Object.keys(data).length;
paginasData=data;
renderPage(currentPage)
});
}
function renderPage(pageNumber ){
//$("body").fadeOut();
console.log(pageNumber)
$("body").empty();
if(pageNumber==0){
2017-11-08 13:08:21 +01:00
my.utils().renderExtTemplate({ name: 'portada_'+sufix, selector: 'body', data: {} })
2017-11-06 12:53:02 +01:00
}
2017-11-07 11:14:07 +01:00
else if(pageNumber==6){
var mdata=paginasData[pageNumber-1]
mdata.showPrev=mdata.showNext=true
2017-11-08 13:08:21 +01:00
my.utils().renderExtTemplate({ name: 'page6_'+sufix, selector: 'body', data: mdata })
2017-11-07 11:14:07 +01:00
}
2017-11-06 12:53:02 +01:00
else{
var mdata=paginasData[pageNumber-1]
mdata.showPrev=mdata.showNext=true
2017-11-07 11:14:07 +01:00
//if(pageNumber==1) mdata.showPrev=false;
2017-11-06 12:53:02 +01:00
if(pageNumber==7) mdata.showNext=false;
2017-11-08 13:08:21 +01:00
my.utils().renderExtTemplate({ name: 'page_'+sufix, selector: 'body', data: mdata })
2017-11-06 12:53:02 +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();
});
};
return {
getPath: getPath,
renderExtTemplate: renderExtTemplate
};
});
function afterLoading(){
$("body").fadeIn();
reloadEvents();
}