Skip to content

Instantly share code, notes, and snippets.

@nuno
nuno / alloy.js
Created September 9, 2013 15:58 — forked from FokkeZB/alloy.js
// For iOS7 only, set the window's top to 20 so they start under the status bar.
Alloy.Globals.windowTop = (OS_IOS && parseInt(Ti.Platform.version[0], 10) >= 7) ? 20 : 0;
// Optionally set the backgroundColor or backgroundImage to show behind the statusbar.
// Please note that the backgroundImage will cover the full screen, but only top 20px is visible.
// Ti.UI.backgroundColor = '#555';
// Ti.UI.backgroundImage = 'statusBar_bg.png';
@nuno
nuno / alloy.js
Last active December 23, 2015 01:39 — forked from FokkeZB/alloy.js
UIStatusBarStyleLightContent
// For iOS7 only, set the window's top to 20 so they start under the status bar.
Alloy.Globals.windowTop = (OS_IOS && parseInt(Ti.Platform.version[0], 10) >= 7) ? 20 : 0;
@nuno
nuno / app.js
Created September 15, 2013 17:05 — forked from skypanther/app.js
var Utils = {
/* modified version of https://gist.github.com/1243697
* adds detection of file extension rather than hard-coding .jpg as in the original
*/
_getExtension: function(fn) {
// from http://stackoverflow.com/a/680982/292947
var re = /(?:\.([^.]+))?$/;
var tmpext = re.exec(fn)[1];
return (tmpext) ? tmpext : '';
},
@nuno
nuno / app.tss
Created September 16, 2013 19:50 — forked from FokkeZB/app.tss
The iOS7 bordered button (like found in AppStore) for iOS6
".btn": {
borderSize: 1,
borderColor: '#1881f9',
borderRadius: 3,
color: '#1881f9',
height: 26,
style: Ti.UI.iPhone.SystemButtonStyle.PLAIN,
font: {
fontSize: 15,
fontFamily: 'HelveticaNeue'
@nuno
nuno / app.tss
Created September 16, 2013 19:53 — forked from tonylukasavage/app.tss
TSS reset for Alloy/Titanium
'Label[platform=android]': {
color: '#000' // all platforms except Android default to black
}
'Window': {
backgroundColor: '#fff' // white background instead of default transparent
}
'Window[platform=android]': {
modal: false // make android windows all heavyweight
@nuno
nuno / examples.js
Created September 19, 2013 01:56 — forked from rborn/examples.js
/**
* Javascript example patterns
*/
/**
* Singleton Object
* Should be used for global, static objects. You should not place memory
* intensive items in here unless they are meant to be used throughout the application
* at anytime. If the item is meant to be reused or instantiated multiple times
* a singleton should not be used.
// I am pretty sure there is a sexier approach, but this works nicely
var isPhone5 = Ti.Platform.displayCaps.platformHeight == 568;
parse568hImages = function(imagePath) {
if (isPhone5){
// Do this because the filename could contain dots
imagePath = imagePath.replace(".png","-568h@2x.png");
imagePath = imagePath.replace(".jpg","-568h@2x.jpg");
imagePath = imagePath.replace(".jpeg","-568h@2x.jpeg");
}
@nuno
nuno / gist:6660509
Last active December 23, 2015 16:09 — forked from benbahrenburg/gist:1103324
Saving XHR Results to a file
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
{
var results = this.responseText;
Ti.API.info('Results from xhr Lookup = ' + results );
var supportDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'my_support');
if(!supportDir.exists()){
supportDir.createDirectory();
}
@nuno
nuno / foo.js
Created September 22, 2013 16:28 — forked from skypanther/foo.js
Within functions, arguments gives access to any parameters passed to the function. But it's a funky object, not a true array. I'm sure the following behavior is documented, but it caught me off-guard. So I thought I'd share.
var myFunction = function() {
if(typeof arguments[0] == 'function') {
arguments[0](); // throws error: [object Object] is not a function
// but this works
var cb = arguments[0];
cb();
}
};
myFunction(function() {
@nuno
nuno / app.js
Created September 22, 2013 16:29 — forked from skypanther/app.js
Cache Remote Images
var Utils = {
/* modified version of https://gist.github.com/1243697
* adds detection of file extension rather than hard-coding .jpg as in the original
*/
_getExtension: function(fn) {
// from http://stackoverflow.com/a/680982/292947
var re = /(?:\.([^.]+))?$/;
var tmpext = re.exec(fn)[1];
return (tmpext) ? tmpext : '';
},