sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Catching the ready event for webdialogs on Mac?

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 2 Posters 169 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      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!

      Thomas Thomassen β€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        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..? πŸ˜’ )

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          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.

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Safari doesn't seem to display JS errors. Any way to make it?

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • jeff hammondJ Offline
              jeff hammond
              last edited by

              @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..

              dotdotdot

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                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...

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement