Skip to content

Instantly share code, notes, and snippets.

View rblalock's full-sized avatar
🚀

Rick Blalock rblalock

🚀
View GitHub Profile
@rblalock
rblalock / index.js
Last active December 15, 2015 09:28
/**
* Helper for opening / animating sidebar
*/
$.openSidebar = function() {
if(isOpen) {
var animateRight = Ti.UI.createAnimation({
left : 0,
curve : Ti.UI.ANIMATION_CURVE_EASE_OUT,
duration : 200
});
@rblalock
rblalock / alloy.js
Last active December 15, 2015 03:58
Dynamic styles for alloy.
/**
* Override createWidget until widget styling is possible in Alloy
*/
Alloy.createWidget = function(id, name, args) {
if ("undefined" != typeof name && null !== name && _.isObject(name) && !_.isString(name)) {
args = name;
name = DEFAULT_WIDGET;
}
var widget = new (require("alloy/widgets/" + id + "/controllers/" + (name || DEFAULT_WIDGET)))(args);
@rblalock
rblalock / swipe.js
Last active December 14, 2015 00:59
// Custom swipe detection for table rows (since technically the "swipe"
// event doesn't apply to individual rows but rather the table. This way we
// don't have to assign a swipe event for each row. One event to manage
// them all is more performant.
var TOUCH_X = 0;
$.list.addEventListener("touchstart", function(e) {
TOUCH_X = e.x;
});
$.list.addEventListener("touchend", function(e) {
if(e.x > (TOUCH_X + 44)) {
@rblalock
rblalock / handleItemSwipe.js
Last active November 18, 2017 19:16
TableViewRow swipe sample
/**
* Handle Item Swipe
* @param {Object} _event
*/
$.handleItemSwipe = function(_event) {
var row = _event.source;
var id = row.id;
var controls = Alloy.createController("rowControls");
row.add(controls.wrapper);
@rblalock
rblalock / alloy.js
Last active December 13, 2015 21:48
Alloy override for analytics
Alloy.createWidget = function(id, name, args) {
Ti.Analytics.featureEvent("widget." + id, args);
return new (require("alloy/widgets/" + id + "/controllers/" + (name || "widget")))(args);
};
Alloy.createController = function(name, args) {
Ti.Analytics.featureEvent("controller." + name, args);
return new (require("alloy/controllers/" + name))(args);
};
function MyModule() {}
module.exports = function(_params) {
// Could even do things in here for pre-init
return new MyModule(_params);
}
// Implementation:
var module = require("mymodule")();
function MyObject() {
var self = this;
self.someProperty = "test";
self.table = Ti.UI.createTableView();
self.someMethod = function() {};
self.table.addEventListner("click", self.someMethod);
// etc.
}
function NavButton() {
var self = this;
self.button = Ti.UI.createButton();
self.select = function() {};
self.unselect = function() {};
//etc.
}
module.exports = NavButton;
@rblalock
rblalock / examples.js
Created October 4, 2012 16:06
sample patterns
/**
* 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.
@rblalock
rblalock / controller.js
Created August 18, 2012 19:40
Alloy template controller
var Alloy = require('alloy'),
Backbone = Alloy.Backbone,
_ = Alloy._,
A$ = Alloy.A;
function Controller() {
require('alloy/controllers/' + <%= parentController %>).apply(this, Array.prototype.slice.call(arguments));
var $ = this;
var exports = {};