How To Bring Back the Right Click Menus in BUI

With the June 2004 BUI patches, we lost the function of the right click on everything except text boxes. With the code show below, you will be able to get that right click menu back without the elements that could cause problems with BUI.

menuexample

As you can see, the resulting menu has just Print, and Select All. Then on selected text, you get the following menu:

menuexample2

This allows for the use of the common clipboard functions. The modification for this can be done in 2 ways. 1, modify the topframe.js file on each BUI server; or 2, place a function in each of your uScript files that you want to have this ability.

Method 1: Modify topframe.js:

Open the topfile.js file. On windows based BUI servers, it’s located in c:\cmhcbui\cmhcweb\cmhcbui\cmhcbui\javascript . Once open, locate the following lines: (around line 26)

function ctxtMenu (evnt) {
        evnt.returnValue = (evnt.srcElement.tagName == 'INPUT' || evnt.srcElement.tagName == 'TEXTAREA' || (evnt.ctrlKey && evnt.altKey));
}


Remove them and replace them with this set: (Download this function here)

// Context Menu Replacement
var oRightPopup = window.createPopup();
var oRightPopupSrcDoc
function ctxtMenu(evnt) {

    oRightPopupSrcDoc = evnt.srcElement.document;

    if (evnt.srcElement.tagName == 'INPUT' || evnt.srcElement.tagName == 'TEXTAREA' || (evnt.ctrlKey && evnt.altKey) || oRightPopupSrcDoc.selection.type != "None") {
        evnt.returnValue = true;
    } else {
        evnt.returnValue = false;

        var oPopBody = oRightPopup.document.body;
        var PopBodyCode;

        oRightPopupSrcDoc = evnt.srcElement.document;

        PopBodyCode = "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\" id=\"PopUpMenu\">";
        PopBodyCode = PopBodyCode + "  <tr>";
        PopBodyCode = PopBodyCode + "    <td onclick=\"parent.oRightPopupSrcDoc.parentWindow.print(); parent.oRightPopup.hide();\" onmouseover=\"this.style.backgroundColor='#6699CC'\" onmouseout=\"this.style.backgroundColor=''\" style=\"cursor: hand; border-bottom:1px solid #000000;\"><font size=\"2\">Print</font></td>";
        PopBodyCode = PopBodyCode + "  </tr>";
        PopBodyCode = PopBodyCode + "  <tr>";
        PopBodyCode = PopBodyCode + "    <td onclick=\"parent.oRightPopupSrcDoc.body.createTextRange().select(); parent.oRightPopup.hide();\" onmouseover=\"this.style.backgroundColor='#6699CC'\" onmouseout=\"this.style.backgroundColor=''\" style=\"cursor: hand;\"><font size=\"2\">Select All</font></td>";
        PopBodyCode = PopBodyCode + "  </tr>";
        PopBodyCode = PopBodyCode + "</table>";

        oPopBody.style.backgroundColor = "lightgrey";
        oPopBody.style.border = "solid black 1px";
        oPopBody.innerHTML = PopBodyCode;

        oRightPopup.show(evnt.x+4, evnt.y+4, 120, 120, evnt.srcElement.document.body);
        oRightPopup.show(evnt.x+4, evnt.y+4, 120, oPopBody.all.PopUpMenu.clientHeight+2, evnt.srcElement.document.body);
    }
}
//End Replacement


Save the file and you’re done. Please note that any BUI patches you apply may remove this modification. So, keep a eye on the JavaScript files that you change.

Method 2: Use a function:

This method doesn’t require changing any of the system JavaScript files but it does require that you change any uscripts that you want to have the menu functionality.

Here’s the new function to add at the bottom of your code: (Download it as a library here.)

function RepRightClk() is null

RightClickCode    is x
%preload RightClickCode line-ending(cr)
<script language="javascript">
<!--
var oRightPopup = window.createPopup();
var oRightPopupSrcDoc
function ctxtMenu2() {

    oRightPopupSrcDoc = event.srcElement.document;

    if (event.srcElement.tagName == 'INPUT' || event.srcElement.tagName == 'TEXTAREA' || (event.ctrlKey && event.altKey) || oRightPopupSrcDoc.selection.type != "None") {
        event.returnValue = true;
    } else {
        event.returnValue = false;

        var oPopBody = oRightPopup.document.body;
        var PopBodyCode;

        PopBodyCode = "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\" id=\"PopUpMenu\">";
        PopBodyCode = PopBodyCode + "  <tr>";
        PopBodyCode = PopBodyCode + "    <td onclick=\"parent.oRightPopupSrcDoc.parentWindow.print(); parent.oRightPopup.hide();\" onmouseover=\"this.style.backgroundColor='#6699CC'\" onmouseout=\"this.style.backgroundColor=''\" style=\"cursor: hand; border-bottom:1px solid #000000;\"><font size=\"2\">Print</font></td>";
        PopBodyCode = PopBodyCode + "  </tr>";
        PopBodyCode = PopBodyCode + "  <tr>";
        PopBodyCode = PopBodyCode + "    <td onclick=\"parent.oRightPopupSrcDoc.body.createTextRange().select(); parent.oRightPopup.hide();\" onmouseover=\"this.style.backgroundColor='#6699CC'\" onmouseout=\"this.style.backgroundColor=''\" style=\"cursor: hand;\"><font size=\"2\">Select All</font></td>";
        PopBodyCode = PopBodyCode + "  </tr>";
        PopBodyCode = PopBodyCode + "</table>";

        oPopBody.style.backgroundColor = "lightgrey";
        oPopBody.style.border = "solid black 1px";
        oPopBody.innerHTML = PopBodyCode;

        oRightPopup.show(event.x+4, event.y+4, 120, 120, event.srcElement.document.body);
        oRightPopup.show(event.x+4, event.y+4, 120, oPopBody.all.PopUpMenu.clientHeight+2, event.srcElement.document.body);
    }
}

document.body.oncontextmenu = ctxtMenu2

//-->
</script>
%endpreload
$ctag(RightClickCode)

end RepRightClk


Now to use this code, add the following line after your $form() statement:

RepRightClk()


or, if your are using the library version, use this code:

"RepRightClk":RepRightClk()


And that’s all there is to it.

Leave a Reply

You must be logged in to post a comment. Login »