Skip to content

Instantly share code, notes, and snippets.

View falkolab's full-sized avatar
🏠
Working from home

Andrey Tkachenko falkolab

🏠
Working from home
  • Russian Federation
View GitHub Profile
@falkolab
falkolab / callLog.js
Created November 27, 2015 08:49
list view databinding helper
exports.populateCallLog = function(listview, items) {
var helper = require('listViewHelper');
return helper.populate(listview, items, false /*no merge*/, function sectionGenerator(lv, items) {
var moment = require("alloy/moment");
var headerViewCtrl = Alloy.createController('modules/call/log/pickerSectionHeaderView');
var dateTitle,
item = items[0],
utcTime = new Date(),
@falkolab
falkolab / actionBarMenuItem.js
Created November 5, 2015 21:23
Icon font MenuItem in ActionBar menu for Titanium SDK
var args = arguments[0] || {};
if(__parentSymbol) {
// recreate menu item
$.getTopLevelViews().length = 0;
__parentSymbol.removeItem(9999);
$.__views.menuItem = __parentSymbol.add(
_.extend(_.pick(args, Alloy.Android.menuItemCreateArgs), {
actionView: $.actionView
})
@falkolab
falkolab / SVGProduct.js
Created October 30, 2015 11:47
How to use SVG as autogenerated raster image
// app/lib/SVGProduct.js
function getImageFileFromSVG(svgOpts, name) {
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory,
Ti.Utils.md5HexDigest(JSON.stringify(svgOpts)));
if (!file.exists()) {
var SVG = require('com.geraudbourdin.svgview');
if (!file.write(SVG.createView(svgOpts).toImage())) {
Ti.API.error("Can't save to file. Product:", name);
return null;
@falkolab
falkolab / index.js
Created October 29, 2015 11:45
How to use SVG as View backgroundImage
$.getView().backgroundImage = getImageFileFromSVG({
image : "/images/hearts.svg",
width : 400,
height : 400,
top : 0,
left : 0
});
function getImageFileFromSVG(svgOpts) {
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory,
require('uiModules')
@falkolab
falkolab / momentLang.js
Last active February 11, 2016 10:11
Set Moment locale to the Titanium SDK Ti.Locale.currentLocale
var moment = require('alloy/moment');
// First add languages that support your application
var languages = ['ru', 'nl', 'fr', 'fr-ca'];
// Full language list: https://github.com/appcelerator/alloy/tree/master/Alloy/builtins/moment/lang
// You must explicit way to require language files in order to compiler saw their.
require('alloy/moment/lang/ru');
require('alloy/moment/lang/nl');
require('alloy/moment/lang/fr');
@falkolab
falkolab / fixmenu.js
Last active February 14, 2016 19:50
Fix for not displayed ActionBar menu in Titanium SDK
// Not rendered menu fix
// Author: Andrey Tkachenko, falkolab
// Source: https://gist.github.com/falkolab/29ab007f4981f1d747f2
exports.fix = function(win) {
if (win.activity) {
win.addEventListener('open', function fixMenu(evt) {
evt.source.removeEventListener(evt.type, fixMenu);
var activity = evt.source.activity;
if (activity.onCreateOptionsMenu) {
activity.onCreateOptionsMenu = _.partial(function(func, e) {
@falkolab
falkolab / alloy.js
Last active October 15, 2015 09:54
Android VERSION_CODES for Titanium SDK
Alloy.Globals.Android = Alloy.Globals.Android || {};
_.extend(Alloy.Globals.Android.VERSION_CODES, {
CUR_DEVELOPMENT: 10000,
BASE: 1,
BASE_1_1: 2,
CUPCAKE: 3,
DONUT: 4,
ECLAIR: 5,
ECLAIR_0_1: 6,
ECLAIR_MR1: 7,
var args = arguments[0] || {};var url = "https://api.github.com/search/repositories?q=pushed:>2015-09-01&order=desc";
var page = 1,
loading = false;
function init() {
$.activityIndicator.show();
load(function(items) {
$.list.setItems(transform(items));
$.activityIndicator.hide();
@falkolab
falkolab / index.js
Last active September 22, 2015 07:53
Memory leak test case for Titanium SDK
function doClick(e) {
Alloy.createController("test").getView().open();
}
$.index.open();