You probably don't need the 0+, but you might be surprised to look at the
characteristics of those parameters:

mycall = function(app,msg,msg2, id) {
  alert(app + " " + msg + " " + msg2 + " id=" + id + " id+1=" + (id + 1) +
" id/2=" + (id/2) + " typeof id=" + (typeof id) + " className=" +
id.__CLASS_NAME__)
}


*jmolApplet0_object script 1 started load $caffeine; id=-3 id+1=-2
id/2=-1.5 typeof id=object className=Integer*
Cool, huh?

On Mon, Feb 10, 2014 at 3:25 PM, Charles Harrison Shubert
<[email protected]>wrote:

>  Hi Bob,
>
>  I cannot reproduce what I was seeing with the
> model.ids.id_jsmol_JmolObject argument to Jmol.getAppletHtml that required
> the prepending of "", so that HACK is not needed. Perhaps I had a cache
> clearing issue with either my localhost server or the browser's
> localStorage.  I'm beginning to use the browser's localStorage for saving
> the model and I still have some work to do to get the behavior that I'm
> after.
>
>  I'm struggling with javascript's inferred typing and I appreciate the
> heads up on number parameter handling.  I never would have guessed the need
> to prepend 0+ to a parameter insure the proper behavior of a function's
> arithmetic.
>
>  Thanks again for your help in getting this app doing what I want,
>
>  --Chuck
>
>  On Feb 10, 2014, at 3:21 PM, Robert Hanson <[email protected]>
>  wrote:
>
>   msg = "" + msg
>
>  Yes, that's generally advisable. This was true in Java and is still true
> in Java/JavaScript. The parameters coming back are objects. Pretty sure
> that relates to numbers as well. So  0+... or ""+... is advised.
>
>
> "" + model.ids.id_jsmol_JmolObject
>
>  I guess if you don't have a string for that, you will need that. But I'd
> like to see why you don't have a string there in the first place....
>
>
>
>
>
> On Mon, Feb 10, 2014 at 1:40 PM, Charles Harrison Shubert <
> [email protected]> wrote:
>
>> Hi,
>>
>>  Below is the javascript for my jsmol initialization (slightly
>> abstracted).  Many thanks to Bob, Angel, and Rolf for helping me get my
>> javascript to do what I what it to do.  The HACK below seems to be related
>> to the handling of incoming and outgoing arguments for jmol
>> callbacks/shared variables.
>>
>>  --Chuck
>>
>>      function myMessageCallback(app, msg) {
>> //        HACK:  to force msg to be a string - you will see this HACK
>> again below when I send a string to Jmol.getAppletHtml
>>           msg = "" + msg;
>> //        console.info(msg);
>>     }
>>
>>      function myReadyFunction(app) {
>>         // ... stuff
>>     }
>>
>>      var jmolObject;
>>
>>      function init_jsmol(state) {  // state is my way of keeping track
>> of things such as ids
>>             var model = state.model;
>>
>>              var Info = {...};
>>             Info.use = "HTML5";
>>              Info.allowjavascript = true;
>> //            Info.debug = true;  // this is very useful
>>
>>              self[model.ids.id_jsmol_messagecallback] =
>> myMessageCallback;
>>
>>               // this is the name of the message callback. It's a string.
>>             Info.messagecallback = model.ids.id_jsmol_messagecallback;
>>
>>              // this is the address of the readyFunction callback. It's
>> a function.
>>             Info.readyFunction = myReadyFunction;
>>
>>              //HACK: without the prepended "" (empty string),
>> jmolObject._applet is null, but everything else looks OK.
>>             $('#' + model.ids.id_jsmol).html(Jmol.getAppletHtml("" +
>> model.ids.id_jsmol_JmolObject, Info));
>>
>>              jmolObject = self[model.ids.id_jsmol_JmolObject];
>>
>>              // This will throw an "_applet is null" exception without
>> the HACK above.
>>              Jmol.resizeApplet(jmolObject, ["100%", "100%"]);
>>     }
>>
>>   On Feb 10, 2014, at 10:17 AM, Robert Hanson <[email protected]>
>>  wrote:
>>
>>   [Sorry, somehow I don't have reference to Chuck's original here...]
>>
>>
>> On Mon, Feb 10, 2014 at 3:24 AM, Angel Herráez <[email protected]>wrote:
>>
>>> Hi Chuck
>>>
>>> I'm returning this to the list thread, for everyone's benefit.
>>>
>>> Charles Harrison Shubert wrote:
>>> > I seem to have gotten the behavior I wanted using your suggestion. I
>>> > not longer need Jmol.setXHTML when I use Jmol.getAppletHTML to invoke
>>> > Jmol.
>>> > Instead of using the "document.getElement ..", I used jQuery: $('#' +
>>> > model.ids.id_jsmol).html( Jmol.getAppletHtml(model.ids.id_jsmol +
>>> > "JmolObject", Info);
>>>
>>>
>>  When you use Jmol.getAppletHtml(xxx, Info),
>>
>> then a JavaScript object is created:
>>
>>  window[model.ids.id_jsmol+"JmolObject"]
>>
>>  That is the "applet" object. If you really don't know what
>> model.ids.id_jsmol is, then you could short-cut that later with:
>>
>>  jmolObject = window[model.ids.id_jsmol+"JmolObject"];
>>
>> I apologize about the ambiguity of "applet" here. We have the JavaScript
>> object and the (formerly/occasionally) Java applet or its JavaScript
>> equivalent. In the JavaScript on the page,
>>
>> jmolObject._applet
>>
>>  is the Java/whatever applet that has all the public functions of the
>> original Jmol Java applet plus, in JavaScript, all private methods and
>> fields, such as
>>
>>  jmolObject._applet.viewer.modelSet.atoms[3].toString()
>>
>>  I probably should not even mention that, because anything not public
>> for the Java, though public for JavaScript, is considered fair game for
>> development changes. No guarantee that "modelSet" will be called that
>> tomorrow! Fair use for testing and development, but don't use this for
>> production.
>>
>>
>>
>>
>>
>>> Yes, that's right. I just thought the HTML version would be more
>>> readable (it is for me), but the equivalent jQuery is OK.
>>>
>>>
>>  Funny the way jQuery grows on you... I now see $("#xxx")[0] as being
>> way nicer than document.getElementById("xxx").
>>
>>
>>
>>> > I then recreated a local jmolObject with:
>>> > jmolObject = eval(model.ids.id_jsmol + "JmolObject");
>>>
>>
>>  as mentioned. Just use window[....] not eval(). Or you could use
>> self[...]. Anyway, in JSmol.js we have:
>>
>>     Jmol._registerApplet = function(id, applet) {
>>         return window[id] = Jmol._applets[id] = Jmol._applets[applet] =
>> applet;
>>     }
>>
>>
>>  So window[id] is guaranteed to be your applet object.
>>
>>
>>
>>
>>
>>
>>> > to use with
>>> > Jmol.resizeApplet(jmolObject, "100%", "100%");
>>>
>>> I learned a few ays ago that you can use this too to refer to the
>>> object, to avoid eval() which seems to raise distrust among
>>> programmers:
>>>
>>>  jmolObject = window[model.ids.id_jsmol + "JmolObject"];
>>>
>>>
>>  There you go. Right, eval() can do more than you want it to. Stick
>> with  window[].
>>
>>
>>
>>> > I'm still a little confused by some of the jmolObject details as is
>>> > my code, but Jmol is now where I want it in my page and has the
>>> > correct size and z-order (that's in my css).
>>> > I'll spend some time tomorrow cleaning up the code and send you a
>>> > summary.
>>>
>>
>>  Next release allows setting the z-order of the applets prior to
>> execution of Jmol.min.js. But now that I think of it, I think
>>
>> Info.zIndexBase
>>
>> would be in order. Note that there are a range of objects that need z
>> indexes -- menu, console, dialogs, etc. That can be customized already, but
>> Info.zIndexBase (currently 9000) would probably be nice to have.
>>
>>  Bob
>>
>>
>>
>>
>>
>>> > Many thanks,
>>> > -Chuck
>>> >
>>> > On Feb 9, 2014, at 4:42 PM, Angel Herráez <[email protected]>
>>> > wrote:
>>> >     Hi Chuck
>>> >     I've been recently playing with ways to inject the Jmol objecr
>>> after
>>> >     page is loaded, so I will try to give a hint, see if it works
>>> >     Jmol.setXHTML(model.ids.id_jsmol);
>>> >     It's not clear to me where you define that ID
>>> >     You need an id in your Jmol container div:
>>> >     <div> app
>>> >     <div> menubar </div>
>>> >     <div>
>>> >     <div> tabs </div>
>>>  >     <divid="JmolPlace"> jmol </div>
>>> >     </div
>>> >     </dib>
>>> >
>>> >     Then
>>> >     document.getElementById("JmolPlace").innerHTML =
>>> >     Jmol.getAppletHtml('myJmol', Info);
>>> >     Does that work?
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Managing the Performance of Cloud-Based Applications
>>> Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
>>> Read the Whitepaper.
>>>
>>> http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
>>> _______________________________________________
>>> Jmol-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/jmol-users
>>>
>>
>>
>>
>> --
>> Robert M. Hanson
>> Larson-Anderson Professor of Chemistry
>> St. Olaf College
>> Northfield, MN
>> http://www.stolaf.edu/people/hansonr
>>
>>
>> If nature does not answer first what we want,
>> it is better to take what answer we get.
>>
>> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
>>
>>
>> ------------------------------------------------------------------------------
>> Managing the Performance of Cloud-Based Applications
>> Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
>> Read the Whitepaper.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk_______________________________________________
>> Jmol-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/jmol-users
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Androi apps run on BlackBerry 10
>> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
>> Now with support for Jelly Bean, Bluetooth, Mapview and more.
>> Get your Android app in front of a whole new audience.  Start now.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Jmol-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/jmol-users
>>
>>
>
>
> --
> Robert M. Hanson
> Larson-Anderson Professor of Chemistry
> St. Olaf College
> Northfield, MN
> http://www.stolaf.edu/people/hansonr
>
>
> If nature does not answer first what we want,
> it is better to take what answer we get.
>
> -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
>
>
> ------------------------------------------------------------------------------
> Androi apps run on BlackBerry 10
> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
> Now with support for Jelly Bean, Bluetooth, Mapview and more.
> Get your Android app in front of a whole new audience.  Start now.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk_______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>
>
>
> ------------------------------------------------------------------------------
> Android apps run on BlackBerry 10
> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
> Now with support for Jelly Bean, Bluetooth, Mapview and more.
> Get your Android app in front of a whole new audience.  Start now.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
> _______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>


-- 
Robert M. Hanson
Larson-Anderson Professor of Chemistry
St. Olaf College
Northfield, MN
http://www.stolaf.edu/people/hansonr


If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to