Serious Issues with Events not Firing

Michel,

Thank you! This looks great. The JavaScript isn’t much, but I was just unsure how to implement it. I think of a script as something that executes once when you call the self.executejavascript method.

I think I see what you’ve done though. Does it need to go to the hashtagchanged event or was that something you did because you know it if a framework based event on the change? I was thinking of having a CursorX or CursorY computed property that would grab the JavaScript whereX and whereY value. Could you do that or not? Just trying to understand why it goes to the HashTagChanged event. OK, let me clarify, I see WHY it goes there. I’d like to know why you chose it to go there…

Thanks.

[quote=219436:@Jon Ogden]Michel,

Thank you! This looks great. The JavaScript isn’t much, but I was just unsure how to implement it. I think of a script as something that executes once when you call the self.executejavascript method.

I think I see what you’ve done though. Does it need to go to the hashtagchanged event or was that something you did because you know it if a framework based event on the change? I was thinking of having a CursorX or CursorY computed property that would grab the JavaScript whereX and whereY value. Could you do that or not? Just trying to understand why it goes to the HashTagChanged event. OK, let me clarify, I see WHY it goes there. I’d like to know why you chose it to go there…

Thanks.[/quote]

You’re welcome. Sorry I could not find the time to prepare that for you yesterday.

Sometimes a snippet does not look like much, but it is still amazing to have seen for years in this forum a constant roar against MouseMove and absolutely no solution to mitigate the huge traffic issue. This ‘not much’ gives you a unique way of knowing when you need it where the mouse is without smothering your app.

Pardon me, but IMHO, engineering is less about complexity than efficiency. More lines may not necessarily mean better programming. Often on the contrary. But I would be glad to complexify if that makes it more palatable. That is the easy part.

To my knowledge, there is two ways to return a JavaScript value to Xojo : through the HashTag, or through the WebSDK Xojo.triggerServerEvent(). I used HashTagChanged because it was faster. I am not aware of any other way you can grab directly the values of JavaScript variables as you describe.

[quote=219443:@Michel Bujardet]You’re welcome. Sorry I could not find the time to prepare that for you yesterday.

Sometimes a snippet does not look like much, but it is still amazing to have seen for years in this forum a constant roar against MouseMove and absolutely no solution to mitigate the huge traffic issue. This ‘not much’ gives you a unique way of knowing when you need it where the mouse is without smothering your app.

Pardon me, but IMHO, engineering is less about complexity than efficiency. More lines may not necessarily mean better programming. Often on the contrary. But I would be glad to complexify if that makes it more palatable. That is the easy part.

To my knowledge, there is two ways to return a JavaScript value to Xojo : through the HashTag, or through the WebSDK Xojo.triggerServerEvent(). I used HashTagChanged because it was faster. I am not aware of any other way you can grab directly the values of JavaScript variables as you describe.[/quote]

Great! That answers my question. That was also where I was getting stuck was where to return the JavaScript value. Perfect! I will have to give this a whirl.

I think I simply plan on calling this via a timer that fires every so often. And since it’s not going back to the server, it’s perfect…

One wonders why it wasn’t developed this way in the first place…

It does make a round trip when you get the values. But nothing compared to the mess of MouseMove.

The only drawback to your method Michel is that it changes the URL of the page basically and shows the hashtag. But it does work.

Maybe I’ll have to see about the WebSDK if I really want to be anal about it… But it works quite well…

OK. So I decided to take my hand at writing a control to do this. Not entirely sure here…So…I have the following in the “locate” constant:

    whereX = 0; 
    whereY = 0;

document.onmousemove = function() {whereFunction(event)};

function whereFunction(e) {
    whereX = e.clientX;
    whereY = e.clientY;  

var pos = [whereX,whereY];
Xojo.triggerServerEvent(‘<<controlid>>’,’jasmove’,pos);
}

I call ExecuteJavaScript(locate) when the control gets show.

I am getting a JavaScript error:

Could not execute returned javascript: Invalid character '\\u8216'

I know also this isn’t how I’d really want to do it as now every mouse move gets set back to the server. That’s the problem now in the regular framework. I want to just get the JavaScript values, but maybe I can’t do that on the page itself.

So obviously I am doing something wrong…

