Catching the ready event for webdialogs on Mac?
-
Anyone manage to catch the ready event on Mac?
Trying to run some code when the webdialog is ready. Adding it to the block in the.show
method doesn't work.This snippet from the docs doesn't work.
dialog.show { dialog.execute_script("alert(10)"); }
If I pass on
dialog.execute_script("alert(10)");
a little bit later after calling show the alert box will show.On PC it works fine. I've even tried to hook up to the .ready even in jQuery, which sends a call back to my ruby script that the dialog is ready. Again that works on PC, but there's no life signal on Mac.
"It just works" my shiny metal ass!
-
hmm... odd...
I do seem to catch the ready event.
function init() { // Add callbacks add_callbacks(); // Signal that we're ready window.location = 'skp;ready'; } function add_callbacks() { $('#cmdSave').click( function() { window.location = 'skp;save'; } ); $('#cmdCancel').click( function() { window.location = 'skp;cancel'; } ); }
Because the add_callbacks() sets up two buttons in my webdialog and they work! BUT! that
window.location = 'skp:ready';
doesn't seem to ever trigger.self.add_action_callback('ready') { |dialog, params| puts '>> Dialog Ready' end
On PC I see '>> Dialog Ready' being printed in the console - but not MAC! Why the bleeding hell not?
(Can anyone detect my frustration level..?
)
-
More oddity!
I made my ruby ready callback do an execute script:
self.add_action_callback('ready') { |dialog, params| puts '>> Dialog Ready' dialog.execute_script("alert('We Are Ready');") end
And when I launch Sketchup I get that alert message!
I do create the WebDialog object when I load my ruby. But on PC that event isn't called until the .show method has been called. But on Mac it seem that it's called when the Webdialog object is created. What gives? I have no clue. -
Safari doesn't seem to display JS errors. Any way to make it?
-
@thomthom said:
Safari doesn't seem to display JS errors. Any way to make it?
not sure if this will help but..
if you go to safari/preferences/advanced
click 'show Develop menu in menu bar' which appears at the very bottom of the window.from the develop menu that now shows up, you can turn on the error console, debug javascript, etc..
-
Thanks jeff. It didn't help for this, but it'll be useful for other stuff.
I found the core of the problem.
Well, there was two issues.
On PC the webpage is created when you call .show.
On Mac it seems to be called immediately as you add HTML to the Webdialog class.So in my case, the ready event was triggered when the ruby loaded and therefor was sent to the console while it was closed.
My other problem was in the difference in how files where read between PC and Mac, I got some trailing whitespace on Mac while reading a file line by line. That caused a bug which mangled the JSON string I sent to the webdialog. On the Mac any JS error messages was suppressed so I got no feedback on this. (Unexpected as on PC I get a popup warning.)
Now it all seems to work. Though - I'm not too happy that the Mac loads the HTML document when I create the Webdialog class. I'd like to behave as on Mac.
Seems that I have a few things to report to the bugtracker tomorrow...
Advertisement