Working demo on jsdo.it.
I have been trying to read from and write to a googlesheet, in the context of my widged project. Writing will be describing in a future post. Reading data is surprisingly easy.
A live demo is available as a ScoreBoard widged.
The goal was to write the code in such a way that data can be passed to it as plugin settings or can be loaded asynchronously from a google spreadsheet. This is managed with a publish-subscribe pattern. This can be done using a combination of bind and trigger, which are included in the jQuery library.
The idea is to avoid tight coupling as much as possible. To accommodate for the fact that different services could be used in the future, best is to keep the code that fetches and parse data from the google spreadsheet completely independent from the interactive that renders the data. We get the interactive to listing to an event "dataChange".
Fetching data from the google spreadsheet is managed by a separate plugin, that we call here dataread.js. A problem is that you have many interactives on the page, each reading data from a different spreadsheet. If you were to dispatch the event at the page level, all interactives would receive a request to update their view using the new data. This is best avoided. The solution we use is to attach the events to a dom element that is specific to an interactive, here, "div#a-0".
I have started playing a bit with jQuery recently to explore its potential for cross-device coding. So far so good. I have created a few learning activities as jQuery plugins.
They run on desktop, iPad, iPod Touch, Android, OLPC browser.