Subversion Repositories Applications.dictionnaire

Compare Revisions

Ignore whitespace Rev 3 → Rev 2

/scripts/dictionnaire.config.defaut.js
File deleted
\ No newline at end of file
/scripts/dictionnaire.js
1,13 → 1,11
var dictionnaire = new Array();
var motsAyantDefinition = null;
var motsAyantDefinition = new Array();
var noeudAyantsDefinition = new Array();
var mouseX = null;
var mouseY = null;
var tempsDepuisRequeteAjax = 0;
var active = false;
 
function getUrlBaseService() {
// provient de dictionnaire.config.js
return URL_BASE_SERVICE;
return 'http://localhost/dictionnaire/services/0.1/dictionnaire/';
}
 
function supprimerAccents(str) {
45,20 → 43,6
.replace('œ',"(œ|oe)");
}
 
function afficherLienDefinitions() {
html = '<div id="conteneur_activation_definition"><a href="#">rechercher les définitions</a></div>';
$('#conteneur_activation_definition').live('click', function(event) {
event.preventDefault();
supprimerToutesDefinitions();
if(motsAyantDefinition == null) {
getMotsADefinitions();
} else {
ajouterDefinitions(motsAyantDefinition);
}
});
$('body').append(html);
}
 
function normaliserMotPourRecherche(str) {
str = supprimerAccents(str);
str = etendreChaineAccents(str);
65,41 → 49,30
return str;
}
 
$.fn.remplacerDefinitions = function(mots) {
$.fn.remplacerDefinition = function(mot) {
motSimplifie = supprimerAccents(mot).toLowerCase();
mot = normaliserMotPourRecherche(mot);
var regExp = new RegExp("("+mot+")", 'ig');
this.each(function() {
$(this).contents().filter(function() {
return this.nodeType == 3;
return this.nodeType == Node.TEXT_NODE;
}).each(function() {
element = $(this);
texte = element.text();
if(texte != "") {
$.each(mots, function(index, valeur) {
def = valeur['cle'];
texte = rechercherEtRemplacerMotParDefinition(texte, def);
});
element.replaceWith(texte);
}
termeDansTexte = regExp.exec($(this).text());
if(termeDansTexte != null && termeDansTexte.length > 0) {
motOriginal = termeDansTexte[0];
templateMotADefinition = formaterTemplateMotADefinition(motSimplifie, motOriginal);
output = $(this).text().replace(regExp, definitionHtml);
$(this).replaceWith(output);
noeudAyantsDefinition.push($(this));
}
});
});
return this;
}
 
function rechercherEtRemplacerMotParDefinition(texte, mot) {
motSimplifie = supprimerAccents(mot).toLowerCase();
mot = normaliserMotPourRecherche(mot);
exclureSpan = '[^(?:class="definition_term">)]';
regExp = new RegExp(exclureSpan+"[ |,|-|;|.]+("+mot+")[a-zA-Z]{1}", 'ig');
termeDansTexte = regExp.exec(texte);
if(termeDansTexte != null && termeDansTexte.length > 1) {
motOriginal = termeDansTexte[1];
templateMotADefinition = formaterTemplateMotADefinition(motSimplifie, motOriginal);
texte = texte.replace(motOriginal, templateMotADefinition);
}
 
return texte;
}
 
function getMotsADefinitions() {
function getMotADefinitions() {
$.ajax({
url: getUrlBaseService()+'mots/',
success: function(data) {
115,8 → 88,10
}
 
function ajouterDefinitions(motsAvecDefinitions) {
set = 'p, span:not("definition_term"), td, pre';
$(set).remplacerDefinitions(motsAvecDefinitions);
jQuery.each(motsAvecDefinitions, function(index) {
def = motsAvecDefinitions[index]['cle'];
$('p, span, td, th, div').remplacerDefinition(def);
});
}
 
function formaterTemplateMotADefinition(motSimplifie, motOriginal) {
140,7 → 115,7
function afficherDefinition(element) {
mot = element.attr('rel');
if(dictionnaire[mot] != null) {
element.after(formaterDefinition(element));
element.append(formaterDefinition(element));
afficherPopupDefinition();
} else {
chargerDefinitionDistante(element);
147,9 → 122,7
}
}
 
function chargerDefinitionDistante(element) {
date = new Date();
tempsDepuisRequeteAjax = date.getTime();
function chargerDefinitionDistante(element) {
$.ajax({
url: getUrlBaseService()+'def/'+mot,
success: function(data) {
156,7 → 129,7
retour = data;
definition = retour.valeur;
dictionnaire[mot] = definition;
element.after(formaterDefinition(element));
element.append(formaterDefinition(element));
afficherPopupDefinition();
},
dataType: "JSON",
177,7 → 150,7
data = dictionnaire[mot];
defHtml = '<div class="definition_container">'+
'<span class="definition_container_fleche"></span>'+
'<span class="definition">'+data+'</span>'+
data+
'</div>';
return defHtml;
}
189,6 → 162,11
cacherPopupsDefinitions();
}
 
function surFinRequeteAjax() {
supprimerToutesDefinitions();
ajouterDefinitions(motsAyantDefinition);
}
 
$(document).bind('mousemove', function(e){
mouseX = e.pageX;
mouseY = e.pageY - $(window).scrollTop();
195,6 → 173,10
});
 
$(document).ready(function() {
afficherLienDefinitions();
getMotADefinitions();
});
 
$(document).ajaxStop(function() {
t = setTimeout(function(){surFinRequeteAjax()},800)
});
 
/scripts/dictionnaire.css
17,8 → 17,7
padding-bottom: 20px;
padding-top: 0px;
border:1px solid black;
z-index: 1000;
text-decoration: none;
z-index: 220;
}
 
.definition_container_fleche {
28,22 → 27,5
left: 10px;
position: relative;
top: -20px;
z-index: 999;
border
}
 
.definition {
border-bottom: none;
text-decoration: none;
}
 
#conteneur_activation_definition {
position: fixed;
left: 0;
top: 0;
padding: 5px;
background-color: #EAEDCD;
border: 1px dotted black;
font-family: Arial,Helvetica,Verdana,sans-serif;
font-size: 0.85em;
z-index: 240;
}