My goal was to create a standalone webpage application that self generates its pages based on interaction with twitter.com. (no further interaction with the originating server)
This is proof of concept code and is not very durable nor complete.
To try the code in action, visit:
- copy index.html to your server
goto dev.twitter.com and register a new twitter web application using your twitter account. You will need to specify an application name, the http address of your server and some other minor info. You will receive a public API key that you must include in the following script tag in the header.
access the webpage using your mobile device browser or computer browser
- if you want to view the application in fullscreen (for an iphone/ipod touch), Select the Add to Home Screen option in Mobile Safari. Then launch the app from your home page.
- this code will first see if you are logged into twitter, if not, it will display a twitter login button. When you press it, it will redirect you to twitter.com to login. After login, twitter will redirect you back to the webpage.
- this app will grab your home timeline from twitter and display it on the screen
- display logged in user's direct messages by pressing the Direct Msg button on the home timeline
- click on @user's to bring up their tweets, click on #subject's to search twitter for that keyword.
- send a general tweet to the world by pressing the Tweet button in the header
- reply to a user's tweet by pressing the right arrow button on the top right of each tweet
- retweet by pressing the circular arrow button located at the bottom-right of each tweet
- send a private message to a user by pressing the Direct Msg button in the footer
- do random searches of twitter using the search box
- this program will autorefresh your home_timeline (default 10 minutes).
- notify user of new tweets
- better error handling
- only tested on an ipod touch
- the UI could be improved significantly, I just wanted to get a feel for the jQuerymobile API
- error handling is almost non-existent
Updating the html of a 'page' that has already been processed by jqm is not very straightforward nor well documented. The method that i am currently using is: remove the jqm processed DOM structure that you wish to update, re-add the modified html to the DOM, then run $(NEWHTML).page() to get jqm to reprocess that section of HTML.
It would be very tricky for jqm to reprocess an already processed DOM (since it can't tell the difference between processed html and new html). So the current solution works but maybe jqm could offer some helper methods.. such as $(structure)).replaceHTML(NEWHTML) where this function would delete the old DOM structure, insert the new HTML into the DOM and rerun page() on the new structure.
Another solution is to save the original html and create a new DOM structure with the processed HTML. When the user wanted to change his html, he would make the changes to the original html, then call a function to reprocess the html. This would probably be a memory hog and could take significant cycles on large pages. But maybe jqm would only use this method if the user flags the original page as being modifiable. If it is readonly, then jqm would default to its current method
jqm markup. I understand that jqm is trying to be a general purpose solution for the most common UI elements used on multiple mobile platforms but sometimes the canned UI elements don't work for an application. I originally wanted an unordered list that had a thumbnail, a title, and a description but readonly. This isn't possible afaik. I had to use thumbnail, a linked title + description in order for jqm to generate the correct markup. I am guessing that jqm is looking for certain html patterns to determine which markup to use. Maybe in the future, a more flexible solution would be nice. Like a checklist (readonly, clickable), thumbnail/no thumbnail, title/no title, etc. but implemented using attributes.
On the css front.. jqm assumes many css parameters such as the thumbnail size. It would be nice if the user could leave hints that jqm would use to generate its css, such as < img width=45 height=45 ...>. I was able to override jqm's CSS by using style="" in my html but it is trickier on jqm generated html. They only use jqm generated classes for css. I overrode the jqm classes to create my desired look but my changes affected other parts of my page. A possible solution would be to automatically propagate classes that I specify in my html to jqm generated html. Then i could override jqm css using my own classes.
jqm hash history assumes ajax or external pages. Consider expanding it to include self generated pages
I had a problem updating the html in headers and footers with data-position=fixed. I needed to change the visible buttons on my fixed footer depending on the page content. I tried to use the trick explained above to replace the html then running page(). This worked for the most part except the fixed function stopped working.. Apparently jqm adds some additional handlers to fixed headers/footers to dynamically adjust their position on the page depending on the current scroll position. But these handlers weren't being reinstalled after i ran page() on the updated html.
Overall, jqm worked very well. My application doesn't use standard ajax or linked pages so i guess that i was stretching the limits of the current alpha jqm.
Twitter has many more capabilities in their restful interface that can be interesting. Like your home_timeline (i.e. tweets from people you follow). Sending tweets to specific people, profiles, etc. All of these commands aren't explained in the main document.
Copyright (c) 2010 Richard Sepulveda
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.