[Plugin: TooltipGlossary] Modification (enhancement?)
-
Hey Thanx for the great plugin!!!
I was having some problems with glossary terms that had a \n (new line) character in the definition, this crashed the tooltip. I made a few mods that others may find useful so I thought I’d post them.
The jist of it is you can use excerpts to generate a short tooltip and then have a much more elaborate definition on your glossary page (with all kinds of fancy formatting).
Only takes a few small changes… All Changes are in glossary.php
#1. Enable the use of excerpts in the editor [line 48]:
'supports' => array('title','editor','author','excerpt'));
#2. Use the excerpt by default if it exists, if not, check the content for \n, replace if necessary, then shorten it up if it’s too long. [around line 95].
original:
if (get_option('red_glossaryTooltip') == 1) { $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . addslashes($glossary_item->post_content) . '\');" onmouseout="tooltip.hide();">$1</a>';
change to:
if (get_option('red_glossaryTooltip') == 1) { /* new */ if(!empty($glossary_item->post_excerpt)){ $tip = $glossary_item->post_excerpt; }elseif(preg_match('/\n+/', $glossary_item->post_content)){ $tip = preg_replace('/\n/', '<br/>', $glossary_item->post_content); }else{ $tip = $glossary_item->post_content; } if (str_word_count($tip) > 50) $tip = implode(' ',array_slice(str_word_count($tip,1),0,50)).'...'; $link_replace = '<a class="glossaryLink" href="' . get_permalink($glossary_item) . '" title="Glossary: '. $glossary_title . '" onmouseover="tooltip.show(\'' . addslashes($tip) . '\');" onmouseout="tooltip.hide();">$1</a>'; /* end new */
Thanx again!
- The topic ‘[Plugin: TooltipGlossary] Modification (enhancement?)’ is closed to new replies.