List of usage examples for com.google.gwt.query.client GQuery removeAttr
public GQuery removeAttr(String key)
From source file:gwtquery.plugins.lazyload.client.LazyLoad.java
License:Apache License
/** * Lazy load selected pictures, only actually fetching the file when the * picture becomes visible in the user's viewport. * * Pictures must have a "data-original" attribute indicating the URL to load, * and they should have a correct size already. * * @param options configuration options. * @return this./*from w w w .j a v a 2 s . co m*/ */ public LazyLoad lazyload(final Options options) { if (get().getLength() == 0) { return this; } final Options opt = options.copy(); final Updater updater = new Updater(get(), opt); each(new Function() { @Override public void f(Element e) { final GQuery current = $(e); current.on(opt.getEventName(), new Function() { @Override public void f(final Element e) { current.off(opt.getEventName(), this); final String data = $(e).attr("data-original"); if (data == null) { return; } $("<img/>").bind(Event.ONLOAD, new Function() { @Override public void f(final Element img) { current.hide().attr("src", $(img).attr("src")); if (opt.getEffect() == null) { current.show(); } else { opt.getEffect().f(e); } } }).attr("src", data); current.removeAttr("data-original"); } }).attr("src", opt.getPlaceholder()); } }); if (opt.getContainer() == null) { final HandlerRegistration registration = Window.addWindowScrollHandler(new Window.ScrollHandler() { @Override public void onWindowScroll(Window.ScrollEvent event) { updater.update(); } }); updater.setHandler(registration); } else { final Function handler; opt.getContainer().on("scroll", handler = new Function() { @Override public boolean f(final Event e) { updater.update(); return true; } }); updater.setContainerHandler(handler); } updater.update(); return this; }