Re: [Jmol-users] Frame, Window, Tab Communication Independent of the DOM

2015-09-03 Thread Otis Rothenberger
Bob,

Clear documentation on this stuff is hard to find. This recent discovery on my 
part is worth mentioning in this chain because it opens more doors for this 
approach. The event object returns very useful info:

e.key – index key name
e.newValue – value being added to key
e.oldValue – value being replaced
e.url – complete url path of event creator page
e.storageArea – ???

The last one is supposed to return, localStorage or sessionStorage, but I’ve 
had some trouble with that one. The specs say that the event has to be sent to 
all active windows except the sender. The event is triggered by the setItem(), 
removeItem(), and clear() methods. With the event carrying the new message, 
"message eating” is not a factor. Also multiple window action is more easily 
controlled.

My red atom color Jmol Script code in the previous note had a : rather than a ; 
Typo!

Otis

--
Otis Rothenberger
o...@chemagic.com
http://chemagic.com

> On Sep 1, 2015, at 4:18 PM, Robert Hanson  wrote:
> 
> That's very cool, Otis. Thanks for the intro to local storage. I especially 
> like the idea of the event notices. 
> 
> Bob
> ​
> --
> ___
> Jmol-users mailing list
> Jmol-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-users




--
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991=/4140
___
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] Frame, Window, Tab Communication Independent of the DOM

2015-09-01 Thread Robert Hanson
That's very cool, Otis. Thanks for the intro to local storage. I especially
like the idea of the event notices.

Bob
​
--
___
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


[Jmol-users] Frame, Window, Tab Communication Independent of the DOM

2015-09-01 Thread Otis Rothenberger
New List Subject but related to Eran’s note...

The approach in this note is motivated by Eran’s questions, but it’s also 
motivated by a number of frame page communication issues that have come up as 
folks move older pages to JSmol.

It’s quick and dirty, but it works (No parent.top… or should it have been 
parent.top.top… or maybe just parent…).
I have not tried it on older frameset pages, but it should work.

The code is fairly simple:

if (window.addEventListener) { window.addEventListener("storage", talkToFriend, 
false); } // false ensures event bubbling - not capture
if (window.attachEvent) { window.attachEvent("storage", talkToFriend, false); } 
// keep i.e. happy - sigh
function talkToFriend(e) {
if (localStorage.getItem('talkToFriend')) {
var data = localStorage.getItem('talkToFriend');
localStorage.removeItem('talkToFriend’); // sending page will 
get this message, but above “if" will kill action. Classic example of eat this 
message!
Jmol.script(jmolApplet0, data);
}
return null;
}

If the above code is in two pages on the same browser (frames, tabs, or 
windows) then they can exchange JmolScript commands independent of the DOM. The 
command to make the change is:

localStorage.setItem('talkToFriend', 'select all:color red');   or   
localStorage.setItem('talkToFriend', 'load $aspirin'); or Etc.

You can try it here:

http://chemagic.com/molecules/VMKMINInotes.htm 


The model kit is in an iFrame. Both pages have the above code. If you go to the 
JS console of the browser - not the Jmol frame, then the containing page will 
be the sender. This page does not even know what Jmol is. It’s a slide show 
page, and it could even be in another tab or window. The DOMs of both pages are 
irrelevant to the dialog. In the console, enter:

localStorage.setItem('talkToFriend', 'select all:color red')

or any other Jmol script. Note that the sending page does not get the event. 
That’s by design. Note also that if the Jmol page were to send a script in this 
case there would be an error. There is no Jmol on the sending page. Tweaking 
the senders event function could prevent an inadvertent event error. For 
example, if the sender never has to listen, the the event function could simply 
return null;

I called this “talkToFriend” because it’s set up for 1 to 1 communication. With 
a little thought, multi frame/window Jmol synchronization should be possible. I 
have to think about this.

Otis

--
Otis Rothenberger
o...@chemagic.com
http://chemagic.com

--
___
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users