Modifying Custom.js

Script files are provided with the Presentation Builder Runtime Service to support communication between an HTML application and the host session for each type of terminal session. When you create an HTML application, a script file, custom.js, is created during design time. When you publish your application, the custom.js is packaged with the application and associated with each HTML page of the presentation. The custom.js file exposes the body onLoad event handler, which allows you to dynamically modify HTML content and add your own custom client-side logic to the HTML document to which the presentation is written.

By modifying the contents of the custom.js file, you can implement additional client-side functionality or behavior in your application; for example, you could change one or more of the event handlers, or override an original function. Original functions are those defined in the common.js script file installed with the run-time service. The default install location for the common.js file is C:\Program Files\Attachmate\HTTPEngine\webapps\epi\WEB-INF\js.

Caution The script files provided with the run-time service are replaced if the run-time service is reinstalled. The script files may also be updated for future releases of Presentation Builder, including renaming the internal script functions. Applications you create by modifying the script files to implement custom functionality may not work as designed with upcoming versions of Presentation Builder.
To modify a custom.js file for a project
  1. Create a new, or open an existing project using Presentation Designer.

  2. From the File menu, choose Save As.

    The Save As dialog box appears.

  3. Type a name for the project, and select a location in which to save it.

  4. Using a text or script editor, open the custom.js file to edit it.

    The file is created in the \js folder for this project. The default install location for the projects folder is C:\Program Files\Attachmate\EAI\PresentationDesigner\Projects\Project_name, where Project_name is the name of your project.

  5. Add your own JavaScript to the custom.js file to customize the application.

  6. Save the changes to custom.js.

  7. Using Presentation Designer, publish your project as an HTML application.

    When the application is published, the custom.js file is published as part of the application.

To add, replace, or extend an event handler
  • Using the custom.js file:
    To
    Use this syntax
    Add a new event handler

    -or-

    Replace an original event handler for a given event

     
    function onloadBodyEx()
    {
    	var ctrl = document.getElementById("elementID");
    	ctrl.eventname = myevent;
    
    	return true;
    }
    
    function myevent()
    {
    	my event behavior
    	..
    	..
    }
    
    Extend the original event handler for a given element
    var orgEventHandler;
    function onloadBodyEx()
    {
    	var ctrl = document.getElementById("elementID");
    	orgEventHandler = ctrl.eventname;
    	ctrl.eventname = myevent;
    
    	return true;
    }
    
    function myevent()
    {
    if (orgEventHandler != null)
    	orgEventHandler();
    
    my event behavior
    ..
    ..
    }
    
To override an original function
  • Add the name and arguments of the function to the custom.js file.

    This causes the function referenced in the custom.js file to be used instead of the original function in common.js.

    For example, if you wanted to change the character set for a numeric host field, you would copy the getKeyEventMsg(type, keyEvent) function from common.js to the custom.js file for a project, and then add or remove conditions in the If statement for the numeric field using the following syntax:

    if (type == "numeric")
    {
    
    // This section validates that data entered is a numeric value; "0123456789,.+- "
    
        if  ((!keyEvent.shiftKey)&&(keyCode>&&(keyCode>=48)&&(keyCode<=57))||
    		((keyCode>=96)&&(keyCode<=105))|| //"0-9
            (keyCode==188)|| //","
            (keyCode == 190)||(keyCode==110)|| // "."
            ((keyEvent.shiftKey)&&(keyCode==187))||(keyCode==107)|| // "+")
            (keyCode==189)||(keyCode==109)|| // "-")
            (keyCode==32)) // " "
            errMsg = null;)
        else)
            errMsg = nummsg;
    }
    
Related Topics
Bullet Extending Applications Programmatically Overview
Bullet Publishing Applications Overview
Bullet Adding Functions to Events
  Attachmate