[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / couteau_suisse / couteau_suisse / outils / glossaire.js
diff --git a/www/plugins/auto/couteau_suisse/couteau_suisse/outils/glossaire.js b/www/plugins/auto/couteau_suisse/couteau_suisse/outils/glossaire.js
new file mode 100644 (file)
index 0000000..2cd2bbe
--- /dev/null
@@ -0,0 +1,141 @@
+var gloss_el = null;\r
+var gloss_dt = null;\r
+var gloss_dd = null;\r
+var gloss_dl = null;\r
+\r
+// compatibilite Ajax : ajouter "this" a "jQuery" pour mieux localiser les actions\r
+// et tagger avec cs_done pour eviter de binder plrs fois le meme bloc\r
+function glossaire_init() {\r
+  if(jQuery('span.gl_js', this).length) {\r
+       if(!jQuery('#glossOverDiv').length) {\r
+               jQuery('body').append('<div id="glossOverDiv" style="position:absolute; display:none; visibility: hidden;"><span class="gl_dl"><span class="gl_dt">TITRE</span><span class="gl_dd">Definition</span></span></div>');\r
+               gloss_el = document.getElementById('glossOverDiv');\r
+               gloss_dl = gloss_el.firstChild;\r
+               gloss_dt = gloss_dl.firstChild;\r
+               gloss_dd = gloss_dl.lastChild;\r
+       }\r
+       jQuery('span.gl_mot', this).cs_todo().hover(\r
+               function(e) {\r
+                       $this = jQuery(this);     \r
+                       // cas du surligneur (SPIP 2)\r
+                       if(this.firstChild.className=="spip_surligne") {\r
+                               this.className = "gl_mot spip_surligne";\r
+                               this.innerHTML = this.firstChild.innerHTML;\r
+                       }\r
+                       gloss_dt.innerHTML = $this.parent().children('.gl_js')[0].title;  // titre\r
+                       gloss_dd.innerHTML = $this.parent().children('.gl_jst')[0].title; // definition\r
+                       reg = $this.css('font-size').match(/^\d\d?(?:\.\d+)?px/);\r
+                       if(reg) gloss_el.style.fontSize = reg[0];\r
+                       jQuery(gloss_el)\r
+                               .css('top', e.pageY.toString()+"px")\r
+                               .css('left', e.pageX.toString()+"px")\r
+                               .css('font-family', jQuery(this).css('font-family'));\r
+                       gloss_el.style.display    = 'block';\r
+                       gloss_el.style.visibility = 'visible';\r
+                       if(typeof jQuery.fn.offset=="function") { // plugin jquery.dimensions disponible a partir de SPIP 2\r
+if(1) {///////////////////////// optimisation du placement, encore en test...\r
+       var $glossOverDiv = jQuery('#glossOverDiv');\r
+       var $gloss_dl = jQuery(gloss_dl);\r
+       positionBy = 'auto'; // Type de positionnement : 'dessus', 'dessous', 'auto', 'mouse' (a tester...)\r
+       ombre = 0;  // Taille d'une ombre, en pixels (non implemente)\r
+       decalX = 2; // decalage entre le glossaire et le lien appelant\r
+       width = 180; // largeur totale de #glossOverDiv : definie dans glossaire.css\r
+       height = 'auto'; // hauteur totale de #glossOverDiv : 'auto' ou nombre de pixels\r
+       // initiation verticale\r
+       var glossHeight, wHeight;\r
+       var linkHeight = this.offsetHeight;\r
+       var defHeight = isNaN(parseInt(height, 10)) ? 'auto' : (/\D/g).test(height) ? height : height + 'px';\r
+       var sTop, linkTop, posY, mouseY, baseLine;\r
+       sTop = jQuery(document).scrollTop();\r
+       // initiation horizontale\r
+       var glossWidth = width + ombre;\r
+       var linkWidth = this.offsetWidth;\r
+       var linkLeft, posX, mouseX, winWidth;\r
+       winWidth = jQuery(window).width();\r
+       // c'est parti !\r
+       linkTop = posY = $this.offset().top;\r
+       linkLeft = $this.offset().left;\r
+       mouseX = e.pageX;\r
+       mouseY = e.pageY;\r
+// securite pour l'instant\r
+$glossOverDiv.css({margin:'0px'}); $gloss_dl.css({margin:'0px'});\r
+       // calcul de la position horizontale : glossaire au centre du lien\r
+       posX = Math.max(linkLeft - (glossWidth-linkWidth)/2,0);\r
+       if (positionBy == 'dessous' || positionBy == 'dessus') { // glossaire fixe\r
+               $glossOverDiv.css({left: posX + 'px'});\r
+       } else {\r
+               // au cas ou, glossaire a droite ou a gauche du lien ?\r
+               posX2 = (linkWidth > linkLeft && linkLeft > glossWidth) || (linkLeft + linkWidth + glossWidth + decalX > winWidth)\r
+                 ? linkLeft - glossWidth - decalX \r
+                 : linkWidth + linkLeft + decalX;\r
+               // suivre la souris ?\r
+               if (positionBy == 'mouse' || linkWidth + glossWidth > winWidth) {\r
+                 posX = Math.max(mouseX - (glossWidth-linkWidth)/2,0); // glossaire au centre de la souris\r
+               /*if (mouseX + 20 + glossWidth > winWidth)\r
+                       posX = (mouseX - glossWidth) >= 0 ? mouseX - glossWidth :  mouseX - (glossWidth/2);\r
+               else posX = mouseX;*/\r
+       }\r
+       var pY = e.pageY;\r
+       $glossOverDiv.css({left: (posX > 0 && positionBy != 'dessus') ? posX : (mouseX + (glossWidth/2) > winWidth) ? winWidth/2 - glossWidth/2 : Math.max(mouseX - (glossWidth/2),0)});\r
+       }\r
+       // calcul de la position verticale\r
+       wHeight = jQuery(window).height();\r
+       $glossOverDiv.css({overflow: defHeight == 'auto' ? 'visible' : 'auto', height: defHeight});\r
+       glossHeight = defHeight == 'auto' ? Math.max($gloss_dl.outerHeight(),$gloss_dl.height()) : parseInt(defHeight,10);   \r
+       glossHeight += ombre;\r
+       tipY = posY;\r
+       baseLine = sTop + wHeight;\r
+       if (positionBy == 'dessous') tipY = posY + linkHeight + 2; // glossaire fixe sous le lien\r
+       else if (positionBy == 'dessus') tipY = posY - glossHeight - 2; // glossaire fixe au-dessus du lien\r
+       else if ( posX < mouseX && Math.max(posX, 0) + glossWidth > mouseX ) { // glossaire cache le lien\r
+               if (posY + glossHeight > baseLine && mouseY - sTop > glossHeight) { \r
+                 tipY = posY - glossHeight - 2;\r
+               } else { \r
+                 tipY = posY + linkHeight + 2;\r
+               }\r
+       } else if ( posY + glossHeight > baseLine ) {\r
+               tipY = (glossHeight >= wHeight) ? sTop : baseLine - glossHeight;\r
+       } else if ($this.css('display') == 'block' || positionBy == 'mouse') {\r
+               tipY = pY;\r
+       } else {\r
+               tipY = posY /*- ombre*/;\r
+       }\r
+       $glossOverDiv.css({top: tipY + 'px'});\r
+}////////////////////////////////////////\r
+\r
+                       } // typeof jQuery.fn.offset=="function"\r
+                       gloss_el.style.visibility = 'visible';\r
+               },\r
+               function(e) {\r
+                       gloss_el.style.display    = 'none';\r
+                       gloss_el.style.visibility = 'hidden';\r
+               }\r
+       );\r
+\r
+       // accessibilite au clavier\r
+       if(typeof jQuery.fn.offset=="function") { // plugin jquery.dimensions disponible a partir de SPIP 2\r
+               jQuery('a.cs_glossaire').focus(\r
+                       function() {\r
+                               legl_mot = this.firstChild;\r
+                               gloss_dt.innerHTML = jQuery(this).children('.gl_js')[0].title;  // titre\r
+                               gloss_dd.innerHTML = jQuery(this).children('.gl_jst')[0].title; // definition\r
+                               reg = jQuery(this.firstChild).css('font-size').match(/^\d\d?(?:\.\d+)?px/);\r
+                               if(reg) gloss_el.style.fontSize = reg[0];\r
+                               var result = jQuery(this).offset({ scroll: false });\r
+                               jQuery(gloss_el)\r
+                                       .css('top',result.top+"px")\r
+                                       .css('left', result.left+"px")\r
+                                       .css('font-family', jQuery(this.firstChild).css('font-family'));\r
+                               gloss_el.style.display    = 'block';\r
+                               gloss_el.style.visibility = 'visible';\r
+                       }\r
+               );\r
+               jQuery('a.cs_glossaire').blur(\r
+                       function() {\r
+                               gloss_el.style.display    = 'none';\r
+                               gloss_el.style.visibility = 'hidden';\r
+                       }\r
+               );\r
+       } // typeof jQuery.fn.offset=="function"\r
+  }\r
+}
\ No newline at end of file