Skip to content

Instantly share code, notes, and snippets.

@alvinsj
Created March 22, 2014 03:59
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 alvinsj/9700872 to your computer and use it in GitHub Desktop.
Save alvinsj/9700872 to your computer and use it in GitHub Desktop.
doi concept
(function(w){
// doi.viewController(config)
// config.viewDelegate
var homeController = doi.ViewController(function(){
// doi.view.TableView(config)
// config.tableViewDelegate
// config.tableViewDatasource
var tableView = doi.view.TableView({
delegate: this;
});
return {
viewWillAppear: function(){
this.tableView = tableView;
this.view.addSubView(tableView);
},
viewDidLoad: function(){
/* load data from remote*/
},
delegation: [doi.delegate.TableViewDataSource, doi.delegate.TableViewDataDelegate],
tableViewDataSource: function (tableView, tableViewDataSource){
tableViewDataSource.cellForRowAtIndexPath = function(indePath){
var cell = doi.view.TableViewCell();
cell.textLabel.text = "";
cell.detailTextLabel.text = "";
cell.accessoryView = doi.view.Button(doi.view.Image("assets/images/refresh.png"));
};
return tableViewDataSource;
},
tableViewDelegate: function(tableView, tableViewDelegate){
tableViewDelegate.didSelectRowAtIndexPath = function(indexPath){
w.location = news[indexPAth.row].url;
};
tableViewDelegate.accessoryButtonTappedForRowWithIndexPath = function(indexPath){
this.pushViewController(detailController, true);
};
return tableViewDelegate;
}
}
});
homeController.news = [];
homeController.reloadNews = function(){
request
.get('/')
.success(function(){
homeController.news = [];
homeController.tableView.reloadData();
})
};
var navigationController = doi.NavigationController(function(){
var topBar = doi.view.NavigationBar;
topBar.titleLabel.text = "HackerWeb";
topBar.leftItem = doi.view.BarButton("About", {
actionTap: function(){
homeController.presentModalViewController(aboutController, true);
}
});
topBar.rightItem = doi.view.BarButton( doi.view.Image("assets/images/refresh.png"), {
actionTap: function(){
/* reload */
homeController.reloadNews();
}
});
return {
mainController: homeControler,
navigationBar: topBar
}
});
var ios = doi.layout.ios(w, navigationController);
doi.init({
layout: { iphone: ios }
});
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment