Introducing DOCJSLIB Version 2.0: Event Handling - Doc JavaScript | WebReference

Introducing DOCJSLIB Version 2.0: Event Handling - Doc JavaScript


onClick Event Handling

As we mentioned earlier, your second challenge in writing DOCJSLIB-based application is the onClick event handler. By now, you should know that DOCJSLIB calls this event handler in a different name, handleImageClick(). Most of your application's ideas and concepts would be implemented in this function. In our Pop-out Elements application, we define it as follows:

function handleImageClick(id, clickParam1, clickParam2) {
  var imgBoxID = id + "Box";      // derive box id
  var visibility = getVisibility(imgBoxID);      // check box visibility
  visibility = !visibility;                      // alternate visibility
  var elementWidth = getWidth(imgBoxID);         // get box width
  var distanceFromLeft = (visibility) ? elementWidth : 0; // set image position
  setPosFromLeft(id, distanceFromLeft);          // move image
  setVisibility(imgBoxID, visibility);           // set box visibility
  maxZ++;                                        // last one always on top
  setZposition(id,  maxZ);                       // set image Z
  setZposition(imgBoxID, maxZ);                  // set box Z
}

The function has three parameters. The image's ID and two other parameters that were passed from the main application. In our example, we don't use these parameters, clickParam1 and clickParam2.

Here is a run down of the function:

Make yourself comfortable with this function. You will spend many hours writing it for your applications.

https://www.internet.com


Created: October 26, 1998
Revised: October 26, 1998

URL: https://www.webreference.com/js/column28/event.html