Skip to content

Instantly share code, notes, and snippets.

View dawsontoth's full-sized avatar

Dawson Toth dawsontoth

View GitHub Profile
@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++) {'
@dawsontoth
dawsontoth / app.js
Created April 16, 2012 19:36
Pullable Left Menu
var win = Ti.UI.createWindow({
backgroundColor: '#333'
});
var menuWidth = 200;
var container = Ti.UI.createScrollView({
disableBounce: false,
horizontalBounce: true,
contentWidth: Ti.Platform.displayCaps.platformWidth + menuWidth
@dawsontoth
dawsontoth / postingToGitHub.html
Created March 14, 2011 17:59
How to post Gists to GitHub
<html>
<head>
<style type="text/css">
body {
font: 14px Verdana, Geneva, sans-serif;
height: 500px;
width: 700px;
margin: 10px 20px;
}
@dawsontoth
dawsontoth / validateForm.js
Created February 4, 2011 23:37
Quick Form Validation in Appcelerator Titanium (very simplistic)
function validateForm() {
var formIsValid = true;
function enforceTextFieldMinLength(field, minLength) {
if (!field.value || field.value.length < minLength) {
formIsValid = false;
}
}
function enforceLabelHasText(label) {
if (!label.text) {
formIsValid = false;
@dawsontoth
dawsontoth / AndroidEmails.js
Created February 17, 2011 17:15
How to send emails in Appcelerator Titanium using activities and intents.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var button = Ti.UI.createButton({ title: 'Share' });
win.add(button);
win.open();
button.addEventListener('click', function() {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND,
type: 'text/plain'
});
#cs ----------------------------------------------------------------------------
Version: v1
Author: Dawson Toth
Script Function:
Taps the tiny unit deselection arrow in They Are Billions 1 to 10 times.
To use, download AutoIt, then drop this in a file named TheyAreBillions-Hotkeys.au3.
Run the script, and then whenever you press `, you can then press ESC or ` to cancel,
or 1, 2, 3, 4 ... 9, or 0 (which means 10) to left click on the deselect arrow in TAB.
@dawsontoth
dawsontoth / RecordingVideo.js
Created February 17, 2011 19:43
How to record video, then share or save it. Using Appcelerator Titanium!
/**
* This sample lets you record and share video with Appcelerator Titanium on Android.
* REQUIRES THE 1.6.0 RC OF TITANIUM MOBILE SDK
* http://developer.appcelerator.com/blog/2011/02/release-candidate-for-titanium-mobile-1-6-0.html
*/
/**
* First, create our UI. We'll have two buttons: record, and share.
*/
var win = Titanium.UI.createWindow({
@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 / InfiniteScrollingTableView.js
Created February 3, 2011 22:49
Infinite loading table view for iOS and Android.
/**
* We're going to create an infinite loading table view. Whenever you get close to the bottom, we'll load more rows.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var isAndroid = Ti.Platform.osname === 'android';
/**
* Create our UI elements.
*/
var table = Ti.UI.createTableView({ top: 0, right: 0, bottom: 0, left: 0 });
function getStackTrace() {
let obj = {};
Error.captureStackTrace(obj, getStackTrace);
return obj.stack;
}
window.activeFuncs = {};
window.originalSetTimeout = window.setTimeout;
window.originalClearTimeout = window.clearTimeout;
window.originalSetInterval = window.setInterval;