|
Overloading _DoClick Here's a technique that I used in constructing the Bloggregator user interface. The upper left hand pane of the UI contains three combo boxes. The Category combo box causes a refresh in that particular pane, which reloads the choices in the Blog combo box. The Blog combo box and the Entries combo box each cause a refresh in the view pane to the right. As anyone who has done any programming with frames in Domino knows, getting something like this to happen without using a "Go" button is difficult because Domino generates special code for onChange event for the select object if you tell it to do the automatic refresh on keyword changes. You need that special code to execute, but you also want your own code to execute in order to update information in a second frame. I accomplish this by taking advantage of the fact that in JavaScript, functions are, in a way, schizophrenic. A JavaScript function exists in two ways. It exists as code, and it exists as an object variable that contains the code. To do what I want, I insert JavaScript code that looks like this into my form: <script language='javascript'>
var Domino_doClick = _doClick
function my_doClick(v,o,t,h)
{
// calculate a URL here
top.OtherFrame.location.href = url
Domino_doClick(v,o,t,h)
}
_doClick = my_doClick
</script>
Domino generates a call to the _doClick function for the onChange event of a keyword field (and for many other events). I need that code to run, but I also need my own code to run. I need to intercept calls to _doClick, take an action, and then let those calls proceed. What I'm doing is saving the _doClick function code that Domino generated in a new object called Domino_doClick. Then I create a new function called my_doClick, which uses the same four arguments as the one that Domino generated. The code in my function does whatever it needs to do, and then it calls the Domino_doClick object passing along all the arguments unchanged. Since the Domino_doClick object contains the same code as _doClick, this accomplishes my objective of allowing Domino's code to run. Once my function is defined, I assign its code to the object variable _doClick, and this accomplishes my objective of intercepting the events before the Domino-generated script gets a chance to execute. Here's my actual code from Bloggregator:
<script language='javascript'>
var Domino_doClick = _doClick
function my_doClick(v,o,t,h)
{
blog=document.forms[0].kwdBlog.options[document.forms[0].kwdBlog.selectedIndex].text
entries=document.forms[0].kwdEntries.options[document.forms[0].kwdEntries.selectedIndex].value
url='http://smokey.rhs.com/web/blog/gregate.nsf/1. Selected Articles/' + entries
if (blog != "All")
  {
url = url + '/' + blog
}
top.Folder.location.href = url
Domino_doClick(v,o,t,h)
}
_doClick = my_doClick
</script> In a nutshell, the code is determining whether the Folder frame is being loaded with a folder that includes entries from All blogs for the selected time frame (in the kwdEntries selection), or just the entries from a specific blog (in the kwdBlog selection). It constructs the appropriate URL, sets the href for the frame, and then calls Domino's original _doClick function to do the keyword refresh. One bit of warning about this technique. Future releases of Domino could conceivably cause it to break by changing the number of arguments to the _doClick function. I believe that there are ways to safeguard against that -- or at least to detect it and throw an error -- and if I used this technique a little more often I'd probably bother to work it out, but as of now I just live with the knowledge that I have to check for changes in _doClick with every major release of Domino.
|