Example usage for com.google.gwt.query.client GQuery blur

List of usage examples for com.google.gwt.query.client GQuery blur

Introduction

In this page you can find the example usage for com.google.gwt.query.client GQuery blur.

Prototype

public GQuery blur(Function... f) 

Source Link

Document

Bind a set of functions to the blur event of each matched element.

Usage

From source file:org.bonitasoft.web.toolkit.client.ui.component.AutoCompleteTextInput.java

License:Open Source License

private void setEvents() {

    final GQuery input = $(inputElement);

    // ON TEXT CHANGE
    input.keypress(new Function() {

        @Override/*from ww  w.jav  a  2s.  c  o  m*/
        public boolean f(final Event e) {

            // Window.alert(e.getKeyCode() + " - " + e.getCharCode());

            switch (e.getKeyCode()) {
            case KeyCodes.KEY_ENTER:
                e.stopPropagation();
                return false;
            case KeyCodes.KEY_ESCAPE:
                AutoCompleteTextInput.this.reset();
                break;
            case KeyCodes.KEY_DELETE:
            case KeyCodes.KEY_BACKSPACE:
            case 0: // Character
            default:

                AutoCompleteTextInput.this.resetValue();

                // ClearTimeout if another key is pressed before the end of previous timeout
                if (input.data(AUTOCOMPLETE_ONCHANGE_TIMER) != null) {
                    final Timer t = (Timer) input.data(AUTOCOMPLETE_ONCHANGE_TIMER);
                    t.cancel();
                    input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER);
                }

                final Timer t = new Timer() {

                    @Override
                    public void run() {
                        input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER);
                        AutoCompleteTextInput.this.refresh();
                    }
                };
                input.data("AUTOCOMPLETE_ONCHANGE_TIMER", t);
                t.schedule(500);
                break;
            }

            return true;
        }
    });

    // ON TEXT BLUR
    input.blur(new Function() {

        @Override
        public void f() {
            if (input.data(AUTOCOMPLETE_ONCHANGE_TIMER) != null) {
                final Timer t = (Timer) input.data(AUTOCOMPLETE_ONCHANGE_TIMER);
                t.cancel();
                input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER);
            }
            boolean isFocused = childrenFocused(dropdown.getElement());
            // && $(AutoCompleteTextInput.this.dropdown.getElement()).find(":focus").size() == 0) {
            if (!$(inputElement).is(".completed") && !isFocused) {

                AutoCompleteTextInput.this.reset();
                dropdown.close();
            }
        }

    });
}