Well, part of your problem is that you’ve got the wrong quote marks in there. You’ve got ’ marks instead of ’ (forward single quotes instead of apostrophes.

The next issue is that your whereFunction is defined as a global function. Because of how executejavascript is called, your function is actually scoped within the call and no longer exists when it gets called later. You should take some time to read the WebSDK docs as there’s an explanation in there about namespaces and how they’re used to make your functions and properties continue to exist.

Lastly, by setting document.onmousemove, you’re going to override the web framework. You should expect some of our events to not work at all if you do this.

That happened to me, until I unchecked “Use smart quotes and dashes” in the Text tab of the Keyboard preferences.

You are right of course. It does suppress MouseMove and possibly MouseEnter and MouseExit.

The solution I found is this :

document.getElementById("XojoContainer").onmousemove = function() {whereFunction(event)};

I know it is not cool to hack the DOM and it can break if you change the framework. But that seems to be the most reliable. I tried using Body, but the events tend to get lost at random.

I guess the “proper” way would be to overlay the entire page with a canvas, and attach the onMouseMove event to it.

I was confused there. Looking in some of the examples, I swear I saw single quotes as opposed to double quotes.

I did read through the docs but I skimmed over the namespaces part as I didn’t think it applied. I’ll have to go back and re-read that.

[quote]
Lastly, by setting document.onmousemove, you’re going to override the web framework. You should expect some of our events to not work at all if you do this.[/quote]

OK. Well, that settles it then. I don’t really want to mess up anything else. I’ll look at implementing your suggestion of the container control and using MouseEnter and MouseExit…

It’s not a matter of single vs double. It’s a matter of which single quotes you are using. In your example, you’ve got the one that is typed by hitting the key just to the left of the 1 key (on a US keyboard) as opposed to an apostrophe (on the same key as the double quote)

If you are trying to send functions to the browser, using namespaces are critical.

It must be that smart quotes are turned on then in the constant value field. I would think you guys would want just plain text in there…

[quote]
If you are trying to send functions to the browser, using namespaces are critical.[/quote]

Got it. I’ve moved away from this approach and am working on implementing yours. I think it will be fine…

And I may actually end up trying that. However, I’m also trying to do things as simply as possible. The issue of overlaying the page with a canvas causes other problems for me. I know because I already did that with the jCanvas control from Daniel Taylor’s Web Custom Controls. He has a MouseMove event in that canvas and it works and works fine. But I didn’t like some of the aspects of having to deal with it which is why I went looking elsewhere.

Greg’s suggestion to use a container and detect the entry and exit is very simple. However, it has some of its own for the way I’m using it. So I have not decided yet what I’m going to end up with in the final product.

And I also didn’t like the URL of the page being changed in the hashtag event which is why I ended up looking to make a custom control but that’s way more complicated…

[quote=219234:@Steve Upton]This sounds like a job for CSS.

create an invisible object in the upper area of the page, assign a style to it that responds to the :hover state and then use a web transition to grow it and perhaps make it visible as needed. It’s efficient and usually does the job.
[/quote]

MouseEnter and MouseExit do exactly the same job as CSS hover…

[quote=219670:@Jon Ogden]And I may actually end up trying that. However, I’m also trying to do things as simply as possible. The issue of overlaying the page with a canvas causes other problems for me. I know because I already did that with the jCanvas control from Daniel Taylor’s Web Custom Controls. He has a MouseMove event in that canvas and it works and works fine. But I didn’t like some of the aspects of having to deal with it which is why I went looking elsewhere.

Greg’s suggestion to use a container and detect the entry and exit is very simple. However, it has some of its own for the way I’m using it. So I have not decided yet what I’m going to end up with in the final product.

And I also didn’t like the URL of the page being changed in the hashtag event which is why I ended up looking to make a custom control but that’s way more complicated…[/quote]

The canvas does not have to cover the entire page if all you have to verify is the position of the mouse within the 60 points boundary. You can even combine Greg’s idea and mine. As for the WebControlWrapper, you just have to suffer through it once ; it can be reused for all your projects.

Yeah, well I don’t have time to try to figure all this out. The “tutorial” in the WebSDK docs doesn’t cover much. So I have to move on. I’ve got lots on my plate.

And in regards to my other issue of trying to find if the menu is displayed or not, yeah, I found where in the DOM where I can determine that. The issue is getting it back to Xojo where I can use it. That I can’t figure out and there’s no examples of anything like that. So I’m moving on. No time to spend a Saturday trying to learn that when I have a lot of other stuff on my plate that isn’t getting done just so something looks prettier…

Another problem with using anything to do with MouseMove as I think Greg pointed out is that it’s not captured on touch devices like an iPhone or iPad. The same goes for the JavaScript solutions.

So there one needs to use MouseDown and look at the coordinates…

FWIW you already have the WebSDK class already made in RubberViewsWE. See WCW. It simply returns a string value passed from JavaScript.

Good luck.

[quote=219678:@Jon Ogden]Another problem with using anything to do with MouseMove as I think Greg pointed out is that it’s not captured on touch devices like an iPhone or iPad. The same goes for the JavaScript solutions.

So there one needs to use MouseDown and look at the coordinates…[/quote]

Touch interface is inherently different from desktop : no mouse cursor…