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
require('uiModules')
@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,
@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 / 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 / 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 / alloy.js
Last active February 7, 2016 02:58
Network state monitor for Titanium SDK
require('networkMonitor').init();
@falkolab
falkolab / demo.js
Created December 5, 2015 12:30
underscore string mixin
//******** underscore.string ***********
var _ = require("alloy/underscore")._;
// Import Underscore.string to separate object,
// because there are conflict functions (include, reverse, contains)
_.str = require('underscore.string');
// Mix in non-conflict functions to Underscore namespace if you want
_.mixin(_.str.exports());
@falkolab
falkolab / resizeToContainer.js
Created January 28, 2016 14:57
Titanium SDK helper to resize
function resizePhoto(blob, size) {
var measurement = require('alloy/measurement'), w, h;
if (blob.width / blob.height >= size.width / size.height) {
w = measurement.dpToPX(size.width);
h = blob.height * measurement.dpToPX(size.width) / blob.width;
} else {
w = blob.width * measurement.dpToPX(size.height) / blob.height;
h = measurement.dpToPX(size.height);
@falkolab
falkolab / fix_timob20357.js
Last active March 14, 2016 13:51
Fix for Titanium SDK bug TC-5848 (Button 9-patch)
/*
Created by: Andrey Tkachenko falko.lab@gmail.com
Source: https://gist.github.com/falkolab/c56585874223216e85d3
This is fix code for https://jira.appcelerator.org/browse/TIMOB-20357
!!! You must use only $.addListener for fixed button NOT button.addEventListener
`win` argument can be omited if controller root is Window already.
example:
@falkolab
falkolab / bbcode2html.js
Created February 6, 2016 18:46
Android: HTML tags and localized strings for Titanium SDK.
/* Escapes a string for use with regular expressions */
function escapeString(input) {
return input.replace(/([\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,
function(c){return "\\" + c;});
}
/* replaces all */
function replaceAll(search, input, replacement, ignore) {
return input.replace(
new RegExp(escapeString(search), "g"+(ignore?"i":"")),