/** * Mobile Site Main script. * * @author : Tosom s.r.l. * @version : 2.02 * * @changelog * 2.01->2.01 * DATE: 2014-06-13 * REFACTORED: form name from "set-lang" to "set-opts" * */ /* MAIN SUPERPOWAHYPERGLOBAL CONF :D */ var PAGE = { orientation : "" , currLang : 0 , supportedLangs : ( typeof _SITE_CONF_LANGS != "undefined" ) ? _SITE_CONF_LANGS : false , calendarLangs : ( typeof _SITE_CONF_LANGS_CAL != "undefined" ) ? _SITE_CONF_LANGS_CAL : false , menuListener : false , currFormSetup : { notticercate : 0 , cambiatoGiorni : false , cambiatoArrivo : false , cambiatoCodice : false }, cam : false , homeSlider : false , pageMenuSize : false , device : false , debug :false } /** * JQUERY-MOBILE INIT PROCEDURE */ $(document).bind("mobileinit",function(){ $.mobile.page.prototype.options.degradeInputs.date = true; }); /** * Inject a new method in date object */ Date.prototype.yyyymmdd = function() { var yyyy = this.getFullYear().toString(); var mm = (this.getMonth()+1).toString(); var dd = this.getDate().toString(); return yyyy + "-"+ (mm[1]?mm:"0"+mm[0]) + "-" +(dd[1]?dd:"0"+dd[0]); }; /** * MAIN PAGE STARTUP !!! */ $(document).ready(function(){ //calculateMainMenuSize(); //CHECK IPHONE PAGE.device = "std" ; if( navigator.userAgent.toLowerCase().indexOf("iphone")>=0 ) { PAGE.device = "iphone" } if( PAGE.debug ) { $("div[data-role='content']").prepend('
'); } general_bindEvents(); if( $.mobile.activePage.is('#cam') ) { initCam(); } resizeSocials(); // Page resize is made by the bindEvents function, no need to call it here }); $(window).load(function(){ // STARTUP MENU LSITENER PAGE.menuListener = window.setInterval( function(){ if( $.mobile.activePage.is('#menu') ) { menu_draw(); } } , 250 ) ; }) ; /** * \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * PAGE FUNCTIONS * ///////////////////////////////////////////////////////////////////////// */ // DEBUG FUNCTIONS function trace(m){if(window.console){window.console.log(m);}} function debug(m){var dbg=$("#dbg pre");if(dbg&&dbg.length){m=''+m+'';dbg.html( dbg.html()+m );}} function gotoMenu(){ $.mobile.changePage("#menu"); } function general_bindEvents() { // BIND MENU $("div.lan").css({cursor:"pointer"}); $("div.lan").click(function(){ $.mobile.changePage($("#"+( $(this).attr("data-ref") )),{ transition:"slide" }); }) // BIND MENU BUTTON // $(".hotelmenu").click(function(){ $.mobile.changePage("#menu") }); // If i have a photogallery add the pohotoswipe var gal = $("#gallery") if( gal && gal.length ) { //window.Code.Util.TouchElement.ActionTypes.doubleTap=false var myPhotoSwipe = $("#swipe-gallery a").photoSwipe({ allowUserZoom : false , enableMouseWheel : false , enableKeyboard : false , backButtonHideEnabled : false }); /*.addEventHandler( /*photoSwipe.EventTypes.onDisplayImage, function(e) { $("#close_this").click(function() { e.target.hide(); }); }* / );*/ //myPhotoSwipe.Animation.TouchElement.ActionTypes.doubleTap=false //trace(window.Code.Util) ; //trace(myPhotoSwipe) ; /* // Std linking is not working under jquery mobile!! var href = window.location.href ; href = href.split("#") ; href = href[0] ; */ href="javascript:goHome()" ; var homeMenu = ' '; var a = $("div.template_page"); jQuery.each(a,function(idx,elem){ var id = $(elem).attr("id"); //$(elem).prepend('') ; if( id!="menu" ) { var b = $(elem).children("div[data-role='content']") b.prepend(homeMenu) ; //var pageMenu = ''; //b.prepend(pageMenu) ; setPageMenuPos(); } }); } // SETUP LANGS MENU STD $.each( $("#languagecontainer .innerlangmenu") , function(idx,elem){ $(elem).css({cursor:"pointer"}); var beLang = $(elem).attr("data-belang") ; var newLang = $(elem).attr("data-newlang") ; $(elem).click( function(){ var form = document.forms["set-lang"] form.lang.value = newLang; form.submit(); }); }); // CUSTOM LANGS MENU $.each( $("table.top-langs .lang-button") , function(idx,elem){ $(elem).css({cursor:"pointer"}); var beLang = $(elem).attr("data-belang") ; $(elem).click( function(){ var newLang = $(this).attr("data-newlang") ; var form = document.forms["set-opts"] trace(form) trace(newLang) form.lang.value = newLang; trace(form) form.submit(); }); }); // CUSTOM BOOK NOW $("#home-book-now").on("click",function(){ /*var go = "reservations" ; var lang = $(this).attr("data-lang") ; var form = document.forms["set-opts"] form.setAttribute("action","./#reservations") ; form.lang.value = lang form.submit(); */ var hotel = $(this).attr("data-hotel"); var lang = $(this).attr("data-lang"); openbe2(hotel,lang); }); /*$(".trigger-book-now").on("click",function(){ alert("BookStart") var hotel = $(this).attr("data-hotel"); var lang = $(this).attr("data-lang"); openbe2(hotel,lang); });*/ /*$(".avacontainer a.trigger-book-now").on("click",function(){ alert("BookNow") /*var hotel = $(this).attr("data-hotel"); var lang = $(this).attr("data-lang"); openbe2(hotel,lang);* / });*/ /* $(".avacontainer a.trigger-book-now").click( function(){ alert("BookGo") } );*/ $(window).bind("orientationchange",function(event){ window.setTimeout( function(){ window.scrollTo(0, 1); }, 50 ); }); // WEBCAM HANDLING // init cam on showing the cam page $("#cam").on("pageshow",function(event, ui){ initCam(); }); // stop cam on quitting a page $("div[data-role='page']").live("pagebeforehide",function(event, ui){ stopCam(); }); // Fix some stuff $("div").live("pageshow",function(event, ui){ var currPage = $.mobile.activePage.attr('id') ; setPageMenuPos(); //if( currPage=="menu" ) //{ menu_draw(); } /*if(window.innerHeight>=document.height){ $(".thefooter").addClass("footerfix"); } else{ $(".thefooter").removeClass("footerfix"); }*/ }); // PAGE RESIZE $(window).bind("resize",function(event){ pageResize(); }); // BE FORM beform_bindEvents(); // Apply the sizing calculations pageResize(); menu_draw(); } function pageResize(opts) { setPageMenuPos(); splash_resize(); resizeSocials(); closeCalendar(); } function goHome() { window.location.href = "./" ; } /** * Calculates new width propotioned from x,y to the new width of the page. * Uses a std basic resolition of 1024, if the 1:1 resolution is different use the originalResolution par * * @param : originalImageWidth => the origina image width * @param : originalImageHeigth => the origina image height * @param : originalResolution => the original reference resolution * * @returns : json object { w:[0,n] , h:[0,n] , r:[0,n] } */ function getNewSize( originalImageWidth , originalImageHeight , originalReferenceResolution ) { // Setup stuff var res = 1024 ; if( typeof originalReferenceResolution != "undefined" && !isNaN(originalReferenceResolution) && originalReferenceResolution > 0 ) { res = originalReferenceResolution ; } var win = { w : $(window).width() , h : $(window).height() } ; // ratio exanded calculation : // originalImageWidth / originalReferenceResolution =[must equals]= newWIdth / win.w ==> // ( originalImageWidth / originalReferenceResolution ) * win.w = newWidth var ratio = originalImageWidth / originalReferenceResolution ; var newWidth = win.w * ratio ; // New Image Height var imgRatio = originalImageWidth / originalImageHeight ; var newHeight = ( newWidth * originalImageHeight ) / originalImageWidth var newSize = { w : newWidth , h : newHeight , r : res } ; return newSize ; } function setPageMenuPos() { var menu = $(".hotelmenu") ; if( menu && menu.length ) { var w = $(window).width() ; var menuW =(20*w)/100 ; var pos = w - menuW ; pos -= 19; menu.css({left:pos,top:0,position:"fixed"}) ; } } function resizeSocials() { // RUN SOCIAL IMAGES AND RESIZE THEM var socials = $(".social-block table.socials-table tr td .home-bottom-icon img ") ; var newWidth = "113" ; var winSize = $(window).width(); var refWinWidth = 1280 ; var refIconWidth = 210 ; if( winSize < refWinWidth ) { newWidth = winSize * refIconWidth /refWinWidth ; socials.css({width : newWidth+"px"}); } } function initCam() { // Initialize cam if not if( !PAGE.cam ) { // CAM size calculations var camSize = {w:400,h:300} var w = $(window).width() ; var h = $(window).height() ; if(w>640) {w=640;} if( h
');
})
}
function calculateMainMenuSize()
{
//PAGE.pageMenuSize
var hor = { w:0,h:0 } ;
var ver = { w:0,h:0 } ;
var w = $(window).width() ;
var h = $(window).height() ;
if(PAGE.device=="iphone")
{
h = $(document).height() - 10 ;
}
var margin = 10 ;
if( w>h ) // Landscape
{
PAGE.orientation = "landscape" ;
// SETUP LANDSCAPE
hor.w = Math.floor( (w-(margin*4)) / 3 ) ;// Menu element width
hor.h = Math.floor( (h-(margin*3)) / 2 ) ;// Menu element height
// SETUP PORTRAIT
ver.w = Math.floor( (h-(margin*3)) / 2 ) ;// Menu element width
ver.h = Math.floor( (w-(margin*4)) / 3 ) ;// Menu element height
}
else // Portrait
{
PAGE.orientation = "portrait" ;
// SETUP LANDSCAPE
hor.w = Math.floor( (h-(margin*4)) / 3 ) ; // Menu element width
hor.h = Math.floor( (w-(margin*3)) / 2 ) ; // Menu element height
//SETUP PORTRAIT
ver.w = Math.floor( (w-(margin*3)) / 2 ) ; // Menu element width
ver.h = Math.floor( (h-(margin*4)) / 3 ) ; // Menu element height
}
//trace( "CALCULATIONS("+PAGE.orientation+") :: "+w+" - "+h+" | "+margin )
PAGE.pageMenuSize = {
hor : hor ,
ver : ver ,
margin : margin
}
}
function menu_draw()
{
//var w = $(window).innerWidth();
//var h = window.innerHeight ? window.innerHeight : $(window).height()
//var h = $(window).innerHeight() ;
//var margin = 50 ;
var size = false ;
calculateMainMenuSize() ;
if( PAGE.orientation == "landscape" ) // Landscape
{ size = PAGE.pageMenuSize.hor ; }
else // Portrait
{ size = PAGE.pageMenuSize.ver ; }
$(".lan").css({
width : size.w ,
height : size.h ,
marginLeft : PAGE.pageMenuSize.margin ,
marginTop : PAGE.pageMenuSize.margin
});
/*if(w>h){
var width= Math.floor(w/3)-margin;
$(".lan").css("width",width);
$(".lan").css("margin-left",14);
var height= Math.floor(h/2)-margin;
$(".lan").css("height",height);
$(".lan").css("margin-top",14);
}
else{
var width= Math.floor(w/2)-margin;
$(".lan").css("width",width);
$(".lan").css("margin-left",14);
var height= Math.floor(h/3)-margin;
$(".lan").css("height",height);
$(".lan").css("margin-top",14);
}*/
}
function splash_resize(){
$("#main-splash").width( $(document).width() );
$("#main-photo").width( $(document).width() );
indexLangResize()
}
// TEST DONE WITH 1280 screen width !!
// To change it test a new font size with a different resolution then change values;
// that resolution have been used as starting value just too use it as a base to get correct proportions.
function indexLangResize()
{
var testRes = 1280 ;
var textFontSize = 40 ;
var newFontSize = textFontSize ;
var pw = $(document).width();
var boxSize = 0 ;
var newBoxSize = boxSize ;
var imageWidth = 80 ;
var newImageWidth = imageWidth ;
var langs = $("#languagecontainer ul li") ;
newFontSize = Math.floor( (pw*textFontSize) / testRes ) ;
newBoxSize = Math.floor( ($("#languagecontainer").width()) / langs.length )-5;
newImageWidth = Math.floor( pw *( imageWidth/testRes ) );
$("#languagecontainer .innerlangmenu").css({fontSize:newFontSize+"px",width:newBoxSize+"px"})
$("#languagecontainer .innerlangmenu img.flag").css({width:newImageWidth+"px"})
}
// Deprecated and dropped....
// CLEAR THIS CODE AFTER RELEASE
function lang_change(newLang,goToPage)
{
/*
// Update global config
var oldLang = PAGE.currLang ; // store prev lang .. justincase :D
var langarray = PAGE.supportedLangs ;
var langarray_ui = PAGE.calendarLangs ;
PAGE.currLang = newLang ;
$("#lingua").val(PAGE.currLang);
for(i=1;i