001package gwt.material.design.addins.client.scrollfire; 002 003/* 004 * #%L 005 * GwtMaterial 006 * %% 007 * Copyright (C) 2015 GwtMaterialDesign 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import com.google.gwt.dom.client.Element; 024import com.google.gwt.user.client.DOM; 025import gwt.material.design.addins.client.MaterialAddins; 026import gwt.material.design.client.MaterialDesignBase; 027 028//@formatter:off 029/** 030 * Material Scrollfire - executes callback functions depending on how far into the page you've scrolled. 031 * 032 * <h3>Java Usage:</h3> 033 * 034 * <pre> 035 * {@code 036 * MaterialScrollfire.apply(Element e, Runnable runnableCallback); 037 * } 038 * </pre> 039 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#scrollfire">Material Scrollfire</a> 040 * @author kevzlou7979 041 */ 042//@formatter:on 043public class MaterialScrollfire { 044 045 static { 046 if(MaterialAddins.isDebug()) { 047 MaterialDesignBase.injectDebugJs(MaterialScrollfireDebugClientBundle.INSTANCE.scrollfireDebugJs()); 048 } else { 049 MaterialDesignBase.injectJs(MaterialScrollfireClientBundle.INSTANCE.scrollfireJs()); 050 } 051 } 052 053 public static void apply(Element element, Runnable callback) { 054 String uid = DOM.createUniqueId(); 055 element.setId(uid); 056 apply("#" + uid, callback); 057 } 058 059 public static native void apply(String selector, Runnable callback) /*-{ 060 $wnd.jQuery(document).ready(function() { 061 var offset = 100; 062 var callbackFn = $entry(function() { 063 callback.@java.lang.Runnable::run()(); 064 }); 065 $wnd.apply(selector, offset, callbackFn); 066 }); 067 }-*/; 068}