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

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

Introduction

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

Prototype

public int scrollTop() 

Source Link

Document

Gets the scroll top offset of the first matched element.

Usage

From source file:com.pronoiahealth.olhie.client.pages.AbstractPage.java

License:Open Source License

/**
 * Add full page scrolling. This can only be done before the page is loaded.
 * //from w  w w  . j a v a 2s  . c  o m
 * @param fullPageScrollingActive
 */
protected void addFullPageScrolling() {
    // Activate full page scrolling
    // Get the root div
    final GQuery gObj = AppSelectors.INSTANCE.getCenterBackground();

    // Called when scrolling stops
    // Timer set in scroll event
    // Address weird Chrome/Safari (Webkit) issue
    // Just asking for some data from the element emitting
    // scroll events seems to refresh the display and
    // help fix the issue
    scrollStopTimer = new Timer() {
        @Override
        public void run() {
            int scrollTop = gObj.scrollTop();
            // gObj.scrollTop(scrollTop + 3);
            // gObj.scrollTop(scrollTop);
        }
    };

    // Make sure its overflow is set to auto
    gObj.css(CSS.OVERFLOW.with(Overflow.AUTO));

    // State of scroll link
    gObj.data("scrollLinkActive", Boolean.FALSE);

    // Create the scroll link
    scrollLink = $("<a href=\"#\" class=\"ph-BulletinBoard-Scrollup\">Scroll</a>");

    final Function fadeIn = new Function() {
        @Override
        public void f(Element e) {
            scrollLink.css(Properties.create("opacity: 1.0;"));
            // super.f(e);
        }
    };

    final Function fadeOut = new Function() {
        @Override
        public void f(Element e) {
            scrollLink.css(Properties.create("opacity: 0.0;"));
            // super.f(e);
        }
    };

    // Append the link to the root div
    gObj.append(scrollLink);

    // Bind the scroll event
    gObj.bind(Event.ONSCROLL, new Function() {
        @Override
        public boolean f(Event e) {
            // GQuery rootDiv = $(e);
            // int scrollTop = rootDiv.scrollTop();
            // Set timer
            scrollStopTimer.cancel();
            scrollStopTimer.schedule(500);

            // Test scroll top
            int scrollTop = gObj.scrollTop();
            boolean scrollLinkActive = (Boolean) gObj.data("scrollLinkActive");
            if (scrollTop >= 100 && scrollLinkActive == false) {
                gObj.data("scrollLinkActive", Boolean.TRUE);
                scrollLink.fadeIn(500, fadeIn);
            } else if (scrollTop < 100 && scrollLinkActive == true) {
                gObj.data("scrollLinkActive", Boolean.FALSE);
                scrollLink.fadeOut(500, fadeOut);
            }

            // return super.f(e);
            return false;
        }
    });

    // Bind to the scrollup link
    scrollLink.bind(Event.ONCLICK, new Function() {
        @Override
        public boolean f(Event e) {
            gObj.animate("scrollTop: 0", 500, (Function) null);
            scrollLink.hide();
            return false;
        }
    });

    this.fullPageScrollingActive = true;
}

From source file:com.pronoiahealth.olhie.client.widgets.scrolldiv.ScrollDiv.java

License:Open Source License

@PostConstruct
protected void postConstruct() {
    // Activate full page scrolling
    // Get the root div
    final GQuery gObj = $(root);

    // Make sure its overflow is set to auto
    gObj.css(CSS.OVERFLOW.with(Overflow.AUTO));

    // Create the scroll link
    scrollLink = $("<a href=\"#\" class=\"ph-BulletinBoard-Scrollup\">Scroll</a>");

    // Append the link to the root div
    gObj.append(scrollLink);//  www . j  ava  2s  .  c  o m

    // Bind the scroll event
    gObj.bind(Event.ONSCROLL, new Function() {
        @Override
        public boolean f(Event e) {
            GQuery rootDiv = $(e);
            int scrollTop = rootDiv.scrollTop();
            if (scrollTop > 100) {
                scrollLink.fadeIn(500, new Function() {
                    @Override
                    public void f(com.google.gwt.dom.client.Element e) {
                        $(e).css(Properties.create("opacity: 1.0;"));
                        // super.f(e);
                    }
                });
            } else {
                scrollLink.fadeOut(500, new Function() {
                    @Override
                    public void f(com.google.gwt.dom.client.Element e) {
                        $(e).css(Properties.create("opacity: 0.0;"));
                        // super.f(e);
                    }
                });
            }
            return super.f(e);
        }
    });

    // Bind to the scrollup link
    scrollLink.bind(Event.ONCLICK, new Function() {
        @Override
        public boolean f(Event e) {
            gObj.animate("scrollTop: 0", 500, (Function) null);
            return false;
        }
    });
}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

