Created
June 18, 2012 14:36
-
-
Save tonylukasavage/2948677 to your computer and use it in GitHub Desktop.
before and after: alloy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Alloy = require("alloy"), _ = Alloy._, A$ = Alloy.A, M$ = Alloy.M, BC$ = Alloy.Backbone.Collection, TFL$ = Ti.UI.FILL, TSZ$ = Ti.UI.SIZE, $ = {}; | |
$.master = A$(Ti.UI.createWindow({ | |
backgroundColor: "white", | |
layout: "vertical", | |
id: "master" | |
}), "Window"), $.table = A$(Ti.UI.createTableView({ | |
id: "table" | |
}), "TableView", $.master), $.master.add($.table), function(exports) { | |
$.table.setData([ Ti.UI.createTableViewRow({ | |
title: "Alcatraz", | |
image: "smallpic1.jpg" | |
}), Ti.UI.createTableViewRow({ | |
title: "American Flag", | |
image: "smallpic2.jpg" | |
}), Ti.UI.createTableViewRow({ | |
title: "Penitentiary Sign", | |
image: "smallpic3.jpg" | |
}) ]), $.table.addEventListener("click", function(e) { | |
exports.fireEvent("rowClick", { | |
image: e.row.image | |
}); | |
}); | |
}($.master) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Alloy for Titanium by Appcelerator | |
* This is generated code, DO NOT MODIFY - changes will be lost! | |
* Copyright (c) 2012 by Appcelerator, Inc. | |
*/ | |
var Alloy = require("alloy"), _ = Alloy._, A$ = Alloy.A, M$ = Alloy.M, BC$ = Alloy.Backbone.Collection, TFL$ = Ti.UI.FILL, TSZ$ = Ti.UI.SIZE, $ = {}; | |
$.master = require('alloy/components/master').create(); | |
// from index.js | |
// I use the convenience function on the component object to open the master view, but I could also have done: | |
// $.master.self.open(); | |
$.master.open(); | |
$.master.doAlert(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Alloy = require("alloy"), _ = Alloy._, A$ = Alloy.A, M$ = Alloy.M, BC$ = Alloy.Backbone.Collection;; | |
var Lifecycle = {}; | |
Lifecycle.beforeCreate = function($) { | |
Ti.API.info('beforeCreate'); | |
}; | |
Lifecycle.afterCreate = function($) { | |
Ti.API.info('afterCreate'); | |
// prints 'white' | |
Ti.API.info($.self.backgroundColor); | |
}; | |
exports.create = function(args) { | |
var $ = {}; | |
args = args || {}; | |
Lifecycle.beforeCreate($); | |
// generated from markup | |
$.master = A$(Ti.UI.createWindow({ | |
backgroundColor: "white", | |
layout: "vertical", | |
id: "master" | |
}), "Window"); | |
$.table = A$(Ti.UI.createTableView({ | |
id: "table" | |
}), "TableView", $.master); | |
$.master.add($.table); | |
// generated from controller | |
$.table.setData([ Ti.UI.createTableViewRow({ | |
title: "Alcatraz", | |
image: "smallpic1.jpg" | |
}), Ti.UI.createTableViewRow({ | |
title: "American Flag", | |
image: "smallpic2.jpg" | |
}), Ti.UI.createTableViewRow({ | |
title: "Penitentiary Sign", | |
image: "smallpic3.jpg" | |
}) ]); | |
$.table.addEventListener("click", function(e) { | |
$.master.fireEvent("rowClick", { | |
image: e.row.image | |
}); | |
}); | |
// custom function exposed from component object | |
$.doAlert = function() { | |
alert('i did an alert'); | |
}; | |
// custom function to make opening the top level window simpler | |
$.open = function(o) { | |
$.self.open(o); | |
} | |
// extend component object with IDed UI elements | |
Lifecycle.afterCreate($); | |
return $; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment