rice-framework/krad-web/src/main/webapp/krad/scripts/krad.initialize.js
/**
 * Sets up and initializes the handlers for enter key actions.
 *
 * <p>This function determines which button/action should fire when the enter key is pressed while focus is on a configured input</p>
 *
 */
Sets up and initializes the handlers for enter key actions.

This function determines which button/action should fire when the enter key is pressed while focus is on a configured input
Sets up and initializes the handlers for enter key actions . This function determines which button / action should fire when the enter key is pressed while focus is on a configured input
function initEnterKeyHandler() {
    jQuery(document).on("keyup", "[data-enter_key]", function (event) {
        var keycode = (event.keyCode ? event.keyCode : event.which);
        if (keycode !== 13) {
            return;
        }
        event.preventDefault();
        event.stopPropagation();
        var enterKeyId = jQuery(event.currentTarget).data(kradVariables.ENTER_KEY_SUFFIX);
        if (jQuery(event.target).is(":not(a, textarea, button, submit, img[data-role='" + kradVariables.DATA_ROLES.ACTION + "'], input[data-role='" + kradVariables.DATA_ROLES.ACTION + "'] )")) {
            if (enterKeyId === kradVariables.ENTER_KEY_DEFAULT) {
                var primaryButtons = jQuery(event.currentTarget).find("[data-default_enter_key_action='true']");
                var primaryButton = primaryButtons.filter(function () {
                    return jQuery(this).parents('[data-enter_key]').length < 2;
                });
                if (primaryButton.length) {
                    enterKeyId = primaryButton.attr("id");
                }
            }
            if (enterKeyId === kradVariables.ENTER_KEY_DEFAULT) {
                return false;
            }
            if (jQuery('#' + enterKeyId).is(":visible") && jQuery('#' + enterKeyId).is(":disabled") === false) {
                jQuery(document).find('#' + enterKeyId).click();
            }
        }
    });
    jQuery(document).on("keydown", "[data-enter_key], [data-inline_edit] [data-role='Control']", function (event) {
        var keycode = (event.keyCode ? event.keyCode : event.which);
        if (keycode === 13 && jQuery(event.target).is("[data-role='Control']") && !jQuery(event.target).is("textarea")) {
            event.preventDefault();
            return false;
        }
    });
}
function initEnterKeyHandler ( ) { jQuery ( document ) . on ( "keyup" , "[data-enter_key]" , function ( event ) { var keycode = ( event . keyCode ? event . keyCode : event . which ) ; if ( keycode !== 13 ) { return ; } event . preventDefault ( ) ; event . stopPropagation ( ) ; var enterKeyId = jQuery ( event . currentTarget ) . data ( kradVariables . ENTER_KEY_SUFFIX ) ; if ( jQuery ( event . target ) . is ( ":not(a, textarea, button, submit, img[data-role='" + kradVariables . DATA_ROLES . ACTION + "'], input[data-role='" + kradVariables . DATA_ROLES . ACTION + "'] )" ) ) { if ( enterKeyId === kradVariables . ENTER_KEY_DEFAULT ) { var primaryButtons = jQuery ( event . currentTarget ) . find ( "[data-default_enter_key_action='true']" ) ; var primaryButton = primaryButtons . filter ( function ( ) { return jQuery ( this ) . parents ( '[data-enter_key]' ) . length < 2 ; } ) ; if ( primaryButton . length ) { enterKeyId = primaryButton . attr ( "id" ) ; } } if ( enterKeyId === kradVariables . ENTER_KEY_DEFAULT ) { return false ; } if ( jQuery ( '#' + enterKeyId ) . is ( ":visible" ) && jQuery ( '#' + enterKeyId ) . is ( ":disabled" ) === false ) { jQuery ( document ) . find ( '#' + enterKeyId ) . click ( ) ; } } } ) ; jQuery ( document ) . on ( "keydown" , "[data-enter_key], [data-inline_edit] [data-role='Control']" , function ( event ) { var keycode = ( event . keyCode ? event . keyCode : event . which ) ; if ( keycode === 13 && jQuery ( event . target ) . is ( "[data-role='Control']" ) && ! jQuery ( event . target ) . is ( "textarea" ) ) { event . preventDefault ( ) ; return false ; } } ) ; }
Sets up and initializes the handlers for enter key actions.
Sets up and initializes the handlers for enter key actions .
// grab the keycode based on browser
 // check for enter key
 // using event bubbling, we search for inner most element with data attribute kradVariables.ENTER_KEY_SUFFIX and assign it's value as an ID
 // make sure the targeted action is a permitted element
 // check to see if primary enter key action button is targeted
 // find all primary action buttons on page with attribute data-default_enter_key_action='true'
 // filter the buttons only one parent section deep
 // if the button exists get it's id
 // if enterKeyAction is still set to  ENTER_KEY_PRIMARY value, do nothing, button doesn't exist
 // make sure action button is visible and not disabled before we fire it
 // a hack to capture the native browser enter key behavior..  keydown and keyup
 // grab the keycode based on browser
 // check for enter key
