Advertisement
Guest User

Untitled

a guest
Jun 14th, 2011
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.83 KB | None | 0 0
  1. // this sets the background color of the master UIView (when there are no windows/tab groups on it)
  2. Titanium.UI.setBackgroundColor('#000');
  3.  
  4. // create tab group
  5. var tabGroup = Titanium.UI.createTabGroup();
  6.  
  7.  
  8. //
  9. // create base UI tab and root window
  10. //
  11. var win1 = Titanium.UI.createWindow({  
  12.     title:'Tab 1',
  13.     backgroundColor:'#fff'
  14. });
  15. var tab1 = Titanium.UI.createTab({  
  16.     icon:'KS_nav_views.png',
  17.     title:'Tab 1',
  18.     window:win1
  19. });
  20.  
  21. var webview = Ti.UI.createWebView();
  22.  
  23. win1.add(webview);
  24.  
  25. //
  26. // create controls tab and root window
  27. //
  28. var win2 = Titanium.UI.createWindow({  
  29.     title:'Tab 2',
  30.     backgroundColor:'#fff'
  31. });
  32. var tab2 = Titanium.UI.createTab({  
  33.     icon:'KS_nav_ui.png',
  34.     title:'Tab 2',
  35.     window:win2
  36. });
  37.  
  38. var label2 = Titanium.UI.createLabel({
  39.     color:'#999',
  40.     text:'I am Window 2',
  41.     font:{fontSize:20,fontFamily:'Helvetica Neue'},
  42.     textAlign:'center',
  43.     width:'auto'
  44. });
  45.  
  46. win2.add(label2);
  47.  
  48.  
  49.  
  50. //
  51. //  add tabs
  52. //
  53. tabGroup.addTab(tab1);  
  54. tabGroup.addTab(tab2);  
  55.  
  56.  
  57. // open tab group
  58. tabGroup.open();
  59.  
  60. Titanium.App.addEventListener('openMyBrower', function (url){
  61.     alert(url);
  62.     //Ti.Platform.openURL(url);
  63. });
  64.  
  65. function replaceURLWithHTMLLinks(text) {
  66.   var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  67.   text = text.replace(exp,"<a href='$1'>$1</a>");
  68.   alert(text);
  69.  
  70.   return myBrowserLinkConverter(text);
  71. }
  72.  
  73. function myBrowserLinkConverter(html_code){
  74.     html_code = html_code.replace(/<a /gi, "<a onClick='Ti.App.fireEvent(\"openMyBrower\", {url: this.href}); return false;'");
  75.     alert(html_code);
  76.    
  77.     return html_code;
  78. }
  79.  
  80. var html = 'hi hello this is an url without an hyperlink\n first one http://google.nl \n second one: http://www.hi.org';
  81.  
  82. var html2 = replaceURLWithHTMLLinks(html);
  83. webview.html = html2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement