Skip to content

Instantly share code, notes, and snippets.

@Arood
Created August 29, 2014 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arood/e418a5548c72f82538a9 to your computer and use it in GitHub Desktop.
Save Arood/e418a5548c72f82538a9 to your computer and use it in GitHub Desktop.
Takes screenshots of a UI control in Titanium and all its parents
var Loopy = function(control, list) {
if (!control || control.apiName.substr(0,5) !== "Ti.UI") {
var html = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "layers.html");
var markup = '<html><head></head><body>';
var toWrap = '';
list.forEach(function(item) {
toWrap = '<div style="position: absolute; background: url('+item.index+'.png) top left; background-size: '+item.width+' '+item.height+'; height: '+item.height+'; width: '+item.width+'; top: '+item.top+'; right: '+item.right+'; left: '+item.left+'; bottom: '+item.bottom+';">'+toWrap+'</div>';
});
markup += toWrap+'</body></html>';
html.write(markup);
return;
}
list = list || [];
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, list.length + ".png");
var blob = control.toImage();
var screenshot = control.toImage(function() {
list.push({
index: list.length,
top: control.top ? parseInt(control.top,10) : "auto",
left: control.left ? parseInt(control.left,10) : "auto",
right: control.right ? parseInt(control.right,10) : "auto",
bottom: control.bottom ? parseInt(control.bottom,10) : "auto",
width: blob.width,
height: blob.height
});
file.write(screenshot);
control.hide();
Loopy(control.getParent(), list);
}, true);
};
Loopy(boxes[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment