You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jonathan Locke <jo...@gmail.com> on 2007/09/13 19:27:37 UTC
beyond image maps
i ran into an interesting problem that igor helped me solve yesterday. i
wanted to get the X, Y coordinate when the user clicks on an image instead
of using an image map because of some very fancy hit-testing and logic i
wanted to do on the server. image maps were not cutting it. anyway, what
we came up with was this useful piece of code:
image.add(new AjaxEventBehavior("onclick") {
@Override
protected CharSequence getCallbackScript(
boolean
onlyTargetActivePage) {
return generateCallbackScript("wicketAjaxGet('"
+ getCallbackUrl(onlyTargetActivePage)
+ "&x=' + event.offsetX + '&y=' +
event.offsetY");
}
@Override
protected void onEvent(AjaxRequestTarget target) {
WebRequest request = ThoofWebRequest.get();
final Map<String, String[]> parameters = request
.getParameterMap();
final int x = Integer.parseInt(parameters.get("x")[0]);
final int y = Integer.parseInt(parameters.get("y")[0]);
--
View this message in context: http://www.nabble.com/beyond-image-maps-tf4437219.html#a12659672
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: beyond image maps
Posted by Jonathan Locke <jo...@gmail.com>.
yeah, it turns out this is browser specific. to save you several hours, you
need this:
<script type="text/javascript">
function getEventX(element, event) {
if (event.offsetX != null) {
return event.offsetX;
}
return event.pageX - element.offsetLeft;
}
function getEventY(element, event) {
if (event.offsetY != null) {
return event.offsetY;
}
return event.pageY - element.offsetTop;
}
</script>
Michael Preiss wrote:
>
> I tested it, but an error occured: event.offsetX (/Y) returns "undefined"
> and the get method on the parameter map throws a
> null pointer exception. I currently need such a function, but I actually
> don't know, how to do it.
>
>
> Jonathan Locke wrote:
>>
>> i ran into an interesting problem that igor helped me solve yesterday. i
>> wanted to get the X, Y coordinate when the user clicks on an image
>> instead of using an image map because of some very fancy hit-testing and
>> logic i wanted to do on the server. image maps were not cutting it.
>> anyway, what we came up with was this useful piece of code:
>>
>> image.add(new AjaxEventBehavior("onclick") {
>>
>> @Override
>> protected CharSequence getCallbackScript(
>> boolean
>> onlyTargetActivePage) {
>> return generateCallbackScript("wicketAjaxGet('"
>> + getCallbackUrl(onlyTargetActivePage)
>> + "&x=' + event.offsetX + '&y=' +
>> event.offsetY");
>> }
>>
>> @Override
>> protected void onEvent(AjaxRequestTarget target) {
>> WebRequest request = ThoofWebRequest.get();
>> final Map<String, String[]> parameters = request
>> .getParameterMap();
>> final int x = Integer.parseInt(parameters.get("x")[0]);
>> final int y = Integer.parseInt(parameters.get("y")[0]);
>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/beyond-image-maps-tf4437219.html#a12927058
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: beyond image maps
Posted by Michael Preiss <mp...@11mp.de>.
I tested it, but an error occured: event.offsetX (/Y) returns "undefined" and
the get method on the parameter map throws a
null pointer exception. I currently need such a function, but I actually
don't know, how to do it.
Jonathan Locke wrote:
>
> i ran into an interesting problem that igor helped me solve yesterday. i
> wanted to get the X, Y coordinate when the user clicks on an image instead
> of using an image map because of some very fancy hit-testing and logic i
> wanted to do on the server. image maps were not cutting it. anyway, what
> we came up with was this useful piece of code:
>
> image.add(new AjaxEventBehavior("onclick") {
>
> @Override
> protected CharSequence getCallbackScript(
> boolean
> onlyTargetActivePage) {
> return generateCallbackScript("wicketAjaxGet('"
> + getCallbackUrl(onlyTargetActivePage)
> + "&x=' + event.offsetX + '&y=' +
> event.offsetY");
> }
>
> @Override
> protected void onEvent(AjaxRequestTarget target) {
> WebRequest request = ThoofWebRequest.get();
> final Map<String, String[]> parameters = request
> .getParameterMap();
> final int x = Integer.parseInt(parameters.get("x")[0]);
> final int y = Integer.parseInt(parameters.get("y")[0]);
>
>
>
--
View this message in context: http://www.nabble.com/beyond-image-maps-tf4437219.html#a12926853
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org