scratch/output/Scratch/js/index.js

195 lines
6 KiB
JavaScript
Raw Normal View History

2010-01-20 15:20:44 +00:00
// Message en fonction du browser
function detectIE() {
2010-04-27 22:13:52 +00:00
if ($.browser["msie"]) {
2010-01-20 15:20:44 +00:00
$('head').append('<script type="text/javascript" src="/Scratch/js/ie.js"></script>');
2010-04-27 22:13:52 +00:00
}
2010-01-20 15:20:44 +00:00
}
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;
}
2010-05-04 23:02:34 +00:00
function fastHideMenu() {
$('#content').css({top: - entete_height()});
$('#menuMessage').html('↓ Menu ↓')
}
2010-01-20 15:20:44 +00:00
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);
}
2010-05-05 18:53:54 +00:00
function fastShowMenu() {
$('#content').css({top:"-1em"});
$('#menuMessage').html('↑ Menu ↑').click(hideMenu);
last+=1;
autoHideMenu(last);
}
2010-01-20 15:20:44 +00:00
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);
2010-05-04 23:02:34 +00:00
fastHideMenu();
2010-01-20 15:20:44 +00:00
}
function setSpecificCss() {
var userAgent = navigator.userAgent.toLowerCase();
if ( /webkit/.test(userAgent) ) {
$('head').append('<link rel="stylesheet" href="/Scratch/assets/css/gen_webkit.css"/>');
} else if ( /mozilla/.test(userAgent) ) {
$('head').append('<link rel="stylesheet" href="/Scratch/assets/css/gen_mozilla.css"/>');
}
}
2010-01-20 15:20:44 +00:00
// Ce que l'on va lancer à l'init.
$(document).ready( function() {
setSpecificCss();
2010-01-20 15:20:44 +00:00
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
});
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-10612400-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
$(function () {
$('a').click(function () {
// tell analytics to save event
try {
_gaq.push(['_trackEvent', thisel.parents('[id!=""]:first').get(0).id, 'clicked', (thisel.text() || thisel.children('img:first').attr('alt'))]);
}
catch (err) {}
// pause to allow google script to run
var date = new Date();
var curDate = null;
do {
curDate = new Date();
} while(curDate-date < 300);
});
});