-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I created my own widget by deriving from Groupbox class and creating some subsequent components in the onCreate method. Everything works fine so far. The only thing I did not get working is to get my widget notified that the user scrolled with the mouse wheel (as in Google Maps or Google Calendar).
I tried to define a new event with addClientEvent for "onMouseWheel" and then add an event listener for this new event, but I do not know what I have to do on the client side.
Are there any examples how to get user defined events working?
Best regards,
Ralf.
Hi, enixser
ZK is not support onMouseWheel
I write a sample component
Myimg.js
mycomp.Myimg = zk.$extends(zul.Widget, { $define: { src: function(v){ var n = this.$n(); if (n) n.src = v || ''; } }, bind_: function(){// after compose this.$supers('bind_', arguments); var node = this.$n(); if (node.addEventListener) node.addEventListener('DOMMouseScroll', this.proxy(this.wheel), false); node.onmousewheel = this.proxy(this.wheel); }, domAttrs_: function(no){ var attr = this.$supers('domAttrs_', arguments); if (!no || !no.content) attr += ' src="' + (this._src || '') + '"'; return attr; }, redraw: function(out){ out.push('<img', this.domAttrs_(), '/>'); }, zoom: function(range){ var node = jq(this.$n()), w = node.width(), h = node.height(); node.width(w * range); node.height(h * range); this.fire("onMouseWheel",{data: }); }, handle: function(delta){ if (delta < 0) this.zoom(0.7) else this.zoom(1.2) }, wheel: function(event){ var delta = 0; if (!event) /* For IE. */ event = window.event; if (event.wheelDelta) { /* IE/Opera. */ delta = event.wheelDelta / 120; if (window.opera) delta = -delta; } else if (event.detail) { delta = -event.detail / 3; } if (delta) this.handle(delta); if (event.preventDefault) event.preventDefault(); event.returnValue = false; } });
MyImg.java
public class MyImg extends XulElement{ private String _src; static { addClientEvent(MyImg.class, "onMouseWheel", CE_REPEAT_IGNORE); } public String getSrc() { return _src; } public void setSrc(String src) { if (src != null && src.length() == 0) src = null; _src = src; smartUpdate("src", new EncodedURL()); } private class EncodedURL implements org.zkoss.zk.ui.util.DeferredValue { public Object getValue() { return getEncodedURL(); } } private String getEncodedURL() { return getDesktop().getExecution().encodeURL(_src); } public void service(org.zkoss.zk.au.AuRequest request, boolean everError) { final String cmd = request.getCommand(); if (cmd.equals("onMouseWheel")) { final JSONArray data = (JSONArray) request.getData().get("data"); Events.postEvent(new Event(cmd, this, data.get(0))); } else super.service(request, everError); } protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws IOException { super.renderProperties(renderer); renderer.render("src", getEncodedURL()); } }
test.zul
<zk> <myimg src="item1.jpg" onMouseWheel='alert("zoom = " + event.data);'/> </zk>
Hi as1225,
where do I specify where to find the JS file? I added the following code to the lang-addon.xml file:
<component>
<extends>groupbox</extends>
<component-name>mycomp</component-name>
<component-class>de.efgapp.zk.components.MyComp</component-class>
</component>
After that I can use the new component in a ZUL file like this:
<mycomp id="c1" title="Test Box" />
Where do I have to put the JS file and how does ZK (or my new component) knows of its existence?
You can refer to here
The example is not clear to me. The example specifies a JS file in the <mold-uri> tag, but the description speaks about a JSP file. So, I guess it's a typo in the example.
The description says that <widget-class> specifies a JavaScript class. The example seems more to be a Java class.
It seems that I'm missing a small piece of information to get it working :-(
If I have the component definition as shown above and I put your JS code (changed to fit my component name) in a file named mycomp.js in the directory /WebContent/scripts in my Eclipse project, how do I have to tell ZK where to find this JS file and that it belongs to my component?
What version of ZK do you used ?
ZK is not support onMouseWheel
My sample is write a new component
You can refer to ZK5: Component Development Guide
or you can post a feature request
Not sure how to post a feature request on the new bug tracker, seems I can only consult.
So the event is still not supported ?
Found this explained on stackoverflow : http://stackoverflow.com/questions/9158411/handle-mousescroll-in-zk
Asked: 2010-02-02 08:37:50 +0800
Seen: 893 times
Last updated: Nov 25 '15