2010-01-20 15:20:44 +00:00
// Message en fonction du browser
function detectIE ( ) {
if ( $ . browser [ "msie" ] ) {
$ ( 'head' ) . append ( '<script type="text/javascript" src="/Scratch/js/ie.js"></script>' ) ;
}
}
2010-01-21 16:26:00 +00:00
// -- multilanguage handling --
// show a message to user
2010-01-21 16:08:48 +00:00
function message ( msg ) {
$ ( '#blackpage' ) . css ( { cursor : 'auto' } ) ;
$ ( '#blackpage' ) . show ( ) . html ( msg ) ;
}
2010-01-21 16:26:00 +00:00
// from cookie first if not, from Navigator
2010-01-21 16:08:48 +00:00
function getUserLanguage ( ) {
var language = $ . cookie ( 'language' ) ;
if ( ! language ) {
if ( ( navigator ) &&
( navigator . language ) &&
( navigator . language . substring ( 0 , 2 ) == 'fr' ) ) {
language = 'fr' ;
} else {
language = 'en' ;
}
}
return language ;
}
2010-01-21 16:26:00 +00:00
// return the path of the equivalent page in another language
2010-01-21 16:08:48 +00:00
function pathToLanguage ( lang ) {
return window . location . pathname . replace ( /(.*\/Scratch\/)(..)(\/.*$)/ , '$1' + lang + '$3' ) ;
}
2010-01-21 16:26:00 +00:00
// return the link to the equivalent page in another language
2010-01-21 16:08:48 +00:00
function linkToLang ( lang , msg ) {
return '<a href="' + pathToLanguage ( lang ) + '">' + msg + '</a>' ;
}
2010-01-21 16:26:00 +00:00
// return a link that will hide the message
2010-01-21 16:08:48 +00:00
function hideClickMessage ( msg ) {
return '<div><a onclick="hideMessage()">' + msg + '</a></div>' ;
}
2010-01-21 16:26:00 +00:00
// put the selected language in the cookie
2010-01-21 16:08:48 +00:00
function setLanguage ( lang ) {
$ . cookie ( 'language' , lang , { path : '/Scratch' } ) ;
}
2010-01-21 16:26:00 +00:00
// select the good language and hide the message
2010-01-21 16:08:48 +00:00
function hideMessage ( ) {
setLanguage ( getPageLanguage ( ) ) ;
$ ( '#blackpage' ) . fadeOut ( ) ;
}
2010-01-21 16:26:00 +00:00
// get the language of the current page
2010-01-21 16:08:48 +00:00
function getPageLanguage ( ) {
return window . location . pathname . replace ( /.*\/Scratch\/(..)\/.*$/ , '$1' ) ;
}
2010-01-21 16:26:00 +00:00
// alert the user if its navigator configuration tell
// me it should prefer another language
2010-01-21 16:08:48 +00:00
function alertLanguage ( ) {
var language = getUserLanguage ( ) ;
var language _of _current _page = getPageLanguage ( ) ;
if ( language != language _of _current _page ) {
if ( language == 'fr' ) {
message ( linkToLang ( 'en' , 'Aller sur la Version Française ?' ) + hideClickMessage ( 'No thanks, I prefer read english.' ) ) ;
} else if ( language == 'en' ) {
message ( linkToLang ( 'en' , 'Go to English Version?' ) + hideClickMessage ( 'Non merci, je préfère le français.' ) ) ;
} else {
// don't know which language the user prefer
message ( linkToLang ( 'en' , 'Go to English Version?' ) + '<br/>' + linkToLang ( 'fr' , 'Version Française ?' ) + hideClickMessage ( 'Non merci, je préfère le français.' ) ) ;
}
return false ;
}
return true ;
}
2010-01-21 16:26:00 +00:00
2010-01-20 15:20:44 +00:00
// --- fin pour la contribution de la fin de IE ---
function detectiPhone ( ) {
if ( ( navigator . userAgent . match ( /iPhone/i ) ) || ( navigator . userAgent . match ( /iPod/i ) ) ) {
$ ( 'head' ) . append ( '<link rel="stylesheet" type="text/css" href="/Scratch/css/iphone.css"/>' ) ;
$ ( 'head' ) . append ( '<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">' ) ;
// $('head').append('<link rel="apple-touch-icon" href="images/template/engage.png"/>');
$ ( 'head' ) . append ( '<link rel="stylesheet" type="text/css" href="/Scratch/css/iphone.css"/>' ) ;
// $('body').attr('onorientation','updateOrientation();');
decalageTop = 0 ;
2010-01-21 16:26:00 +00:00
// disable the animation of the menu
2010-01-20 15:20:44 +00:00
initMenu = function ( ) { } ;
}
}
2010-01-20 15:45:12 +00:00
// initialisation du menu
2010-01-20 15:20:44 +00:00
var decalageTop = 10 ;
function entete _height ( ) {
return $ ( '#entete' ) . height ( ) - $ ( '#menuMessage' ) . height ( ) + decalageTop ;
}
function hideMenu ( ) {
$ ( '#content' ) . animate ( { top : - entete _height ( ) } , 500 ) ;
$ ( '#menuMessage' ) . html ( '↓ Menu ↓' )
}
function showMenu ( ) {
$ ( '#content' ) . animate ( { top : "-1em" } , 500 ) ;
$ ( '#menuMessage' ) . html ( '↑ Menu ↑' ) . click ( hideMenu ) ;
last += 1 ;
autoHideMenu ( last ) ;
}
function toggleMenu ( ) {
if ( $ ( '#entete' ) . css ( 'top' ) == entete _height ( ) ) {
showMenu ( ) ;
} else {
hideMenu ( ) ;
}
}
var last = 0 ;
function autoHideMenu ( value ) {
setTimeout ( function ( ) {
if ( last == value ) {
hideMenu ( ) ;
}
} , 5000 ) ;
}
function initMenu ( ) {
$ ( '#titre' ) . css ( { top : - entete _height } ) ;
$ ( '#entete' ) . append ( '<div id="menuMessage">↓ Menu ↓</div>' ) ;
$ ( '#entete' ) . hover ( showMenu ) ;
$ ( '#entete' ) . hover ( function ( ) { last += 1 ; } , function ( ) { autoHideMenu ( last ) ; } ) ;
autoHideMenu ( 0 ) ;
hideMenu ( ) ;
}
// Ce que l'on va lancer à l'init.
$ ( document ) . ready ( function ( ) {
detectIE ( ) ;
detectiPhone ( ) ;
initMenu ( ) ;
2010-01-21 16:08:48 +00:00
// affiche la page une fois propre et la langue choisie
if ( alertLanguage ( ) ) {
$ ( '#blackpage' ) . fadeOut ( ) ;
}
2010-01-20 15:20:44 +00:00
} ) ;