Skip to Content

searchTermHighlighter()

Highlight search terms on search results pages.

JavaScript February 22, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Source File

Located in /assets/js/nebula.js on line 2231.

JavaScript
nebula.searchTermHighlighter = function(){
    window.requestAnimationFrame(function(){
        var searchTerm = document.URL.split('?s=')[1];
        if ( typeof searchTerm !== 'undefined' ){
            var reg = new RegExp("(?![^<]+>)(" + preg_quote(searchTerm.replace(/(\+|%22|%20)/g, ' ')) + ")", "ig");
            jQuery('article .entry-title a, article .entry-summary').each(function(i){
                jQuery(this).html(function(i, html){
                    return html.replace(reg, '<mark class="searchresultword">$1</mark>');
                });
            });

            nebula.emphasizeSearchTerms();
        }
    });
};

Override

To override or disable this JavaScript function, simply redeclare it with the exact same function name.

JavaScript
nebula.searchTermHighlighter = function(){
    //Write your own code here, leave it blank, or return false.
}