Skip to content

Instantly share code, notes, and snippets.

@pec1985
pec1985 / require.js
Created April 21, 2011 00:38
How to use require() with Titanium
// this would be app.js (for example)
var UI = require('myfile'); // no .js extension
var win = UI.Window({backgroundColor:'#999'});
var view = UI.View({top:20,left:20,right:20,bottom:20,backgroundColor:'#ccc'});
win.add(view);
win.open();
var win = Titanium.UI.createWindow({
top:0,
backgroundColor:'#ccc'
});
var toolbar = Ti.UI.createToolbar({
top:0
});
var b1 = Ti.UI.createButton({
var win = Ti.UI.createWindow({backgroundColor:'#ccc'});
var isRunning = false;
var btn = Ti.UI.createButton({
title:'start',
bottom:10,
height:50,
left:10,
right:10
});
var slider = Ti.UI.createSlider({
@pec1985
pec1985 / uploadImage.js
Created April 27, 2011 02:56
Upload Image
Titanium.Media.openPhotoGallery({
success:function(event){
var myImage = event.media;
var xhr = Titanium.Network.createHTTPClient();
xhr.open('POST','http:// ------ /uploads.php');
xhr.onerror = function(e){alert(e.error);};
xhr.setTimeout(200000);
@pec1985
pec1985 / customRowEdit.js
Created May 13, 2011 10:27
Swipe on a row to add custom elements
var win = Titanium.UI.createWindow({
title:'table',
});
var table = Ti.UI.createTableView({});
win.add(table);
var oldRow = {};
function swipe(a,b,c){
// a = view
@pec1985
pec1985 / chess.js
Created May 19, 2011 05:03
Chess for Appcelerator
// Simple and tiny chess for Appcelerator
// Javascript chess engine (c)2011 Oscar Toledo G.
// Modified by @pecdev with the help of @pec1985 (follow us on twitter)
// For information on the code, please visit: http://nanochess.110mb.com/chess4.html
var B,i,y,u,b,I=[],G=120,x=10,z=15,M=1e4,l=[5,3,4,6,2,4,3,5,1,1,1,1,1,1,1,1,9,9,9,9
,9,9,9,9,13,11,12,14,10,12,11,13,0,99,0,306,297,495,846,-1,0,1,2,2,1,0,-1,-1,1,-10,
10,-11,-9,9,11,10,20,-9,-11,-10,-20,-21,-19,-12,-8,8,12,19,21];function X(w,c,h,e,S
,s){var t,o,L,E,d,O=e,N=-M*M,K=78-h<<x,p,g,n,m,A,q,r,C,J,a=y?-x:x;y^=8;G++;d=w||s&&
s>=h&&X(0,0,0,21,0,0)>M;do{if(o=I[p=O]){q=o&z^y;if(q<7){A=q--&2?8:4;C=o-9&z?[53,47,
@pec1985
pec1985 / fireEvent.js
Created May 29, 2011 04:25
Custom Event in browser JavaScript
// tested only in safari. Use at your own risk.
Element.prototype.fireEvent = function(a,b) {
b = b || {};
b.type = a;
b.source = this;
var evt = document.createEvent("Events");
evt.initEvent(a, true, true);
for(var i in b){
if(b){ evt[i] = b[i]; }
@pec1985
pec1985 / textfield.js
Created June 6, 2011 21:20
Previous and Next on textFields
var win = Ti.UI.createWindow({
backgroundColor:'#ccc'
});
var mainView = Ti.UI.createScrollView({
top:0,
bottom:0,
right:0,
left:0,
contentWidth:320,
@pec1985
pec1985 / CustomTableAndroid.js
Created June 7, 2011 17:12
Custom Table View
var win = Ti.UI.createWindow({
backgroundColor:'white'
});
function myRow(e){
e = e || {};
e.height = e.height || 44;
e.left = 0;
e.right = 0;
@pec1985
pec1985 / zoomImage.js
Created June 8, 2011 16:25
Zoom in zoom out on a remote image
ar win = Ti.UI.createWindow({backgroundColor:'#676767'});
//FYI - this image is big, it will take a few seconds to appear
var file = 'http://bassemk.files.wordpress.com/2009/12/landscape-fall-creek-falls-and-snake-river-idaho.jpg';
var start=function(file){
var newHeight;
var newWidth;
var fileWidth=file.blob.width;
var fileHeight=file.blob.height;