|
19 | 19 | */ |
20 | 20 | package gwt.material.design.client.ui; |
21 | 21 |
|
| 22 | +import com.google.gwt.core.client.GWT; |
| 23 | +import com.google.gwt.core.client.Scheduler; |
22 | 24 | import com.google.gwt.user.client.ui.Widget; |
23 | 25 | import gwt.material.design.client.js.JsPushpinOptions; |
24 | 26 |
|
|
40 | 42 | */ |
41 | 43 | public class MaterialPushpin { |
42 | 44 |
|
43 | | - public static void apply(Widget widget, double offset) { |
44 | | - apply(widget, 0, 0, offset); |
| 45 | + /** |
| 46 | + * A pushpinned element has 3 states. One above and below the scrolling threshold, |
| 47 | + * and the pinned state where the element becomes fixed. |
| 48 | + * |
| 49 | + * @param widget - Target widget to apply the pushpin feature |
| 50 | + * @param offset - The offset from the top the element will be fixed at. (Default: 0) |
| 51 | + */ |
| 52 | + public static void apply(Widget widget, Double offset) { |
| 53 | + apply(widget, null, null, offset); |
45 | 54 | } |
46 | 55 |
|
47 | | - public static void apply(Widget widget, double top, double bottom, double offset) { |
48 | | - JsPushpinOptions options = new JsPushpinOptions(); |
49 | | - options.top = top; |
50 | | - options.offset = offset; |
51 | | - options.bottom = bottom; |
| 56 | + /** |
| 57 | + * A pushpinned element has 3 states. One above and below the scrolling threshold, |
| 58 | + * and the pinned state where the element becomes fixed. |
| 59 | + * |
| 60 | + * @param widget - Target widget to apply the pushpin feature |
| 61 | + * @param top - The distance in pixels from the top of the page where the element becomes fixed. (Default: 0) |
| 62 | + * @param offset - The offset from the top the element will be fixed at. (Default: 0) |
| 63 | + */ |
| 64 | + public static void apply(Widget widget, Double top, Double offset) { |
| 65 | + apply(widget, top, null, offset); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * A pushpinned element has 3 states. One above and below the scrolling threshold, |
| 70 | + * and the pinned state where the element becomes fixed. |
| 71 | + * |
| 72 | + * @param widget - Target widget to apply the pushpin feature |
| 73 | + * @param top - The distance in pixels from the top of the page where the element becomes fixed. (Default: 0) |
| 74 | + * @param bottom - The distance in pixels from the top of the page where the elements stops being fixed. (Default: Infinity) |
| 75 | + * @param offset - The offset from the top the element will be fixed at. (Default: 0) |
| 76 | + */ |
| 77 | + public static void apply(Widget widget, Double top, Double bottom, Double offset) { |
| 78 | + Scheduler.get().scheduleDeferred(() -> { |
| 79 | + JsPushpinOptions options = new JsPushpinOptions(); |
| 80 | + options.top = (top != null) ? top : 0; |
| 81 | + options.offset = (offset != null) ? offset : 0; |
| 82 | + options.bottom = (bottom != null) ? bottom : "Infinity"; |
| 83 | + |
| 84 | + GWT.log(top + " : Top"); |
| 85 | + GWT.log(offset + " : Offset"); |
| 86 | + GWT.log(bottom + " : Bottom"); |
52 | 87 |
|
53 | | - $(widget.getElement()).pushpin(options); |
| 88 | + $(widget.getElement()).pushpin(options); |
| 89 | + }); |
54 | 90 | } |
55 | 91 | } |
0 commit comments