• Resolved Chris

    (@web2guru)


    I’ve looked in to the code, but have not spent enough time with it to figure it out yet. It runs the code that does the highlighting on “jQuery(document).ready()”.

    I’m using some AJAX to load some content based on the search term. As expected, the search terms in this content is not highlighted.

    Is there a way to re-trigger the highlighting? Even manually calling a function would work, just some way to have the highlighting run after an an ajax call is run.

    http://wordpress.org/extend/plugins/highlight-search-terms/

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m afraid that won’t be possible without reworking the complete js…

    Thread Starter Chris

    (@web2guru)

    Thanks for the reply, Ravan. I got it working. I pulled some of the code from the plugin script and turned it into a second function (currently added to my themes scripts.js). It’s a short function, you could add this to the plugin and call it from within the get_hlst_query function (in place of the original code).

    Here is the new function:

    function ajaxHighlight(hlst_areas,hlst_query) {
    	var area; var i; var s;
    	for (s in hlst_areas){
    		area = jQuery(hlst_areas[s]);
    		if (area.length != 0){
    			for (var l = 0; l < area.length; l++) {
    				for (i in hlst_query){
    					area.eq(l).highlight(hlst_query[i], 1, 'hilite term-' + i);
    				}
    			}
    		}
    	}
    }

    Then just call the function at the end of the ajax post (the variables are already loaded on the page).

    ajaxHighlight(hlst_areas,hlst_query);

    On a side note, I had to remove the break in the for loop because it would not do highlighting in the other “areas” I specified. Not sure what purpose this has here, but it worked perfectly after removing it. Why would you stop it from looping through the other specified areas?

    Great! I’ll consider this (or something like it anyway, maybe with a handler) for the next release 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How To Run Again After AJAX Call’ is closed to new replies.