Subversion Repositories wimsdev

Rev

Rev 3425 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. var hudPadding = 30;
  2. var hudActif = false;
  3.  
  4. function DOM_HUD() {
  5.         if (navigateurEstIncompatible()) return false;
  6.  
  7.         // ajout du div overlay à la fin du body
  8.         var overlay = document.createElement("div");
  9.         overlay.setAttribute('id', 'overlay');
  10.         overlay.style.opacity = '0';
  11.         document.body.insertBefore(overlay, document.body.childNodes[0]);
  12.  
  13. }
  14.  
  15. //  WIMS OVERLAY *************************************************************************************************************
  16.  
  17. function DOM_HUD_WIMS() {
  18.         if (navigateurEstIncompatible()) return false;
  19.  
  20.         // Recherche des liens
  21.         var liens, lien, sticky, reflet, icone = null;
  22.         liens = getElementsByClassName('lien_externe_reload(.*)');
  23.         for (i=0; i< liens.length; i++) { // boucle sur les liens
  24.                 lien = liens[i];
  25.                 if (lien.tagName.toLowerCase() == "a") {
  26.                       lien.setAttribute('onclick', 'afficherOverlayWims();');
  27.                }
  28.         }
  29. }
  30.  
  31. function afficherOverlayWims() {
  32.         if (navigateurEstIncompatible()) return false;
  33.         element = document.getElementById('hud_wims_actualiser');
  34.         if (element) {
  35.              hudCentrerElement(element);
  36.              hudAfficherOverlay()
  37.              element.style.display = 'block';
  38.         }
  39. }
  40.  
  41. function masquerOverlayWims() {
  42.         //window.location.reload();
  43.         window.location.href = window.location.href;
  44. }
  45.  
  46.  
  47. //  VIDEO INTRO OVERLAY *************************************************************************************************************
  48.  
  49. function afficherOverlayVideoIntro() {
  50.         if (navigateurEstIncompatible()) return false;
  51.         elementId = 'hud_video_intro';
  52.         element = document.getElementById(elementId);
  53.         if (element) {
  54.              hudActif = true;
  55.              hudCentrerElement(element);
  56.              hudAfficherOverlay()
  57.              setTimeout("hudAnimationOuverture(elementId)", 500);
  58.         }
  59. }
  60.  
  61. function masquerOverlayVideoIntro() {
  62.         element = document.getElementById('hud_video_intro');
  63.         if (element) {
  64.                 hudActif = false;
  65.                 hudAnimationFermeture(element.id);
  66.         }
  67. }
  68. //  AJOUT DES ELEMENTS *************************************************************************************************************
  69.  
  70. function hudCreerElement(lElement, lTitre, lLangue, lFeedbackObject, lElementWidth) { // Ajout de la class hud_element aux nodes qui ont un id
  71.         if (hudObjetEstValide(lElement)) {
  72.  
  73.                 // ajout de la classe et stockage d'un object de feedback different de l'element (si fourni)
  74.                 addClassName(lElement, 'hud_element');
  75.                 lElement.hudFeedbackObject = lFeedbackObject;
  76.                 if (lElementWidth) { lElement.style.width = lElementWidth; }
  77.                 desactiverAutocomplete(lElement);
  78.  
  79.                 // creation et ajout du titre
  80.                 h = document.createElement("h3");
  81.                 h.appendChild(document.createTextNode(lTitre));
  82.                 lElement.insertBefore(h, lElement.firstChild);
  83.  
  84.                 // creation et ajout de la zone de boutons et du bouton annuler
  85.                 boutons = document.createElement("div");
  86.                 boutons.setAttribute('id', lElement.id+'_hud_boutons');
  87.                 boutons.className = 'hud_boutons';
  88.                 lElement.appendChild(boutons);
  89.         }
  90. }
  91.  
  92. function hudAjouterBouton(lType, lElement, lTitre, lName, lLangue, lImg, lAction, lAppend, lOnClick) { // Ajout d'un bouton (annuler, enregistrer...) + stockage des objets
  93.         if (hudObjetEstValide(lElement)) {
  94.                 boutons = document.getElementById(lElement.id+'_hud_boutons');
  95.  
  96.                 imgPath = 'images_css/boutons/'+lLangue+'/'+lImg;
  97.                 if (lType == 'IMAGE') {
  98.                         bouton = createImageLink(imgPath, "hudBoutonsAction(this)", lTitre, lAppend);
  99.                 } else if (lType == 'SUBMIT') {
  100.                         bouton = document.createElement("input");
  101.                         bouton.setAttribute('type', 'image');
  102.                         bouton.setAttribute('name', lName);
  103.                         bouton.setAttribute('src', imgPath);
  104.                         bouton.setAttribute('value', 'Valider');
  105.                 } else {
  106.                         return null;
  107.                 }
  108.  
  109.                 bouton.hudElement = lElement;
  110.                 bouton.hudAction  = lAction;
  111.                 bouton.hudAppend  = lAppend;
  112.                 if (lOnClick) { bouton.onclick = lOnClick; }
  113.                 if (lAppend) { boutons.appendChild(bouton); }
  114.                 return bouton;
  115.         }
  116.         return null;
  117. }
  118.  
  119. function hudCreerBoutons(lElement, lInfosSubmit, lActionValider, lActionAnnuler, lLangue, lImg, lOnClick) { // Ajout des 2 boutons par défaut
  120.         hudAjouterBouton('IMAGE',  lElement, lInfosSubmit['cancel'], '', lLangue, 'bouton_niveau4_annuler.png', lActionAnnuler, true, false);
  121.         hudAjouterBouton('SUBMIT', lElement, lInfosSubmit['value'], lInfosSubmit['name'], lLangue, 'bouton_niveau4_'+lImg+'.png', lActionValider, true, lOnClick);
  122. }
  123.  
  124. function hudCreerBoutonLancement(lElement, lTitre, lAction, lLangue, lImg, lNiveau) { // creation du bouton de lancement du HUD (false => pas inseré dans bloc boutons)
  125.         return hudAjouterBouton('IMAGE', lElement, lTitre, '', lLangue, 'bouton_niveau'+lNiveau+'_'+lImg+'.png', lAction, false, false);
  126. }
  127.  
  128. function hudCreerLancement(lElement, lTitre, lAction, lLangue, lImg, lNiveau, lId, lClass) { // creation du bouton de lancement du HUD et de son div
  129.         bouton = hudCreerBoutonLancement(lElement, lTitre, lAction, lLangue, lImg, lNiveau);
  130.         div = document.createElement("div");
  131.         div.setAttribute('id', lId);
  132.         div.setAttribute('class', 'hud_lancement');
  133.         if (lClass) { addClassName(div, lClass); }
  134.         div.appendChild(bouton);
  135.         return div;
  136. }
  137.  
  138.  
  139. // ACTIONS *************************************************************************************************************
  140.  
  141. function hudBoutonsAction(obj) { // appelé par click sur un des boutons hud
  142.         if (obj.hudAction) { obj.hudAction((obj.hudElement.hudFeedbackObject ? obj.hudElement.hudFeedbackObject : obj.hudElement)); } // appel du feedback avec element ou object feedback
  143.         if (!obj.hudAppend) { // bouton lancement (pas dans le bloc des boutons)
  144.              if (!hudActif) {
  145.                 hudActif = true;
  146.                 elementId = obj.hudElement.id;
  147.                 //hudAfficherOverlay();
  148.                 hudCentrerElement(obj.hudElement);
  149.                 setTimeout("hudAnimationOuverture(elementId)", 500);
  150.                 /*obj.hudElement.style.display = 'block';
  151.                 obj.hudElement.style.opacity = 1;
  152.                 obj.hudElement.style.zIndex   = 9999;
  153.                 obj.hudElement.style.position = 'absolute';*/
  154.             }
  155.         } else {
  156.                 hudActif = false;
  157.                 hudAnimationFermeture(elementId);
  158.         }
  159.      return false;
  160. }
  161.  
  162. // ANIMATION ********************************************************************************************************
  163. var z=0;
  164. function hudAnimationOuverture(obj) { // animation d'ouverture
  165.  
  166. if(z==1){
  167.         element = document.getElementById(obj);
  168.         element.style.display = 'block';
  169.         //$(obj).effects({duration:1}).start({'opacity':[1,1]});
  170.         //$(obj).effects({duration:1500, transition:Fx.Transitions.Elastic.easeOut}).start({'padding':[0,hudPadding], 'margin':[0,-hudPadding]});
  171.         //setTimeout("hudFocus1erChamps(element)", 1501);
  172.        hudFocus1erChamps(element);
  173.          }
  174.          z=1;
  175.  
  176.  
  177. }
  178.  
  179. function hudFocus1erChamps(obj) {
  180.        elementsForm = chercherElementsDeFormulaire(obj);
  181.        if (elementsForm.length > 0) {
  182.            if (elementsForm[0].type != 'image') { // AM : chercherElementsDeFormulaire renvoie d'abord les inputs => si pas d'input, renvoi le bouton submit => modifier en bouclant sur les champs et chercher autres que input
  183.                 elementsForm[0].blur();
  184.                 elementsForm[0].focus();
  185.            }
  186.       }
  187. }
  188.  
  189. function hudAnimationFermeture(obj) { // animation de fermeture et masquage de l'overlay
  190.         tempVar = obj;
  191.         this._prepareIE("", "");
  192.         //$(obj).effects({duration:200}).start({'opacity':[1,0]});
  193.         str =       "document.getElementById(tempVar).style.display = 'none';";
  194.         str = str + "document.getElementById(tempVar).style.position = 'relative';";
  195.         str = str + "document.getElementById(tempVar).style.top = '';";
  196.         str = str + "document.getElementById(tempVar).style.left = '';";
  197.         str = str + "document.getElementById(tempVar).style.padding = '0';";
  198.         str = str + "document.getElementById('overlay').style.display = 'none';";
  199.         str = str + "tempVar=false;";
  200.         setTimeout(str, 200);
  201.         chrono=null;
  202.         anime();
  203.  
  204. }
  205.  
  206.  
  207. function hudCentrerElement(element) { // centrage d'un element
  208.         element.style.position = 'absolute';
  209.         element.style.zIndex   = 9999;
  210.         tailleElement = getDimensions(element);
  211.         x = positionDocVisible().x+(tailleDocVisible().width - tailleElement.width)/2;
  212.         y = positionDocVisible().y+(tailleDocVisible().height - tailleElement.height)/3;
  213.         x = (x >= positionDocVisible().x ? x : positionDocVisible().x);
  214.         y = (y >= positionDocVisible().y ? y : positionDocVisible().y);
  215.         element.style.left = x+'px';
  216.         element.style.top  = y+'px';
  217. }
  218. var k=0;
  219. function hudAfficherOverlay() {
  220.  
  221. if(k==1){
  222.         this._setOverlay();
  223.         document.getElementById('overlay').style.opacity = '0.75';
  224.         document.getElementById('overlay').style.display = 'block';
  225. }
  226. k=1;
  227. }
  228.  
  229. // UTILS *************************************************************************************************************
  230.  
  231. function hudObjetEstValide(lElement) { // verification de l'id de l'element
  232.         if (lElement) {
  233.                 return (lElement.id != null && lElement.id != "");
  234.         }
  235.         return false;
  236. }
  237.  
  238. function _setOverlay() {
  239.         if(navigator.appVersion.match(/\bMSIE\b/)) {
  240.                 this._prepareIE("100%", "hidden");
  241.                         //if (!navigator.appVersion.match(/\b7.0\b/)) window.scrollTo(0,0); // Disable scrolling on top for IE7
  242.         }
  243. }
  244.  
  245. function _prepareIE(height, overflow){
  246.         var body = document.getElementsByTagName('body')[0];
  247.         body.style.height = height;
  248.         body.style.overflow = overflow;
  249.  
  250.         var html = document.getElementsByTagName('html')[0];
  251.         html.style.height = height;
  252.         html.style.overflow = overflow;
  253. }
  254.  
  255.  
  256. // LOAD *******************************************************************************************************
  257.  
  258. addEvent(window,'load', function() { DOM_HUD();} );
  259. addEvent(window,'load', function() { DOM_HUD_WIMS();} );
  260.  
  261.  
  262. addEvent(window,'load', function() { afficherOverlayVideoIntro();} );
  263.  
  264.