Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
dawsontoth / app.js
Created February 4, 2011 23:21
CSS Injection on External Websites using Appcelerator Titanium
// create our web view
var win = Ti.UI.createWindow({ backgroundColor: "#fff" });
var web = Ti.UI.createWebView({ url: "http://chicago.craigslist.org/" });
// inject our css when the web view finishes loading (because we need to inject into the head element)
web.addEventListener('load', function () {
// first, specify the CSS file that we should load
var cssFileName = 'styles.css';
// read in the contents
var cssFromFile = Ti.Filesystem.getFile(cssFileName);
@dawsontoth
dawsontoth / tweetView.js
Created February 10, 2011 04:07
Make tweets and links clickable in Titanium Mobile! Here I make a tweet look just like it does on Twitter, and interact the same too.
/**
* 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 Parser(text) {
var html = text;
var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
@dawsontoth
dawsontoth / LinksInWebViews.js
Created March 3, 2011 16:54
The following snippet takes over links in webviews, causing them to do nothing but Ti.App.fireEvent('linkClicked', { href: 'http://example.com' }). This lets you load in web pages, and control what should happen when a link is clicked.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var html = '<html><body>'
+ '<a href="http://pedro.com">Pedro</a> '
+ '<a href="http://is.com">is</a> '
+ '<a href="http://a.com">a</a> '
+ '<a href="http://balla.com">balla!</a>.'
+ '</body></html>';
var web = Ti.UI.createWebView({
@dawsontoth
dawsontoth / LinksInExternalWebViews.js
Created March 21, 2011 16:51
The following snippet takes over links in a webview of a remote URL, causing them to do nothing but Ti.App.fireEvent('linkClicked', { href: 'http://example.com' }). This lets you load in web pages, and control what should happen when a link is clicked (li
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var web = Ti.UI.createWebView({
url: 'http://www.appcelerator.com/'
});
var linkJS = 'document.titaniumLinkQueue = [];'
+ '(function(){'
+ 'var links = document.getElementsByTagName("a");'
+ 'for(var i = 0, l = links.length; i < l; i++) {'
@kosso
kosso / gist:981250
Created May 19, 2011 17:11
Titanium sample: Multiple selection types in a window form
// Appcelerator Titanium (JS) code to produce multiple selection type data entry in a single window.
// via @CJ_Reed
// and Dan Tamas : http://cssgallery.info/making-a-combo-box-in-titanium-appcelerator-code-and-video
var win = Titanium.UI.currentWindow;
// build custom tableView data/layout
@dawsontoth
dawsontoth / app.js
Created June 6, 2011 20:40
Rate my app in Appcelerator Titanium Mobile
/**
* The following snippet will ask the user to rate your app the second time they launch it.
* It lets the user rate it now, "Remind Me Later" or never rate the app.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
win.addEventListener('open', checkReminderToRate);
win.add(Ti.UI.createLabel({ text: 'This is a simple app that will remind you to rate it.' }));
win.open();
function checkReminderToRate() {
@mattheworiordan
mattheworiordan / drag.js
Created July 9, 2011 18:12
Drag and drop example for Titanium
var circle = Titanium.UI.createView({
height:200,
width:200,
borderRadius:50,
backgroundColor:'#336699',
top:10,
left:50
});
currentWindow.add(circle);
@oroce
oroce / _for iOS users
Created November 2, 2011 18:20
Appcelerator share to native facebook, twitter
This gist is only for Android.
If you would like launch native apps
on iPhone, iPad, you can find information about it in Appcelerator Docs:
-https://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Platform.canOpenURL-method.html
-https://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Platform.openURL-method.html
More info about iOS URL Schemes: http://handleopenurl.com/
@furi2
furi2 / gist:1378595
Created November 19, 2011 07:36
Uploading multipart/form-data type data from Titanium
var content = '';
var boundary = '---------------------------170062046428149';
content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="uploadToken"\r\n';
content += '\r\n';
content += upload_token + '\r\n';
content += '--'+ boundary + '\r\n';
content += 'Content-Disposition: form-data; name="destFolderPath"\r\n';
content += '\r\n';
@bob-sims
bob-sims / 00-README.txt
Created December 3, 2011 23:22
Demo of charts display using simulated web service data. Charts are rendered in WebViews using the RGraph JS library within Titanium Mobile, which works nicely on Android.
This app uses RGraph library to build Android-compatible pie charts using Titanium Mobile.
Brief screencast to demo functionality:
http://youtu.be/itTEwQmvNfY?hd=1
This was for a work prototype/mockup, so excuse the esoteric text labels and fake activity indicator.
I borrowed heavily from prior art.
Aaron Saunder's "Titanium Appcelerator Quickie: Google Charts and Appcelerator"