/**
 * convert a relative position to a absolute position and vice versa.
 *
 * @param absolute  if true the position is convert to an absolute position, if
 *                  false it is convert in a relative position
 * @param aPosition position to convert// www . j  a  v a  2s.c o  m
 * @return
 */
public Offset convertPositionTo(boolean absolute, Offset aPosition) {
    int mod = absolute ? 1 : -1;
    GQuery scroll = getScrollParent();
    boolean scrollIsRootNode = isRootNode(scroll.get(0));

    int top = aPosition.top + relativeOffset.top * mod + parentOffset.top * mod
            - ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollTop()
                    : scrollIsRootNode ? 0 : scroll.scrollTop()) * mod;

    int left = aPosition.left + relativeOffset.left * mod + parentOffset.left * mod
            - ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollLeft()
                    : scrollIsRootNode ? 0 : scroll.scrollLeft()) * mod;

    return new Offset(left, top);

}

From source file:gwtquery.plugins.draggable.client.DraggableHandler.java

License:Apache License

private Offset generatePosition(GqEvent e, boolean initPosition) {

    GQuery scroll = getScrollParent();
    boolean scrollIsRootNode = isRootNode(scroll.get(0));

    int pageX = e.pageX();
    int pageY = e.pageY();

    if (!initPosition) {
        if (containment != null && containment.length == 4) {
            if (e.pageX() - offsetClick.left < containment[0]) {
                pageX = containment[0] + offsetClick.left;
            }/*from w  w w  .j  a v  a 2 s. c o  m*/
            if (e.pageY() - offsetClick.top < containment[1]) {
                pageY = containment[1] + offsetClick.top;
            }
            if (e.pageX() - offsetClick.left > containment[2]) {
                pageX = containment[2] + offsetClick.left;
            }
            if (e.pageY() - offsetClick.top > containment[3]) {
                pageY = containment[3] + offsetClick.top;
            }
        }

        if (options.getGrid() != null) {
            int[] grid = options.getGrid();
            int roundedTop = originalEventPageY + Math.round((pageY - originalEventPageY) / grid[1]) * grid[1];
            int roundedLeft = originalEventPageX + Math.round((pageX - originalEventPageX) / grid[0]) * grid[0];

            if (containment != null && containment.length == 4) {
                boolean isOutOfContainment0 = roundedLeft - offsetClick.left < containment[0];
                boolean isOutOfContainment1 = roundedTop - offsetClick.top < containment[1];
                boolean isOutOfContainment2 = roundedLeft - offsetClick.left > containment[2];
                boolean isOutOfContainment3 = roundedTop - offsetClick.top > containment[3];

                pageY = !(isOutOfContainment1 || isOutOfContainment3) ? roundedTop
                        : (!isOutOfContainment1) ? roundedTop - grid[1] : roundedTop + grid[1];
                pageX = !(isOutOfContainment0 || isOutOfContainment2) ? roundedLeft
                        : (!isOutOfContainment0) ? roundedLeft - grid[0] : roundedLeft + grid[0];

            } else {
                pageY = roundedTop;
                pageX = roundedLeft;
            }

        }
    }

    int top = pageY - offsetClick.top - relativeOffset.top - parentOffset.top
            + ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollTop()
                    : scrollIsRootNode ? 0 : scroll.scrollTop());

    int left = pageX - offsetClick.left - relativeOffset.left - parentOffset.left
            + ("fixed".equals(helperCssPosition) ? -helperScrollParent.scrollLeft()
                    : scrollIsRootNode ? 0 : scroll.scrollLeft());
    return new Offset(left, top);
}