From a6af215a7eb76b6827e828fe2f116602d79e9916 Mon Sep 17 00:00:00 2001 From: davux <da@weeno.net> Date: Sun, 20 Jun 2010 14:30:22 +0000 Subject: [PATCH] =?UTF-8?q?Accepter=20une=20option=20tag=5Fname=20(valeur?= =?UTF-8?q?=20par=20d=C3=A9faut:=20"span")=20pour=20sp=C3=A9cifier=20la=20?= =?UTF-8?q?balise=20servant=20=C3=A0=20encadrer=20le=20surlignage=20des=20?= =?UTF-8?q?recherches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Au lieu d'utiliser un tag "span" en dur, permettre de spécifier une autre balise, par exemple "b" ou encore "mark" (vous me voyez venir). La valeur par défaut reste span. --- prive/javascript/SearchHighlight.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/prive/javascript/SearchHighlight.js b/prive/javascript/SearchHighlight.js index ee4dfc6e87..11eeed57e5 100644 --- a/prive/javascript/SearchHighlight.js +++ b/prive/javascript/SearchHighlight.js @@ -14,8 +14,11 @@ * "whole" : find partial matches but highlight whole words * "partial": find and highlight partial matches * + * - tag_name (string, default:'span') + * The tag that is used to wrap the matched words + * * - style_name (string, default:'hilite') - * The class given to the span wrapping the matched words. + * The class given to the tag wrapping the matched words. * * - style_name_suffix (boolean, default:true) * If true a different number is added to style_name for every different matched word. @@ -51,7 +54,7 @@ if (window.jQuery) var ref = options.debug_referrer || document.referrer; if(!ref && options.keys==undefined) return this; - SearchHighlight.options = $.extend({exact:"exact",style_name:'hilite',style_name_suffix:true},options); + SearchHighlight.options = $.extend({exact:"exact",tag_name:'span',style_name:'hilite',style_name_suffix:true},options); if(options.engines) SearchHighlight.engines.unshift(options.engines); var q = SearchHighlight.splitKeywords(options.keys!=undefined?options.keys.toLowerCase():SearchHighlight.decodeURL(ref,SearchHighlight.engines)); @@ -196,14 +199,14 @@ if (window.jQuery) var newtext="",match,index=0; SearchHighlight.regex.lastIndex = 0; while(match = SearchHighlight.regex.exec(textNoAcc)) { - newtext += SearchHighlight.fixTags(text.substr(index,match.index-index))+'<span class="'+ - SearchHighlight.subs[match[matchIndex].toLowerCase()]+'">'+SearchHighlight.fixTags(text.substr(match.index,match[0].length))+"</span>"; + newtext += SearchHighlight.fixTags(text.substr(index,match.index-index))+'<'+SearchHighlight.options.tag_name+' class="'+ + SearchHighlight.subs[match[matchIndex].toLowerCase()]+'">'+SearchHighlight.fixTags(text.substr(match.index,match[0].length))+"</"+SearchHighlight.options.tag_name+">"; index = match.index+match[0].length; } if(newtext) { //add the last part of the text newtext += SearchHighlight.fixTags(text.substring(index)); - var repl = $.merge([],$("<span>"+newtext+"</span>")[0].childNodes); + var repl = $.merge([],$("<"+SearchHighlight.options.tag_name+">"+newtext+"</"+SearchHighlight.options.tag_name+">")[0].childNodes); endIndex += repl.length-1; startIndex += repl.length-1; $(item).before(repl).remove(); -- GitLab