[Code] WebDialog communication

[Code] WebDialog communication

Postby Aerilius » Thu Jul 19, 2012 6:24 pm

As I mentioned elsewhere, I was working on some code to improve communication between Ruby and WebDialogs, especially because the methods provided by the API are rather low-level.

This class provides wrapper methods that handle all escaping/ encoding and work around the message length limit.
They accept any amount of arguments of any data type of JSON:
String, Fixnum/Integer, Float, Array, Hash/Object, Boolean, nil/null
(no custom objects or JavaScript functions or SketchUp entities)


Since JavaScript to Ruby is asynchronous, you can make use of the callback functions "success", "error", "complete" that trigger after the Ruby callback has finished. Thereof success/complete hold as argument the result of the Ruby callback, and error holds a string of the Ruby error.

Ruby to WebDialog:

    dlg = Beta::UI::WebDialogX.new
  • dlg.call_to( "functionName", arg1, arg2, ... )
    This calls a JavaScript function and returns the result (synchronous).

  • dlg.exec_script( "JavaScriptCode" )
    This transfers the given string of JavaScript code as a string (to suppress syntax/parsing errors), executes it and returns the result (synchronous).

  • dlg.set_element_value( element_id, argument )
    Just for completion.
WebDialog to Ruby:

    dlg = Beta.UI.WebDialogX
  • dlg.callTo( "methodName", arg1, arg2, ... )
    or dlg.callTo( optionsObject )
    This calls the given Ruby method and optionally returns the result to a JavaScript callback.

    with optionsObject={name: "methodName", data: arg, ...} (see below)

  • dlg.execScript( "codeString", optionsObject[optional] )
    This executes the given string of Ruby code and optionally returns the result to a JavaScript callback.

  • dlg.callback( "callbackName", arg1, arg2, ... )
    or dlg.callback( optionsObject )
    This calls the Ruby code block that has been created with dlg.add_action_callback. The action callback then receives as many arguments as you have specified: dlg.add_action_callback("doSomething"){|dlg, arg1, arg2, arg3| ... }.

    with optionsObject = {name:"callbackName", data:{}, success:function, error:function, complete:function, direct:true/false}
    • direct: false (or indirect: true)
      Means the data is passed via a hidden input element and the Ruby method get_element_value
    • direct: true (or indirect: false)
      Means the data is encoded, split in chunks smaller than 2083 characters (if necessary) and passed via an skp url
1
Last edited by Aerilius on Sat Jul 21, 2012 10:30 am, edited 3 times in total.

Aerilius 
PluginStore Author
PluginStore Author
 

Re: [Code] WebDialog communication

Postby thomthom » Thu Jul 19, 2012 9:23 pm

Seems we've done pretty much the same work. I've been implementing pretty much the same in the upcoming TT_Lib2.

It's something the API should have had natively though.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] WebDialog communication

Postby Aerilius » Fri Jul 20, 2012 1:41 pm

I based the namings a bit on jQuery.ajax(). I also found afterwards that it is surprisingly similar to Google's/SketchUp's dcBridge.js. Unfortunately they don't have the Ruby backend open source and it's a bit complex and overloaded to reverse-engineer.
0

Aerilius 
PluginStore Author
PluginStore Author
 

Re: [Code] WebDialog communication

Postby thomthom » Fri Jul 20, 2012 5:23 pm

Does it clean up the <SCRIPT> element that WebDialog.execute_script adds to <BODY> ?
I use this snippet in the function that executes on the JS side: $('body script').detach();
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] WebDialog communication

Postby Aerilius » Fri Jul 20, 2012 5:40 pm

That's good to add. Do the remaining script elements have an noticeable impact or is it just for cleanliness?
As for execute_script, if the passed JavaScript contains errors they wouldn't be catched but display popups. I then pass the code as String and eval the string.
0

Aerilius 
PluginStore Author
PluginStore Author
 

Re: [Code] WebDialog communication

Postby thomthom » Fri Jul 20, 2012 7:07 pm

Aerilius wrote:That's good to add. Do the remaining script elements have an noticeable impact or is it just for cleanliness?

I remove them to be safe. Considering that a Ruby might call a WebDialogs thousands of times, depending, I want to ensure the DOM is clean.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Code] WebDialog communication

