Text nach Keywords durchsuchen und automatisch ein Tooltip generieren?

Dustin84

Erfahrenes Mitglied
Hallo,

ich brauche einen kleinen Denkanstoss wie ich folgendes umsetzen kann:

Ich habe einen Text mit Fachbegriffen. Die Fachbegriffe sind in meinem CMS als Objekte hinterlegt und nun würde ich für die Fachbegriffe im Text gerne automatisch einen Tooltip mit der Erklärung aus den Objekten generieren.

Hat jemand einen Lösungsansatz? Gibt es da evtl. was von jQuery?

Gruß
D.
 
.inhalt ist mein Container mit dem Seitentext.
Code:
	$(".inhalt:contains('Bienenwachs')").css("text-decoration", "underline");

Die Richtung stimmt schon aber jetzt wird JEDES Wort unterstrichen. Es sollte aber nur Bienenwachs sein.

jemand eine Idee?
 
Ein Plugin extra für dich

Javascript:
(function($) {
	$.fn.words = function(list) {
		var rx = new RegExp('\\s(' + list.join('|') + ')\\s', 'gi');
		
		return this.each(function() {
			this.innerHTML = this.innerHTML.replace(rx, ' <a href="#$1">$1</a> ')
		});
	}
})(jQuery);

Beispiel

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<title>Words</title>
</head>

<body>
	<div>
	<p class="inhalt">Venison jerky pancetta, hamburger ground round pork belly tenderloin. Chicken pork ham hock pastrami, flank swine pig pork chop bresaola andouille. Pork belly pig ham, pork strip steak tri-tip brisket tail headcheese rump t-bone pastrami tongue turkey corned beef. Chuck jerky spare ribs meatball meatloaf pork chop. Shankle turkey spare ribs, tri-tip tail swine ham rump flank biltong ham hock venison short loin meatball hamburger. Venison rump fatback spare ribs ground round. Fatback venison pork flank andouille, meatloaf tri-tip sirloin pancetta chuck spare ribs shank strip steak bacon brisket.</p>

	<p class="inhalt">Pastrami pork belly shoulder pork loin. Corned beef ham spare ribs beef shoulder beef ribs, short ribs swine drumstick tail bacon pig pork belly. Venison chuck meatloaf rump. Fatback beef meatloaf shank, shoulder ball tip ham hock swine venison pork belly brisket tenderloin. Chicken brisket headcheese, bresaola pork chop salami sirloin pancetta sausage ground round short ribs pork belly andouille shankle ham hock. Ham hock chicken ball tip pork chop pig, tri-tip corned beef jerky ground round salami fatback ribeye beef ribs. Bacon ball tip strip steak biltong.</p>

	<p class="inhalt">Ham pork boudin sirloin, pork belly sausage ribeye jowl jerky swine beef ribs spare ribs headcheese pancetta. Tongue sausage pork short loin, sirloin rump pork belly ham beef brisket flank tri-tip turkey swine. Jowl ham hock ground round, short loin chuck drumstick bresaola pork chop pig brisket ribeye. Jowl pork chop boudin, drumstick ball tip meatball jerky brisket shoulder corned beef beef tail flank bacon. Meatball jowl meatloaf tail, ham hock ground round pork chop t-bone ribeye sausage pork. Chuck ground round pork chop, ham spare ribs salami drumstick sirloin swine tenderloin. Short ribs tail ham, tenderloin fatback jerky pastrami sausage.</p>

	<p class="inhalt">Pork belly headcheese pig shoulder. Boudin ham hock sirloin, jerky beef shankle venison t-bone shoulder brisket bacon pork belly drumstick. Chicken t-bone hamburger tongue ham hock, turkey pork loin ribeye andouille shank. Drumstick jerky venison, biltong shank flank cow pancetta andouille swine pork belly tail chicken pork tenderloin. Meatball tail pork loin rump shoulder ribeye. Shoulder salami beef ribs, ball tip tongue beef shankle chuck corned beef ground round pig turkey meatball pancetta short ribs. Jowl strip steak bacon meatloaf shoulder.</p>

	<p class="inhalt">Ham hock brisket strip steak, pork loin short ribs meatloaf chicken. Pancetta andouille meatball hamburger strip steak. Turkey bresaola shank chicken, strip steak shoulder t-bone ribeye tongue andouille pastrami. Ground round bresaola corned beef venison, tongue ribeye shank turkey biltong boudin rump meatloaf andouille drumstick. Bacon biltong short ribs venison swine ground round, sirloin pancetta. Tongue bacon rump tail drumstick meatloaf. Pastrami tri-tip beef ribs tail chuck, short ribs sausage shankle bresaola ground round pork chop jerky.</p>
	</div>
	
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
	<script type="text/javascript">
	/* <![CDATA[ */
	//Plugin
	(function($) {
		$.fn.words = function(list) {
			var rx = new RegExp('\\s(' + list.join('|') + ')\\s', 'gi');
			
			return this.each(function() {
				this.innerHTML = this.innerHTML.replace(rx, ' <a href="#$1">$1</a> ')
			});
		}
	})(jQuery);
	
	$(function() {
		$('.inhalt').words(['bacon', 'pork', 'steak']);
	});
	/* ]]> */
	</script>
</body>

</html>
 
Zurück