Skip to content
Extraits de code Groupes Projets
Valider 8d7951cd rédigé par renato's avatar renato
Parcourir les fichiers

ajoute la classe pas_surlignable a le body du page de recherche pour ne pas...

ajoute la classe pas_surlignable a le body du page de recherche pour ne pas surligner les resultats;
maintenaint on surligne pas que les mots de 3 chars ou plus;
le script de surligne ne separe pas le mots d'une phrase entre guillemets
parent 60db370d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* @author Renato Formato <renatoformato@virgilio.it> * @author Renato Formato <renatoformato@virgilio.it>
* *
* @version 0.33 * @version 0.34
* *
* Options * Options
* - exact (string, default:"exact") * - exact (string, default:"exact")
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
* - keys (string, default:null) * - keys (string, default:null)
* Disable the analisys of the referrer and search for the words given as argument * Disable the analisys of the referrer and search for the words given as argument
* *
* - min_length (number, defalt:null)
* Set the minimun length of a key
*
*/ */
(function($){ (function($){
...@@ -50,20 +53,21 @@ ...@@ -50,20 +53,21 @@
SearchHighlight.options = $.extend({exact:"exact",style_name:'hilite',style_name_suffix:true},options); SearchHighlight.options = $.extend({exact:"exact",style_name:'hilite',style_name_suffix:true},options);
if(options.engines) SearchHighlight.engines.unshift(options.engines); if(options.engines) SearchHighlight.engines.unshift(options.engines);
var q = options.keys!=undefined?options.keys.toLowerCase().split(/[\s,\+\.]+/):SearchHighlight.decodeURL(ref,SearchHighlight.engines); var q = SearchHighlight.splitKeywords(options.keys!=undefined?options.keys.toLowerCase():SearchHighlight.decodeURL(ref,SearchHighlight.engines));
if(q && q.join("")) { if(q && q.join("")) {
SearchHighlight.buildReplaceTools(q); SearchHighlight.buildReplaceTools(q);
if(!SearchHighlight.regex) return this;
return this.each(function(){ return this.each(function(){
var el = this; var el = this;
if(el==document) el = $("body")[0]; if(el==document) el = $("body")[0];
SearchHighlight.hiliteElement(el, q); SearchHighlight.hiliteElement(el);
}) })
} else return this; } else return this;
}; };
var SearchHighlight = { var SearchHighlight = {
options: {}, options: {},
regex: [], regex: null,
engines: [ engines: [
[/^http:\/\/(www\.)?google\./i, /q=([^&]+)/i], // Google [/^http:\/\/(www\.)?google\./i, /q=([^&]+)/i], // Google
[/^http:\/\/(www\.)?search\.yahoo\./i, /p=([^&]+)/i], // Yahoo [/^http:\/\/(www\.)?search\.yahoo\./i, /p=([^&]+)/i], // Yahoo
...@@ -96,13 +100,29 @@ ...@@ -96,13 +100,29 @@
} }
}); });
if (query) {
query = query.replace(/(\'|")/, '\$1');
query = query.split(/[\s,\+\.]+/);
}
return query; return query;
}, },
splitKeywords: function(query) {
if(query) {
//do not split keywords enclosed by "
var m = query.match(/"([^"]*)"/g);
if(m)
for(var i=0, ml=m.length;i<ml;i++) {
var regex = new RegExp(m[i]);
query = query.replace(regex,'@@@'+i+'@@@');
}
query = query.split(/[\s,\+\.]+/);
if(m)
for(var i=0,l = query.length;i<l;i++) {
for(var j=0, ml=m.length;j<ml;j++) {
var regex = new RegExp("@@@"+j+"@@@");
query[i] = query[i].replace(regex,m[j].substring(1,m[j].length-1))
}
}
};
return query;
},
regexAccent : [ regexAccent : [
[/[\xC0-\xC5\u0100-\u0105]/ig,'a'], [/[\xC0-\xC5\u0100-\u0105]/ig,'a'],
[/[\xC7\u0106-\u010D]/ig,'c'], [/[\xC7\u0106-\u010D]/ig,'c'],
...@@ -129,10 +149,12 @@ ...@@ -129,10 +149,12 @@
buildReplaceTools : function(query) { buildReplaceTools : function(query) {
var re = [], regex; var re = [], regex;
$.each(query,function(i,n){ $.each(query,function(i,n){
if(n = SearchHighlight.replaceAccent(n).replace(SearchHighlight.escapeRegEx,"$1\\$2")) if(SearchHighlight.options.min_length && n.length>=SearchHighlight.options.min_length)
re.push(n); if(n = SearchHighlight.replaceAccent(n).replace(SearchHighlight.escapeRegEx,"$1\\$2"))
re.push(n);
}); });
if(!re.length) return;
regex = re.join("|"); regex = re.join("|");
switch(SearchHighlight.options.exact) { switch(SearchHighlight.options.exact) {
case "exact": case "exact":
...@@ -150,17 +172,17 @@ ...@@ -150,17 +172,17 @@
}); });
}, },
nosearch: /s(?:cript|tyle)|textarea/i, nosearch: /s(?:cript|tyle)|textarea/i,
hiliteElement: function(el, query) { hiliteElement: function(el) {
var opt = SearchHighlight.options, elHighlight, noHighlight; var opt = SearchHighlight.options, elHighlight, noHighlight;
elHighlight = opt.highlight?$(opt.highlight):$("body"); elHighlight = opt.highlight?$(opt.highlight):$("body");
if(!elHighlight.length) elHighlight = $("body"); if(!elHighlight.length) elHighlight = $("body");
noHighlight = opt.nohighlight?$(opt.nohighlight):$([]); noHighlight = opt.nohighlight?$(opt.nohighlight):$([]);
elHighlight.each(function(){ elHighlight.each(function(){
SearchHighlight.hiliteTree(this,query,noHighlight); SearchHighlight.hiliteTree(this,noHighlight);
}); });
}, },
hiliteTree : function(el,query,noHighlight) { hiliteTree : function(el,noHighlight) {
if(noHighlight.index(el)!=-1) return; if(noHighlight.index(el)!=-1) return;
var matchIndex = SearchHighlight.options.exact=="whole"?1:0; var matchIndex = SearchHighlight.options.exact=="whole"?1:0;
for(var startIndex=0,endIndex=el.childNodes.length;startIndex<endIndex;startIndex++) { for(var startIndex=0,endIndex=el.childNodes.length;startIndex<endIndex;startIndex++) {
...@@ -186,7 +208,7 @@ ...@@ -186,7 +208,7 @@
} }
} else { } else {
if(item.nodeType==1 && item.nodeName.search(SearchHighlight.nosearch)==-1) if(item.nodeType==1 && item.nodeName.search(SearchHighlight.nosearch)==-1)
SearchHighlight.hiliteTree(item,query,noHighlight); SearchHighlight.hiliteTree(item,noHighlight);
} }
} }
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<meta name="robots" content="none" /> <meta name="robots" content="none" />
</head> </head>
<body class="page_recherche"> <body class="page_recherche pas_surlignable">
<div id="page"> <div id="page">
[(#REM) Entete de la page + titre du site ] [(#REM) Entete de la page + titre du site ]
...@@ -129,4 +129,4 @@ ...@@ -129,4 +129,4 @@
</div><!--#page--> </div><!--#page-->
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -63,7 +63,8 @@ function surligner_mots($page) { ...@@ -63,7 +63,8 @@ function surligner_mots($page) {
highlight:'.surlignable', highlight:'.surlignable',
nohighlight:'.pas_surlignable'". nohighlight:'.pas_surlignable'".
($surcharge_surligne?", ($surcharge_surligne?",
keys:'$surcharge_surligne'":"")." keys:'$surcharge_surligne'":"").",
min_length: 3
}) })
}); });
</script> </script>
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter