1 | /**
|
2 | * The reload plugin to free your finger.
|
3 | *
|
4 | * Active this plugin with seajs hook:
|
5 | *
|
6 | * - ?seajs-reload
|
7 | * - ?seajs-reload=8000
|
8 | * - ?seajs-reload=192.168.1.2:8000
|
9 | *
|
10 | * The default request location is localhost:8000
|
11 | *
|
12 | * You need a reload server that supports it.
|
13 | * The server should watch the file changes, and sent a "update" message.
|
14 | *
|
15 | * For example:
|
16 | *
|
17 | * var io = require('socket.io').listen(8000)
|
18 | * io.sockets.on('connection', function(socket) {
|
19 | * // if (fileChanged) {
|
20 | * socket.emit('update', {message: 'file changed'})
|
21 | * // }
|
22 | * })
|
23 | *
|
24 | * We provided a server for you at:
|
25 | *
|
26 | * https://github.com/seajs/reload-server
|
27 | */
|
28 | define('seajs/plugin-reload', [], function(require) {
|
29 |
|
30 | var loc = location.search.match(/seajs-reload=?([^:]*:)?(\d+)?/)
|
31 | var host = loc[1] || 'localhost:'
|
32 | var port = loc[2] || '8000'
|
33 | var url = 'http://' + host + port
|
34 |
|
35 | require.async(url + '/socket.io/socket.io.js', function() {
|
36 | var socket = io.connect(url)
|
37 | socket.on('update', function() {
|
38 | location.reload()
|
39 | })
|
40 | })
|
41 |
|
42 | });
|