Modifying tripane search results with Javascript

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
amygil
Propeller Head
Posts: 11
Joined: Tue Dec 06, 2011 4:38 pm

Modifying tripane search results with Javascript

Post by amygil »

I wrote some code to modify the path in the search results to show the name of the document instead and remove everything after the slash. Path is not helpful to my users but it would be good to show the docoument. Here's the code:

Code: Select all

$(document).ready(function(){
  $('.url cite').each(function() {
    var node = $(this)
    var book = node.html().replace(/([^\/]*)\/.*/,'Document: $1').split('_').join(' ');
    node.html(book)
  })
});
When I put it in the console on a browser, it does the job.

My problem is, I don't know where to put this code. I tried putting it in the Toolbar javascript for skin but that doesn't work. I tried putting it in javascript that I have for the topic body and that doesn't work. Does anyone know of a way to manipulate the search results with Javascript?
amygil
Propeller Head
Posts: 11
Joined: Tue Dec 06, 2011 4:38 pm

Re: Modifying tripane search results with Javascript

Post by amygil »

In case anybody is interested in doing something similar, I solved this.

Incidentally, we switched to Side Navigation skin but the solution should be the same for any skin that uses this search engine.

Here's the fix. I needed to wait for the search results to be written to the page (DOM):

Code: Select all

$().ready(function(){
  if ( $('#searchPane').length ) {
    waitfor('cite',function() {
      $('cite').each(function() {
        var node = $(this)
        var book = node.html().replace(/([^\/]*)\/.*/,'Document: $1').split('_').join(' ');
        node.html(book)
      })
    })
  }
  var stopTimer = null, stop = false;
  function waitfor(sel,fn){
      var node = document.querySelector(sel);
      if ( ! node || node.childNodes.length == 0 ) {
        if ( stop ) return;
        setTimeout(function(){ waitfor(sel,fn);});
      }
      else {
        clearTimeout(stopTimer);
        fn();
      }
  }
});
What this does is turn this:

Reference/Explicitly_Activating_and.htm

into this:

Document: Reference

To link your own js to every page, put it in the head section of your master page, like this:

Code: Select all

<script src="../Scripts/myscript.js"></script>
ETA: My post was missing some code. This is now fixed:
Post Reply