Permalink
Browse files

moved twitter parser out to twitter detail window where it belongs

  • Loading branch information...
1 parent 53fa967 commit edfd3b7369712c488dffbc11ec15818b8ca9a5f0 @tonylukasavage tonylukasavage committed Sep 13, 2011
Showing with 50 additions and 65 deletions.
  1. +0 −32 Resources/lib/misc.js
  2. +50 −33 Resources/windows/TwitterDetailWindow.js
View
@@ -15,38 +15,6 @@
* along with DrupalCon Mobile. If not, see <http://www.gnu.org/licenses/>.
*/
-// Using the parsing method shown https://gist.github.com/819929
-/**
- * Define our parser class. It takes in some text, and then you can call "linkifyURLs", or one of the other methods,
- * and then call "getHTML" to get the fully parsed text back as HTML!
- * @param text that you want parsed
- */
-function twitterParser(text) {
-
- var html = text;
-
- var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
- var hashTagRegex = /#([^ ]+)/gi;
- var atTagRegex = /\@([a-z]+)/ig;
-
- this.linkifyURLs = function() {
- html = html.replace(urlRegex, '<a href="$1">$1</a>');
- // html = html.replace(urlRegex, '<a onclick="Ti.App.fireEvent(\'openURL\', { url: \'$1\' });">$1</a>');
- };
- this.linkifyHashTags = function() {
- html = html.replace(hashTagRegex, '<a href="http://twitter.com/#!/search?q=%23$1">#$1</a>');
- };
- this.linkifyAtTags = function() {
- html = html.replace(atTagRegex, '<a href="http://mobile.twitter.com/$1">@$1</a>');
- };
-
- this.getHTML = function() {
- return html;
- };
-
-}
-
-
/*
* Clean up some of the special characters we are running into.
*/
@@ -14,44 +14,61 @@
* You should have received a copy of the GNU General Public License
* along with DrupalCon Mobile. If not, see <http://www.gnu.org/licenses/>.
*/
+(function () {
+ // Using the parsing method shown https://gist.github.com/819929
+ var TwitterParser = function (text) {
+ var html = text;
+ var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
+ var hashTagRegex = /#([^ ]+)/gi;
+ var atTagRegex = /\@([a-z]+)/ig;
-(function() {
+ this.linkifyURLs = function () {
+ html = html.replace(urlRegex, '<a href="$1">$1</a>');
+ };
+ this.linkifyHashTags = function () {
+ html = html.replace(hashTagRegex, '<a href="http://twitter.com/#!/search?q=%23$1">#$1</a>');
+ };
+ this.linkifyAtTags = function () {
+ html = html.replace(atTagRegex, '<a href="http://mobile.twitter.com/$1">@$1</a>');
+ };
- DrupalCon.ui.createTwitterDetailWindow = function(settings) {
- Drupal.setDefaults(settings, {
- title: 'title here',
- uid: '',
- name: ''
- });
+ this.getHTML = function () {
+ return html;
+ };
+ };
- var twitterDetailWindow = Titanium.UI.createWindow({
- id: 'twitterDetailWindow',
- title: settings.title,
- backgroundColor: '#FFF',
- barColor: '#414444',
- fullscreen: false
- });
- twitterDetailWindow.orientationModes = [Ti.UI.PORTRAIT];
- var baseHTMLStart = '<html><head><link rel="stylesheet" type="text/css" href="windows/tweetWebView.css" />' +
- '<meta name="viewport" content="user-scalable=yes, width=device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 10.0" /> <meta name="apple-mobile-web-app-capable" content="yes" />' +
- '</head><body class="tweets"><div class="created-at">' + settings.date + '</div>',
- baseHTMLEnd = '<script type="text/javascript" src="windows/tweetWebView.js"></script></body></html>';
+ DrupalCon.ui.createTwitterDetailWindow = function (settings) {
+ Drupal.setDefaults(settings, {
+ title: 'title here',
+ uid: '',
+ name: ''
+ });
- var tweet = settings.text;
+ var twitterDetailWindow = Titanium.UI.createWindow({
+ id: 'twitterDetailWindow',
+ title: settings.title,
+ backgroundColor: '#FFF',
+ barColor: '#414444',
+ fullscreen: false
+ });
+ twitterDetailWindow.orientationModes = [Ti.UI.PORTRAIT];
+ var baseHTMLStart = '<html><head><link rel="stylesheet" type="text/css" href="windows/tweetWebView.css" />' + '<meta name="viewport" content="user-scalable=yes, width=device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 10.0" /> <meta name="apple-mobile-web-app-capable" content="yes" />' + '</head><body class="tweets"><div class="created-at">' + settings.date + '</div>',
+ baseHTMLEnd = '<script type="text/javascript" src="windows/tweetWebView.js"></script></body></html>';
+ var tweet = settings.text;
+ var web = Ti.UI.createWebView({
+ scalesPageToFit: true
+ });
+ twitterDetailWindow.add(web);
- var web = Ti.UI.createWebView({scalesPageToFit:true});
- twitterDetailWindow.add(web);
+ // parse the tweet and set it as the HTML for the web view
+ var parser = new TwitterParser(tweet);
+ parser.linkifyURLs();
+ parser.linkifyHashTags();
+ parser.linkifyAtTags();
+ var parsedPage = baseHTMLStart + parser.getHTML() + baseHTMLEnd;
+ web.html = parsedPage;
- // parse the tweet and set it as the HTML for the web view
- var parser = new twitterParser(tweet);
- parser.linkifyURLs();
- parser.linkifyHashTags();
- parser.linkifyAtTags();
- var parsedPage = baseHTMLStart + parser.getHTML() + baseHTMLEnd;
-
- web.html = parsedPage;
-
- return twitterDetailWindow;
- };
+ return twitterDetailWindow;
+ };
})();

0 comments on commit edfd3b7

Please sign in to comment.