├── .gitignore
├── README.md
├── chapter-02
├── helloworld-timeout.js
├── helloworld.js
├── readFile-infiniteloop.js
├── readFile.js
├── server1.js
├── server2.js
├── server3.js
└── test.txt
├── chapter-03
├── 3.1
│ ├── argv.js
│ ├── exit.js
│ ├── global.js
│ ├── nextTick.js
│ ├── readFile-infiniteloop.js
│ ├── sigint.js
│ ├── stdin.js
│ ├── test.txt
│ └── uncaughtException.js
├── 3.11
│ ├── exec.js
│ └── spawn.js
├── 3.12
│ ├── cluster-server.js
│ ├── cluster.js
│ ├── message.js
│ └── plain-server.js
├── 3.13
│ ├── tcp-chat01.js
│ ├── tcp-chat02.js
│ └── tcp-chat03.js
├── 3.6
│ ├── example.txt
│ ├── rename.js
│ ├── stat.js
│ ├── test.txt
│ ├── watchFile.js
│ └── writeFile.js
└── 3.8
│ ├── createConnection.js
│ └── createServer.js
├── chapter-05
├── app1.js
├── app2.js
├── app3.js
├── app4.js
└── package.json
├── chapter-06
├── joinin-mongodb
│ ├── app.js
│ ├── package.json
│ ├── public
│ │ └── stylesheets
│ │ │ └── style.css
│ ├── repository.js
│ ├── routes
│ │ └── index.js
│ └── views
│ │ ├── index.jade
│ │ ├── join-fail.jade
│ │ ├── join-form.jade
│ │ ├── join-result.jade
│ │ └── layout.jade
├── joinin-mysql
│ ├── app.js
│ ├── package.json
│ ├── public
│ │ └── stylesheets
│ │ │ └── style.css
│ ├── repository.js
│ ├── routes
│ │ └── index.js
│ └── views
│ │ ├── index.jade
│ │ ├── join-fail.jade
│ │ ├── join-form.jade
│ │ ├── join-result.jade
│ │ └── layout.jade
├── joinin
│ ├── app.js
│ ├── package.json
│ ├── public
│ │ └── stylesheets
│ │ │ └── style.css
│ ├── routes
│ │ └── index.js
│ └── views
│ │ ├── index.jade
│ │ ├── join-form.jade
│ │ ├── join-result.jade
│ │ └── layout.jade
└── simpleweb
│ ├── app.js
│ ├── package.json
│ ├── public
│ └── stylesheets
│ │ └── style.css
│ ├── routes
│ └── index.js
│ └── views
│ ├── index.jade
│ └── layout.jade
├── chapter-07
├── connect
│ ├── index.html
│ ├── package.json
│ └── server.js
├── custom-event
│ ├── index.html
│ ├── package.json
│ └── server.js
├── message
│ ├── index.html
│ ├── package.json
│ └── server.js
├── namespace
│ ├── index.html
│ ├── package.json
│ └── server.js
├── room
│ ├── index.html
│ ├── package.json
│ └── server.js
└── volatile
│ ├── index.html
│ ├── package.json
│ └── server.js
├── chapter-08
└── simple-chat
│ ├── app.js
│ ├── chat.js
│ ├── package.json
│ ├── public
│ ├── javascripts
│ │ └── jquery-1.7.0.min.js
│ └── stylesheets
│ │ └── style.css
│ ├── rooms.js
│ └── views
│ ├── enter.jade
│ ├── index.jade
│ ├── layout.jade
│ ├── makeRoom.jade
│ └── room.jade
├── chapter-09
├── a.js
├── b.js
├── c.js
├── console.js
├── package.json
└── test.js
├── chapter-10
├── simple-expresso
│ ├── output.json
│ ├── src-cov
│ │ └── sum.js
│ ├── src
│ │ └── sum.js
│ └── test
│ │ └── sum.test.js
├── simple-vows
│ ├── package.json
│ └── spec
│ │ ├── callback.js
│ │ └── example.js
└── webserver-expresso
│ ├── app.js
│ ├── package.json
│ ├── public
│ └── stylesheets
│ │ └── style.css
│ ├── test
│ └── server.test.js
│ └── views
│ ├── index.jade
│ └── layout.jade
└── chapter-11
├── cloudfoundry
├── simple-webserver
│ ├── app.js
│ ├── package.json
│ ├── public
│ │ └── stylesheets
│ │ │ └── style.css
│ └── views
│ │ ├── index.jade
│ │ └── layout.jade
└── simpleweb-mongodb
│ ├── app.js
│ ├── package.json
│ ├── public
│ └── stylesheets
│ │ └── style.css
│ ├── repository.js
│ ├── routes.js
│ └── views
│ ├── index.jade
│ ├── join-form.jade
│ ├── join-result.jade
│ └── layout.jade
└── heroku
└── simple-webserver
├── Procfile
├── app.js
├── package.json
├── public
└── stylesheets
│ └── style.css
└── views
├── index.jade
└── layout.jade
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | *.swp
4 | .monitor
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Node.js 프로그래밍 : 클라우드 컴퓨팅 시대의 고성능 자바스크립트 플랫폼
2 | ==========================
3 |
4 | * [Node.js 프로그래밍](http://blog.outsider.ne.kr/738)의 예제 소스입니다.
5 | - [에이콘 출판사 소개](http://www.acornpub.co.kr/book/nodejs)
6 | - [Yes 24](http://www.yes24.com/24/goods/6271069)
7 | - [알라딘](http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8960772763)
8 | - [강컴](http://kangcom.com/sub/view.asp?topid=5&sku=201202070001)
9 | - [인터파크](http://book.interpark.com/product/BookDisplay.do?_method=detail&sc.shopNo=0000400000&sc.prdNo=209853133&bookblockname=b_sch&booklinkname=bprd_title)
10 | - [교보문고](http://www.kyobobook.co.kr/product/detailViewKor.laf?mallGb=KOR&ejkGb=KOR&barcode=9788960772762)
11 | * 이 예제는 Node.js v0.6.6 기반으로 작성되었습니다.
12 | * 잘못된 부분을 발견하시면 이슈에 등록해 주세요.
13 |
14 | * node 0.8.x 및 express 3.x와 관련한 오류가 발생하시는 분은 [features/node-0.8 브랜치](https://github.com/outsideris/node.js-programming/tree/features/node-0.8)를 참고해 주세요.
15 | * [features/node-0.10 브랜치](https://github.com/outsideris/node.js-programming/tree/features/node-0.10) : node v0.10.25 기준 및 의존성 모듈의 최신버전에 맞게 업데이트한 버전(Jade관련 오류가 수정되었습니다.) - [수정된 내용](https://github.com/outsideris/node.js-programming/commit/522b894abba1dabfe667bfe0df0deb42fe7d3a80)
16 |
17 |
--------------------------------------------------------------------------------
/chapter-02/helloworld-timeout.js:
--------------------------------------------------------------------------------
1 | // 리스트 2.2
2 | setTimeout(function() {
3 | console.log('World');
4 | }, 2000);
5 |
6 | console.log('Hello');
7 |
--------------------------------------------------------------------------------
/chapter-02/helloworld.js:
--------------------------------------------------------------------------------
1 | // 리스트 2.1
2 | console.log('Hello World');
3 |
--------------------------------------------------------------------------------
/chapter-02/readFile-infiniteloop.js:
--------------------------------------------------------------------------------
1 | // 리스트 2.4
2 | var fs = require('fs');
3 |
4 | fs.readFile('./test.txt', encoding='utf-8', function(err, data) {
5 | if (err) {
6 | throw err;
7 | }
8 | console.log(data);
9 | });
10 |
11 | console.log('파일의 내용 : ');
12 |
13 | while(true) {}
14 |
--------------------------------------------------------------------------------
/chapter-02/readFile.js:
--------------------------------------------------------------------------------
1 | // 리스트 2.3
2 | var fs = require('fs');
3 |
4 | fs.readFile('./test.txt', encoding='utf-8', function(err, data) {
5 | if (err) {
6 | throw err;
7 | }
8 | console.log(data);
9 | });
10 |
11 | console.log('파일의 내용 : ');
12 |
--------------------------------------------------------------------------------
/chapter-02/server1.js:
--------------------------------------------------------------------------------
1 | //리스트 2.5
2 | var server = require('http');
3 |
4 | server.createServer(function(req, res) {
5 |
6 | }).listen(3000, 'localhost');
7 |
--------------------------------------------------------------------------------
/chapter-02/server2.js:
--------------------------------------------------------------------------------
1 | // 리스트 2.6
2 | var server = require('http');
3 |
4 | server.createServer(function(req, res) {
5 | res.writeHead(200, {'Content-Type':'text/plain'});
6 | res.end('Hello World\n');
7 | }).listen(3000, 'localhost');
8 |
9 | console.log('서버가 http://localhost:3000으로 시작되었습니다.');
10 |
--------------------------------------------------------------------------------
/chapter-02/server3.js:
--------------------------------------------------------------------------------
1 | // 리스트 2.7
2 | var server = require('http');
3 |
4 | server.createServer(function(req, res) {
5 | res.writeHead(200, {'Content-Type':'text/plain'});
6 | setTimeout(function() {
7 | res.end('World\n');
8 | },2000);
9 | res.write('Hello\n');
10 | }).listen(3000, 'localhost');
11 |
12 | console.log('서버가 http://localhost:3000으로 시작되었습니다.');
13 |
--------------------------------------------------------------------------------
/chapter-02/test.txt:
--------------------------------------------------------------------------------
1 | Hello World
2 |
--------------------------------------------------------------------------------
/chapter-03/3.1/argv.js:
--------------------------------------------------------------------------------
1 | process.argv.forEach(function(val, index, array) {
2 | console.log(index + ': ' + val);
3 | });
4 |
--------------------------------------------------------------------------------
/chapter-03/3.1/exit.js:
--------------------------------------------------------------------------------
1 | process.on('exit', function() {
2 | console.log('Good Bye');
3 | });
4 |
--------------------------------------------------------------------------------
/chapter-03/3.1/global.js:
--------------------------------------------------------------------------------
1 | console.log(__filename);
2 | console.log(__dirname);
3 |
--------------------------------------------------------------------------------
/chapter-03/3.1/nextTick.js:
--------------------------------------------------------------------------------
1 | process.nextTick(function() {
2 | console.log('nextTick으로 호출되었습니다.');
3 | });
4 | console.log('이 메시지가 먼저 출력됩니다.');
5 |
--------------------------------------------------------------------------------
/chapter-03/3.1/readFile-infiniteloop.js:
--------------------------------------------------------------------------------
1 | // 리스트 2.4
2 | var fs = require('fs');
3 |
4 | fs.readFile('./test.txt', encoding='utf-8', function(err, data) {
5 | if (err) {
6 | throw err;
7 | }
8 | console.log(data);
9 | });
10 |
11 | console.log('파일의 내용 : ');
12 |
13 | while(true) {
14 | process.nextTick(function() {
15 | console.log('t');
16 | });
17 | }
18 |
--------------------------------------------------------------------------------
/chapter-03/3.1/sigint.js:
--------------------------------------------------------------------------------
1 | process.stdin.resume();
2 |
3 | process.on('SIGINT', function() {
4 | console.log('Got SIGINT. Press Control-D to exit.');
5 | });
6 |
--------------------------------------------------------------------------------
/chapter-03/3.1/stdin.js:
--------------------------------------------------------------------------------
1 | process.stdin.resume();
2 | process.stdin.setEncoding('utf8');
3 |
4 | process.stdin.on('data', function(chunk) {
5 | process.stdout.write('data: ' + chunk);
6 | });
7 |
8 | process.stdin.on('end', function() {
9 | process.stdout.write('end');
10 | });
11 |
--------------------------------------------------------------------------------
/chapter-03/3.1/test.txt:
--------------------------------------------------------------------------------
1 | Hello World
2 |
--------------------------------------------------------------------------------
/chapter-03/3.1/uncaughtException.js:
--------------------------------------------------------------------------------
1 | process.on('uncaughtException', function(err) {
2 | console.log('예외: ' + err);
3 | });
4 |
5 | setTimeout(function() {
6 | console.log('이 코드는 실행됩니다.');
7 | }, 500);
8 |
9 | // 존재하지 않는 함수 실행
10 | nonExistentFunction();
11 |
12 | console.log('이 코드는 실행되지 않습니다.');
13 |
--------------------------------------------------------------------------------
/chapter-03/3.11/exec.js:
--------------------------------------------------------------------------------
1 | var exec = require('child_process').exec;
2 |
3 | exec('cat *.js bad_file | wc -l',
4 | function (error, stdout, stderr) {
5 | console.log('stdout: ' + stdout);
6 | console.log('stderr: ' + stderr);
7 | if (error !== null) {
8 | console.log('exec error: ' + error);
9 | }
10 | });
11 |
--------------------------------------------------------------------------------
/chapter-03/3.11/spawn.js:
--------------------------------------------------------------------------------
1 | var spawn = require('child_process').spawn
2 | , ls = spawn('ls', ['-l', './']);
3 |
4 | ls.stdout.on('data', function (data) {
5 | console.log('stdout: ' + data);
6 | });
7 |
8 | ls.stderr.on('data', function (data) {
9 | console.log('stderr: ' + data);
10 | });
11 |
12 | ls.on('exit', function (code) {
13 | console.log('child process exited with code ' + code);
14 | });
15 |
--------------------------------------------------------------------------------
/chapter-03/3.12/cluster-server.js:
--------------------------------------------------------------------------------
1 | var cluster = require('cluster')
2 | , http = require('http')
3 | , numCPUs = require('os').cpus().length;
4 |
5 | if (cluster.isMaster) {
6 | for (var i = 0; i < numCPUs; i++) {
7 | var worker = cluster.fork();
8 | }
9 | } else {
10 | http.Server(function(req, res) {
11 | res.writeHead(200);
12 | for (var i = 0; i < 1000000000; i++) {
13 | }
14 |
15 | res.end("hello world\n");
16 | }).listen(8000);
17 | }
18 |
--------------------------------------------------------------------------------
/chapter-03/3.12/cluster.js:
--------------------------------------------------------------------------------
1 | var cluster = require('cluster');
2 | var http = require('http');
3 | var numCPUs = require('os').cpus().length;
4 |
5 | if (cluster.isMaster) {
6 | // 워커 생성
7 | for (var i = 0; i < numCPUs; i++) {
8 | cluster.fork();
9 | }
10 |
11 | cluster.on('death', function(worker) {
12 | console.log('worker ' + worker.pid + ' died');
13 | });
14 | } else {
15 | // 워커프로세스는 HTTP 서버를 생성한다.
16 | http.Server(function(req, res) {
17 | res.writeHead(200);
18 | res.end("hello world\n");
19 | }).listen(8000);
20 | }
21 |
--------------------------------------------------------------------------------
/chapter-03/3.12/message.js:
--------------------------------------------------------------------------------
1 | var cluster = require('cluster');
2 | var http = require('http');
3 | var numReqs = 0;
4 |
5 | if (cluster.isMaster) {
6 | // 워커 생성
7 | for (var i = 0; i < 2; i++) {
8 | var worker = cluster.fork();
9 |
10 | worker.on('message', function(msg) {
11 | if (msg.cmd && msg.cmd == 'notifyRequest') {
12 | numReqs++;
13 | }
14 | });
15 | }
16 |
17 | setInterval(function() {
18 | console.log("numReqs =", numReqs);
19 | }, 1000);
20 | } else {
21 | // 워커프로세스는 HTTP 서버를 생성한다.
22 | http.Server(function(req, res) {
23 | res.writeHead(200);
24 | res.end("hello world\n");
25 | // 마스터 프로세스로 메세지를 보낸다.
26 | process.send({ cmd: 'notifyRequest' });
27 | }).listen(8000);
28 | }
29 |
--------------------------------------------------------------------------------
/chapter-03/3.12/plain-server.js:
--------------------------------------------------------------------------------
1 | var http = require('http');
2 |
3 | http.Server(function(req, res) {
4 | res.writeHead(200);
5 | for (var i = 0; i < 1000000000; i++) {
6 | }
7 |
8 | res.end("hello world\n");
9 | }).listen(8000);
10 |
--------------------------------------------------------------------------------
/chapter-03/3.13/tcp-chat01.js:
--------------------------------------------------------------------------------
1 | // 리스트 3.17
2 | var net = require('net')
3 | , sockets = [];
4 |
5 | var server = net.createServer(function(socket) {
6 | sockets.push(socket);
7 | });
8 |
9 | server.listen(8000);
10 | console.log('TCP 채팅 서버가 시작되었습니다.');
11 |
--------------------------------------------------------------------------------
/chapter-03/3.13/tcp-chat02.js:
--------------------------------------------------------------------------------
1 | // 리스트 3.18
2 | var net = require('net')
3 | , sockets = [];
4 |
5 | var server = net.createServer(function(socket) {
6 | sockets.push(socket);
7 |
8 | socket.on('data', function(data) {
9 | for (var i = 0; i < sockets.length; i++) {
10 | if (sockets[i] !== socket) {
11 | sockets[i].write(socket.remoteAddress + '님의 말: ' + data);
12 | }
13 | }
14 | });
15 | });
16 |
17 | server.listen(8000);
18 | console.log('TCP 채팅 서버가 시작되었습니다.');
19 |
--------------------------------------------------------------------------------
/chapter-03/3.13/tcp-chat03.js:
--------------------------------------------------------------------------------
1 | // 리스트 3.19
2 | var net = require('net')
3 | , sockets = [];
4 |
5 | var server = net.createServer(function(socket) {
6 | sockets.push(socket);
7 |
8 | socket.on('data', function(data) {
9 | for (var i = 0; i < sockets.length; i++) {
10 | if (sockets[i] !== socket) {
11 | sockets[i].write(socket.remoteAddress + '님의 말: ' + data);
12 | }
13 | }
14 | });
15 |
16 | socket.on('end', function() {
17 | var i = sockets.indexOf(socket);
18 | sockets.splice(i, 1);
19 | });
20 | });
21 |
22 | server.listen(8000);
23 | console.log('TCP 채팅 서버가 시작되었습니다.');
24 |
--------------------------------------------------------------------------------
/chapter-03/3.6/example.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/outsideris/node.js-programming/b75d2fe960411f7e06a69c9ce94227b1b7bfb83d/chapter-03/3.6/example.txt
--------------------------------------------------------------------------------
/chapter-03/3.6/rename.js:
--------------------------------------------------------------------------------
1 | // 리스트 3.7
2 | var fs = require('fs');
3 |
4 | fs.rename('./test.txt', './demo.txt', function(err) {
5 | if (err) throw err;
6 | console.log('수정되었습니다.');
7 | });
8 |
--------------------------------------------------------------------------------
/chapter-03/3.6/stat.js:
--------------------------------------------------------------------------------
1 | // 리스트 3.8
2 | var fs = require('fs');
3 |
4 | fs.stat('./stat.js', function(err, stats) {
5 | if (err) throw err;
6 | console.log(stats);
7 | console.log('isFile: ' + stats.isFile());
8 | });
9 |
--------------------------------------------------------------------------------
/chapter-03/3.6/test.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/outsideris/node.js-programming/b75d2fe960411f7e06a69c9ce94227b1b7bfb83d/chapter-03/3.6/test.txt
--------------------------------------------------------------------------------
/chapter-03/3.6/watchFile.js:
--------------------------------------------------------------------------------
1 | // 리스트 3.10
2 | var fs = require('fs');
3 |
4 | fs.watchFile('./example.txt'
5 | , {persistent: true, interval: 0}
6 | , function(curr, prev) {
7 | console.log('현재 파일의 수정시간: ' + curr.mtime);
8 | console.log('이전 파일의 수정시간: ' + prev.mtime);
9 | }
10 | );
11 |
--------------------------------------------------------------------------------
/chapter-03/3.6/writeFile.js:
--------------------------------------------------------------------------------
1 | // 리스트 3.9
2 | var fs = require('fs');
3 |
4 | fs.writeFile('./example.txt', 'Hello World', encoding='utf-8', function(err) {
5 | if (err) throw err;
6 | console.log('파일을 작성하였습니다.');
7 | });
8 |
--------------------------------------------------------------------------------
/chapter-03/3.8/createConnection.js:
--------------------------------------------------------------------------------
1 | var net = require('net');
2 |
3 | var client = net.connect(8124, function() {
4 | console.log('클라이어트가 연결되었습니다.');
5 | client.write('world!\r\n');
6 | });
7 |
8 | client.on('data', function(data) {
9 | console.log(data.toString());
10 | client.end();
11 | });
12 | client.on('end', function() {
13 | console.log('클라이언트 연결이 종료되었습니다.');
14 | });
15 |
--------------------------------------------------------------------------------
/chapter-03/3.8/createServer.js:
--------------------------------------------------------------------------------
1 | var net = require('net');
2 |
3 | var server = net.createServer(function(socket) {
4 | console.log('서버에 연결되었습니다.');
5 | socket.on('end', function() {
6 | console.log('연결이 종료되었습니다.');
7 | });
8 |
9 | socket.write('Hello\r\n');
10 | });
11 |
12 | server.listen(8124, '127.0.0.1', function() {
13 | console.log('서버가 %d포트로 연결되었습니다.', server.address().port);
14 | });
15 |
--------------------------------------------------------------------------------
/chapter-05/app1.js:
--------------------------------------------------------------------------------
1 | var rest = require('restler');
2 |
3 | var Tweet = {
4 | sinceId: '1'
5 | , getTweets: function(search, callback) {
6 | search = encodeURIComponent(search);
7 |
8 | rest.get(
9 | 'http://search.twitter.com/search.json?q=' + search +
10 | '&result_type=recent' +
11 | '&rpp=100' +
12 | '&since_id=' + Tweet.sinceId
13 | ).on('complete', function(data) {
14 | console.log(data);
15 | });
16 | }
17 | }
18 |
19 | Tweet.getTweets('#nodejs');
20 |
--------------------------------------------------------------------------------
/chapter-05/app2.js:
--------------------------------------------------------------------------------
1 | var rest = require('restler')
2 | , fs = require('fs');
3 |
4 | var Tweet = {
5 | sinceId: '1'
6 | , getTweets: function(search, callback) {
7 | search = encodeURIComponent(search);
8 |
9 | rest.get(
10 | 'http://search.twitter.com/search.json?q=' + search +
11 | '&result_type=recent' +
12 | '&rpp=100' +
13 | '&since_id=' + Tweet.sinceId
14 | ).on('complete', function(data) {
15 | var text = "";
16 | data.results.forEach(function(elem, index, array) {
17 | text += elem.from_user + ': ' +
18 | elem.text + ' at' + elem.created_at + '\n';
19 | });
20 |
21 | fs.open('./tweets.txt', 'a', 0666, function(err, fd) {
22 | if(err) { throw err; }
23 | var buffer = new Buffer(text);
24 | fs.write(fd, buffer, 0, buffer.length, null
25 | , function(err) {
26 | fs.close(fd, function() {
27 | });
28 | });
29 | });
30 | });
31 | }
32 | }
33 |
34 | Tweet.getTweets('#nodejs');
35 |
36 |
--------------------------------------------------------------------------------
/chapter-05/app3.js:
--------------------------------------------------------------------------------
1 | var rest = require('restler')
2 | , fs = require('fs');
3 |
4 | var Tweet = {
5 | sinceId: '1'
6 | , isOpened: false
7 | , getTweets: function(search, callback) {
8 | search = encodeURIComponent(search);
9 |
10 | fs.readFile('./maxid.txt', 'utf8', function(err, maxId) {
11 | if (err) { Tweet.sinceId = 1; }
12 | else { Tweet.sinceId = maxId; }
13 |
14 | rest.get(
15 | 'http://search.twitter.com/search.json?q=' + search +
16 | '&result_type=recent' +
17 | '&rpp=100' +
18 | '&since_id=' + Tweet.sinceId
19 | ).on('complete', function(data) {
20 | var text = "";
21 | data.results.forEach(function(elem, index, array) {
22 | text += elem.from_user + ': ' +
23 | elem.text + ' at' + elem.created_at + '\n';
24 | });
25 |
26 | if (!Tweet.isOpened) {
27 | fs.open('./tweets.txt', 'a', 0666, function(err, fd) {
28 | if(err) { throw err; }
29 |
30 | Tweet.isOpened = true;
31 | var buffer = new Buffer(text);
32 | fs.write(fd, buffer, 0, buffer.length, null
33 | , function(err) {
34 | fs.close(fd, function() {
35 | Tweet.isOpened = false;
36 | fs.writeFile('./maxid.txt'
37 | , data.max_id.toString()
38 | , function(err) {}
39 | );
40 | });
41 | });
42 | });
43 | }
44 | });
45 | });
46 | }
47 | }
48 |
49 | Tweet.getTweets('#nodejs');
50 |
51 |
--------------------------------------------------------------------------------
/chapter-05/app4.js:
--------------------------------------------------------------------------------
1 | var rest = require('restler')
2 | , fs = require('fs')
3 | , schedule = require('node-schedule');
4 |
5 | var Tweet = {
6 | sinceId: '1'
7 | , isOpened: false
8 | , getTweets: function(search, callback) {
9 | search = encodeURIComponent(search);
10 |
11 | fs.readFile('./maxid.txt', 'utf8', function(err, maxId) {
12 | if (err) { Tweet.sinceId = 1; }
13 | else { Tweet.sinceId = maxId; }
14 |
15 | rest.get(
16 | 'http://search.twitter.com/search.json?q=' + search +
17 | '&result_type=recent' +
18 | '&rpp=100' +
19 | '&since_id=' + Tweet.sinceId
20 | ).on('complete', function(data) {
21 | var text = "";
22 | data.results.forEach(function(elem, index, array) {
23 | text += elem.from_user + ': ' +
24 | elem.text + ' at' + elem.created_at + '\n';
25 | });
26 |
27 | if (!Tweet.isOpened) {
28 | fs.open('./tweets.txt', 'a', 0666, function(err, fd) {
29 | if(err) { throw err; }
30 |
31 | Tweet.isOpened = true;
32 | var buffer = new Buffer(text);
33 | fs.write(fd, buffer, 0, buffer.length, null
34 | , function(err) {
35 | fs.close(fd, function() {
36 | Tweet.isOpened = false;
37 | fs.writeFile('./maxid.txt'
38 | , data.max_id.toString()
39 | , function(err) {}
40 | );
41 | });
42 | });
43 | });
44 | }
45 | });
46 | });
47 | }
48 | }
49 |
50 | var rule = new schedule.RecurrenceRule();
51 | rule.hour = new schedule.Range(0, 23);
52 | rule.minute = [0, 10, 20, 30, 40, 50];
53 |
54 | var j = schedule.scheduleJob(rule, function(){
55 | Tweet.getTweets('#nodejs');
56 | console.log('Backup is completed at ' + new Date());
57 | });
58 |
59 |
--------------------------------------------------------------------------------
/chapter-05/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "author": "",
3 | "name": "tweet",
4 | "version": "0.0.0",
5 | "repository": {
6 | "url": ""
7 | },
8 | "engines": {
9 | "node": "~v0.4.10"
10 | },
11 | "dependencies": {
12 | "node-schedule": "~0.1.4"
13 | , "restler": "~0.2.3"
14 | },
15 | "devDependencies": {}
16 | }
17 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/app.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Module dependencies.
4 | */
5 |
6 | var express = require('express')
7 | , routes = require('./routes')
8 |
9 | var app = module.exports = express.createServer();
10 |
11 | // Configuration
12 |
13 | app.configure(function(){
14 | app.set('views', __dirname + '/views');
15 | app.set('view engine', 'jade');
16 | app.use(express.bodyParser());
17 | app.use(express.methodOverride());
18 | app.use(app.router);
19 | app.use(express.static(__dirname + '/public'));
20 | });
21 |
22 | app.configure('development', function(){
23 | app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
24 | });
25 |
26 | app.configure('production', function(){
27 | app.use(express.errorHandler());
28 | });
29 |
30 | // Routes
31 |
32 | app.get('/', routes.index);
33 | app.get('/join', routes.form);
34 | app.post('/join', routes.join);
35 |
36 | app.listen(3000);
37 | console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
38 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "express": "~2.5.0",
7 | "jade": ">= 0.0.1",
8 | "mongolian": "~0.1.14"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/repository.js:
--------------------------------------------------------------------------------
1 | var Mongolian = require('mongolian')
2 | , server = new Mongolian
3 | , db = server.db('node_test')
4 | , users = db.collection('members');
5 |
6 |
7 | var mysqlUtil = module.exports = {
8 | insertUser: function(user, res) {
9 | users.insert({
10 | name: user.name
11 | , email: user.email
12 | }, function(err, result) {
13 | if (err) {
14 | throw err;
15 | }
16 | res.render('join-result', {
17 | username: result.name
18 | , useremail: result.email
19 | , title: 'Express'
20 | });
21 | });
22 | }
23 | , hasNameAndEmail: function(user, res) {
24 | users.findOne({'$or': [{'name':user.name}, {'email':user.email}]}, function(err, result) {
25 | if (err) {
26 | throw err;
27 | }
28 | if (result) {
29 | res.render('join-fail', {
30 | title: 'Express'
31 | });
32 | } else {
33 | mysqlUtil.insertUser(user, res);
34 | }
35 | });
36 | }
37 | };
38 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/routes/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * GET home page.
3 | */
4 |
5 | var repo = require('../repository');
6 |
7 | exports.index = function(req, res){
8 | res.render('index', { title: 'Express' })
9 | };
10 |
11 | exports.form = function(req, res) {
12 | res.render('join-form', { title: 'Express' });
13 | };
14 |
15 | exports.join = function(req, res) {
16 | repo.hasNameAndEmail(req.body, res);
17 | };
18 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/views/index.jade:
--------------------------------------------------------------------------------
1 | h1= title
2 | p Welcome to #{title}
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/views/join-fail.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입 오류
2 | p 이미 가입된 이름 또는 이메일입니다.
3 | a(href='/join') 회원 가입페이지로 돌아가기
4 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/views/join-form.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입
2 | p 회원에 가입해 주세요.
3 | form(id='joinForm', method='POST', action='/join')
4 | label(for='name') 이름 :
5 | input(type='text', name='name', id='name')
6 | label(for='email') 이메일 :
7 | input(type='text', name='email', id='email')
8 | input(type='submit', value='전송')
9 |
10 | script(type='text/javascript')
11 | $(document).ready(function() {
12 | $('#joinForm').submit(function(e) {
13 | if ($.trim($('#name').val()) === '' || $.trim($('#email').val()) === '') {
14 | alert('이름과 이메일을 입력해 주세요.');
15 | return false;
16 | }
17 | });
18 | });
19 |
20 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/views/join-result.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입완료
2 | p 가입한 회원 정보는 아래와 같습니다.
3 | div
4 | ul
5 | li 이름 : #{username}
6 | li 이메일 : #{useremail}
7 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mongodb/views/layout.jade:
--------------------------------------------------------------------------------
1 | !!!
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/stylesheets/style.css')
6 | script(type='text/javascript', src='http://code.jquery.com/jquery-1.7.0.min.js')
7 | body!= body
8 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/app.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Module dependencies.
4 | */
5 |
6 | var express = require('express')
7 | , routes = require('./routes')
8 |
9 | var app = module.exports = express.createServer();
10 |
11 | // Configuration
12 |
13 | app.configure(function(){
14 | app.set('views', __dirname + '/views');
15 | app.set('view engine', 'jade');
16 | app.use(express.bodyParser());
17 | app.use(express.methodOverride());
18 | app.use(app.router);
19 | app.use(express.static(__dirname + '/public'));
20 | });
21 |
22 | app.configure('development', function(){
23 | app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
24 | });
25 |
26 | app.configure('production', function(){
27 | app.use(express.errorHandler());
28 | });
29 |
30 | // Routes
31 |
32 | app.get('/', routes.index);
33 | app.get('/join', routes.form);
34 | app.post('/join', routes.join);
35 |
36 | app.listen(3000);
37 | console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
38 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "express": "~2.5.0",
7 | "jade": ">= 0.0.1",
8 | "mysql": "~0.9.5"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/repository.js:
--------------------------------------------------------------------------------
1 | var mysql = require('mysql')
2 | , DATABASE = 'node_test'
3 | , TABLE = 'members'
4 | , client = mysql.createClient({
5 | user: 'node'
6 | , password: 'pass'
7 | });
8 |
9 | client.query('USE ' + DATABASE);
10 |
11 | var mysqlUtil = module.exports = {
12 | insertUser: function(user, res) {
13 | client.query(
14 | 'INSERT INTO ' + TABLE + ' SET name = ?, email = ?'
15 | , [user.name, user.email]
16 | , function(err) {
17 | client.query(
18 | 'SELECT * FROM ' + TABLE + ' WHERE name = ?'
19 | , [user.name]
20 | , function(err, results, fields) {
21 | if (err) {
22 | throw err;
23 | }
24 | res.render('join-result', {
25 | username: results[0].name
26 | , useremail: results[0].email
27 | , title: 'Express'
28 | });
29 | });
30 | }
31 | );
32 | }
33 | , hasNameAndEmail: function(user, res) {
34 | client.query(
35 | 'SELECT * FROM ' + TABLE + ' WHERE name = ? OR email = ?'
36 | , [user.name, user.email]
37 | , function(err, results, fields) {
38 | if (err) {
39 | throw err;
40 | }
41 | if (results.length > 0) {
42 | res.render('join-fail', {
43 | title: 'Express'
44 | });
45 | } else {
46 | mysqlUtil.insertUser(user, res);
47 | }
48 | });
49 | }
50 | };
51 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/routes/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * GET home page.
3 | */
4 |
5 | var repo = require('../repository');
6 |
7 | exports.index = function(req, res){
8 | res.render('index', { title: 'Express' })
9 | };
10 |
11 | exports.form = function(req, res) {
12 | res.render('join-form', { title: 'Express' });
13 | };
14 |
15 | exports.join = function(req, res) {
16 | repo.hasNameAndEmail(req.body, res);
17 | };
18 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/views/index.jade:
--------------------------------------------------------------------------------
1 | h1= title
2 | p Welcome to #{title}
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/views/join-fail.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입 오류
2 | p 이미 가입된 이름 또는 이메일입니다.
3 | a(href='/join') 회원 가입페이지로 돌아가기
4 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/views/join-form.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입
2 | p 회원에 가입해 주세요.
3 | form(id='joinForm', method='POST', action='/join')
4 | label(for='name') 이름 :
5 | input(type='text', name='name', id='name')
6 | label(for='email') 이메일 :
7 | input(type='text', name='email', id='email')
8 | input(type='submit', value='전송')
9 |
10 | script(type='text/javascript')
11 | $(document).ready(function() {
12 | $('#joinForm').submit(function(e) {
13 | if ($.trim($('#name').val()) === '' || $.trim($('#email').val()) === '') {
14 | alert('이름과 이메일을 입력해 주세요.');
15 | return false;
16 | }
17 | });
18 | });
19 |
20 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/views/join-result.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입완료
2 | p 가입한 회원 정보는 아래와 같습니다.
3 | div
4 | ul
5 | li 이름 : #{username}
6 | li 이메일 : #{useremail}
7 |
--------------------------------------------------------------------------------
/chapter-06/joinin-mysql/views/layout.jade:
--------------------------------------------------------------------------------
1 | !!!
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/stylesheets/style.css')
6 | script(type='text/javascript', src='http://code.jquery.com/jquery-1.7.0.min.js')
7 | body!= body
8 |
--------------------------------------------------------------------------------
/chapter-06/joinin/app.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Module dependencies.
4 | */
5 |
6 | var express = require('express')
7 | , routes = require('./routes')
8 |
9 | var app = module.exports = express.createServer();
10 |
11 | // Configuration
12 |
13 | app.configure(function(){
14 | app.set('views', __dirname + '/views');
15 | app.set('view engine', 'jade');
16 | app.use(express.bodyParser());
17 | app.use(express.methodOverride());
18 | app.use(app.router);
19 | app.use(express.static(__dirname + '/public'));
20 | });
21 |
22 | app.configure('development', function(){
23 | app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
24 | });
25 |
26 | app.configure('production', function(){
27 | app.use(express.errorHandler());
28 | });
29 |
30 | // Routes
31 |
32 | app.get('/', routes.index);
33 | app.get('/join', routes.form);
34 | app.post('/join', routes.join);
35 |
36 | app.listen(3000);
37 | console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
38 |
--------------------------------------------------------------------------------
/chapter-06/joinin/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name"
3 | , "version": "0.0.1"
4 | , "private": true
5 | , "dependencies": {
6 | "express": "~2.5.0"
7 | , "jade": ">= 0.0.1"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/chapter-06/joinin/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
--------------------------------------------------------------------------------
/chapter-06/joinin/routes/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * GET home page.
3 | */
4 |
5 | exports.index = function(req, res){
6 | res.render('index', { title: 'Express' })
7 | };
8 |
9 | exports.form = function(req, res) {
10 | res.render('join-form', { title: 'Express' });
11 | };
12 |
13 | exports.join = function(req, res) {
14 | res.render('join-result', {
15 | username: req.body.name
16 | , useremail: req.body.email
17 | , title: 'Express'
18 | });
19 | };
20 |
--------------------------------------------------------------------------------
/chapter-06/joinin/views/index.jade:
--------------------------------------------------------------------------------
1 | h1= title
2 | p Welcome to #{title}
--------------------------------------------------------------------------------
/chapter-06/joinin/views/join-form.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입
2 | p 회원에 가입해 주세요.
3 | form(id='joinForm', method='POST', action='/join')
4 | label(for='name') 이름 :
5 | input(type='text', name='name', id='name')
6 | label(for='email') 이메일 :
7 | input(type='text', name='email', id='email')
8 | input(type='submit', value='전송')
9 |
10 | script(type='text/javascript')
11 | $(document).ready(function() {
12 | $('#joinForm').submit(function(e) {
13 | if ($.trim($('#name').val()) === '' || $.trim($('#email').val()) === '') {
14 | alert('이름과 이메일을 입력해 주세요.');
15 | return false;
16 | }
17 | });
18 | });
19 |
20 |
--------------------------------------------------------------------------------
/chapter-06/joinin/views/join-result.jade:
--------------------------------------------------------------------------------
1 | h3 회원가입완료
2 | p 가입한 회원 정보는 아래와 같습니다.
3 | div
4 | ul
5 | li 이름 : #{username}
6 | li 이메일 : #{useremail}
7 |
--------------------------------------------------------------------------------
/chapter-06/joinin/views/layout.jade:
--------------------------------------------------------------------------------
1 | !!!
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/stylesheets/style.css')
6 | script(type='text/javascript', src='http://code.jquery.com/jquery-1.7.0.min.js')
7 | body!= body
8 |
--------------------------------------------------------------------------------
/chapter-06/simpleweb/app.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Module dependencies.
4 | */
5 |
6 | var express = require('express')
7 | , routes = require('./routes')
8 |
9 | var app = module.exports = express.createServer();
10 |
11 | // Configuration
12 |
13 | app.configure(function(){
14 | app.set('views', __dirname + '/views');
15 | app.set('view engine', 'jade');
16 | app.use(express.bodyParser());
17 | app.use(express.methodOverride());
18 | app.use(app.router);
19 | app.use(express.static(__dirname + '/public'));
20 | });
21 |
22 | app.configure('development', function(){
23 | app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
24 | });
25 |
26 | app.configure('production', function(){
27 | app.use(express.errorHandler());
28 | });
29 |
30 | // Routes
31 |
32 | app.get('/', routes.index);
33 |
34 | app.listen(3000);
35 | console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
36 |
--------------------------------------------------------------------------------
/chapter-06/simpleweb/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name"
3 | , "version": "0.0.1"
4 | , "private": true
5 | , "dependencies": {
6 | "express": "~2.5.0"
7 | , "jade": ">= 0.0.1"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/chapter-06/simpleweb/public/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
--------------------------------------------------------------------------------
/chapter-06/simpleweb/routes/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * GET home page.
3 | */
4 |
5 | exports.index = function(req, res){
6 | res.render('index', { title: 'Express' })
7 | };
--------------------------------------------------------------------------------
/chapter-06/simpleweb/views/index.jade:
--------------------------------------------------------------------------------
1 | h1= title
2 | p Welcome to #{title}
--------------------------------------------------------------------------------
/chapter-06/simpleweb/views/layout.jade:
--------------------------------------------------------------------------------
1 | !!!
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/stylesheets/style.css')
6 | body!= body
--------------------------------------------------------------------------------
/chapter-07/connect/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Socket.IO 예제
5 |
6 |
7 |
8 |
9 |
10 |
11 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/chapter-07/connect/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "socket.io": "0.8.7"
7 | },
8 | "devDependencies": {},
9 | "engines": {
10 | "node": "*"
11 | },
12 | "author": "",
13 | "repository": {
14 | "url": ""
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter-07/connect/server.js:
--------------------------------------------------------------------------------
1 | var http = require('http')
2 | , fs = require('fs')
3 | , path = require('path')
4 | , io = require('socket.io');
5 |
6 | var server = http.createServer(function(req, res) {
7 | var filename = path.join(process.cwd(), req.url);
8 |
9 | path.exists(filename, function(exists) {
10 | if(!exists) {
11 | res.writeHead(404, {"Content-Type": "text/plain"});
12 | res.write("404 Not Found\n");
13 | res.end();
14 | return;
15 | }
16 |
17 | fs.readFile('./index.html', encoding='utf-8', function(err, data) {
18 | if (err) {
19 | res.writeHead(500, {"Content-Type": "text/plain"});
20 | res.write(err + "\n");
21 | res.end();
22 | return;
23 | }
24 | res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
25 | res.end(data);
26 | });
27 | });
28 | });
29 |
30 | server.listen(3000);
31 |
32 | io = io.listen(server);
33 |
34 | io.configure(function(){
35 | io.enable('browser client etag');
36 | io.set('log level', 3);
37 | io.set('transports', [
38 | 'websocket'
39 | , 'flashsocket'
40 | , 'htmlfile'
41 | , 'xhr-polling'
42 | , 'jsonp-polling'
43 | ]);
44 |
45 | });
46 |
47 | io.sockets.on('connection', function(socket) {
48 | console.log('connected');
49 | socket.on('disconnect', function() {
50 | console.log('Good-bye');
51 | });
52 |
53 | });
54 |
55 | console.log("서버가 시작되었습니다. http://localhost:3000");
56 |
--------------------------------------------------------------------------------
/chapter-07/custom-event/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Socket.IO 예제
5 |
6 |
7 |
8 |
9 |
10 |
11 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/chapter-07/custom-event/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "socket.io": "0.8.7"
7 | },
8 | "devDependencies": {},
9 | "engines": {
10 | "node": "*"
11 | },
12 | "author": "",
13 | "repository": {
14 | "url": ""
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter-07/custom-event/server.js:
--------------------------------------------------------------------------------
1 | var http = require('http')
2 | , fs = require('fs')
3 | , path = require('path')
4 | , io = require('socket.io');
5 |
6 | var server = http.createServer(function(req, res) {
7 | var filename = path.join(process.cwd(), req.url);
8 |
9 | path.exists(filename, function(exists) {
10 | if(!exists) {
11 | res.writeHead(404, {"Content-Type": "text/plain"});
12 | res.write("404 Not Found\n");
13 | res.end();
14 | return;
15 | }
16 |
17 | fs.readFile('./index.html', encoding='utf-8', function(err, data) {
18 | if (err) {
19 | res.writeHead(500, {"Content-Type": "text/plain"});
20 | res.write(err + "\n");
21 | res.end();
22 | return;
23 | }
24 | res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
25 | res.end(data);
26 | });
27 | });
28 | });
29 |
30 | server.listen(3000);
31 |
32 | io = io.listen(server);
33 |
34 | io.configure(function(){
35 | io.enable('browser client etag');
36 | io.set('log level', 3);
37 | io.set('transports', [
38 | 'websocket'
39 | , 'flashsocket'
40 | , 'htmlfile'
41 | , 'xhr-polling'
42 | , 'jsonp-polling'
43 | ]);
44 |
45 | });
46 |
47 | io.sockets.on('connection', function(socket) {
48 | console.log('connected');
49 | socket.on('disconnect', function() {
50 | console.log('Good-bye');
51 | });
52 |
53 | socket.on('message', function(msg) {
54 | console.log(msg);
55 | socket.send('서버쪽 메시지 테스트');
56 | });
57 |
58 | socket.send('send로 보내는 메시지', function() {
59 | console.log('메시지가 전달되었습니다.');
60 | });
61 |
62 | socket.on('from client', function(data) {
63 | console.log(data.text);
64 | socket.emit('from server', {text:'서버에서 보낸 emit'}, function(res) {
65 | console.log('from server 이벤트:' + res);
66 | });
67 | });
68 | });
69 |
70 | console.log("서버가 시작되었습니다. http://localhost:3000");
71 |
--------------------------------------------------------------------------------
/chapter-07/message/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Socket.IO 예제
5 |
6 |
7 |
8 |
9 |
10 |
11 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/chapter-07/message/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "socket.io": "0.8.7"
7 | },
8 | "devDependencies": {},
9 | "engines": {
10 | "node": "*"
11 | },
12 | "author": "",
13 | "repository": {
14 | "url": ""
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter-07/message/server.js:
--------------------------------------------------------------------------------
1 | var http = require('http')
2 | , fs = require('fs')
3 | , path = require('path')
4 | , io = require('socket.io');
5 |
6 | var server = http.createServer(function(req, res) {
7 | var filename = path.join(process.cwd(), req.url);
8 |
9 | path.exists(filename, function(exists) {
10 | if(!exists) {
11 | res.writeHead(404, {"Content-Type": "text/plain"});
12 | res.write("404 Not Found\n");
13 | res.end();
14 | return;
15 | }
16 |
17 | fs.readFile('./index.html', encoding='utf-8', function(err, data) {
18 | if (err) {
19 | res.writeHead(500, {"Content-Type": "text/plain"});
20 | res.write(err + "\n");
21 | res.end();
22 | return;
23 | }
24 | res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
25 | res.end(data);
26 | });
27 | });
28 | });
29 |
30 | server.listen(3000);
31 |
32 | io = io.listen(server);
33 |
34 | io.configure(function(){
35 | io.enable('browser client etag');
36 | io.set('log level', 3);
37 | io.set('transports', [
38 | 'websocket'
39 | , 'flashsocket'
40 | , 'htmlfile'
41 | , 'xhr-polling'
42 | , 'jsonp-polling'
43 | ]);
44 |
45 | });
46 |
47 | io.sockets.on('connection', function(socket) {
48 | console.log('connected');
49 | socket.on('disconnect', function() {
50 | console.log('Good-bye');
51 | });
52 |
53 | socket.on('message', function(msg) {
54 | console.log(msg);
55 | socket.send('서버쪽 메시지 테스트');
56 | });
57 |
58 | socket.send('send로 보내는 메시지', function() {
59 | console.log('메시지가 전달되었습니다.');
60 | });
61 |
62 | });
63 |
64 | console.log("서버가 시작되었습니다. http://localhost:3000");
65 |
--------------------------------------------------------------------------------
/chapter-07/namespace/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Socket.IO 예제
5 |
6 |
7 |
8 |
9 |
10 |
11 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/chapter-07/namespace/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "socket.io": "0.8.7"
7 | },
8 | "devDependencies": {},
9 | "engines": {
10 | "node": "*"
11 | },
12 | "author": "",
13 | "repository": {
14 | "url": ""
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter-07/namespace/server.js:
--------------------------------------------------------------------------------
1 | var http = require('http')
2 | , fs = require('fs')
3 | , path = require('path')
4 | , io = require('socket.io');
5 |
6 | var server = http.createServer(function(req, res) {
7 | var filename = path.join(process.cwd(), req.url);
8 |
9 | path.exists(filename, function(exists) {
10 | if(!exists) {
11 | res.writeHead(404, {"Content-Type": "text/plain"});
12 | res.write("404 Not Found\n");
13 | res.end();
14 | return;
15 | }
16 |
17 | fs.readFile('./index.html', encoding='utf-8', function(err, data) {
18 | if (err) {
19 | res.writeHead(500, {"Content-Type": "text/plain"});
20 | res.write(err + "\n");
21 | res.end();
22 | return;
23 | }
24 | res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
25 | res.end(data);
26 | });
27 | });
28 | });
29 |
30 | server.listen(3000);
31 |
32 | io = io.listen(server);
33 |
34 | io.configure(function(){
35 | io.enable('browser client etag');
36 | io.set('log level', 3);
37 | io.set('transports', [
38 | 'websocket'
39 | , 'flashsocket'
40 | , 'htmlfile'
41 | , 'xhr-polling'
42 | , 'jsonp-polling'
43 | ]);
44 |
45 | });
46 |
47 | io.sockets.on('connection', function(socket) {
48 | console.log('connected');
49 | socket.on('disconnect', function() {
50 | console.log('Good-bye');
51 | });
52 |
53 | socket.on('message', function(msg) {
54 | console.log(msg);
55 | socket.send('서버쪽 메시지 테스트');
56 | });
57 |
58 | socket.send('send로 보내는 메세지', function() {
59 | console.log('메시지가 전달되었습니다.');
60 | });
61 |
62 | socket.on('from client', function(data) {
63 | console.log(data.text);
64 | socket.emit('from server', {text:'서버에서 보낸 emit'}, function(res) {
65 | console.log('from server 이벤트:' + res);
66 | });
67 | });
68 |
69 | var timer = setInterval(function() {
70 | socket.volatile.emit('as volatile', new Date());
71 | }, 2000);
72 |
73 | setTimeout(function() {
74 | clearInterval(timer);
75 | }, 10000);
76 | });
77 |
78 | var another = io.of('/another').on('connection', function(socket) {
79 | socket.send('another네임스페이스로 보낸 send 메시지');
80 |
81 | socket.on('nickname', function(nickname) {
82 | socket.set('nickname', nickname, function() {
83 | console.log('닉네임이 저장되었습니다.');
84 | });
85 | socket.get('nickname', function(err, nickname) {
86 | socket.emit('nickname', '닉네임: ' + nickname);
87 | });
88 | });
89 | });
90 |
91 | console.log("서버가 시작되었습니다. http://localhost:3000");
92 |
--------------------------------------------------------------------------------
/chapter-07/room/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Socket.IO 예제
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/chapter-07/room/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "socket.io": "0.8.7"
7 | },
8 | "devDependencies": {},
9 | "engines": {
10 | "node": "*"
11 | },
12 | "author": "",
13 | "repository": {
14 | "url": ""
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter-07/room/server.js:
--------------------------------------------------------------------------------
1 | var http = require('http')
2 | , fs = require('fs')
3 | , path = require('path')
4 | , io = require('socket.io');
5 |
6 | var server = http.createServer(function(req, res) {
7 | var filename = path.join(process.cwd(), req.url);
8 |
9 | path.exists(filename, function(exists) {
10 | if(!exists) {
11 | res.writeHead(404, {"Content-Type": "text/plain"});
12 | res.write("404 Not Found\n");
13 | res.end();
14 | return;
15 | }
16 |
17 | fs.readFile('./index.html', encoding='utf-8', function(err, data) {
18 | if (err) {
19 | res.writeHead(500, {"Content-Type": "text/plain"});
20 | res.write(err + "\n");
21 | res.end();
22 | return;
23 | }
24 | res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
25 | res.end(data);
26 | });
27 | });
28 | });
29 |
30 | server.listen(3000);
31 |
32 | io = io.listen(server);
33 |
34 | io.configure(function(){
35 | io.enable('browser client etag');
36 | io.set('log level', 3);
37 | io.set('transports', [
38 | 'websocket'
39 | , 'flashsocket'
40 | , 'htmlfile'
41 | , 'xhr-polling'
42 | , 'jsonp-polling'
43 | ]);
44 |
45 | });
46 |
47 | io.sockets.on('connection', function(socket) {
48 | console.log('connected');
49 | socket.on('disconnect', function() {
50 | console.log('Good-bye');
51 | });
52 |
53 | socket.on('message', function(msg) {
54 | console.log(msg);
55 | socket.send('서버쪽 메시지 테스트');
56 | });
57 |
58 | socket.send('send로 보내는 메시지', function() {
59 | console.log('메시지가 전달되었습니다.');
60 | });
61 |
62 | socket.on('from client', function(data) {
63 | console.log(data.text);
64 | socket.emit('from server', {text:'서버에서 보낸 emit'}, function(res) {
65 | console.log('from server 이벤트:' + res);
66 | });
67 | });
68 |
69 | var timer = setInterval(function() {
70 | socket.volatile.emit('as volatile', new Date());
71 | }, 2000);
72 |
73 | setTimeout(function() {
74 | clearInterval(timer);
75 | }, 10000);
76 | });
77 |
78 | var another = io.of('/another').on('connection', function(socket) {
79 | socket.send('another네임스페이스로 보낸 send 메시지');
80 |
81 | socket.on('nickname', function(nickname) {
82 | socket.set('nickname', nickname, function() {
83 | console.log('닉네임이 저장되었습니다.');
84 | });
85 | socket.get('nickname', function(err, nickname) {
86 | socket.emit('nickname', '닉네임: ' + nickname);
87 | });
88 | });
89 |
90 | socket.on('joinroom', function(msg) {
91 | console.log(msg);
92 | socket.join('some room');
93 | });
94 |
95 | socket.on('leaveroom', function(msg) {
96 | console.log(msg);
97 | socket.leave('some room');
98 | });
99 |
100 | var timer = setInterval(function() {
101 | var time = new Date();
102 | socket.broadcast.to('some room').emit('in room', time);
103 | }, 2000);
104 | });
105 |
106 | console.log("서버가 시작되었습니다. http://localhost:3000");
107 |
--------------------------------------------------------------------------------
/chapter-07/volatile/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Socket.IO 예제
5 |
6 |
7 |
8 |
9 |
10 |
11 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/chapter-07/volatile/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "socket.io": "0.8.7"
7 | },
8 | "devDependencies": {},
9 | "engines": {
10 | "node": "*"
11 | },
12 | "author": "",
13 | "repository": {
14 | "url": ""
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/chapter-07/volatile/server.js:
--------------------------------------------------------------------------------
1 | var http = require('http')
2 | , fs = require('fs')
3 | , path = require('path')
4 | , io = require('socket.io');
5 |
6 | var server = http.createServer(function(req, res) {
7 | var filename = path.join(process.cwd(), req.url);
8 |
9 | path.exists(filename, function(exists) {
10 | if(!exists) {
11 | res.writeHead(404, {"Content-Type": "text/plain"});
12 | res.write("404 Not Found\n");
13 | res.end();
14 | return;
15 | }
16 |
17 | fs.readFile('./index.html', encoding='utf-8', function(err, data) {
18 | if (err) {
19 | res.writeHead(500, {"Content-Type": "text/plain"});
20 | res.write(err + "\n");
21 | res.end();
22 | return;
23 | }
24 | res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
25 | res.end(data);
26 | });
27 | });
28 | });
29 |
30 | server.listen(3000);
31 |
32 | io = io.listen(server);
33 |
34 | io.configure(function(){
35 | io.enable('browser client etag');
36 | io.set('log level', 3);
37 | io.set('transports', [
38 | 'websocket'
39 | , 'flashsocket'
40 | , 'htmlfile'
41 | , 'xhr-polling'
42 | , 'jsonp-polling'
43 | ]);
44 |
45 | });
46 |
47 | io.sockets.on('connection', function(socket) {
48 | console.log('connected');
49 | socket.on('disconnect', function() {
50 | console.log('Good-bye');
51 | });
52 |
53 | socket.on('message', function(msg) {
54 | console.log(msg);
55 | socket.send('서버쪽 메시지 테스트');
56 | });
57 |
58 | socket.send('send로 보내는 메시지', function() {
59 | console.log('메시지가 전달되었습니다.');
60 | });
61 |
62 | socket.on('from client', function(data) {
63 | console.log(data.text);
64 | socket.emit('from server', {text:'서버에서 보낸 emit'}, function(res) {
65 | console.log('from server 이벤트:' + res);
66 | });
67 | });
68 |
69 | var timer = setInterval(function() {
70 | socket.volatile.emit('as volatile', new Date());
71 | }, 2000);
72 |
73 | setTimeout(function() {
74 | clearInterval(timer);
75 | }, 10000);
76 | });
77 |
78 | console.log("서버가 시작되었습니다. http://localhost:3000");
79 |
--------------------------------------------------------------------------------
/chapter-08/simple-chat/app.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Module dependencies.
4 | */
5 |
6 | var express = require('express')
7 | , Chat = require('./chat');
8 |
9 | var app = module.exports = express.createServer();
10 |
11 | // Configuration
12 |
13 | app.configure(function(){
14 | app.set('views', __dirname + '/views');
15 | app.set('view engine', 'jade');
16 | app.use(express.bodyParser());
17 | app.use(express.cookieParser());
18 | app.use(express.session({secret: 'secret key'}));
19 | app.use(app.router);
20 | app.use(express.static(__dirname + '/public'));
21 | });
22 |
23 | app.configure('development', function(){
24 | app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
25 | });
26 |
27 | app.configure('production', function(){
28 | app.use(express.errorHandler());
29 | });
30 |
31 | // Routes
32 |
33 | app.get('/', function(req, res){
34 | res.render('index');
35 | });
36 |
37 | app.post('/enter', function(req, res) {
38 | var isSuccess = false
39 | , nickname = req.body.nickname;
40 |
41 | if (nickname && nickname.trim() !== '') {
42 | if (!Chat.hasUser(nickname)) {
43 | Chat.addUser(nickname);
44 | req.session.nickname = nickname;
45 | isSuccess = true;
46 | }
47 | }
48 |
49 | res.render('enter', {
50 | isSuccess: isSuccess
51 | , nickname: nickname
52 | , roomList: Chat.getRoomList()
53 | });
54 | });
55 |
56 | app.get('/enter', function(req, res) {
57 | if (req.session.nickname) {
58 | res.render('enter', {
59 | isSuccess: true
60 | , nickname: req.session.nickname
61 | , roomList: Chat.getRoomList()
62 | });
63 | } else {
64 | res.render('enter', {
65 | isSuccess: false
66 | , nickname: ''
67 | });
68 |
69 | }
70 | });
71 |
72 | app.post('/makeRoom', function(req, res) {
73 | var isSuccess = false
74 | , roomName = req.body.roomname;
75 |
76 | if(roomName && roomName.trim() != '') {
77 | if (!Chat.hasRoom(roomName)) {
78 | Chat.addRoom(roomName);
79 | isSuccess = true;
80 | }
81 | }
82 |
83 | res.render('makeRoom', {
84 | isSuccess: isSuccess
85 | , roomName: roomName
86 | });
87 | });
88 |
89 | app.get('/join/:id', function(req, res) {
90 | var isSuccess = false
91 | , roomName = req.params.id;
92 |
93 | if (Chat.hasRoom(roomName)) {
94 | isSuccess = true;
95 | }
96 |
97 | res.render('room', {
98 | isSuccess: isSuccess
99 | , roomName: roomName
100 | , nickName: req.session.nickname
101 | , attendants: Chat.getAttendantsList(roomName)
102 | });
103 | });
104 |
105 | app.listen(3000);
106 |
107 | // Socket.io
108 | require('./rooms')(app);
109 |
110 | console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
111 |
--------------------------------------------------------------------------------
/chapter-08/simple-chat/chat.js:
--------------------------------------------------------------------------------
1 | var Chat = module.exports = {
2 | users: []
3 | , rooms: []
4 | // 사용자 관련
5 | , hasUser: function(nickname) {
6 | var users = this.users.filter(function(element) {
7 | return (element === nickname);
8 | });
9 |
10 | if (users.length > 0) {
11 | return true;
12 | } else {
13 | return false;
14 | }
15 | }
16 | , addUser: function(nickname) {
17 | this.users.push(nickname);
18 | }
19 | // 방 관련
20 | , hasRoom: function(roomName) {
21 | var rooms = this.rooms.filter(function(element) {
22 | return (element.name === roomName);
23 | });
24 |
25 | if (rooms.length > 0) {
26 | return true;
27 | } else {
28 | return false;
29 | }
30 | }
31 | , addRoom: function(roomName) {
32 | this.rooms.push({name:roomName, attendants:[]});
33 | }
34 | , getRoomList: function() {
35 | return this.rooms.map(function(element) {
36 | return element.name;
37 | });;
38 | }
39 | , joinRoom: function(roomName, user) {
40 | var rooms = this.rooms.filter(function(element) {
41 | return (element.name === roomName);
42 | });
43 | if (!this.hasAttendant(rooms[0].attendants, user)) {
44 | rooms[0].attendants.push(user);
45 | }
46 | }
47 | , hasAttendant: function(attendants, user) {
48 | return attendants.some(function(element) {
49 | return (element === user);
50 | });
51 | }
52 | , leaveRoom: function(roomName, user) {
53 | var rooms = this.rooms.filter(function(element) {
54 | return (element.name === roomName);
55 | });
56 | rooms[0].attendants.forEach(function(element, index, arr) {
57 | if (element === user) {
58 | arr.splice(index, 1);
59 | }
60 | });
61 | }
62 | , getAttendantsList: function(roomName) {
63 | var rooms = this.rooms.filter(function(element) {
64 | return (element.name === roomName);
65 | });
66 | return rooms[0].attendants;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/chapter-08/simple-chat/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application-name",
3 | "version": "0.0.1",
4 | "private": true,
5 | "dependencies": {
6 | "express": "~2.5.0",
7 | "jade": ">= 0.0.1",
8 | "socket.io": "~0.8.7"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chapter-08/simple-chat/public/javascripts/jquery-1.7.0.min.js:
--------------------------------------------------------------------------------
1 | /*! jQuery v1.7 jquery.com | jquery.org/license */
2 | (function(a,b){function cA(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cx(a){if(!cm[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cn||(cn=c.createElement("iframe"),cn.frameBorder=cn.width=cn.height=0),b.appendChild(cn);if(!co||!cn.createElement)co=(cn.contentWindow||cn.contentDocument).document,co.write((c.compatMode==="CSS1Compat"?"":"")+""),co.close();d=co.createElement(a),co.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cn)}cm[a]=e}return cm[a]}function cw(a,b){var c={};f.each(cs.concat.apply([],cs.slice(0,b)),function(){c[this]=a});return c}function cv(){ct=b}function cu(){setTimeout(cv,0);return ct=f.now()}function cl(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ck(){try{return new a.XMLHttpRequest}catch(b){}}function ce(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){c!=="border"&&f.each(e,function(){c||(d-=parseFloat(f.css(a,"padding"+this))||0),c==="margin"?d+=parseFloat(f.css(a,c+this))||0:d-=parseFloat(f.css(a,"border"+this+"Width"))||0});return d+"px"}d=bB(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0,c&&f.each(e,function(){d+=parseFloat(f.css(a,"padding"+this))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+this+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+this))||0)});return d+"px"}function br(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bi,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bq(a){var b=(a.nodeName||"").toLowerCase();b==="input"?bp(a):b!=="script"&&typeof a.getElementsByTagName!="undefined"&&f.grep(a.getElementsByTagName("input"),bp)}function bp(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bo(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bn(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bm(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c,d,e,g=f._data(a),h=f._data(b,g),i=g.events;if(i){delete h.handle,h.events={};for(c in i)for(d=0,e=i[c].length;d=0===c})}function V(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function N(){return!0}function M(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/\d/,n=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,o=/^[\],:{}\s]*$/,p=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,q=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,r=/(?:^|:|,)(?:\s*\[)+/g,s=/(webkit)[ \/]([\w.]+)/,t=/(opera)(?:.*version)?[ \/]([\w.]+)/,u=/(msie) ([\w.]+)/,v=/(mozilla)(?:.*? rv:([\w.]+))?/,w=/-([a-z]|[0-9])/ig,x=/^-ms-/,y=function(a,b){return(b+"").toUpperCase()},z=d.userAgent,A,B,C,D=Object.prototype.toString,E=Object.prototype.hasOwnProperty,F=Array.prototype.push,G=Array.prototype.slice,H=String.prototype.trim,I=Array.prototype.indexOf,J={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=n.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7",length:0,size:function(){return this.length},toArray:function(){return G.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?F.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),B.add(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(G.apply(this,arguments),"slice",G.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:F,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;B.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!B){B=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",C,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",C),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&K()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return a!=null&&m.test(a)&&!isNaN(a)},type:function(a){return a==null?String(a):J[D.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!E.call(a,"constructor")&&!E.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||E.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(o.test(b.replace(p,"@").replace(q,"]").replace(r,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(x,"ms-").replace(w,y)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;ca ",d=a.getElementsByTagName("*"),e=a.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=a.getElementsByTagName("input")[0],k={leadingWhitespace:a.firstChild.nodeType===3,tbody:!a.getElementsByTagName("tbody").length,htmlSerialize:!!a.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,unknownElems:!!a.getElementsByTagName("nav").length,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:a.className!=="t",enctype:!!c.createElement("form").enctype,submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,k.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,k.optDisabled=!h.disabled;try{delete a.test}catch(v){k.deleteExpando=!1}!a.addEventListener&&a.attachEvent&&a.fireEvent&&(a.attachEvent("onclick",function(){k.noCloneEvent=!1}),a.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),k.radioValue=i.value==="t",i.setAttribute("checked","checked"),a.appendChild(i),l=c.createDocumentFragment(),l.appendChild(a.lastChild),k.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,a.innerHTML="",a.style.width=a.style.paddingLeft="1px",m=c.getElementsByTagName("body")[0],o=c.createElement(m?"div":"body"),p={visibility:"hidden",width:0,height:0,border:0,margin:0,background:"none"},m&&f.extend(p,{position:"absolute",left:"-999px",top:"-999px"});for(t in p)o.style[t]=p[t];o.appendChild(a),n=m||b,n.insertBefore(o,n.firstChild),k.appendChecked=i.checked,k.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,k.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="
",k.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="",q=a.getElementsByTagName("td"),u=q[0].offsetHeight===0,q[0].style.display="",q[1].style.display="none",k.reliableHiddenOffsets=u&&q[0].offsetHeight===0,a.innerHTML="",c.defaultView&&c.defaultView.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",a.appendChild(j),k.reliableMarginRight=(parseInt((c.defaultView.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(a.attachEvent)for(t in{submit:1,change:1,focusin:1})s="on"+t,u=s in a,u||(a.setAttribute(s,"return;"),u=typeof a[s]=="function"),k[t+"Bubbles"]=u;f(function(){var a,b,d,e,g,h,i=1,j="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",l="visibility:hidden;border:0;",n="style='"+j+"border:5px solid #000;padding:0;'",p=""+"";m=c.getElementsByTagName("body")[0];!m||(a=c.createElement("div"),a.style.cssText=l+"width:0;height:0;position:static;top:0;margin-top:"+i+"px",m.insertBefore(a,m.firstChild),o=c.createElement("div"),o.style.cssText=j+l,o.innerHTML=p,a.appendChild(o),b=o.firstChild,d=b.firstChild,g=b.nextSibling.firstChild.firstChild,h={doesNotAddBorder:d.offsetTop!==5,doesAddBorderForTableAndCells:g.offsetTop===5},d.style.position="fixed",d.style.top="20px",h.fixedPosition=d.offsetTop===20||d.offsetTop===15,d.style.position=d.style.top="",b.style.overflow="hidden",b.style.position="relative",h.subtractsBorderForOverflowNotVisible=d.offsetTop===-5,h.doesNotIncludeMarginInBodyOffset=m.offsetTop!==i,m.removeChild(a),o=a=null,f.extend(k,h))}),o.innerHTML="",n.removeChild(o),o=l=g=h=m=j=a=i=null;return k}(),f.boxModel=f.support.boxModel;var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[f.expando]:a[f.expando]&&f.expando,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[f.expando]=n=++f.uuid:n=f.expando),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[f.expando]:f.expando;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)?b=b:b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" "));for(e=0,g=b.length;e-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];if(!arguments.length){if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}return b}e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!a||j===3||j===8||j===2)return b;if(e&&c in f.attrFn)return f(a)[c](d);if(!("getAttribute"in a))return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return b}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g},removeAttr:function(a,b){var c,d,e,g,h=0;if(a.nodeType===1){d=(b||"").split(p),g=d.length;for(;h=0}})});var z=/\.(.*)$/,A=/^(?:textarea|input|select)$/i,B=/\./g,C=/ /g,D=/[^\w\s.|`]/g,E=/^([^\.]*)?(?:\.(.+))?$/,F=/\bhover(\.\S+)?/,G=/^key/,H=/^(?:mouse|contextmenu)|click/,I=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,J=function(a){var b=I.exec(a);b&&
3 | (b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},K=function(a,b){return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||a.id===b[2])&&(!b[3]||b[3].test(a.className))},L=function(a){return f.event.special.hover?a:a.replace(F,"mouseenter$1 mouseleave$1")};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=L(c).split(" ");for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"",(g||!e)&&c.preventDefault();if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,n=null;for(m=e.parentNode;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;l=0:t===b&&(t=o[s]=r.quick?K(m,r.quick):f(m).is(s)),t&&q.push(r);q.length&&j.push({elem:m,matches:q})}d.length>e&&j.push({elem:this,matches:d.slice(e)});for(k=0;k0?this.bind(b,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),G.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),H.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c ",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML=" ",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="
";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(V(c[0])||V(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c),g=S.call(arguments);O.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!U[a]?f.unique(e):e,(this.length>1||Q.test(d))&&P.test(a)&&(e=e.reverse());return this.pushStack(e,a,g.join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var Y="abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",Z=/ jQuery\d+="(?:\d+|null)"/g,$=/^\s+/,_=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,ba=/<([\w:]+)/,bb=/",""],legend:[1,""," "],thead:[1,""],tr:[2,""],td:[3,""],col:[2,""],area:[1,""," "],_default:[0,"",""]},bk=X(c);bj.optgroup=bj.option,bj.tbody=bj.tfoot=bj.colgroup=bj.caption=bj.thead,bj.th=bj.td,f.support.htmlSerialize||(bj._default=[1,"div","
"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){f(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after"
4 | ,arguments);a.push.apply(a,f(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Z,""):null;if(typeof a=="string"&&!bd.test(a)&&(f.support.leadingWhitespace||!$.test(a))&&!bj[(ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(_,"<$1>$2>");try{for(var c=0,d=this.length;c1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d=a.cloneNode(!0),e,g,h;if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bn(a,d),e=bo(a),g=bo(d);for(h=0;e[h];++h)g[h]&&bn(e[h],g[h])}if(b){bm(a,d);if(c){e=bo(a),g=bo(d);for(h=0;e[h];++h)bm(e[h],g[h])}}e=g=null;return d},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!bc.test(k))k=b.createTextNode(k);else{k=k.replace(_,"<$1>$2>");var l=(ba.exec(k)||["",""])[1].toLowerCase(),m=bj[l]||bj._default,n=m[0],o=b.createElement("div");b===c?bk.appendChild(o):X(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=bb.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]===""&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&$.test(k)&&o.insertBefore(b.createTextNode($.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bt.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bs,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bs.test(g)?g.replace(bs,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bB(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bC=function(a,c){var d,e,g;c=c.replace(bu,"-$1").toLowerCase();if(!(e=a.ownerDocument.defaultView))return b;if(g=e.getComputedStyle(a,null))d=g.getPropertyValue(c),d===""&&!f.contains(a.ownerDocument.documentElement,a)&&(d=f.style(a,c));return d}),c.documentElement.currentStyle&&(bD=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bv.test(f)&&bw.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bB=bC||bD,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bF=/%20/g,bG=/\[\]$/,bH=/\r?\n/g,bI=/#.*$/,bJ=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bK=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bL=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bM=/^(?:GET|HEAD)$/,bN=/^\/\//,bO=/\?/,bP=/