scratch/output/Scratch/js/index.js

207 lines
6.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-06-18 21:40:41 +00:00
// --- code popup ---
function openWide() {
$(this).clone(false).appendTo($("#_code"));
$('#_code a').css({"margin-right":"3em"});
$("#_code").show();
}
function returnToNormal() {
$("#_code").html("");
$("#_code").hide();
}
function initCode() {
$(".code").click(openWide);
$(".code").css({cursor: "pointer"});
$('body').append('<div id="_code"></div>');
2010-06-18 23:27:41 +00:00
$('#_code').css( { 'font-size':$('.corps:first').css('font-size'), 'text-align': "justify", position: "fixed", left:0, top:0, width: "100%", height: "100%", "background-color": "rgba(0, 0, 0, 0.8)", 'z-index':2000, 'padding':'3px'} );
2010-06-18 21:40:41 +00:00
$('#_code').hide();
$('#_code').click(returnToNormal);
}
// --- end of code popup section ---
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() {
var lang=window.location.pathname.replace(/.*\/Scratch\/(..).*$/,'$1');
if ( lang == window.location.pathname ) {
return "";
}
else {
return lang;
}
2010-01-21 16:08:48 +00:00
}
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_of_current_page == "" ) {
return true;
}
2010-01-21 16:08:48 +00:00
if (language != language_of_current_page) {
if ( language == 'fr' ) {
2010-07-13 22:06:57 +00:00
message(linkToLang('fr','Aller sur la Version Française ?') + hideClickMessage('No thanks, I prefer read english.'));
2010-01-21 16:08:48 +00:00
} 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))) {
2010-09-03 07:52:57 +00:00
$('head').append('<meta name="viewport" content="width=device-width; initial-scale=2.0; maximum-scale=2.0;">');
$('head').append('<link rel="stylesheet" type="text/css" href="/Scratch/css/iPhone.css"/>');
2010-01-20 15:20:44 +00:00
// $('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
2010-01-20 15:20:44 +00:00
function setSpecificCss() {
var userAgent = navigator.userAgent.toLowerCase();
2010-07-31 12:36:46 +00:00
// if ( /chrome/.test(userAgent) ) {
// $('head').append('<link rel="stylesheet" href="/Scratch/assets/css/gen_chrome.css"/>');
// } else 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();
2010-06-18 21:40:41 +00:00
initCode();
2010-07-13 11:50:28 +00:00
2010-01-21 16:08:48 +00:00
// affiche la page une fois propre et la langue choisie
if ( alertLanguage() ) {
$('#blackpage').fadeOut();
}
var admin = $.cookie('admin');
if (! admin) {
// console.log("you're logged by google analytics");
// add an event to all link for google analytics
$('a').click(function () {
// tell analytics to save event
try {
var identifier=$(this).attr('id') ;
var href=$(this).attr('href')
var label="";
if ( typeof( identifier ) != 'undefined' ) {
label=label+'[id]:'+identifier
category='JSLink'
}
if ( typeof( href ) != 'undefined' ) {
label=label+' [href]:'+href
if ( href[0] == '#' ) {
category='Anchor';
} else {
category='Link';
}
2010-06-17 09:37:12 +00:00
}
_gaq.push(['_trackEvent', category, 'clicked', label]);
// console.log('[tracked]: ' + category + ' ; clicked ; ' + label );
}
catch (err) {
console.log(err);
2010-06-17 08:56:20 +00:00
}
// pause to allow google script to run
var date = new Date();
var curDate = null;
do {
curDate = new Date();
} while(curDate-date < 300);
});
} else {
console.log("[WARNING] you're HIDDEN to analytics");
}
});
2010-05-20 16:01:37 +00:00
if ( ! $.cookie('admin') ) {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-10612400-1']);
_gaq.push(['_trackPageview']);
2010-05-20 16:01:37 +00:00
(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);
})();
} else {
console.log("[WARNING] you're HIDDEN to analytics");
}
2010-05-20 16:01:37 +00:00