Return to Snippet

Revision: 22841
at January 23, 2010 23:59 by PandaWood


Initial Code
var grammar = {
	BracedTextRegex : new RegExp('\{.*\}')
};

$('td.kanji').linkBracedText();

$.fn.linkBracedText = function() {

	this.each(function() {
		// get text in curly-braces, abort if nothing
		var sentence = $(this).text();
		var $bracedText = sentence.match(grammar.BracedTextRegex);
		if ($bracedText === null) return;
		var bracedText = $bracedText[0].substr(1,$bracedText[0].length-2);

		// replace curly-braced text with a span, which serves as an insertion point
		sentence = sentence.replace(grammar.BracedTextRegex,'<span></span>');

		// find the 1st link (magically the 1 I need), change text to what was in curly braces
		var link = $(this).closest('tr').find('a:first').clone();
		link.text(bracedText);

		//overwrite this element with a copy that has curly-braced replaced with appropriate link
		$(this).html(sentence).find('span').append(link);
})};

Initial URL


Initial Description


Initial Title
jQuery plugin that doesn't work

Initial Tags


Initial Language
jQuery