Widget:Highlight: Difference between revisions

From Rangjung Yeshe Wiki - Dharma Dictionary
Jump to navigation Jump to search
((by SublimeText.Mediawiker))
((by SublimeText.Mediawiker))
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
<script>
<includeonly><script src="https://code.jquery.com/jquery-1.12.4.min.js"integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="crossorigin="anonymous"></script>
function highlight(text) {
<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.min.js"integrity="sha512-mhbv5DqBMgrWL+32MmsDOt/OAvqr/cHimk6B8y/bx/xS88MVkYGPiVv2ixKVrkywF2qHplNRUvFsAHUdxZ3Krg=="crossorigin="anonymous"referrerpolicy="no-referrer"></script>
var inputText = document.getElementById("bodyContent");
<!--{foreach from=$term item=item}--><script>$(".mark-terms").mark("<!--{$item}-->");</script><!--{/foreach}--></includeonly>
var innerHTML = inputText.innerHTML;
var index = innerHTML.indexOf(text);
if (index >= 0) {
innerHTML = innerHTML.substring(0,index) + "<span class='highlight'>" + innerHTML.substring(index,index+text.length) + "</span>" + innerHTML.substring(index + text.length);
inputText.innerHTML = innerHTML;
}
}
window.onload = highlight("<!--{$term}-->");
</script>

Latest revision as of 06:45, 20 June 2022