Permalink
Browse files

improve adding event listner

  • Loading branch information...
naoya committed Oct 29, 2011
1 parent 7cdf7de commit dc805ea10d1f42145fa6bfceefddb822f84bda55
Showing with 90 additions and 76 deletions.
  1. +3 −0 Resources/app.coffee
  2. +3 −0 Resources/app.js
  3. +3 −1 Resources/ui.coffee
  4. +1 −1 Resources/ui.js
  5. +36 −28 server/app.js
  6. +44 −46 server/public/javascripts/frontend.js
View
@@ -42,6 +42,9 @@ tabGroup.open()
# alert "incoming push notification!"
# Ti.API.debug e
+table.addEventListener 'click', (e) ->
+ e.rowData.clickEvent()
+
## events
socket.connect win
View
@@ -25,6 +25,9 @@ tab = Ti.UI.createTab({
});
tabGroup.addTab(tab);
tabGroup.open();
+table.addEventListener('click', function(e) {
+ return e.rowData.clickEvent();
+});
socket.connect(win);
socket.on("hello", function(e) {
return alert("hello!");
View
@@ -6,6 +6,8 @@ $$.ui =
layout: 'absolute'
hasChild: params.hasChild
+ row.clickEvent = params.click
+
container = Ti.UI.createView
top: 10
left: 10
@@ -66,6 +68,6 @@ $$.ui =
row.add container
# row.add date
- row.addEventListener 'click', params.click
+ # row.addEventListener 'click', params.click
return row
View
@@ -9,6 +9,7 @@ $$.ui = {
layout: 'absolute',
hasChild: params.hasChild
});
+ row.clickEvent = params.click;
container = Ti.UI.createView({
top: 10,
left: 10,
@@ -70,7 +71,6 @@ $$.ui = {
container.add(titleContainer);
container.add(message);
row.add(container);
- row.addEventListener('click', params.click);
return row;
}
};
View
@@ -1,38 +1,46 @@
-
-/**
- * Module dependencies.
- */
-
-var express = require('express');
-
-var app = module.exports = express.createServer();
-
-// Configuration
-
-app.configure(function(){
- app.set('views', __dirname + '/views');
- app.set('view engine', 'ejs');
+var app, express, io;
+express = require("express");
+app = module.exports = express.createServer();
+app.configure(function() {
+ app.set("views", __dirname + "/views");
+ app.set("view engine", "ejs");
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
- app.use(express.static(__dirname + '/public'));
+ return app.use(express.static(__dirname + "/public"));
});
-
-app.configure('development', function(){
- app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+app.configure("development", function() {
+ return app.use(express.errorHandler({
+ dumpExceptions: true,
+ showStack: true
+ }));
});
-
-app.configure('production', function(){
- app.use(express.errorHandler());
+app.configure("production", function() {
+ return app.use(express.errorHandler());
});
-
-// Routes
-
-app.get('/', function(req, res){
- res.render('index', {
- title: 'Express'
+app.get("/", function(req, res) {
+ return res.render("index", {
+ title: "Express"
});
});
-
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+io = require('socket.io').listen(app);
+io.sockets.on('connection', function(socket) {
+ socket.on('fireEvent:hello', function() {
+ return socket.broadcast.emit('hello');
+ });
+ socket.on('fireEvent:openUrl', function(data) {
+ console.log(data);
+ return socket.broadcast.emit('openUrl', data);
+ });
+ socket.on('fireEvent:openMap', function(data) {
+ return socket.broadcast.emit('openMap', data);
+ });
+ socket.on('fireEvent:phoneCall', function(data) {
+ return socket.broadcast.emit('phoneCall', data);
+ });
+ return socket.on('fireEvent:pbcopy', function(data) {
+ return socket.broadcast.emit('pbcopy', data);
+ });
+});
@@ -1,47 +1,45 @@
-(function() {
- $(document).bind('ready', function() {
- var socket;
- socket = io.connect('http://localhost:3000');
- $("#hello").click(function() {
- return socket.emit('fireEvent:hello');
- });
- $("#openUrl").click(function() {
- var url;
- url = $("#urlForm").val();
- if (url && url.match(/^http:\/\//)) {
- return socket.emit('fireEvent:openUrl', {
- url: url
- });
- }
- });
- $("#phoneCall").click(function() {
- var tel;
- tel = $("#tel").val();
- if (tel) {
- return socket.emit('fireEvent:phoneCall', {
- tel: tel
- });
- }
- });
- $("#openMap").click(function() {
- var lat, lng;
- lat = $("#latitude").val();
- lng = $("#longitude").val();
- if (lat && lng) {
- return socket.emit('fireEvent:openMap', {
- latitude: lat,
- longitude: lng
- });
- }
- });
- return $("#pbcopy").click(function() {
- var text;
- text = $("#pbcopyForm").val();
- if (text) {
- return socket.emit('fireEvent:pbcopy', {
- text: text
- });
- }
- });
+$(document).bind('ready', function() {
+ var socket;
+ socket = io.connect('http://localhost:3000');
+ $("#hello").click(function() {
+ return socket.emit('fireEvent:hello');
});
-}).call(this);
+ $("#openUrl").click(function() {
+ var url;
+ url = $("#urlForm").val();
+ if (url && url.match(/^http:\/\//)) {
+ return socket.emit('fireEvent:openUrl', {
+ url: url
+ });
+ }
+ });
+ $("#phoneCall").click(function() {
+ var tel;
+ tel = $("#tel").val();
+ if (tel) {
+ return socket.emit('fireEvent:phoneCall', {
+ tel: tel
+ });
+ }
+ });
+ $("#openMap").click(function() {
+ var lat, lng;
+ lat = $("#latitude").val();
+ lng = $("#longitude").val();
+ if (lat && lng) {
+ return socket.emit('fireEvent:openMap', {
+ latitude: lat,
+ longitude: lng
+ });
+ }
+ });
+ return $("#pbcopy").click(function() {
+ var text;
+ text = $("#pbcopyForm").val();
+ if (text) {
+ return socket.emit('fireEvent:pbcopy', {
+ text: text
+ });
+ }
+ });
+});

0 comments on commit dc805ea

Please sign in to comment.