hawkins 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 885636094f687e054388e0a6d71da378df326612
4
- data.tar.gz: dcc088a40490a073879771f5b8970f3967f0094c
3
+ metadata.gz: a1bd11a41ba71a67896b81cb43ee0c52027290a5
4
+ data.tar.gz: b51ee35d4b5fa17c4c28591370d2e1abb064276b
5
5
  SHA512:
6
- metadata.gz: 7d0d52c3eed985b496ea2f0f47ac0329377321a5656475c636de6db2342a46fb7c4ba32a2194e55c17a9e22aa3f9a5b20a79dd1925509a915aa266b2ab8cf23d
7
- data.tar.gz: 46c03d67882570a6a3a398277ef05093823c8475d4f4681876bfdb22aef2a027d7951a6f000953ece955f04a9da1094e3b4c554b6306b31b76933ee62c06fc29
6
+ metadata.gz: 627dd5cc3dfdc7a2cbd9be3ec967c050bc29f43419e13605a9b74988842ab3cd2ee6f2293b9d4fc79982c92084a907ea732d12c400a5ea08e8262c9c37f437b0
7
+ data.tar.gz: 8e48083f7781a9155b95685b9a85d8cf725e666c3f313147242d96b230e41fe819664a3d0b60893033ebbc10c42452427c76473de5a40fff37c53fdba0084a1a
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ - 2.0.0
6
+ script: bundle exec rake check
7
+ branches:
8
+ only:
9
+ - master
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/awood/hawkins.png?branch=master)](https://travis-ci.org/awood/hawkins)
2
+
1
3
  # Hawkins
2
4
  Hawkins is a [Jekyll](http://jekyllrb.com) 3.1+ plugin that incorporates
3
5
  [LiveReload](http://www.livereload.com) into the Jekyll "serve" process.
@@ -27,6 +29,14 @@ If you don't have a browser that implements WebSockets, you can use the
27
29
  `--swf` option that will have Hawkins load a Flash file that implements
28
30
  WebSockets.
29
31
 
32
+ ## Using `--ignore`
33
+
34
+ LiveReload errs on the side of reloading when it comes to the message it gets.
35
+ If, for example, a page is ignored but a CSS file linked in the page isn't, the
36
+ page will still be reloaded if the CSS file is contained in the message sent to
37
+ LiveReload. Additionally, the path matching is very loose so that a message to
38
+ reload "/" will always lead the page to reload since every page starts with "/".
39
+
30
40
  ## A Note on SSL/TLS
31
41
  If you tell Jekyll to serve your files over SSL/TLS (by specifying the
32
42
  `--ssl-cert` and `--ssl-key` options), then LiveReload will attempt to use
@@ -37,6 +47,11 @@ that Jekyll is serving content over and also for the server and port that
37
47
  LiveReload is running on. Generally speaking, these exceptions will be
38
48
  "127.0.0.1:4000" and "127.0.0.1:35729".
39
49
 
50
+ ## A Note on Compatibility
51
+
52
+ Hawkins does not currently work on JRuby. I'm working on figuring out why, but
53
+ be forewarned.
54
+
40
55
  ## Thanks
41
56
  Lots of thanks to [guard-livereload](https://github.com/guard/guard-livereload)
42
57
  and [rack-livereload](https://github.com/johnbintz/rack-livereload) which
@@ -1,372 +1,647 @@
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1
2
  (function() {
2
- var __customevents = {}, __protocol = {}, __connector = {}, __timer = {}, __options = {}, __reloader = {}, __livereload = {}, __less = {}, __startup = {};
3
-
4
- // customevents
5
- var CustomEvents;
6
- CustomEvents = {
7
- bind: function(element, eventName, handler) {
8
- if (element.addEventListener) {
9
- return element.addEventListener(eventName, handler, false);
10
- } else if (element.attachEvent) {
11
- element[eventName] = 1;
12
- return element.attachEvent('onpropertychange', function(event) {
13
- if (event.propertyName === eventName) {
14
- return handler();
15
- }
3
+ var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref;
4
+
5
+ _ref = require('./protocol'), Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7;
6
+
7
+ Version = '2.2.2';
8
+
9
+ exports.Connector = Connector = (function() {
10
+ function Connector(options, WebSocket, Timer, handlers) {
11
+ this.options = options;
12
+ this.WebSocket = WebSocket;
13
+ this.Timer = Timer;
14
+ this.handlers = handlers;
15
+ this._uri = "ws" + (this.options.https ? "s" : "") + "://" + this.options.host + ":" + this.options.port + "/livereload";
16
+ this._nextDelay = this.options.mindelay;
17
+ this._connectionDesired = false;
18
+ this.protocol = 0;
19
+ this.protocolParser = new Parser({
20
+ connected: (function(_this) {
21
+ return function(protocol) {
22
+ _this.protocol = protocol;
23
+ _this._handshakeTimeout.stop();
24
+ _this._nextDelay = _this.options.mindelay;
25
+ _this._disconnectionReason = 'broken';
26
+ return _this.handlers.connected(protocol);
27
+ };
28
+ })(this),
29
+ error: (function(_this) {
30
+ return function(e) {
31
+ _this.handlers.error(e);
32
+ return _this._closeOnError();
33
+ };
34
+ })(this),
35
+ message: (function(_this) {
36
+ return function(message) {
37
+ return _this.handlers.message(message);
38
+ };
39
+ })(this)
16
40
  });
17
- } else {
18
- throw new Error("Attempt to attach custom event " + eventName + " to something which isn't a DOMElement");
41
+ this._handshakeTimeout = new Timer((function(_this) {
42
+ return function() {
43
+ if (!_this._isSocketConnected()) {
44
+ return;
45
+ }
46
+ _this._disconnectionReason = 'handshake-timeout';
47
+ return _this.socket.close();
48
+ };
49
+ })(this));
50
+ this._reconnectTimer = new Timer((function(_this) {
51
+ return function() {
52
+ if (!_this._connectionDesired) {
53
+ return;
54
+ }
55
+ return _this.connect();
56
+ };
57
+ })(this));
58
+ this.connect();
19
59
  }
20
- },
21
- fire: function(element, eventName) {
22
- var event;
23
- if (element.addEventListener) {
24
- event = document.createEvent('HTMLEvents');
25
- event.initEvent(eventName, true, true);
26
- return document.dispatchEvent(event);
27
- } else if (element.attachEvent) {
28
- if (element[eventName]) {
29
- return element[eventName]++;
60
+
61
+ Connector.prototype._isSocketConnected = function() {
62
+ return this.socket && this.socket.readyState === this.WebSocket.OPEN;
63
+ };
64
+
65
+ Connector.prototype.connect = function() {
66
+ this._connectionDesired = true;
67
+ if (this._isSocketConnected()) {
68
+ return;
30
69
  }
31
- } else {
32
- throw new Error("Attempt to fire custom event " + eventName + " on something which isn't a DOMElement");
33
- }
34
- }
35
- };
36
- __customevents.bind = CustomEvents.bind;
37
- __customevents.fire = CustomEvents.fire;
38
-
39
- // protocol
40
- var PROTOCOL_6, PROTOCOL_7, Parser, ProtocolError;
41
- var __indexOf = Array.prototype.indexOf || function(item) {
42
- for (var i = 0, l = this.length; i < l; i++) {
43
- if (this[i] === item) return i;
44
- }
45
- return -1;
46
- };
47
- __protocol.PROTOCOL_6 = PROTOCOL_6 = 'http://livereload.com/protocols/official-6';
48
- __protocol.PROTOCOL_7 = PROTOCOL_7 = 'http://livereload.com/protocols/official-7';
49
- __protocol.ProtocolError = ProtocolError = (function() {
50
- function ProtocolError(reason, data) {
51
- this.message = "LiveReload protocol error (" + reason + ") after receiving data: \"" + data + "\".";
52
- }
53
- return ProtocolError;
54
- })();
55
- __protocol.Parser = Parser = (function() {
56
- function Parser(handlers) {
57
- this.handlers = handlers;
58
- this.reset();
59
- }
60
- Parser.prototype.reset = function() {
61
- return this.protocol = null;
62
- };
63
- Parser.prototype.process = function(data) {
64
- var command, message, options, _ref;
65
- try {
66
- if (!(this.protocol != null)) {
67
- if (data.match(/^!!ver:([\d.]+)$/)) {
68
- this.protocol = 6;
69
- } else if (message = this._parseMessage(data, ['hello'])) {
70
- if (!message.protocols.length) {
71
- throw new ProtocolError("no protocols specified in handshake message");
72
- } else if (__indexOf.call(message.protocols, PROTOCOL_7) >= 0) {
73
- this.protocol = 7;
74
- } else if (__indexOf.call(message.protocols, PROTOCOL_6) >= 0) {
75
- this.protocol = 6;
76
- } else {
77
- throw new ProtocolError("no supported protocols found");
70
+ this._reconnectTimer.stop();
71
+ this._disconnectionReason = 'cannot-connect';
72
+ this.protocolParser.reset();
73
+ this.handlers.connecting();
74
+ this.socket = new this.WebSocket(this._uri);
75
+ this.socket.onopen = (function(_this) {
76
+ return function(e) {
77
+ return _this._onopen(e);
78
+ };
79
+ })(this);
80
+ this.socket.onclose = (function(_this) {
81
+ return function(e) {
82
+ return _this._onclose(e);
83
+ };
84
+ })(this);
85
+ this.socket.onmessage = (function(_this) {
86
+ return function(e) {
87
+ return _this._onmessage(e);
88
+ };
89
+ })(this);
90
+ return this.socket.onerror = (function(_this) {
91
+ return function(e) {
92
+ return _this._onerror(e);
93
+ };
94
+ })(this);
95
+ };
96
+
97
+ Connector.prototype.disconnect = function() {
98
+ this._connectionDesired = false;
99
+ this._reconnectTimer.stop();
100
+ if (!this._isSocketConnected()) {
101
+ return;
102
+ }
103
+ this._disconnectionReason = 'manual';
104
+ return this.socket.close();
105
+ };
106
+
107
+ Connector.prototype._scheduleReconnection = function() {
108
+ if (!this._connectionDesired) {
109
+ return;
110
+ }
111
+ if (!this._reconnectTimer.running) {
112
+ this._reconnectTimer.start(this._nextDelay);
113
+ return this._nextDelay = Math.min(this.options.maxdelay, this._nextDelay * 2);
114
+ }
115
+ };
116
+
117
+ Connector.prototype.sendCommand = function(command) {
118
+ if (this.protocol == null) {
119
+ return;
120
+ }
121
+ return this._sendCommand(command);
122
+ };
123
+
124
+ Connector.prototype._sendCommand = function(command) {
125
+ return this.socket.send(JSON.stringify(command));
126
+ };
127
+
128
+ Connector.prototype._closeOnError = function() {
129
+ this._handshakeTimeout.stop();
130
+ this._disconnectionReason = 'error';
131
+ return this.socket.close();
132
+ };
133
+
134
+ Connector.prototype._onopen = function(e) {
135
+ var hello;
136
+ this.handlers.socketConnected();
137
+ this._disconnectionReason = 'handshake-failed';
138
+ hello = {
139
+ command: 'hello',
140
+ protocols: [PROTOCOL_6, PROTOCOL_7]
141
+ };
142
+ hello.ver = Version;
143
+ if (this.options.ext) {
144
+ hello.ext = this.options.ext;
145
+ }
146
+ if (this.options.extver) {
147
+ hello.extver = this.options.extver;
148
+ }
149
+ if (this.options.snipver) {
150
+ hello.snipver = this.options.snipver;
151
+ }
152
+ this._sendCommand(hello);
153
+ return this._handshakeTimeout.start(this.options.handshake_timeout);
154
+ };
155
+
156
+ Connector.prototype._onclose = function(e) {
157
+ this.protocol = 0;
158
+ this.handlers.disconnected(this._disconnectionReason, this._nextDelay);
159
+ return this._scheduleReconnection();
160
+ };
161
+
162
+ Connector.prototype._onerror = function(e) {};
163
+
164
+ Connector.prototype._onmessage = function(e) {
165
+ return this.protocolParser.process(e.data);
166
+ };
167
+
168
+ return Connector;
169
+
170
+ })();
171
+
172
+ }).call(this);
173
+
174
+ },{"./protocol":6}],2:[function(require,module,exports){
175
+ (function() {
176
+ var CustomEvents;
177
+
178
+ CustomEvents = {
179
+ bind: function(element, eventName, handler) {
180
+ if (element.addEventListener) {
181
+ return element.addEventListener(eventName, handler, false);
182
+ } else if (element.attachEvent) {
183
+ element[eventName] = 1;
184
+ return element.attachEvent('onpropertychange', function(event) {
185
+ if (event.propertyName === eventName) {
186
+ return handler();
78
187
  }
79
- }
80
- return this.handlers.connected(this.protocol);
81
- } else if (this.protocol === 6) {
82
- message = JSON.parse(data);
83
- if (!message.length) {
84
- throw new ProtocolError("protocol 6 messages must be arrays");
85
- }
86
- command = message[0], options = message[1];
87
- if (command !== 'refresh') {
88
- throw new ProtocolError("unknown protocol 6 command");
89
- }
90
- return this.handlers.message({
91
- command: 'reload',
92
- path: options.path,
93
- liveCSS: (_ref = options.apply_css_live) != null ? _ref : true
94
188
  });
95
189
  } else {
96
- message = this._parseMessage(data, ['reload', 'alert']);
97
- return this.handlers.message(message);
190
+ throw new Error("Attempt to attach custom event " + eventName + " to something which isn't a DOMElement");
98
191
  }
99
- } catch (e) {
100
- if (e instanceof ProtocolError) {
101
- return this.handlers.error(e);
192
+ },
193
+ fire: function(element, eventName) {
194
+ var event;
195
+ if (element.addEventListener) {
196
+ event = document.createEvent('HTMLEvents');
197
+ event.initEvent(eventName, true, true);
198
+ return document.dispatchEvent(event);
199
+ } else if (element.attachEvent) {
200
+ if (element[eventName]) {
201
+ return element[eventName]++;
202
+ }
102
203
  } else {
103
- throw e;
204
+ throw new Error("Attempt to fire custom event " + eventName + " on something which isn't a DOMElement");
104
205
  }
105
206
  }
106
207
  };
107
- Parser.prototype._parseMessage = function(data, validCommands) {
108
- var message, _ref;
109
- try {
110
- message = JSON.parse(data);
111
- } catch (e) {
112
- throw new ProtocolError('unparsable JSON', data);
113
- }
114
- if (!message.command) {
115
- throw new ProtocolError('missing "command" key', data);
116
- }
117
- if (_ref = message.command, __indexOf.call(validCommands, _ref) < 0) {
118
- throw new ProtocolError("invalid command '" + message.command + "', only valid commands are: " + (validCommands.join(', ')) + ")", data);
208
+
209
+ exports.bind = CustomEvents.bind;
210
+
211
+ exports.fire = CustomEvents.fire;
212
+
213
+ }).call(this);
214
+
215
+ },{}],3:[function(require,module,exports){
216
+ (function() {
217
+ var LessPlugin;
218
+
219
+ module.exports = LessPlugin = (function() {
220
+ LessPlugin.identifier = 'less';
221
+
222
+ LessPlugin.version = '1.0';
223
+
224
+ function LessPlugin(window, host) {
225
+ this.window = window;
226
+ this.host = host;
119
227
  }
120
- return message;
121
- };
122
- return Parser;
123
- })();
124
-
125
- // connector
126
- // Generated by CoffeeScript 1.3.3
127
- var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref;
128
-
129
- _ref = __protocol, Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7;
130
-
131
- Version = '2.0.8';
132
-
133
- __connector.Connector = Connector = (function() {
134
-
135
- function Connector(options, WebSocket, Timer, handlers) {
136
- var _this = this;
137
- this.options = options;
138
- this.WebSocket = WebSocket;
139
- this.Timer = Timer;
140
- this.handlers = handlers;
141
- this._uri = HAWKINS_LIVERELOAD_PROTOCOL + this.options.host + ":" + this.options.port + "/livereload";
142
- this._nextDelay = this.options.mindelay;
143
- this._connectionDesired = false;
144
- this.protocol = 0;
145
- this.protocolParser = new Parser({
146
- connected: function(protocol) {
147
- _this.protocol = protocol;
148
- _this._handshakeTimeout.stop();
149
- _this._nextDelay = _this.options.mindelay;
150
- _this._disconnectionReason = 'broken';
151
- return _this.handlers.connected(protocol);
152
- },
153
- error: function(e) {
154
- _this.handlers.error(e);
155
- return _this._closeOnError();
156
- },
157
- message: function(message) {
158
- return _this.handlers.message(message);
228
+
229
+ LessPlugin.prototype.reload = function(path, options) {
230
+ if (this.window.less && this.window.less.refresh) {
231
+ if (path.match(/\.less$/i)) {
232
+ return this.reloadLess(path);
233
+ }
234
+ if (options.originalPath.match(/\.less$/i)) {
235
+ return this.reloadLess(options.originalPath);
236
+ }
159
237
  }
160
- });
161
- this._handshakeTimeout = new Timer(function() {
162
- if (!_this._isSocketConnected()) {
163
- return;
238
+ return false;
239
+ };
240
+
241
+ LessPlugin.prototype.reloadLess = function(path) {
242
+ var link, links, _i, _len;
243
+ links = (function() {
244
+ var _i, _len, _ref, _results;
245
+ _ref = document.getElementsByTagName('link');
246
+ _results = [];
247
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
248
+ link = _ref[_i];
249
+ if (link.href && link.rel.match(/^stylesheet\/less$/i) || (link.rel.match(/stylesheet/i) && link.type.match(/^text\/(x-)?less$/i))) {
250
+ _results.push(link);
251
+ }
252
+ }
253
+ return _results;
254
+ })();
255
+ if (links.length === 0) {
256
+ return false;
164
257
  }
165
- _this._disconnectionReason = 'handshake-timeout';
166
- return _this.socket.close();
167
- });
168
- this._reconnectTimer = new Timer(function() {
169
- if (!_this._connectionDesired) {
170
- return;
258
+ for (_i = 0, _len = links.length; _i < _len; _i++) {
259
+ link = links[_i];
260
+ link.href = this.host.generateCacheBustUrl(link.href);
171
261
  }
172
- return _this.connect();
173
- });
174
- this.connect();
175
- }
262
+ this.host.console.log("LiveReload is asking LESS to recompile all stylesheets");
263
+ this.window.less.refresh(true);
264
+ return true;
265
+ };
176
266
 
177
- Connector.prototype._isSocketConnected = function() {
178
- return this.socket && this.socket.readyState === this.WebSocket.OPEN;
179
- };
267
+ LessPlugin.prototype.analyze = function() {
268
+ return {
269
+ disable: !!(this.window.less && this.window.less.refresh)
270
+ };
271
+ };
272
+
273
+ return LessPlugin;
274
+
275
+ })();
276
+
277
+ }).call(this);
278
+
279
+ },{}],4:[function(require,module,exports){
280
+ (function() {
281
+ var Connector, LiveReload, Options, Reloader, Timer,
282
+ __hasProp = {}.hasOwnProperty;
283
+
284
+ Connector = require('./connector').Connector;
285
+
286
+ Timer = require('./timer').Timer;
180
287
 
181
- Connector.prototype.connect = function() {
182
- var _this = this;
183
- this._connectionDesired = true;
184
- if (this._isSocketConnected()) {
185
- return;
288
+ Options = require('./options').Options;
289
+
290
+ Reloader = require('./reloader').Reloader;
291
+
292
+ exports.LiveReload = LiveReload = (function() {
293
+ function LiveReload(window) {
294
+ var k, v, _ref;
295
+ this.window = window;
296
+ this.listeners = {};
297
+ this.plugins = [];
298
+ this.pluginIdentifiers = {};
299
+ this.console = this.window.console && this.window.console.log && this.window.console.error ? this.window.location.href.match(/LR-verbose/) ? this.window.console : {
300
+ log: function() {},
301
+ error: this.window.console.error.bind(this.window.console)
302
+ } : {
303
+ log: function() {},
304
+ error: function() {}
305
+ };
306
+ if (!(this.WebSocket = this.window.WebSocket || this.window.MozWebSocket)) {
307
+ this.console.error("LiveReload disabled because the browser does not seem to support web sockets");
308
+ return;
309
+ }
310
+ if ('LiveReloadOptions' in window) {
311
+ this.options = new Options();
312
+ _ref = window['LiveReloadOptions'];
313
+ for (k in _ref) {
314
+ if (!__hasProp.call(_ref, k)) continue;
315
+ v = _ref[k];
316
+ this.options.set(k, v);
317
+ }
318
+ } else {
319
+ this.options = Options.extract(this.window.document);
320
+ if (!this.options) {
321
+ this.console.error("LiveReload disabled because it could not find its own <SCRIPT> tag");
322
+ return;
323
+ }
324
+ }
325
+ this.reloader = new Reloader(this.window, this.console, Timer);
326
+ this.connector = new Connector(this.options, this.WebSocket, Timer, {
327
+ connecting: (function(_this) {
328
+ return function() {};
329
+ })(this),
330
+ socketConnected: (function(_this) {
331
+ return function() {};
332
+ })(this),
333
+ connected: (function(_this) {
334
+ return function(protocol) {
335
+ var _base;
336
+ if (typeof (_base = _this.listeners).connect === "function") {
337
+ _base.connect();
338
+ }
339
+ _this.log("LiveReload is connected to " + _this.options.host + ":" + _this.options.port + " (protocol v" + protocol + ").");
340
+ return _this.analyze();
341
+ };
342
+ })(this),
343
+ error: (function(_this) {
344
+ return function(e) {
345
+ if (e instanceof ProtocolError) {
346
+ if (typeof console !== "undefined" && console !== null) {
347
+ return console.log("" + e.message + ".");
348
+ }
349
+ } else {
350
+ if (typeof console !== "undefined" && console !== null) {
351
+ return console.log("LiveReload internal error: " + e.message);
352
+ }
353
+ }
354
+ };
355
+ })(this),
356
+ disconnected: (function(_this) {
357
+ return function(reason, nextDelay) {
358
+ var _base;
359
+ if (typeof (_base = _this.listeners).disconnect === "function") {
360
+ _base.disconnect();
361
+ }
362
+ switch (reason) {
363
+ case 'cannot-connect':
364
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + ", will retry in " + nextDelay + " sec.");
365
+ case 'broken':
366
+ return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + ", reconnecting in " + nextDelay + " sec.");
367
+ case 'handshake-timeout':
368
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec.");
369
+ case 'handshake-failed':
370
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake failed), will retry in " + nextDelay + " sec.");
371
+ case 'manual':
372
+ break;
373
+ case 'error':
374
+ break;
375
+ default:
376
+ return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec.");
377
+ }
378
+ };
379
+ })(this),
380
+ message: (function(_this) {
381
+ return function(message) {
382
+ switch (message.command) {
383
+ case 'reload':
384
+ return _this.performReload(message);
385
+ case 'alert':
386
+ return _this.performAlert(message);
387
+ }
388
+ };
389
+ })(this)
390
+ });
391
+ this.initialized = true;
186
392
  }
187
- this._reconnectTimer.stop();
188
- this._disconnectionReason = 'cannot-connect';
189
- this.protocolParser.reset();
190
- this.handlers.connecting();
191
- this.socket = new this.WebSocket(this._uri);
192
- this.socket.onopen = function(e) {
193
- return _this._onopen(e);
393
+
394
+ LiveReload.prototype.on = function(eventName, handler) {
395
+ return this.listeners[eventName] = handler;
194
396
  };
195
- this.socket.onclose = function(e) {
196
- return _this._onclose(e);
397
+
398
+ LiveReload.prototype.log = function(message) {
399
+ return this.console.log("" + message);
197
400
  };
198
- this.socket.onmessage = function(e) {
199
- return _this._onmessage(e);
401
+
402
+ LiveReload.prototype.performReload = function(message) {
403
+ var _ref, _ref1;
404
+ this.log("LiveReload received reload request: " + (JSON.stringify(message, null, 2)));
405
+ return this.reloader.reload(message.path, {
406
+ liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
407
+ liveImg: (_ref1 = message.liveImg) != null ? _ref1 : true,
408
+ originalPath: message.originalPath || '',
409
+ overrideURL: message.overrideURL || '',
410
+ serverURL: "http://" + this.options.host + ":" + this.options.port
411
+ });
200
412
  };
201
- return this.socket.onerror = function(e) {
202
- return _this._onerror(e);
413
+
414
+ LiveReload.prototype.performAlert = function(message) {
415
+ return alert(message.message);
203
416
  };
204
- };
205
417
 
206
- Connector.prototype.disconnect = function() {
207
- this._connectionDesired = false;
208
- this._reconnectTimer.stop();
209
- if (!this._isSocketConnected()) {
210
- return;
211
- }
212
- this._disconnectionReason = 'manual';
213
- return this.socket.close();
214
- };
418
+ LiveReload.prototype.shutDown = function() {
419
+ var _base;
420
+ if (!this.initialized) {
421
+ return;
422
+ }
423
+ this.connector.disconnect();
424
+ this.log("LiveReload disconnected.");
425
+ return typeof (_base = this.listeners).shutdown === "function" ? _base.shutdown() : void 0;
426
+ };
215
427
 
216
- Connector.prototype._scheduleReconnection = function() {
217
- if (!this._connectionDesired) {
218
- return;
219
- }
220
- if (!this._reconnectTimer.running) {
221
- this._reconnectTimer.start(this._nextDelay);
222
- return this._nextDelay = Math.min(this.options.maxdelay, this._nextDelay * 2);
223
- }
224
- };
428
+ LiveReload.prototype.hasPlugin = function(identifier) {
429
+ return !!this.pluginIdentifiers[identifier];
430
+ };
225
431
 
226
- Connector.prototype.sendCommand = function(command) {
227
- if (this.protocol == null) {
228
- return;
229
- }
230
- return this._sendCommand(command);
231
- };
432
+ LiveReload.prototype.addPlugin = function(pluginClass) {
433
+ var plugin;
434
+ if (!this.initialized) {
435
+ return;
436
+ }
437
+ if (this.hasPlugin(pluginClass.identifier)) {
438
+ return;
439
+ }
440
+ this.pluginIdentifiers[pluginClass.identifier] = true;
441
+ plugin = new pluginClass(this.window, {
442
+ _livereload: this,
443
+ _reloader: this.reloader,
444
+ _connector: this.connector,
445
+ console: this.console,
446
+ Timer: Timer,
447
+ generateCacheBustUrl: (function(_this) {
448
+ return function(url) {
449
+ return _this.reloader.generateCacheBustUrl(url);
450
+ };
451
+ })(this)
452
+ });
453
+ this.plugins.push(plugin);
454
+ this.reloader.addPlugin(plugin);
455
+ };
232
456
 
233
- Connector.prototype._sendCommand = function(command) {
234
- return this.socket.send(JSON.stringify(command));
235
- };
457
+ LiveReload.prototype.analyze = function() {
458
+ var plugin, pluginData, pluginsData, _i, _len, _ref;
459
+ if (!this.initialized) {
460
+ return;
461
+ }
462
+ if (!(this.connector.protocol >= 7)) {
463
+ return;
464
+ }
465
+ pluginsData = {};
466
+ _ref = this.plugins;
467
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
468
+ plugin = _ref[_i];
469
+ pluginsData[plugin.constructor.identifier] = pluginData = (typeof plugin.analyze === "function" ? plugin.analyze() : void 0) || {};
470
+ pluginData.version = plugin.constructor.version;
471
+ }
472
+ this.connector.sendCommand({
473
+ command: 'info',
474
+ plugins: pluginsData,
475
+ url: this.window.location.href
476
+ });
477
+ };
236
478
 
237
- Connector.prototype._closeOnError = function() {
238
- this._handshakeTimeout.stop();
239
- this._disconnectionReason = 'error';
240
- return this.socket.close();
241
- };
479
+ return LiveReload;
242
480
 
243
- Connector.prototype._onopen = function(e) {
244
- var hello;
245
- this.handlers.socketConnected();
246
- this._disconnectionReason = 'handshake-failed';
247
- hello = {
248
- command: 'hello',
249
- protocols: [PROTOCOL_6, PROTOCOL_7]
250
- };
251
- hello.ver = Version;
252
- if (this.options.ext) {
253
- hello.ext = this.options.ext;
254
- }
255
- if (this.options.extver) {
256
- hello.extver = this.options.extver;
257
- }
258
- if (this.options.snipver) {
259
- hello.snipver = this.options.snipver;
260
- }
261
- this._sendCommand(hello);
262
- return this._handshakeTimeout.start(this.options.handshake_timeout);
263
- };
481
+ })();
264
482
 
265
- Connector.prototype._onclose = function(e) {
266
- this.protocol = 0;
267
- this.handlers.disconnected(this._disconnectionReason, this._nextDelay);
268
- return this._scheduleReconnection();
269
- };
483
+ }).call(this);
270
484
 
271
- Connector.prototype._onerror = function(e) {};
485
+ },{"./connector":1,"./options":5,"./reloader":7,"./timer":9}],5:[function(require,module,exports){
486
+ (function() {
487
+ var Options;
488
+
489
+ exports.Options = Options = (function() {
490
+ function Options() {
491
+ this.https = false;
492
+ this.host = null;
493
+ this.port = 35729;
494
+ this.snipver = null;
495
+ this.ext = null;
496
+ this.extver = null;
497
+ this.mindelay = 1000;
498
+ this.maxdelay = 60000;
499
+ this.handshake_timeout = 5000;
500
+ }
272
501
 
273
- Connector.prototype._onmessage = function(e) {
274
- return this.protocolParser.process(e.data);
275
- };
502
+ Options.prototype.set = function(name, value) {
503
+ if (typeof value === 'undefined') {
504
+ return;
505
+ }
506
+ if (!isNaN(+value)) {
507
+ value = +value;
508
+ }
509
+ return this[name] = value;
510
+ };
276
511
 
277
- return Connector;
512
+ return Options;
278
513
 
279
- })();
514
+ })();
280
515
 
281
- // timer
282
- var Timer;
283
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
284
- __timer.Timer = Timer = (function() {
285
- function Timer(func) {
286
- this.func = func;
287
- this.running = false;
288
- this.id = null;
289
- this._handler = __bind(function() {
290
- this.running = false;
291
- this.id = null;
292
- return this.func();
293
- }, this);
294
- }
295
- Timer.prototype.start = function(timeout) {
296
- if (this.running) {
297
- clearTimeout(this.id);
516
+ Options.extract = function(document) {
517
+ var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len1, _ref, _ref1;
518
+ _ref = document.getElementsByTagName('script');
519
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
520
+ element = _ref[_i];
521
+ if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) {
522
+ options = new Options();
523
+ options.https = src.indexOf("https") === 0;
524
+ if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?$/)) {
525
+ options.host = mm[1];
526
+ if (mm[2]) {
527
+ options.port = parseInt(mm[2], 10);
528
+ }
529
+ }
530
+ if (m[2]) {
531
+ _ref1 = m[2].split('&');
532
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
533
+ pair = _ref1[_j];
534
+ if ((keyAndValue = pair.split('=')).length > 1) {
535
+ options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('='));
536
+ }
537
+ }
538
+ }
539
+ return options;
540
+ }
298
541
  }
299
- this.id = setTimeout(this._handler, timeout);
300
- return this.running = true;
542
+ return null;
301
543
  };
302
- Timer.prototype.stop = function() {
303
- if (this.running) {
304
- clearTimeout(this.id);
305
- this.running = false;
306
- return this.id = null;
544
+
545
+ }).call(this);
546
+
547
+ },{}],6:[function(require,module,exports){
548
+ (function() {
549
+ var PROTOCOL_6, PROTOCOL_7, Parser, ProtocolError,
550
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
551
+
552
+ exports.PROTOCOL_6 = PROTOCOL_6 = 'http://livereload.com/protocols/official-6';
553
+
554
+ exports.PROTOCOL_7 = PROTOCOL_7 = 'http://livereload.com/protocols/official-7';
555
+
556
+ exports.ProtocolError = ProtocolError = (function() {
557
+ function ProtocolError(reason, data) {
558
+ this.message = "LiveReload protocol error (" + reason + ") after receiving data: \"" + data + "\".";
307
559
  }
308
- };
309
- return Timer;
310
- })();
311
- Timer.start = function(timeout, func) {
312
- return setTimeout(func, timeout);
313
- };
314
-
315
- // options
316
- var Options;
317
- __options.Options = Options = (function() {
318
- function Options() {
319
- this.host = null;
320
- this.port = HAWKINS_LIVERELOAD_PORT;
321
- this.snipver = null;
322
- this.ext = null;
323
- this.extver = null;
324
- this.mindelay = 1000;
325
- this.maxdelay = 60000;
326
- this.handshake_timeout = 5000;
327
- }
328
- Options.prototype.set = function(name, value) {
329
- switch (typeof this[name]) {
330
- case 'undefined':
331
- break;
332
- case 'number':
333
- return this[name] = +value;
334
- default:
335
- return this[name] = value;
560
+
561
+ return ProtocolError;
562
+
563
+ })();
564
+
565
+ exports.Parser = Parser = (function() {
566
+ function Parser(handlers) {
567
+ this.handlers = handlers;
568
+ this.reset();
336
569
  }
337
- };
338
- return Options;
339
- })();
340
- Options.extract = function(document) {
341
- var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len2, _ref, _ref2;
342
- _ref = document.getElementsByTagName('script');
343
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
344
- element = _ref[_i];
345
- if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) {
346
- options = new Options();
347
- if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?$/)) {
348
- options.host = mm[1];
349
- if (mm[2]) {
350
- options.port = parseInt(mm[2], 10);
351
- }
352
- }
353
- if (m[2]) {
354
- _ref2 = m[2].split('&');
355
- for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
356
- pair = _ref2[_j];
357
- if ((keyAndValue = pair.split('=')).length > 1) {
358
- options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('='));
570
+
571
+ Parser.prototype.reset = function() {
572
+ return this.protocol = null;
573
+ };
574
+
575
+ Parser.prototype.process = function(data) {
576
+ var command, e, message, options, _ref;
577
+ try {
578
+ if (this.protocol == null) {
579
+ if (data.match(/^!!ver:([\d.]+)$/)) {
580
+ this.protocol = 6;
581
+ } else if (message = this._parseMessage(data, ['hello'])) {
582
+ if (!message.protocols.length) {
583
+ throw new ProtocolError("no protocols specified in handshake message");
584
+ } else if (__indexOf.call(message.protocols, PROTOCOL_7) >= 0) {
585
+ this.protocol = 7;
586
+ } else if (__indexOf.call(message.protocols, PROTOCOL_6) >= 0) {
587
+ this.protocol = 6;
588
+ } else {
589
+ throw new ProtocolError("no supported protocols found");
590
+ }
591
+ }
592
+ return this.handlers.connected(this.protocol);
593
+ } else if (this.protocol === 6) {
594
+ message = JSON.parse(data);
595
+ if (!message.length) {
596
+ throw new ProtocolError("protocol 6 messages must be arrays");
359
597
  }
598
+ command = message[0], options = message[1];
599
+ if (command !== 'refresh') {
600
+ throw new ProtocolError("unknown protocol 6 command");
601
+ }
602
+ return this.handlers.message({
603
+ command: 'reload',
604
+ path: options.path,
605
+ liveCSS: (_ref = options.apply_css_live) != null ? _ref : true
606
+ });
607
+ } else {
608
+ message = this._parseMessage(data, ['reload', 'alert']);
609
+ return this.handlers.message(message);
610
+ }
611
+ } catch (_error) {
612
+ e = _error;
613
+ if (e instanceof ProtocolError) {
614
+ return this.handlers.error(e);
615
+ } else {
616
+ throw e;
360
617
  }
361
618
  }
362
- return options;
363
- }
364
- }
365
- return null;
366
- };
619
+ };
620
+
621
+ Parser.prototype._parseMessage = function(data, validCommands) {
622
+ var e, message, _ref;
623
+ try {
624
+ message = JSON.parse(data);
625
+ } catch (_error) {
626
+ e = _error;
627
+ throw new ProtocolError('unparsable JSON', data);
628
+ }
629
+ if (!message.command) {
630
+ throw new ProtocolError('missing "command" key', data);
631
+ }
632
+ if (_ref = message.command, __indexOf.call(validCommands, _ref) < 0) {
633
+ throw new ProtocolError("invalid command '" + message.command + "', only valid commands are: " + (validCommands.join(', ')) + ")", data);
634
+ }
635
+ return message;
636
+ };
637
+
638
+ return Parser;
639
+
640
+ })();
641
+
642
+ }).call(this);
367
643
 
368
- // reloader
369
- // Generated by CoffeeScript 1.3.1
644
+ },{}],7:[function(require,module,exports){
370
645
  (function() {
371
646
  var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
372
647
 
@@ -455,10 +730,7 @@ Options.extract = function(document) {
455
730
  }
456
731
  ];
457
732
 
458
- __reloader.Reloader = Reloader = (function() {
459
-
460
- Reloader.name = 'Reloader';
461
-
733
+ exports.Reloader = Reloader = (function() {
462
734
  function Reloader(window, console, Timer) {
463
735
  this.window = window;
464
736
  this.console = console;
@@ -541,11 +813,11 @@ Options.extract = function(document) {
541
813
  };
542
814
 
543
815
  Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
544
- var rule, rules, styleNames, _i, _j, _len, _len1;
816
+ var e, rule, rules, styleNames, _i, _j, _len, _len1;
545
817
  try {
546
818
  rules = styleSheet != null ? styleSheet.cssRules : void 0;
547
- } catch (e) {
548
-
819
+ } catch (_error) {
820
+ e = _error;
549
821
  }
550
822
  if (!rules) {
551
823
  return;
@@ -569,19 +841,20 @@ Options.extract = function(document) {
569
841
  };
570
842
 
571
843
  Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
572
- var newValue, styleName, value, _i, _len,
573
- _this = this;
844
+ var newValue, styleName, value, _i, _len;
574
845
  for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
575
846
  styleName = styleNames[_i];
576
847
  value = style[styleName];
577
848
  if (typeof value === 'string') {
578
- newValue = value.replace(/\burl\s*\(([^)]*)\)/, function(match, src) {
579
- if (pathsMatch(path, pathFromUrl(src))) {
580
- return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")";
581
- } else {
582
- return match;
583
- }
584
- });
849
+ newValue = value.replace(/\burl\s*\(([^)]*)\)/, (function(_this) {
850
+ return function(match, src) {
851
+ if (pathsMatch(path, pathFromUrl(src))) {
852
+ return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")";
853
+ } else {
854
+ return match;
855
+ }
856
+ };
857
+ })(this));
585
858
  if (newValue !== value) {
586
859
  style[styleName] = newValue;
587
860
  }
@@ -590,15 +863,14 @@ Options.extract = function(document) {
590
863
  };
591
864
 
592
865
  Reloader.prototype.reloadStylesheet = function(path) {
593
- var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1,
594
- _this = this;
866
+ var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1;
595
867
  links = (function() {
596
868
  var _i, _len, _ref, _results;
597
869
  _ref = this.document.getElementsByTagName('link');
598
870
  _results = [];
599
871
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
600
872
  link = _ref[_i];
601
- if (link.rel === 'stylesheet' && !link.__LiveReload_pendingRemoval) {
873
+ if (link.rel.match(/^stylesheet$/i) && !link.__LiveReload_pendingRemoval) {
602
874
  _results.push(link);
603
875
  }
604
876
  }
@@ -624,9 +896,11 @@ Options.extract = function(document) {
624
896
  }
625
897
  }
626
898
  this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets");
627
- match = pickBestMatch(path, links.concat(imported), function(l) {
628
- return pathFromUrl(_this.linkHref(l));
629
- });
899
+ match = pickBestMatch(path, links.concat(imported), (function(_this) {
900
+ return function(l) {
901
+ return pathFromUrl(_this.linkHref(l));
902
+ };
903
+ })(this));
630
904
  if (match) {
631
905
  if (match.object.rule) {
632
906
  this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
@@ -646,11 +920,11 @@ Options.extract = function(document) {
646
920
  };
647
921
 
648
922
  Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
649
- var index, rule, rules, _i, _len;
923
+ var e, index, rule, rules, _i, _len;
650
924
  try {
651
925
  rules = styleSheet != null ? styleSheet.cssRules : void 0;
652
- } catch (e) {
653
-
926
+ } catch (_error) {
927
+ e = _error;
654
928
  }
655
929
  if (rules && rules.length) {
656
930
  for (index = _i = 0, _len = rules.length; _i < _len; index = ++_i) {
@@ -675,30 +949,35 @@ Options.extract = function(document) {
675
949
  };
676
950
 
677
951
  Reloader.prototype.waitUntilCssLoads = function(clone, func) {
678
- var callbackExecuted, executeCallback, poll,
679
- _this = this;
952
+ var callbackExecuted, executeCallback, poll;
680
953
  callbackExecuted = false;
681
- executeCallback = function() {
682
- if (callbackExecuted) {
683
- return;
684
- }
685
- callbackExecuted = true;
686
- return func();
687
- };
688
- clone.onload = function() {
689
- console.log("onload!");
690
- _this.knownToSupportCssOnLoad = true;
691
- return executeCallback();
692
- };
693
- if (!this.knownToSupportCssOnLoad) {
694
- (poll = function() {
695
- if (clone.sheet) {
696
- console.log("polling!");
697
- return executeCallback();
698
- } else {
699
- return _this.Timer.start(50, poll);
954
+ executeCallback = (function(_this) {
955
+ return function() {
956
+ if (callbackExecuted) {
957
+ return;
700
958
  }
701
- })();
959
+ callbackExecuted = true;
960
+ return func();
961
+ };
962
+ })(this);
963
+ clone.onload = (function(_this) {
964
+ return function() {
965
+ _this.console.log("LiveReload: the new stylesheet has finished loading");
966
+ _this.knownToSupportCssOnLoad = true;
967
+ return executeCallback();
968
+ };
969
+ })(this);
970
+ if (!this.knownToSupportCssOnLoad) {
971
+ (poll = (function(_this) {
972
+ return function() {
973
+ if (clone.sheet) {
974
+ _this.console.log("LiveReload is polling until the new CSS finishes loading...");
975
+ return executeCallback();
976
+ } else {
977
+ return _this.Timer.start(50, poll);
978
+ }
979
+ };
980
+ })(this))();
702
981
  }
703
982
  return this.Timer.start(this.options.stylesheetReloadTimeout, executeCallback);
704
983
  };
@@ -708,8 +987,7 @@ Options.extract = function(document) {
708
987
  };
709
988
 
710
989
  Reloader.prototype.reattachStylesheetLink = function(link) {
711
- var clone, parent,
712
- _this = this;
990
+ var clone, parent;
713
991
  if (link.__LiveReload_pendingRemoval) {
714
992
  return;
715
993
  }
@@ -729,28 +1007,29 @@ Options.extract = function(document) {
729
1007
  } else {
730
1008
  parent.insertBefore(clone, link.nextSibling);
731
1009
  }
732
- return this.waitUntilCssLoads(clone, function() {
733
- var additionalWaitingTime;
734
- if (/AppleWebKit/.test(navigator.userAgent)) {
735
- additionalWaitingTime = 5;
736
- } else {
737
- additionalWaitingTime = 200;
738
- }
739
- return _this.Timer.start(additionalWaitingTime, function() {
740
- var _ref;
741
- if (!link.parentNode) {
742
- return;
1010
+ return this.waitUntilCssLoads(clone, (function(_this) {
1011
+ return function() {
1012
+ var additionalWaitingTime;
1013
+ if (/AppleWebKit/.test(navigator.userAgent)) {
1014
+ additionalWaitingTime = 5;
1015
+ } else {
1016
+ additionalWaitingTime = 200;
743
1017
  }
744
- link.parentNode.removeChild(link);
745
- clone.onreadystatechange = null;
746
- return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0;
747
- });
748
- });
1018
+ return _this.Timer.start(additionalWaitingTime, function() {
1019
+ var _ref;
1020
+ if (!link.parentNode) {
1021
+ return;
1022
+ }
1023
+ link.parentNode.removeChild(link);
1024
+ clone.onreadystatechange = null;
1025
+ return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0;
1026
+ });
1027
+ };
1028
+ })(this));
749
1029
  };
750
1030
 
751
1031
  Reloader.prototype.reattachImportedRule = function(_arg) {
752
- var href, index, link, media, newRule, parent, rule, tempLink,
753
- _this = this;
1032
+ var href, index, link, media, newRule, parent, rule, tempLink;
754
1033
  rule = _arg.rule, index = _arg.index, link = _arg.link;
755
1034
  parent = rule.parentStyleSheet;
756
1035
  href = this.generateCacheBustUrl(rule.href);
@@ -764,25 +1043,27 @@ Options.extract = function(document) {
764
1043
  if (link.parentNode) {
765
1044
  link.parentNode.insertBefore(tempLink, link);
766
1045
  }
767
- return this.Timer.start(this.importCacheWaitPeriod, function() {
768
- if (tempLink.parentNode) {
769
- tempLink.parentNode.removeChild(tempLink);
770
- }
771
- if (rule.__LiveReload_newHref !== href) {
772
- return;
773
- }
774
- parent.insertRule(newRule, index);
775
- parent.deleteRule(index + 1);
776
- rule = parent.cssRules[index];
777
- rule.__LiveReload_newHref = href;
778
- return _this.Timer.start(_this.importCacheWaitPeriod, function() {
1046
+ return this.Timer.start(this.importCacheWaitPeriod, (function(_this) {
1047
+ return function() {
1048
+ if (tempLink.parentNode) {
1049
+ tempLink.parentNode.removeChild(tempLink);
1050
+ }
779
1051
  if (rule.__LiveReload_newHref !== href) {
780
1052
  return;
781
1053
  }
782
1054
  parent.insertRule(newRule, index);
783
- return parent.deleteRule(index + 1);
784
- });
785
- });
1055
+ parent.deleteRule(index + 1);
1056
+ rule = parent.cssRules[index];
1057
+ rule.__LiveReload_newHref = href;
1058
+ return _this.Timer.start(_this.importCacheWaitPeriod, function() {
1059
+ if (rule.__LiveReload_newHref !== href) {
1060
+ return;
1061
+ }
1062
+ parent.insertRule(newRule, index);
1063
+ return parent.deleteRule(index + 1);
1064
+ });
1065
+ };
1066
+ })(this));
786
1067
  };
787
1068
 
788
1069
  Reloader.prototype.generateUniqueString = function() {
@@ -790,14 +1071,16 @@ Options.extract = function(document) {
790
1071
  };
791
1072
 
792
1073
  Reloader.prototype.generateCacheBustUrl = function(url, expando) {
793
- var hash, oldParams, params, _ref;
1074
+ var hash, oldParams, originalUrl, params, _ref;
794
1075
  if (expando == null) {
795
1076
  expando = this.generateUniqueString();
796
1077
  }
797
1078
  _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
798
1079
  if (this.options.overrideURL) {
799
1080
  if (url.indexOf(this.options.serverURL) < 0) {
1081
+ originalUrl = url;
800
1082
  url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url);
1083
+ this.console.log("LiveReload is overriding source URL " + originalUrl + " with " + url);
801
1084
  }
802
1085
  }
803
1086
  params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
@@ -819,237 +1102,82 @@ Options.extract = function(document) {
819
1102
 
820
1103
  }).call(this);
821
1104
 
822
- // livereload
823
- var Connector, LiveReload, Options, Reloader, Timer;
824
-
825
- Connector = __connector.Connector;
826
-
827
- Timer = __timer.Timer;
828
-
829
- Options = __options.Options;
1105
+ },{}],8:[function(require,module,exports){
1106
+ (function() {
1107
+ var CustomEvents, LiveReload, k;
830
1108
 
831
- Reloader = __reloader.Reloader;
1109
+ CustomEvents = require('./customevents');
832
1110
 
833
- __livereload.LiveReload = LiveReload = (function() {
1111
+ LiveReload = window.LiveReload = new (require('./livereload').LiveReload)(window);
834
1112
 
835
- function LiveReload(window) {
836
- var _this = this;
837
- this.window = window;
838
- this.listeners = {};
839
- this.plugins = [];
840
- this.pluginIdentifiers = {};
841
- this.console = this.window.location.href.match(/LR-verbose/) && this.window.console && this.window.console.log && this.window.console.error ? this.window.console : {
842
- log: function() {},
843
- error: function() {}
844
- };
845
- if (!(this.WebSocket = this.window.WebSocket || this.window.MozWebSocket)) {
846
- console.error("LiveReload disabled because the browser does not seem to support web sockets");
847
- return;
848
- }
849
- if (!(this.options = Options.extract(this.window.document))) {
850
- console.error("LiveReload disabled because it could not find its own <SCRIPT> tag");
851
- return;
1113
+ for (k in window) {
1114
+ if (k.match(/^LiveReloadPlugin/)) {
1115
+ LiveReload.addPlugin(window[k]);
852
1116
  }
853
- this.reloader = new Reloader(this.window, this.console, Timer);
854
- this.connector = new Connector(this.options, this.WebSocket, Timer, {
855
- connecting: function() {},
856
- socketConnected: function() {},
857
- connected: function(protocol) {
858
- var _base;
859
- if (typeof (_base = _this.listeners).connect === "function") {
860
- _base.connect();
861
- }
862
- _this.log("LiveReload is connected to " + _this.options.host + ":" + _this.options.port + " (protocol v" + protocol + ").");
863
- return _this.analyze();
864
- },
865
- error: function(e) {
866
- if (e instanceof ProtocolError) {
867
- return console.log("" + e.message + ".");
868
- } else {
869
- return console.log("LiveReload internal error: " + e.message);
870
- }
871
- },
872
- disconnected: function(reason, nextDelay) {
873
- var _base;
874
- if (typeof (_base = _this.listeners).disconnect === "function") {
875
- _base.disconnect();
876
- }
877
- switch (reason) {
878
- case 'cannot-connect':
879
- return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + ", will retry in " + nextDelay + " sec.");
880
- case 'broken':
881
- return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + ", reconnecting in " + nextDelay + " sec.");
882
- case 'handshake-timeout':
883
- return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec.");
884
- case 'handshake-failed':
885
- return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake failed), will retry in " + nextDelay + " sec.");
886
- case 'manual':
887
- break;
888
- case 'error':
889
- break;
890
- default:
891
- return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec.");
892
- }
893
- },
894
- message: function(message) {
895
- switch (message.command) {
896
- case 'reload':
897
- return _this.performReload(message);
898
- case 'alert':
899
- return _this.performAlert(message);
900
- }
901
- }
902
- });
903
1117
  }
904
1118
 
905
- LiveReload.prototype.on = function(eventName, handler) {
906
- return this.listeners[eventName] = handler;
907
- };
1119
+ LiveReload.addPlugin(require('./less'));
908
1120
 
909
- LiveReload.prototype.log = function(message) {
910
- return this.console.log("" + message);
911
- };
1121
+ LiveReload.on('shutdown', function() {
1122
+ return delete window.LiveReload;
1123
+ });
912
1124
 
913
- LiveReload.prototype.performReload = function(message) {
914
- var _ref, _ref2;
915
- this.log("LiveReload received reload request for " + message.path + ".");
916
- return this.reloader.reload(message.path, {
917
- liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
918
- liveImg: (_ref2 = message.liveImg) != null ? _ref2 : true,
919
- originalPath: message.originalPath || '',
920
- overrideURL: message.overrideURL || '',
921
- serverURL: "http://" + this.options.host + ":" + this.options.port
922
- });
923
- };
1125
+ LiveReload.on('connect', function() {
1126
+ return CustomEvents.fire(document, 'LiveReloadConnect');
1127
+ });
924
1128
 
925
- LiveReload.prototype.performAlert = function(message) {
926
- return alert(message.message);
927
- };
1129
+ LiveReload.on('disconnect', function() {
1130
+ return CustomEvents.fire(document, 'LiveReloadDisconnect');
1131
+ });
928
1132
 
929
- LiveReload.prototype.shutDown = function() {
930
- var _base;
931
- this.connector.disconnect();
932
- this.log("LiveReload disconnected.");
933
- return typeof (_base = this.listeners).shutdown === "function" ? _base.shutdown() : void 0;
934
- };
1133
+ CustomEvents.bind(document, 'LiveReloadShutDown', function() {
1134
+ return LiveReload.shutDown();
1135
+ });
935
1136
 
936
- LiveReload.prototype.hasPlugin = function(identifier) {
937
- return !!this.pluginIdentifiers[identifier];
938
- };
1137
+ }).call(this);
939
1138
 
940
- LiveReload.prototype.addPlugin = function(pluginClass) {
941
- var plugin;
942
- var _this = this;
943
- if (this.hasPlugin(pluginClass.identifier)) return;
944
- this.pluginIdentifiers[pluginClass.identifier] = true;
945
- plugin = new pluginClass(this.window, {
946
- _livereload: this,
947
- _reloader: this.reloader,
948
- _connector: this.connector,
949
- console: this.console,
950
- Timer: Timer,
951
- generateCacheBustUrl: function(url) {
952
- return _this.reloader.generateCacheBustUrl(url);
953
- }
954
- });
955
- this.plugins.push(plugin);
956
- this.reloader.addPlugin(plugin);
957
- };
1139
+ },{"./customevents":2,"./less":3,"./livereload":4}],9:[function(require,module,exports){
1140
+ (function() {
1141
+ var Timer;
958
1142
 
959
- LiveReload.prototype.analyze = function() {
960
- var plugin, pluginData, pluginsData, _i, _len, _ref;
961
- if (!(this.connector.protocol >= 7)) return;
962
- pluginsData = {};
963
- _ref = this.plugins;
964
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
965
- plugin = _ref[_i];
966
- pluginsData[plugin.constructor.identifier] = pluginData = (typeof plugin.analyze === "function" ? plugin.analyze() : void 0) || {};
967
- pluginData.version = plugin.constructor.version;
1143
+ exports.Timer = Timer = (function() {
1144
+ function Timer(func) {
1145
+ this.func = func;
1146
+ this.running = false;
1147
+ this.id = null;
1148
+ this._handler = (function(_this) {
1149
+ return function() {
1150
+ _this.running = false;
1151
+ _this.id = null;
1152
+ return _this.func();
1153
+ };
1154
+ })(this);
968
1155
  }
969
- this.connector.sendCommand({
970
- command: 'info',
971
- plugins: pluginsData,
972
- url: this.window.location.href
973
- });
974
- };
975
-
976
- return LiveReload;
977
1156
 
978
- })();
979
-
980
- // less
981
- var LessPlugin;
982
- __less = LessPlugin = (function() {
983
- LessPlugin.identifier = 'less';
984
- LessPlugin.version = '1.0';
985
- function LessPlugin(window, host) {
986
- this.window = window;
987
- this.host = host;
988
- }
989
- LessPlugin.prototype.reload = function(path, options) {
990
- if (this.window.less && this.window.less.refresh) {
991
- if (path.match(/\.less$/i)) {
992
- return this.reloadLess(path);
1157
+ Timer.prototype.start = function(timeout) {
1158
+ if (this.running) {
1159
+ clearTimeout(this.id);
993
1160
  }
994
- if (options.originalPath.match(/\.less$/i)) {
995
- return this.reloadLess(options.originalPath);
996
- }
997
- }
998
- return false;
999
- };
1000
- LessPlugin.prototype.reloadLess = function(path) {
1001
- var link, links, _i, _len;
1002
- links = (function() {
1003
- var _i, _len, _ref, _results;
1004
- _ref = document.getElementsByTagName('link');
1005
- _results = [];
1006
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1007
- link = _ref[_i];
1008
- if (link.href && link.rel === 'stylesheet/less' || (link.rel.match(/stylesheet/) && link.type.match(/^text\/(x-)?less$/))) {
1009
- _results.push(link);
1010
- }
1161
+ this.id = setTimeout(this._handler, timeout);
1162
+ return this.running = true;
1163
+ };
1164
+
1165
+ Timer.prototype.stop = function() {
1166
+ if (this.running) {
1167
+ clearTimeout(this.id);
1168
+ this.running = false;
1169
+ return this.id = null;
1011
1170
  }
1012
- return _results;
1013
- })();
1014
- if (links.length === 0) {
1015
- return false;
1016
- }
1017
- for (_i = 0, _len = links.length; _i < _len; _i++) {
1018
- link = links[_i];
1019
- link.href = this.host.generateCacheBustUrl(link.href);
1020
- }
1021
- this.host.console.log("LiveReload is asking LESS to recompile all stylesheets");
1022
- this.window.less.refresh(true);
1023
- return true;
1024
- };
1025
- LessPlugin.prototype.analyze = function() {
1026
- return {
1027
- disable: !!(this.window.less && this.window.less.refresh)
1028
1171
  };
1172
+
1173
+ return Timer;
1174
+
1175
+ })();
1176
+
1177
+ Timer.start = function(timeout, func) {
1178
+ return setTimeout(func, timeout);
1029
1179
  };
1030
- return LessPlugin;
1031
- })();
1032
-
1033
- // startup
1034
- var CustomEvents, LiveReload, k;
1035
- CustomEvents = __customevents;
1036
- LiveReload = window.LiveReload = new (__livereload.LiveReload)(window);
1037
- for (k in window) {
1038
- if (k.match(/^LiveReloadPlugin/)) {
1039
- LiveReload.addPlugin(window[k]);
1040
- }
1041
- }
1042
- LiveReload.addPlugin(__less);
1043
- LiveReload.on('shutdown', function() {
1044
- return delete window.LiveReload;
1045
- });
1046
- LiveReload.on('connect', function() {
1047
- return CustomEvents.fire(document, 'LiveReloadConnect');
1048
- });
1049
- LiveReload.on('disconnect', function() {
1050
- return CustomEvents.fire(document, 'LiveReloadDisconnect');
1051
- });
1052
- CustomEvents.bind(document, 'LiveReloadShutDown', function() {
1053
- return LiveReload.shutDown();
1054
- });
1055
- })();
1180
+
1181
+ }).call(this);
1182
+
1183
+ },{}]},{},[8]);