Postby Dan Rathbun » Fri Jul 20, 2012 10:52 pm

thomthom wrote:I remove them to be safe. Considering that a Ruby might call a WebDialogs thousands of times, depending, I want to ensure the DOM is clean.

A major reason would be if there are limits to the number of certain elements. (For instance, there is a limit to the number of <STYLE> elements [StyleSheets collection members,] in MSIE.)

Can you limit the cleanup to elements that have NO id ?? (That way a author can prevent cleanup of a certain <SCRIPT> element, by using an id attribute.)

I think there was another topic recently where Chris and Jim discussed this ?
OK here it is: [ Code ] Cleanup After execute_script
0
Last edited by Dan Rathbun on Fri Jul 20, 2012 11:03 pm, edited 1 time in total.
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [Code] WebDialog communication

    Postby Dan Rathbun » Fri Jul 20, 2012 10:54 pm

    Have either of you looked into doing callbacks via: document.external
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: [Code] WebDialog communication

      Postby thomthom » Sat Jul 21, 2012 1:43 am

      Dan Rathbun wrote:Have either of you looked into doing callbacks via: document.external

      That appear to be MS only.
      0
      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund
      User avatar
      thomthom 
      PluginStore Author
      PluginStore Author
       

      Re: [Code] WebDialog communication

      Postby Dan Rathbun » Sat Jul 21, 2012 2:34 am

      thomthom wrote:
      Dan Rathbun wrote:Have either of you looked into doing callbacks via: document.external

      That appear to be MS only.

      Yea.. I just spent some time trying to look up info on it.
      There IS an External interface in the DOM, but it seems to be an interface for the window object.

      Is there a Safari & Webkit DOM/Js/HTML Reference website ??
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        Re: [Code] WebDialog communication

        Postby Dan Rathbun » Sat Jul 21, 2012 2:35 am

          (Devil's Advocate)

          [A] exec() is both a Js method, and a global Ruby method.

          In Js, exec() applies to Regular Expression searches.

          In Ruby, exec() applies to executing an external process. (Although in embedded Ruby, as in SketchUp, it is worthless, because it kills the current Sketchup Process.)
          So we have been teaching people to avoid using it.

          Since this is a subclass, and you are fixing execute_script(), you might as well just override it, fix the arguments and then pass the new arguments as:
          super("Dialog._fromRuby(#{id}, \"#{function_name}\", \"#{arguments_string.inspect[1..-2]}\")")
          Also you can alias the Ruby method as: execScript as this seems to that the ruby side method was named after the Js and VBS method: (ie: window.execScript which is compatible with MSIE and Chrome, and is likely to be added as a standard. See Also: http://help.dottoro.com/ljoswolk.php )

          So I'm arguing against using exec() as method name.



          [B] Also, I do not agree with your use of call(). You use it in a non-standard way.
          Normally it runs against the receiver:
          proc_obj.call( args... )
          or
          method_obj.call( args... )
          Anyway... I suggest using call_to() or call_func()



          [C] Errors.. whether or not errors are suppressed, should be controlled via an @debug instance var, owned by the subclass instance.



          [D] Nice idea for adding block forms for the 'execute' type methods with auto return value! (I also noticed the glaring lack of a set_element_value method in the WebDialog API class.)



          P.S. - In public library classes and modules, Ruby conventions should be followed, as closely as we can. (I would not nickpick about these things, if this was just a private class within your own namespace.)
          0
          Last edited by Dan Rathbun on Sat Jul 21, 2012 3:36 am, edited 1 time in total.
            I'm not here much anymore. But a PM will fire email notifications.
            User avatar
            Dan Rathbun 
            PluginStore Author
            PluginStore Author
             

            Re: [Code] WebDialog communication

            Postby Dan Rathbun » Sat Jul 21, 2012 3:35 am

              (More Devil's Advocate)

              I do realize it is beta.. but:



              [E] Namespace: I will always crab about defining non-Ruby CORE classes within TOPLEVEL_BINDING. This should be considered Ruby's namespace.

              Just as ThomThom is defining his subclass within a module namespace TT_Lib2 or whatever he decides, this class needs to go in some namespace.

              Temporarily ... with Dev::Test::UI or Beta::UI, just something that does not show newbies that we define classes that will potentially clash with Ruby Core objects, or other wrongly written, custom classes, that are defined at the toplevel.

              Think about the WxSU / WxRuby extensions, they have Dialog class, but it is within the Wx namespace. (See the file "wxruby/lib/wx/keyword_defs.rb" in the WxRuby source.)



              [F] Classname: The name Dialog, is potentially confusing. Most would think it will refer to native dialogs (Win32/MFC on Windows, Cocoa or Carbon on Mac.)
              I was thinking of something like: WebDialogDeluxe or WebDialogEx as a classname. [ see next post ]

              Remember that even a class name is a Constant reference, and any plugin author, within their own namespace, can define their own reference to classes in other namespaces, to save typing, (if they so desire.) Ex:
              Code: Select all
              module JoeCoder

                WDE = SKX::GUI::WebDialogEx

                @@dlg = WDE.new("Plugin Options", ... )

              end # module

              On the Javascript side, is using such a common word as a namespace wise ??

              (Are we sure this will not clash with any possible framework that an author might wish to use: JQuery, DHTMLSuite, etc.)
              0
              Last edited by Dan Rathbun on Sat Jul 21, 2012 6:37 am, edited 2 times in total.
                I'm not here much anymore. But a PM will fire email notifications.
                User avatar
                Dan Rathbun 
                PluginStore Author
                PluginStore Author
                 

                Re: [Code] WebDialog communication

                Postby Dan Rathbun » Sat Jul 21, 2012 3:36 am

                   I also  have been working on a UI::WebDialog subclass, but only briefly thought about communication issues, and decided to leave that for version 2.0 (... but then here you've already done the groundwork.)

                  It's very possible we can marry your code and mine, into a mutually beneficial subclass.

                  For instance, I (& Driven,) have already solved injection issues.

                  As well as, fixing current bugs concerning the superclass' show & show_modal methods in block forms, for both platforms. (On PC blocks run before content is ready, on Mac they never run.)
                  Meaning I have already overriden those methods in my edition, so you would not need to.

                  We only need to decide, how to inject your base Js "WebDialog framework". You need to think about whether it will be easier to maintain as a pure .js file, injected into the <HEAD>, as a <SCRIPT src='path/to/dialogfunc.js'> element, rather than a heredoc text block embedded within the Ruby. (The reason I ask is I have already added in this ability to inject external css stylesheets, so this can be used for script files as well.)
                  0
                    I'm not here much anymore. But a PM will fire email notifications.
                    User avatar
                    Dan Rathbun 
                    PluginStore Author
                    PluginStore Author
                     

                    Re: [Code] WebDialog communication

                    Postby Aerilius » Sat Jul 21, 2012 10:53 am

                    I fixed [A], [\B], [C], [E].
                    Dan Rathbun wrote:[F] Classname: The name Dialog

                    The classname was a placeholder to be changed when using the code (I corrected it to avoid misuse).

                    Dan Rathbun wrote:You need to think about whether it will be easier to maintain as a pure .js file, [...] rather than a heredoc text block embedded within the Ruby.

                    The reason was just to have it more compact (one file, no external requirements). But it has grown a lot, and a separate file gives also nicer JS code-highlighting :)

                    I have one issue with using an overriden execute_script instead my method because I pass the code string to JavaScript as a String and eval it there. Now this requires that the JS framework is already loaded, but originally I load it with execute_script in the show method... I'm curious about your external script/css injection.

                    Marriage sounds always good, I think merging the code is better than having several competing less complete solutions.
                    0

                    Aerilius 
                    PluginStore Author
                    PluginStore Author
                     

                    Re: [Code] WebDialog communication

                    Postby Dan Rathbun » Sun Jul 22, 2012 12:23 am

                    Aerilius wrote:I have one issue with using an overriden execute_script ...


                    Yes.. I agree... after I posted, I looked at my code, and realized that we need to keep it as it is.

                    What I did was:

                    1) write a private internal show_handler() method, (called from the overridden show() and show_modal(),)

                    2) which calls the appropriate aliased api_show() or api_show_modal() methods,
                    EDIT: No longer aliasing these. Using super now.

                    3) then enters a UI.start_timer loop, which keeps calling:

                      a) execute_script() to determine the readyState
                      (which returns false while the document's readyState is "loading", so nothing happens, until the DOM can actually execute the script arg, where upon it returns true. Meanwhile a callback gets the actual readyState value, and stores it in an instance var.)

                      b) back in the loop, it checks the readystate though query method instance var wrappers:
                        (i) if the page is still loading, the loop waits the delay interval, and runs again.
                        (ii) if the readyState is interactive, stylesheets are conditionally injected, and then an "show interactive proc" is run if one has been defined; the loop continues if the page has not yet reached 'complete'.
                        (iii) if the readyState is complete, the timer is stopped, and the "show complete proc" is run if one has been defined.

                    So, while the page and content are loading, I need execute_script to run FAST, without any parsing of the argument.
                    I use a single quoted string so Ruby will not parse it, thus:
                    %q[window.location="skp:readyState_callback@"+document.readyState]

                    So anyway.. there's no way to avoid having some aliased "api_" methods, because sometimes we just cannot use super (at least the way I have it written. I hate to have to duplicate a bunch of code, just to use super and avoid aliased methods, but dang sometimes I hate having aliased superclass methods also.)
                    EDIT: No longer aliasing any api methods. Using super now within any overrides.
                    0
                    Last edited by Dan Rathbun on Wed Jul 25, 2012 9:53 am, edited 1 time in total.
                      I'm not here much anymore. But a PM will fire email notifications.
                      User avatar
                      Dan Rathbun 
                      PluginStore Author
                      PluginStore Author
                       

                      Re: [Code] WebDialog communication

                      Postby Dan Rathbun » Sun Jul 22, 2012 2:37 am

                      Aerilius wrote:I fixed ...

                      OK.. looking over the new version.

                      Aerilius wrote: But it has grown a lot, and a separate file gives also nicer JS code-highlighting.

                      Exactly what I was thinking...

                      Off-Topic:
                      I wish Notepad++'s lexer would recognize inline dialects from other languages, and highlight them correctly. It does seem to work for Js embedded into HTML, but not CSS embedded into HTML, everything within the style tag is white. (Maybe we can get the Notepad++ core guys to "invent" some editor hash codes for inline language changes?)

                      Aerilius wrote:I have one issue with using an overriden execute_script instead my method because I pass the code string to JavaScript as a String and eval it there. Now this requires that the JS framework is already loaded, but originally I load it with execute_script in the show method... I'm curious about your external script/css injection.

                      This will need to be moved into the show_handler(), just after stylesheeet injection. It will need to be done PRIOR to any "interactive proc" running, in case an author wishes to use your Js framework, in that proc (if they define one.)

                      Aerilius wrote:The reason was just to have it more compact (one file, no external requirements). ... Marriage sounds always good, I think merging the code is better than having several competing less complete solutions.

                      OK I am reorganizing my code. (One big change is I was actually playing around with patching the actual UI::WebDialog class, but realized their was just no way I could release such a patch. It's a BIG "no-no".)

                      So I have to make changes so it is a subclass. Which solves some things. We can now define the readyState_callback within the initialize method, simplifying the show_handler method, and other code as well.

                      It gives access to the constructor arguments, which I need to try to solve another of the UI::WebDialog bugs, but that's low priority for now. Organization comes first.

                      Multiple files: I learned multiple files are really best, especially while debugging.

                      Off-Topic:
                      Also I use my editor in 2 pane mode, left pane edit, and right pane for referring to code in other files of the plugin. Saves scrolling way up, and way back down, etc.
                      I move various files back and forth between the left and right editor panes, depending on which one I am editing.
                      I also use Mike Foster's NPP Session Manager plugin (with custom mouse context-menu,) to quickly load all the files in the project, and save changes (like which pane each file is loaded into.) See the latest help file for his plugin, if you use NPP.

                      I hate scrolling so much.. that I often insert "section fold" brackets like:
                      #{# INSTANCE METHODS
                      #

                      #
                      #}#

                      ... and use the fold shortcuts ALT+level_number_key to quickly expand / contract block levels.



                      Anyway I'll need a day or two to re-organize and make some changes, and merge some code.
                      0
                      Last edited by Dan Rathbun on Sun Jul 22, 2012 2:45 am, edited 1 time in total.
                        I'm not here much anymore. But a PM will fire email notifications.
                        User avatar
                        Dan Rathbun 
                        PluginStore Author
                        PluginStore Author
                         

                        Re: [Code] WebDialog communication

                        Postby Dan Rathbun » Sun Jul 22, 2012 2:41 am

                          Off-Topic:
                          Side Note: A "wrapper class" and a subclass are two different things.

                          A wrapper:
                          Code: Select all
                          class Author::WebDialog

                            attr_reader(:dialog)
                           
                            def initialize(*args)
                              if @dialog.nil?
                                @dialog = UI::WebDialog.new(*args)
                              end
                              # other init code
                            end

                            def execute_script(code)
                              # do some manipulation to the code string
                              result = @dialog.execute_script(code)
                            end

                          end # wrapper class

                          Basically a "wrapper" mimics the "wrapped class" (with modifications,) and so must contain a "wrapper instance method" for each of the "wrapped class's" instance methods.

                          A wrapper is usually more work and requires higher diligence in coding to get things to work correctly. But sometimes has advantages over subclassing. Some of the Extended Ruby Library classes are written as a "wrapper" class. (The Delegate classes come to mind.)
                          0
                            I'm not here much anymore. But a PM will fire email notifications.
                            User avatar
                            Dan Rathbun 
                            PluginStore Author
                            PluginStore Author
                             

                            Re: [Code] WebDialog communication

                            Postby thomthom » Sun Jul 22, 2012 7:38 am

                            This code would be nice to have on GitHub. @Aerilius : what you think?
                            0
                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund
                            User avatar
                            thomthom 
                            PluginStore Author
                            PluginStore Author
                             

                            Re: [Code] WebDialog communication

                            Postby Dan Rathbun » Mon Jul 23, 2012 8:41 am

                            thomthom wrote:This code would be nice to have on GitHub. @Aerilius : what you think?

                            No it would not. I have a GitHub acct. They force a commie-socialist GPL-like license on any code posted.

                            I currently have a week or more in my part, est ~2500 dollars; and I'm sure Aerilius has at least the same. John has put near 3 days at least into testing as well. We are approaching ~6000 dollars in value invested, and may have even reached this.

                            I am not willing to let some person(s) or company(ies) just take our code from GitHub, re-brand it, and sell it without compensation.

                            I know by the time we get through the beta phase, with testing, that we'll have over 10,000 dollars in value into this.

                            The other issue is forking. The world is full of idiots who do not understand how their fork can "throw a wench into the works."

                            Go to RubyGems.org, search on "SAX" (which stands for Simple API for XML,) and see how many forks there are for SAXMachine. If you take the time to go to the documentation page for each one, you'll see NONE of these "forkin' idiots" changed the namespace. Nor did any of them even bother to wrap their fork in their author namespace.

                            I'd like to retain some semblance of control, so I typed up a preliminary EULA, that declares copyright (by our group,) and prohibits re-branding, re-packaging, re-distribution, forking or subclassing. (I am not yet sure about wrapping, still need to think on this.)

                            But I do not think, at this time, anyone will NEED to do any of these things, as we are making this extension eXtremely fleXible.



                            I'm not sure but perhaps Google Codesite, may not force GPL-like license on projects, and may be able to use Git now ??
                            I'm all for making it easier to collaborate, but not at the expense of surrendering my rights.
                            0
                              I'm not here much anymore. But a PM will fire email notifications.
                              User avatar
                              Dan Rathbun 
                              PluginStore Author
                              PluginStore Author
                               

                              Re: [Code] WebDialog communication

                              Postby thomthom » Mon Jul 23, 2012 9:15 am

                              oookay.... BitBucket then?
                              0
                              Thomas Thomassen — SketchUp Monkey & Coding addict
                              List of my plugins and link to the CookieWare fund
                              User avatar
                              thomthom 
                              PluginStore Author
                              PluginStore Author
                               

                              Re: [Code] WebDialog communication

                              Postby Dan Rathbun » Mon Jul 23, 2012 10:26 am

                              thomthom wrote:oookay.... BitBucket.org then?

                              Now that looks alot better! I'll have to read their ToS alot closer, but like they say right up front, private repositories (with access control.) We won't be ready till later in the week for this, let's get past this first major merge here between Aerilius' code and mine.
                              0
                                I'm not here much anymore. But a PM will fire email notifications.
                                User avatar
                                Dan Rathbun 
                                PluginStore Author
                                PluginStore Author
                                 

                                Re: [Code] WebDialog communication

                                Postby thomthom » Mon Jul 23, 2012 1:04 pm

                                Only thing is that I'm not sure if BitBucket allow free private repos to have multiple users. But I don't think free public repos enforce any licenses (open source or not). Up to the owner AFIK. (Correct me if I'm wrong.)

                                Btw, I never noticed that GitHub forced public repos to be open source?
                                0
                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund
                                User avatar
                                thomthom 
                                PluginStore Author
                                PluginStore Author
                                 

                                Re: [Code] WebDialog communication

                                Postby Dan Rathbun » Mon Jul 23, 2012 5:43 pm

                                It says 5 users is free.
                                0
                                  I'm not here much anymore. But a PM will fire email notifications.
                                  User avatar
                                  Dan Rathbun 
                                  PluginStore Author
                                  PluginStore Author
                                   

                                  Re: [Code] WebDialog communication

                                  Postby Dan Rathbun » Tue Jul 24, 2012 5:34 am

                                    OK, obviously we need a shorter Js-side namespace name.



                                    Fisrt choice: WDX
                                    I did a search on "+javascript +WDX"
                                    * got no hits.
                                    Search acronyms: WDX
                                    It stands for Wavelength Dispersive X-ray spectroscopy. (Not likely to be used as a namespace in Js, at least with SketchUp.)

                                    However... there is also the ".wdx" binary file format. It stands for Wolfram Data Exchange, used by Mathematica. see: http://reference.wolfram.com/mathematic ... t/WDX.html
                                    There ARE APIs associated with this, (although they do not yet have ".skp" import/export, they could in the future.)
                                    It is also quite possible someone would create a web interface 'framework' that uses this acronym.

                                    I think we should avoid this one.



                                    Next choice: SWDX ( SketchUp WebDialogX )
                                    No hits at http://www.dictionary.com
                                    or http://acronyms.thefreedictionary.com
                                    or http://en.wikipedia.org/wiki/Special:Search?search=SWDX&go=Go

                                    I think we should use SWDX, on the Js-side.

                                    Thots ?
                                    0
                                      I'm not here much anymore. But a PM will fire email notifications.
                                      User avatar
                                      Dan Rathbun 
                                      PluginStore Author
                                      PluginStore Author
                                       

                                      Re: [Code] WebDialog communication

                                      Postby chrisglasier » Tue Jul 24, 2012 8:04 am

                                      Dan Rathbun wrote:OK, obviously we need a shorter Js-side namespace name.


                                      Excuse me for butting in but the subject relates to what I am trying to do.

                                      I think I asked about this before here but certainly at Stackoverflow.

                                      In a nutshell if I append a new external script file after loading its names overwrite any duplicates in memory. The act of (re-)appending a file defines the namespace (or at least its content) which seems more reliable than human acronymisation (sorry). I suspect there is some dreadful twist to this but I am still looking.
                                      0
                                      With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
                                      User avatar
                                      chrisglasier 
                                      PluginStore Author
                                      PluginStore Author
                                       

                                      Re: [Code] WebDialog communication

                                      Postby Dan Rathbun » Tue Jul 24, 2012 11:32 am

                                        No problem, Chris.

                                        So far we are not unloading an external script, and will be appending the external script via <SCRIPT src='some/path/WebDialogX.js'>, but to the <HEAD> element, and only ONCE, just after the DOM readyState reaches "interactive".

                                        I think there may be a subtle difference between appending to the <HEAD> and <BODY>, ... well for us, at least the big difference is we want the WebDialogX framework out of the line of the <SCRIPT> tag cleanup function.

                                        Also I had mentioned this before... there may be some authors who have <SCRIPT> tags attached to the <BODY>, and do not wish them removed.

                                        So do we test for an id attribute, and leave those tags alone ??

                                        (One thing Aerilius tried to do was, delete only 1 tag at a time, just after execute_script() returned. Kind of making it cleanup after itself.)
                                        0
                                          I'm not here much anymore. But a PM will fire email notifications.
                                          User avatar
                                          Dan Rathbun 
                                          PluginStore Author
                                          PluginStore Author
                                           

                                          Re: [Code] WebDialog communication

                                          Postby chrisglasier » Tue Jul 24, 2012 12:04 pm

                                          Actually it isn't the external file cleanup I was concerned with, it is trying to avoid uniquely naming a namespace by allowing duplicate names for js objects.

                                          So for example I have a number of devices (plugins), one for positioning, one for timing, one for animation, one for music and so forth. Each device has function start(){...}. When I want to use one I create and append a new script element with the relevant source file. When that is properly loaded its start function overwrites the one in memory, and the same for any other duplicate name.

                                          I know that all the Ruby plugins have to be loaded with Sketchup, but this is not true with the js side of webdialogs.
                                          0
                                          With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
                                          User avatar
                                          chrisglasier 
                                          PluginStore Author
                                          PluginStore Author
                                           

                                          Re: [Code] WebDialog communication

                                          Postby Dan Rathbun » Tue Jul 24, 2012 2:16 pm

                                          OK.. well that is all fine and dandy. It should not effect us because all our functions will be within a Js namespace, and your functions will be outside it.

                                          So far the only objects that are global will be 3 vars, that will all probably be prefixed "swdx_" (or a downcase of whatever the namespace will be.)
                                          These 3 vars, I think (correct me if I am wrong,) can be deleted, after the element append is over and done with.
                                          Although I have not tried to do this yet. I suppose it might just as well be easier, if I wrap the routine in an anonymous function, so the vars just go out of scope, when the dirty deed is done?

                                          So I guess my question to you is, are you loading your devices / functions into the global Js namespace, or do you use a Glasier namespace ??
                                          0
                                            I'm not here much anymore. But a PM will fire email notifications.
                                            User avatar
                                            Dan Rathbun 
                                            PluginStore Author
                                            PluginStore Author
                                             

                                            Re: [Code] WebDialog communication

                                            Postby Aerilius » Tue Jul 24, 2012 4:01 pm

                                            Dan Rathbun wrote:So do we test for an id attribute, and leave those tags alone ??

                                            I've added the check for an id (not yet uploaded). Since the code of all <script> elements goes into memory when the script tag is loaded, it shouldn't matter if we just delete all script tags. Except an executing script needs a reference to a <script> element (probably with id, but not necessarily).
                                            A very mild way would be to use dlg.execute_script("/*delete this*/ someCode()")
                                            and then delete script elements if their innerHTML starts with "/*delete this*/". We'd like SketchUp not to flood the DOM with script elements, but is the innerHTML approach overdone?

                                            As for a license, I initially thought about keeping the extension relatively open. I'm a bit worried whether we should allow/disallow redistribution and how it makes plugin installation more difficult. Do others think plugins that require separate downloads is not so much a problem?
                                            0
                                            Last edited by Aerilius on Tue Jul 24, 2012 5:07 pm, edited 1 time in total.

                                            Aerilius 
                                            PluginStore Author
                                            PluginStore Author
                                             

                                            Re: [Code] WebDialog communication

                                            Postby chrisglasier » Tue Jul 24, 2012 5:04 pm

                                            Dan Rathbun wrote:OK.. well that is all fine and dandy.

                                            ...

                                            So I guess my question to you is, are you loading your devices / functions into the global Js namespace, or do you use a Glasier namespace ??


                                            All variables are parts of three global json objects:

                                            1 - one to hold all the records (eg all properties and attributes of entities, layers and scenes and special collections),

                                            2 - one that holds the main display configuration plus built-in menus and device keys and value options,

                                            3 - one as 2 above but specifically for the only connected device.

                                            Apart from these only functions are global variables. Device functions can be called anything provided they are not prefixed core or mac (dedicated to 1 and 2). Any conflicts with previously loaded devices are resolved by having the active device functions loaded last.

                                            In these circumstances is there any point in having a dedicated namespace?

                                            Aerilius wrote:Since the code of all <script> elements goes into memory when the script tag is loaded, it shouldn't matter if we just delete all script tags.


                                            Precisely ... in a way I was responsible for muddying the waters with script id's - sorry.
                                            0
                                            With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.
                                            User avatar
                                            chrisglasier 
                                            PluginStore Author
                                            PluginStore Author
                                             

                                            SketchUcation One-Liner Adverts

                                            by Ad Machine » 5 minutes ago



                                            Ad Machine 
                                            Robot
                                             

                                            Next


                                             

                                            Return to Developers' Forum

                                            Who is online

                                            Users browsing this forum: No registered users and 16 guests