rack-livereload 0.3.17 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/js/livereload.js CHANGED
@@ -1,1055 +1,1056 @@
1
1
  (function() {
2
- var __customevents = {}, __protocol = {}, __connector = {}, __timer = {}, __options = {}, __reloader = {}, __livereload = {}, __less = {}, __startup = {};
2
+ var __customevents = {}, __protocol = {}, __connector = {}, __timer = {}, __options = {}, __reloader = {}, __livereload = {}, __less = {}, __startup = {};
3
3
 
4
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();
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
+ }
16
+ });
17
+ } else {
18
+ throw new Error("Attempt to attach custom event " + eventName + " to something which isn't a DOMElement");
19
+ }
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]++;
30
+ }
31
+ } else {
32
+ throw new Error("Attempt to fire custom event " + eventName + " on something which isn't a DOMElement");
33
+ }
15
34
  }
16
- });
17
- } else {
18
- throw new Error("Attempt to attach custom event " + eventName + " to something which isn't a DOMElement");
19
- }
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]++;
30
- }
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;
35
+ };
36
+ __customevents.bind = CustomEvents.bind;
37
+ __customevents.fire = CustomEvents.fire;
38
38
 
39
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");
78
- }
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;
79
44
  }
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");
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 + "\".";
85
52
  }
86
- command = message[0], options = message[1];
87
- if (command !== 'refresh') {
88
- throw new ProtocolError("unknown protocol 6 command");
53
+ return ProtocolError;
54
+ })();
55
+ __protocol.Parser = Parser = (function() {
56
+ function Parser(handlers) {
57
+ this.handlers = handlers;
58
+ this.reset();
89
59
  }
90
- return this.handlers.message({
91
- command: 'reload',
92
- path: options.path,
93
- liveCSS: (_ref = options.apply_css_live) != null ? _ref : true
94
- });
95
- } else {
96
- message = this._parseMessage(data, ['reload', 'alert']);
97
- return this.handlers.message(message);
98
- }
99
- } catch (e) {
100
- if (e instanceof ProtocolError) {
101
- return this.handlers.error(e);
102
- } else {
103
- throw e;
104
- }
105
- }
106
- };
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);
119
- }
120
- return message;
121
- };
122
- return Parser;
123
- })();
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");
78
+ }
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
+ });
95
+ } else {
96
+ message = this._parseMessage(data, ['reload', 'alert']);
97
+ return this.handlers.message(message);
98
+ }
99
+ } catch (e) {
100
+ if (e instanceof ProtocolError) {
101
+ return this.handlers.error(e);
102
+ } else {
103
+ throw e;
104
+ }
105
+ }
106
+ };
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);
119
+ }
120
+ return message;
121
+ };
122
+ return Parser;
123
+ })();
124
124
 
125
125
  // connector
126
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 = "ws://" + 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);
159
- }
160
- });
161
- this._handshakeTimeout = new Timer(function() {
162
- if (!_this._isSocketConnected()) {
163
- return;
164
- }
165
- _this._disconnectionReason = 'handshake-timeout';
166
- return _this.socket.close();
167
- });
168
- this._reconnectTimer = new Timer(function() {
169
- if (!_this._connectionDesired) {
170
- return;
171
- }
172
- return _this.connect();
173
- });
174
- this.connect();
175
- }
176
-
177
- Connector.prototype._isSocketConnected = function() {
178
- return this.socket && this.socket.readyState === this.WebSocket.OPEN;
179
- };
180
-
181
- Connector.prototype.connect = function() {
182
- var _this = this;
183
- this._connectionDesired = true;
184
- if (this._isSocketConnected()) {
185
- return;
186
- }
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);
194
- };
195
- this.socket.onclose = function(e) {
196
- return _this._onclose(e);
197
- };
198
- this.socket.onmessage = function(e) {
199
- return _this._onmessage(e);
200
- };
201
- return this.socket.onerror = function(e) {
202
- return _this._onerror(e);
203
- };
204
- };
205
-
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
- };
215
-
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
- };
225
-
226
- Connector.prototype.sendCommand = function(command) {
227
- if (this.protocol == null) {
228
- return;
229
- }
230
- return this._sendCommand(command);
231
- };
232
-
233
- Connector.prototype._sendCommand = function(command) {
234
- return this.socket.send(JSON.stringify(command));
235
- };
236
-
237
- Connector.prototype._closeOnError = function() {
238
- this._handshakeTimeout.stop();
239
- this._disconnectionReason = 'error';
240
- return this.socket.close();
241
- };
242
-
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
- };
264
-
265
- Connector.prototype._onclose = function(e) {
266
- this.protocol = 0;
267
- this.handlers.disconnected(this._disconnectionReason, this._nextDelay);
268
- return this._scheduleReconnection();
269
- };
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 = this.options.scheme + "://" + 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);
159
+ }
160
+ });
161
+ this._handshakeTimeout = new Timer(function() {
162
+ if (!_this._isSocketConnected()) {
163
+ return;
164
+ }
165
+ _this._disconnectionReason = 'handshake-timeout';
166
+ return _this.socket.close();
167
+ });
168
+ this._reconnectTimer = new Timer(function() {
169
+ if (!_this._connectionDesired) {
170
+ return;
171
+ }
172
+ return _this.connect();
173
+ });
174
+ this.connect();
175
+ }
270
176
 
271
- Connector.prototype._onerror = function(e) {};
177
+ Connector.prototype._isSocketConnected = function() {
178
+ return this.socket && this.socket.readyState === this.WebSocket.OPEN;
179
+ };
272
180
 
273
- Connector.prototype._onmessage = function(e) {
274
- return this.protocolParser.process(e.data);
275
- };
181
+ Connector.prototype.connect = function() {
182
+ var _this = this;
183
+ this._connectionDesired = true;
184
+ if (this._isSocketConnected()) {
185
+ return;
186
+ }
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);
194
+ };
195
+ this.socket.onclose = function(e) {
196
+ return _this._onclose(e);
197
+ };
198
+ this.socket.onmessage = function(e) {
199
+ return _this._onmessage(e);
200
+ };
201
+ return this.socket.onerror = function(e) {
202
+ return _this._onerror(e);
203
+ };
204
+ };
276
205
 
277
- return Connector;
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
+ };
278
215
 
279
- })();
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
+ };
280
225
 
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);
298
- }
299
- this.id = setTimeout(this._handler, timeout);
300
- return this.running = true;
301
- };
302
- Timer.prototype.stop = function() {
303
- if (this.running) {
304
- clearTimeout(this.id);
305
- this.running = false;
306
- return this.id = null;
307
- }
308
- };
309
- return Timer;
310
- })();
311
- Timer.start = function(timeout, func) {
312
- return setTimeout(func, timeout);
313
- };
226
+ Connector.prototype.sendCommand = function(command) {
227
+ if (this.protocol == null) {
228
+ return;
229
+ }
230
+ return this._sendCommand(command);
231
+ };
314
232
 
315
- // options
316
- var Options;
317
- __options.Options = Options = (function() {
318
- function Options() {
319
- this.host = null;
320
- this.port = RACK_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;
336
- }
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('='));
359
- }
360
- }
361
- }
362
- return options;
363
- }
364
- }
365
- return null;
366
- };
233
+ Connector.prototype._sendCommand = function(command) {
234
+ return this.socket.send(JSON.stringify(command));
235
+ };
367
236
 
368
- // reloader
369
- // Generated by CoffeeScript 1.3.1
370
- (function() {
371
- var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
372
-
373
- splitUrl = function(url) {
374
- var hash, index, params;
375
- if ((index = url.indexOf('#')) >= 0) {
376
- hash = url.slice(index);
377
- url = url.slice(0, index);
378
- } else {
379
- hash = '';
380
- }
381
- if ((index = url.indexOf('?')) >= 0) {
382
- params = url.slice(index);
383
- url = url.slice(0, index);
384
- } else {
385
- params = '';
386
- }
387
- return {
388
- url: url,
389
- params: params,
390
- hash: hash
391
- };
392
- };
393
-
394
- pathFromUrl = function(url) {
395
- var path;
396
- url = splitUrl(url).url;
397
- if (url.indexOf('file://') === 0) {
398
- path = url.replace(/^file:\/\/(localhost)?/, '');
399
- } else {
400
- path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/');
401
- }
402
- return decodeURIComponent(path);
403
- };
237
+ Connector.prototype._closeOnError = function() {
238
+ this._handshakeTimeout.stop();
239
+ this._disconnectionReason = 'error';
240
+ return this.socket.close();
241
+ };
404
242
 
405
- pickBestMatch = function(path, objects, pathFunc) {
406
- var bestMatch, object, score, _i, _len;
407
- bestMatch = {
408
- score: 0
409
- };
410
- for (_i = 0, _len = objects.length; _i < _len; _i++) {
411
- object = objects[_i];
412
- score = numberOfMatchingSegments(path, pathFunc(object));
413
- if (score > bestMatch.score) {
414
- bestMatch = {
415
- object: object,
416
- score: score
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);
417
263
  };
418
- }
419
- }
420
- if (bestMatch.score > 0) {
421
- return bestMatch;
422
- } else {
423
- return null;
424
- }
425
- };
426
-
427
- numberOfMatchingSegments = function(path1, path2) {
428
- var comps1, comps2, eqCount, len;
429
- path1 = path1.replace(/^\/+/, '').toLowerCase();
430
- path2 = path2.replace(/^\/+/, '').toLowerCase();
431
- if (path1 === path2) {
432
- return 10000;
433
- }
434
- comps1 = path1.split('/').reverse();
435
- comps2 = path2.split('/').reverse();
436
- len = Math.min(comps1.length, comps2.length);
437
- eqCount = 0;
438
- while (eqCount < len && comps1[eqCount] === comps2[eqCount]) {
439
- ++eqCount;
440
- }
441
- return eqCount;
442
- };
443
-
444
- pathsMatch = function(path1, path2) {
445
- return numberOfMatchingSegments(path1, path2) > 0;
446
- };
447
-
448
- IMAGE_STYLES = [
449
- {
450
- selector: 'background',
451
- styleNames: ['backgroundImage']
452
- }, {
453
- selector: 'border',
454
- styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
455
- }
456
- ];
457
264
 
458
- __reloader.Reloader = Reloader = (function() {
265
+ Connector.prototype._onclose = function(e) {
266
+ this.protocol = 0;
267
+ this.handlers.disconnected(this._disconnectionReason, this._nextDelay);
268
+ return this._scheduleReconnection();
269
+ };
459
270
 
460
- Reloader.name = 'Reloader';
271
+ Connector.prototype._onerror = function(e) {};
461
272
 
462
- function Reloader(window, console, Timer) {
463
- this.window = window;
464
- this.console = console;
465
- this.Timer = Timer;
466
- this.document = this.window.document;
467
- this.importCacheWaitPeriod = 200;
468
- this.plugins = [];
469
- }
273
+ Connector.prototype._onmessage = function(e) {
274
+ return this.protocolParser.process(e.data);
275
+ };
470
276
 
471
- Reloader.prototype.addPlugin = function(plugin) {
472
- return this.plugins.push(plugin);
473
- };
277
+ return Connector;
474
278
 
475
- Reloader.prototype.analyze = function(callback) {
476
- return results;
477
- };
279
+ })();
478
280
 
479
- Reloader.prototype.reload = function(path, options) {
480
- var plugin, _base, _i, _len, _ref;
481
- this.options = options;
482
- if ((_base = this.options).stylesheetReloadTimeout == null) {
483
- _base.stylesheetReloadTimeout = 15000;
484
- }
485
- _ref = this.plugins;
486
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
487
- plugin = _ref[_i];
488
- if (plugin.reload && plugin.reload(path, options)) {
489
- return;
490
- }
491
- }
492
- if (options.liveCSS) {
493
- if (path.match(/\.css$/i)) {
494
- if (this.reloadStylesheet(path)) {
495
- return;
496
- }
497
- }
498
- }
499
- if (options.liveImg) {
500
- if (path.match(/\.(jpe?g|png|gif)$/i)) {
501
- this.reloadImages(path);
502
- return;
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);
503
294
  }
504
- }
505
- return this.reloadPage();
506
- };
507
-
508
- Reloader.prototype.reloadPage = function() {
509
- return this.window.document.location.reload();
295
+ Timer.prototype.start = function(timeout) {
296
+ if (this.running) {
297
+ clearTimeout(this.id);
298
+ }
299
+ this.id = setTimeout(this._handler, timeout);
300
+ return this.running = true;
301
+ };
302
+ Timer.prototype.stop = function() {
303
+ if (this.running) {
304
+ clearTimeout(this.id);
305
+ this.running = false;
306
+ return this.id = null;
307
+ }
308
+ };
309
+ return Timer;
310
+ })();
311
+ Timer.start = function(timeout, func) {
312
+ return setTimeout(func, timeout);
510
313
  };
511
314
 
512
- Reloader.prototype.reloadImages = function(path) {
513
- var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results;
514
- expando = this.generateUniqueString();
515
- _ref = this.document.images;
516
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
517
- img = _ref[_i];
518
- if (pathsMatch(path, pathFromUrl(img.src))) {
519
- img.src = this.generateCacheBustUrl(img.src, expando);
520
- }
521
- }
522
- if (this.document.querySelectorAll) {
523
- for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
524
- _ref1 = IMAGE_STYLES[_j], selector = _ref1.selector, styleNames = _ref1.styleNames;
525
- _ref2 = this.document.querySelectorAll("[style*=" + selector + "]");
526
- for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
527
- img = _ref2[_k];
528
- this.reloadStyleImages(img.style, styleNames, path, expando);
529
- }
530
- }
531
- }
532
- if (this.document.styleSheets) {
533
- _ref3 = this.document.styleSheets;
534
- _results = [];
535
- for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
536
- styleSheet = _ref3[_l];
537
- _results.push(this.reloadStylesheetImages(styleSheet, path, expando));
315
+ // options
316
+ var Options;
317
+ __options.Options = Options = (function() {
318
+ function Options() {
319
+ this.host = null;
320
+ this.port = RACK_LIVERELOAD_PORT;
321
+ this.scheme = RACK_LIVERELOAD_SCHEME;
322
+ this.snipver = null;
323
+ this.ext = null;
324
+ this.extver = null;
325
+ this.mindelay = 1000;
326
+ this.maxdelay = 60000;
327
+ this.handshake_timeout = 5000;
538
328
  }
539
- return _results;
540
- }
541
- };
542
-
543
- Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
544
- var rule, rules, styleNames, _i, _j, _len, _len1;
545
- try {
546
- rules = styleSheet != null ? styleSheet.cssRules : void 0;
547
- } catch (e) {
548
-
549
- }
550
- if (!rules) {
551
- return;
552
- }
553
- for (_i = 0, _len = rules.length; _i < _len; _i++) {
554
- rule = rules[_i];
555
- switch (rule.type) {
556
- case CSSRule.IMPORT_RULE:
557
- this.reloadStylesheetImages(rule.styleSheet, path, expando);
558
- break;
559
- case CSSRule.STYLE_RULE:
560
- for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
561
- styleNames = IMAGE_STYLES[_j].styleNames;
562
- this.reloadStyleImages(rule.style, styleNames, path, expando);
329
+ Options.prototype.set = function(name, value) {
330
+ switch (typeof this[name]) {
331
+ case 'undefined':
332
+ break;
333
+ case 'number':
334
+ return this[name] = +value;
335
+ default:
336
+ return this[name] = value;
337
+ }
338
+ };
339
+ return Options;
340
+ })();
341
+ Options.extract = function(document) {
342
+ var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len2, _ref, _ref2;
343
+ _ref = document.getElementsByTagName('script');
344
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
345
+ element = _ref[_i];
346
+ if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) {
347
+ options = new Options();
348
+ if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?$/)) {
349
+ options.host = mm[1];
350
+ if (mm[2]) {
351
+ options.port = parseInt(mm[2], 10);
352
+ }
353
+ }
354
+ if (m[2]) {
355
+ _ref2 = m[2].split('&');
356
+ for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
357
+ pair = _ref2[_j];
358
+ if ((keyAndValue = pair.split('=')).length > 1) {
359
+ options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('='));
360
+ }
361
+ }
362
+ }
363
+ return options;
563
364
  }
564
- break;
565
- case CSSRule.MEDIA_RULE:
566
- this.reloadStylesheetImages(rule, path, expando);
567
365
  }
568
- }
366
+ return null;
569
367
  };
570
368
 
571
- Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
572
- var newValue, styleName, value, _i, _len,
573
- _this = this;
574
- for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
575
- styleName = styleNames[_i];
576
- value = style[styleName];
577
- 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)) + ")";
369
+ // reloader
370
+ // Generated by CoffeeScript 1.3.1
371
+ (function() {
372
+ var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
373
+
374
+ splitUrl = function(url) {
375
+ var hash, index, params;
376
+ if ((index = url.indexOf('#')) >= 0) {
377
+ hash = url.slice(index);
378
+ url = url.slice(0, index);
581
379
  } else {
582
- return match;
380
+ hash = '';
583
381
  }
584
- });
585
- if (newValue !== value) {
586
- style[styleName] = newValue;
587
- }
588
- }
589
- }
590
- };
382
+ if ((index = url.indexOf('?')) >= 0) {
383
+ params = url.slice(index);
384
+ url = url.slice(0, index);
385
+ } else {
386
+ params = '';
387
+ }
388
+ return {
389
+ url: url,
390
+ params: params,
391
+ hash: hash
392
+ };
393
+ };
591
394
 
592
- 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;
595
- links = (function() {
596
- var _i, _len, _ref, _results;
597
- _ref = this.document.getElementsByTagName('link');
598
- _results = [];
599
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
600
- link = _ref[_i];
601
- if (link.rel === 'stylesheet' && !link.__LiveReload_pendingRemoval) {
602
- _results.push(link);
603
- }
604
- }
605
- return _results;
606
- }).call(this);
607
- imported = [];
608
- _ref = this.document.getElementsByTagName('style');
609
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
610
- style = _ref[_i];
611
- if (style.sheet) {
612
- this.collectImportedStylesheets(style, style.sheet, imported);
613
- }
614
- }
615
- for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
616
- link = links[_j];
617
- this.collectImportedStylesheets(link, link.sheet, imported);
618
- }
619
- if (this.window.StyleFix && this.document.querySelectorAll) {
620
- _ref1 = this.document.querySelectorAll('style[data-href]');
621
- for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
622
- style = _ref1[_k];
623
- links.push(style);
624
- }
625
- }
626
- 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
- });
630
- if (match) {
631
- if (match.object.rule) {
632
- this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
633
- this.reattachImportedRule(match.object);
634
- } else {
635
- this.console.log("LiveReload is reloading stylesheet: " + (this.linkHref(match.object)));
636
- this.reattachStylesheetLink(match.object);
637
- }
638
- } else {
639
- this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one");
640
- for (_l = 0, _len3 = links.length; _l < _len3; _l++) {
641
- link = links[_l];
642
- this.reattachStylesheetLink(link);
643
- }
644
- }
645
- return true;
646
- };
395
+ pathFromUrl = function(url) {
396
+ var path;
397
+ url = splitUrl(url).url;
398
+ if (url.indexOf('file://') === 0) {
399
+ path = url.replace(/^file:\/\/(localhost)?/, '');
400
+ } else {
401
+ path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/');
402
+ }
403
+ return decodeURIComponent(path);
404
+ };
647
405
 
648
- Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
649
- var index, rule, rules, _i, _len;
650
- try {
651
- rules = styleSheet != null ? styleSheet.cssRules : void 0;
652
- } catch (e) {
653
-
654
- }
655
- if (rules && rules.length) {
656
- for (index = _i = 0, _len = rules.length; _i < _len; index = ++_i) {
657
- rule = rules[index];
658
- switch (rule.type) {
659
- case CSSRule.CHARSET_RULE:
660
- continue;
661
- case CSSRule.IMPORT_RULE:
662
- result.push({
663
- link: link,
664
- rule: rule,
665
- index: index,
666
- href: rule.href
667
- });
668
- this.collectImportedStylesheets(link, rule.styleSheet, result);
669
- break;
670
- default:
671
- break;
672
- }
673
- }
674
- }
675
- };
406
+ pickBestMatch = function(path, objects, pathFunc) {
407
+ var bestMatch, object, score, _i, _len;
408
+ bestMatch = {
409
+ score: 0
410
+ };
411
+ for (_i = 0, _len = objects.length; _i < _len; _i++) {
412
+ object = objects[_i];
413
+ score = numberOfMatchingSegments(path, pathFunc(object));
414
+ if (score > bestMatch.score) {
415
+ bestMatch = {
416
+ object: object,
417
+ score: score
418
+ };
419
+ }
420
+ }
421
+ if (bestMatch.score > 0) {
422
+ return bestMatch;
423
+ } else {
424
+ return null;
425
+ }
426
+ };
676
427
 
677
- Reloader.prototype.waitUntilCssLoads = function(clone, func) {
678
- var callbackExecuted, executeCallback, poll,
679
- _this = this;
680
- 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);
700
- }
701
- })();
702
- }
703
- return this.Timer.start(this.options.stylesheetReloadTimeout, executeCallback);
704
- };
428
+ numberOfMatchingSegments = function(path1, path2) {
429
+ var comps1, comps2, eqCount, len;
430
+ path1 = path1.replace(/^\/+/, '').toLowerCase();
431
+ path2 = path2.replace(/^\/+/, '').toLowerCase();
432
+ if (path1 === path2) {
433
+ return 10000;
434
+ }
435
+ comps1 = path1.split('/').reverse();
436
+ comps2 = path2.split('/').reverse();
437
+ len = Math.min(comps1.length, comps2.length);
438
+ eqCount = 0;
439
+ while (eqCount < len && comps1[eqCount] === comps2[eqCount]) {
440
+ ++eqCount;
441
+ }
442
+ return eqCount;
443
+ };
705
444
 
706
- Reloader.prototype.linkHref = function(link) {
707
- return link.href || link.getAttribute('data-href');
708
- };
445
+ pathsMatch = function(path1, path2) {
446
+ return numberOfMatchingSegments(path1, path2) > 0;
447
+ };
709
448
 
710
- Reloader.prototype.reattachStylesheetLink = function(link) {
711
- var clone, parent,
712
- _this = this;
713
- if (link.__LiveReload_pendingRemoval) {
714
- return;
715
- }
716
- link.__LiveReload_pendingRemoval = true;
717
- if (link.tagName === 'STYLE') {
718
- clone = this.document.createElement('link');
719
- clone.rel = 'stylesheet';
720
- clone.media = link.media;
721
- clone.disabled = link.disabled;
722
- } else {
723
- clone = link.cloneNode(false);
724
- }
725
- clone.href = this.generateCacheBustUrl(this.linkHref(link));
726
- parent = link.parentNode;
727
- if (parent.lastChild === link) {
728
- parent.appendChild(clone);
729
- } else {
730
- parent.insertBefore(clone, link.nextSibling);
731
- }
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;
743
- }
744
- link.parentNode.removeChild(link);
745
- clone.onreadystatechange = null;
746
- return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0;
747
- });
748
- });
749
- };
449
+ IMAGE_STYLES = [
450
+ {
451
+ selector: 'background',
452
+ styleNames: ['backgroundImage']
453
+ }, {
454
+ selector: 'border',
455
+ styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
456
+ }
457
+ ];
750
458
 
751
- Reloader.prototype.reattachImportedRule = function(_arg) {
752
- var href, index, link, media, newRule, parent, rule, tempLink,
753
- _this = this;
754
- rule = _arg.rule, index = _arg.index, link = _arg.link;
755
- parent = rule.parentStyleSheet;
756
- href = this.generateCacheBustUrl(rule.href);
757
- media = rule.media.length ? [].join.call(rule.media, ', ') : '';
758
- newRule = "@import url(\"" + href + "\") " + media + ";";
759
- rule.__LiveReload_newHref = href;
760
- tempLink = this.document.createElement("link");
761
- tempLink.rel = 'stylesheet';
762
- tempLink.href = href;
763
- tempLink.__LiveReload_pendingRemoval = true;
764
- if (link.parentNode) {
765
- link.parentNode.insertBefore(tempLink, link);
766
- }
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() {
779
- if (rule.__LiveReload_newHref !== href) {
780
- return;
781
- }
782
- parent.insertRule(newRule, index);
783
- return parent.deleteRule(index + 1);
784
- });
785
- });
786
- };
459
+ __reloader.Reloader = Reloader = (function() {
787
460
 
788
- Reloader.prototype.generateUniqueString = function() {
789
- return 'livereload=' + Date.now();
790
- };
461
+ Reloader.name = 'Reloader';
791
462
 
792
- Reloader.prototype.generateCacheBustUrl = function(url, expando) {
793
- var hash, oldParams, params, _ref;
794
- if (expando == null) {
795
- expando = this.generateUniqueString();
796
- }
797
- _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
798
- if (this.options.overrideURL) {
799
- if (url.indexOf(this.options.serverURL) < 0) {
800
- url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url);
801
- }
802
- }
803
- params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
804
- return "" + sep + expando;
805
- });
806
- if (params === oldParams) {
807
- if (oldParams.length === 0) {
808
- params = "?" + expando;
809
- } else {
810
- params = "" + oldParams + "&" + expando;
811
- }
812
- }
813
- return url + params + hash;
814
- };
463
+ function Reloader(window, console, Timer) {
464
+ this.window = window;
465
+ this.console = console;
466
+ this.Timer = Timer;
467
+ this.document = this.window.document;
468
+ this.importCacheWaitPeriod = 200;
469
+ this.plugins = [];
470
+ }
815
471
 
816
- return Reloader;
472
+ Reloader.prototype.addPlugin = function(plugin) {
473
+ return this.plugins.push(plugin);
474
+ };
475
+
476
+ Reloader.prototype.analyze = function(callback) {
477
+ return results;
478
+ };
479
+
480
+ Reloader.prototype.reload = function(path, options) {
481
+ var plugin, _base, _i, _len, _ref;
482
+ this.options = options;
483
+ if ((_base = this.options).stylesheetReloadTimeout == null) {
484
+ _base.stylesheetReloadTimeout = 15000;
485
+ }
486
+ _ref = this.plugins;
487
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
488
+ plugin = _ref[_i];
489
+ if (plugin.reload && plugin.reload(path, options)) {
490
+ return;
491
+ }
492
+ }
493
+ if (options.liveCSS) {
494
+ if (path.match(/\.css$/i)) {
495
+ if (this.reloadStylesheet(path)) {
496
+ return;
497
+ }
498
+ }
499
+ }
500
+ if (options.liveImg) {
501
+ if (path.match(/\.(jpe?g|png|gif)$/i)) {
502
+ this.reloadImages(path);
503
+ return;
504
+ }
505
+ }
506
+ return this.reloadPage();
507
+ };
508
+
509
+ Reloader.prototype.reloadPage = function() {
510
+ return this.window.document.location.reload();
511
+ };
512
+
513
+ Reloader.prototype.reloadImages = function(path) {
514
+ var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results;
515
+ expando = this.generateUniqueString();
516
+ _ref = this.document.images;
517
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
518
+ img = _ref[_i];
519
+ if (pathsMatch(path, pathFromUrl(img.src))) {
520
+ img.src = this.generateCacheBustUrl(img.src, expando);
521
+ }
522
+ }
523
+ if (this.document.querySelectorAll) {
524
+ for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
525
+ _ref1 = IMAGE_STYLES[_j], selector = _ref1.selector, styleNames = _ref1.styleNames;
526
+ _ref2 = this.document.querySelectorAll("[style*=" + selector + "]");
527
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
528
+ img = _ref2[_k];
529
+ this.reloadStyleImages(img.style, styleNames, path, expando);
530
+ }
531
+ }
532
+ }
533
+ if (this.document.styleSheets) {
534
+ _ref3 = this.document.styleSheets;
535
+ _results = [];
536
+ for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
537
+ styleSheet = _ref3[_l];
538
+ _results.push(this.reloadStylesheetImages(styleSheet, path, expando));
539
+ }
540
+ return _results;
541
+ }
542
+ };
543
+
544
+ Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
545
+ var rule, rules, styleNames, _i, _j, _len, _len1;
546
+ try {
547
+ rules = styleSheet != null ? styleSheet.cssRules : void 0;
548
+ } catch (e) {
549
+
550
+ }
551
+ if (!rules) {
552
+ return;
553
+ }
554
+ for (_i = 0, _len = rules.length; _i < _len; _i++) {
555
+ rule = rules[_i];
556
+ switch (rule.type) {
557
+ case CSSRule.IMPORT_RULE:
558
+ this.reloadStylesheetImages(rule.styleSheet, path, expando);
559
+ break;
560
+ case CSSRule.STYLE_RULE:
561
+ for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
562
+ styleNames = IMAGE_STYLES[_j].styleNames;
563
+ this.reloadStyleImages(rule.style, styleNames, path, expando);
564
+ }
565
+ break;
566
+ case CSSRule.MEDIA_RULE:
567
+ this.reloadStylesheetImages(rule, path, expando);
568
+ }
569
+ }
570
+ };
571
+
572
+ Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
573
+ var newValue, styleName, value, _i, _len,
574
+ _this = this;
575
+ for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
576
+ styleName = styleNames[_i];
577
+ value = style[styleName];
578
+ if (typeof value === 'string') {
579
+ newValue = value.replace(/\burl\s*\(([^)]*)\)/, function(match, src) {
580
+ if (pathsMatch(path, pathFromUrl(src))) {
581
+ return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")";
582
+ } else {
583
+ return match;
584
+ }
585
+ });
586
+ if (newValue !== value) {
587
+ style[styleName] = newValue;
588
+ }
589
+ }
590
+ }
591
+ };
592
+
593
+ Reloader.prototype.reloadStylesheet = function(path) {
594
+ var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1,
595
+ _this = this;
596
+ links = (function() {
597
+ var _i, _len, _ref, _results;
598
+ _ref = this.document.getElementsByTagName('link');
599
+ _results = [];
600
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
601
+ link = _ref[_i];
602
+ if (link.rel === 'stylesheet' && !link.__LiveReload_pendingRemoval) {
603
+ _results.push(link);
604
+ }
605
+ }
606
+ return _results;
607
+ }).call(this);
608
+ imported = [];
609
+ _ref = this.document.getElementsByTagName('style');
610
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
611
+ style = _ref[_i];
612
+ if (style.sheet) {
613
+ this.collectImportedStylesheets(style, style.sheet, imported);
614
+ }
615
+ }
616
+ for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
617
+ link = links[_j];
618
+ this.collectImportedStylesheets(link, link.sheet, imported);
619
+ }
620
+ if (this.window.StyleFix && this.document.querySelectorAll) {
621
+ _ref1 = this.document.querySelectorAll('style[data-href]');
622
+ for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
623
+ style = _ref1[_k];
624
+ links.push(style);
625
+ }
626
+ }
627
+ this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets");
628
+ match = pickBestMatch(path, links.concat(imported), function(l) {
629
+ return pathFromUrl(_this.linkHref(l));
630
+ });
631
+ if (match) {
632
+ if (match.object.rule) {
633
+ this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
634
+ this.reattachImportedRule(match.object);
635
+ } else {
636
+ this.console.log("LiveReload is reloading stylesheet: " + (this.linkHref(match.object)));
637
+ this.reattachStylesheetLink(match.object);
638
+ }
639
+ } else {
640
+ this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one");
641
+ for (_l = 0, _len3 = links.length; _l < _len3; _l++) {
642
+ link = links[_l];
643
+ this.reattachStylesheetLink(link);
644
+ }
645
+ }
646
+ return true;
647
+ };
648
+
649
+ Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
650
+ var index, rule, rules, _i, _len;
651
+ try {
652
+ rules = styleSheet != null ? styleSheet.cssRules : void 0;
653
+ } catch (e) {
654
+
655
+ }
656
+ if (rules && rules.length) {
657
+ for (index = _i = 0, _len = rules.length; _i < _len; index = ++_i) {
658
+ rule = rules[index];
659
+ switch (rule.type) {
660
+ case CSSRule.CHARSET_RULE:
661
+ continue;
662
+ case CSSRule.IMPORT_RULE:
663
+ result.push({
664
+ link: link,
665
+ rule: rule,
666
+ index: index,
667
+ href: rule.href
668
+ });
669
+ this.collectImportedStylesheets(link, rule.styleSheet, result);
670
+ break;
671
+ default:
672
+ break;
673
+ }
674
+ }
675
+ }
676
+ };
677
+
678
+ Reloader.prototype.waitUntilCssLoads = function(clone, func) {
679
+ var callbackExecuted, executeCallback, poll,
680
+ _this = this;
681
+ callbackExecuted = false;
682
+ executeCallback = function() {
683
+ if (callbackExecuted) {
684
+ return;
685
+ }
686
+ callbackExecuted = true;
687
+ return func();
688
+ };
689
+ clone.onload = function() {
690
+ console.log("onload!");
691
+ _this.knownToSupportCssOnLoad = true;
692
+ return executeCallback();
693
+ };
694
+ if (!this.knownToSupportCssOnLoad) {
695
+ (poll = function() {
696
+ if (clone.sheet) {
697
+ console.log("polling!");
698
+ return executeCallback();
699
+ } else {
700
+ return _this.Timer.start(50, poll);
701
+ }
702
+ })();
703
+ }
704
+ return this.Timer.start(this.options.stylesheetReloadTimeout, executeCallback);
705
+ };
706
+
707
+ Reloader.prototype.linkHref = function(link) {
708
+ return link.href || link.getAttribute('data-href');
709
+ };
710
+
711
+ Reloader.prototype.reattachStylesheetLink = function(link) {
712
+ var clone, parent,
713
+ _this = this;
714
+ if (link.__LiveReload_pendingRemoval) {
715
+ return;
716
+ }
717
+ link.__LiveReload_pendingRemoval = true;
718
+ if (link.tagName === 'STYLE') {
719
+ clone = this.document.createElement('link');
720
+ clone.rel = 'stylesheet';
721
+ clone.media = link.media;
722
+ clone.disabled = link.disabled;
723
+ } else {
724
+ clone = link.cloneNode(false);
725
+ }
726
+ clone.href = this.generateCacheBustUrl(this.linkHref(link));
727
+ parent = link.parentNode;
728
+ if (parent.lastChild === link) {
729
+ parent.appendChild(clone);
730
+ } else {
731
+ parent.insertBefore(clone, link.nextSibling);
732
+ }
733
+ return this.waitUntilCssLoads(clone, function() {
734
+ var additionalWaitingTime;
735
+ if (/AppleWebKit/.test(navigator.userAgent)) {
736
+ additionalWaitingTime = 5;
737
+ } else {
738
+ additionalWaitingTime = 200;
739
+ }
740
+ return _this.Timer.start(additionalWaitingTime, function() {
741
+ var _ref;
742
+ if (!link.parentNode) {
743
+ return;
744
+ }
745
+ link.parentNode.removeChild(link);
746
+ clone.onreadystatechange = null;
747
+ return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0;
748
+ });
749
+ });
750
+ };
751
+
752
+ Reloader.prototype.reattachImportedRule = function(_arg) {
753
+ var href, index, link, media, newRule, parent, rule, tempLink,
754
+ _this = this;
755
+ rule = _arg.rule, index = _arg.index, link = _arg.link;
756
+ parent = rule.parentStyleSheet;
757
+ href = this.generateCacheBustUrl(rule.href);
758
+ media = rule.media.length ? [].join.call(rule.media, ', ') : '';
759
+ newRule = "@import url(\"" + href + "\") " + media + ";";
760
+ rule.__LiveReload_newHref = href;
761
+ tempLink = this.document.createElement("link");
762
+ tempLink.rel = 'stylesheet';
763
+ tempLink.href = href;
764
+ tempLink.__LiveReload_pendingRemoval = true;
765
+ if (link.parentNode) {
766
+ link.parentNode.insertBefore(tempLink, link);
767
+ }
768
+ return this.Timer.start(this.importCacheWaitPeriod, function() {
769
+ if (tempLink.parentNode) {
770
+ tempLink.parentNode.removeChild(tempLink);
771
+ }
772
+ if (rule.__LiveReload_newHref !== href) {
773
+ return;
774
+ }
775
+ parent.insertRule(newRule, index);
776
+ parent.deleteRule(index + 1);
777
+ rule = parent.cssRules[index];
778
+ rule.__LiveReload_newHref = href;
779
+ return _this.Timer.start(_this.importCacheWaitPeriod, function() {
780
+ if (rule.__LiveReload_newHref !== href) {
781
+ return;
782
+ }
783
+ parent.insertRule(newRule, index);
784
+ return parent.deleteRule(index + 1);
785
+ });
786
+ });
787
+ };
788
+
789
+ Reloader.prototype.generateUniqueString = function() {
790
+ return 'livereload=' + Date.now();
791
+ };
792
+
793
+ Reloader.prototype.generateCacheBustUrl = function(url, expando) {
794
+ var hash, oldParams, params, _ref;
795
+ if (expando == null) {
796
+ expando = this.generateUniqueString();
797
+ }
798
+ _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
799
+ if (this.options.overrideURL) {
800
+ if (url.indexOf(this.options.serverURL) < 0) {
801
+ url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url);
802
+ }
803
+ }
804
+ params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
805
+ return "" + sep + expando;
806
+ });
807
+ if (params === oldParams) {
808
+ if (oldParams.length === 0) {
809
+ params = "?" + expando;
810
+ } else {
811
+ params = "" + oldParams + "&" + expando;
812
+ }
813
+ }
814
+ return url + params + hash;
815
+ };
816
+
817
+ return Reloader;
817
818
 
818
- })();
819
+ })();
819
820
 
820
- }).call(this);
821
+ }).call(this);
821
822
 
822
823
  // livereload
823
- var Connector, LiveReload, Options, Reloader, Timer;
824
+ var Connector, LiveReload, Options, Reloader, Timer;
824
825
 
825
- Connector = __connector.Connector;
826
+ Connector = __connector.Connector;
826
827
 
827
- Timer = __timer.Timer;
828
+ Timer = __timer.Timer;
828
829
 
829
- Options = __options.Options;
830
+ Options = __options.Options;
830
831
 
831
- Reloader = __reloader.Reloader;
832
+ Reloader = __reloader.Reloader;
832
833
 
833
- __livereload.LiveReload = LiveReload = (function() {
834
+ __livereload.LiveReload = LiveReload = (function() {
834
835
 
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;
852
- }
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);
836
+ function LiveReload(window) {
837
+ var _this = this;
838
+ this.window = window;
839
+ this.listeners = {};
840
+ this.plugins = [];
841
+ this.pluginIdentifiers = {};
842
+ this.console = this.window.location.href.match(/LR-verbose/) && this.window.console && this.window.console.log && this.window.console.error ? this.window.console : {
843
+ log: function() {},
844
+ error: function() {}
845
+ };
846
+ if (!(this.WebSocket = this.window.WebSocket || this.window.MozWebSocket)) {
847
+ console.error("LiveReload disabled because the browser does not seem to support web sockets");
848
+ return;
849
+ }
850
+ if (!(this.options = Options.extract(this.window.document))) {
851
+ console.error("LiveReload disabled because it could not find its own <SCRIPT> tag");
852
+ return;
853
+ }
854
+ this.reloader = new Reloader(this.window, this.console, Timer);
855
+ this.connector = new Connector(this.options, this.WebSocket, Timer, {
856
+ connecting: function() {},
857
+ socketConnected: function() {},
858
+ connected: function(protocol) {
859
+ var _base;
860
+ if (typeof (_base = _this.listeners).connect === "function") {
861
+ _base.connect();
862
+ }
863
+ _this.log("LiveReload is connected to " + _this.options.host + ":" + _this.options.port + " (protocol v" + protocol + ").");
864
+ return _this.analyze();
865
+ },
866
+ error: function(e) {
867
+ if (e instanceof ProtocolError) {
868
+ return console.log("" + e.message + ".");
869
+ } else {
870
+ return console.log("LiveReload internal error: " + e.message);
871
+ }
872
+ },
873
+ disconnected: function(reason, nextDelay) {
874
+ var _base;
875
+ if (typeof (_base = _this.listeners).disconnect === "function") {
876
+ _base.disconnect();
877
+ }
878
+ switch (reason) {
879
+ case 'cannot-connect':
880
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + ", will retry in " + nextDelay + " sec.");
881
+ case 'broken':
882
+ return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + ", reconnecting in " + nextDelay + " sec.");
883
+ case 'handshake-timeout':
884
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec.");
885
+ case 'handshake-failed':
886
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake failed), will retry in " + nextDelay + " sec.");
887
+ case 'manual':
888
+ break;
889
+ case 'error':
890
+ break;
891
+ default:
892
+ return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec.");
893
+ }
894
+ },
895
+ message: function(message) {
896
+ switch (message.command) {
897
+ case 'reload':
898
+ return _this.performReload(message);
899
+ case 'alert':
900
+ return _this.performAlert(message);
901
+ }
902
+ }
903
+ });
900
904
  }
901
- }
902
- });
903
- }
904
-
905
- LiveReload.prototype.on = function(eventName, handler) {
906
- return this.listeners[eventName] = handler;
907
- };
908
-
909
- LiveReload.prototype.log = function(message) {
910
- return this.console.log("" + message);
911
- };
912
-
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
- };
924
-
925
- LiveReload.prototype.performAlert = function(message) {
926
- return alert(message.message);
927
- };
928
-
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
- };
935
-
936
- LiveReload.prototype.hasPlugin = function(identifier) {
937
- return !!this.pluginIdentifiers[identifier];
938
- };
939
-
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
- };
958
-
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;
968
- }
969
- this.connector.sendCommand({
970
- command: 'info',
971
- plugins: pluginsData,
972
- url: this.window.location.href
973
- });
974
- };
975
905
 
976
- return LiveReload;
906
+ LiveReload.prototype.on = function(eventName, handler) {
907
+ return this.listeners[eventName] = handler;
908
+ };
909
+
910
+ LiveReload.prototype.log = function(message) {
911
+ return this.console.log("" + message);
912
+ };
913
+
914
+ LiveReload.prototype.performReload = function(message) {
915
+ var _ref, _ref2;
916
+ this.log("LiveReload received reload request for " + message.path + ".");
917
+ return this.reloader.reload(message.path, {
918
+ liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
919
+ liveImg: (_ref2 = message.liveImg) != null ? _ref2 : true,
920
+ originalPath: message.originalPath || '',
921
+ overrideURL: message.overrideURL || '',
922
+ serverURL: "http://" + this.options.host + ":" + this.options.port
923
+ });
924
+ };
925
+
926
+ LiveReload.prototype.performAlert = function(message) {
927
+ return alert(message.message);
928
+ };
929
+
930
+ LiveReload.prototype.shutDown = function() {
931
+ var _base;
932
+ this.connector.disconnect();
933
+ this.log("LiveReload disconnected.");
934
+ return typeof (_base = this.listeners).shutdown === "function" ? _base.shutdown() : void 0;
935
+ };
936
+
937
+ LiveReload.prototype.hasPlugin = function(identifier) {
938
+ return !!this.pluginIdentifiers[identifier];
939
+ };
940
+
941
+ LiveReload.prototype.addPlugin = function(pluginClass) {
942
+ var plugin;
943
+ var _this = this;
944
+ if (this.hasPlugin(pluginClass.identifier)) return;
945
+ this.pluginIdentifiers[pluginClass.identifier] = true;
946
+ plugin = new pluginClass(this.window, {
947
+ _livereload: this,
948
+ _reloader: this.reloader,
949
+ _connector: this.connector,
950
+ console: this.console,
951
+ Timer: Timer,
952
+ generateCacheBustUrl: function(url) {
953
+ return _this.reloader.generateCacheBustUrl(url);
954
+ }
955
+ });
956
+ this.plugins.push(plugin);
957
+ this.reloader.addPlugin(plugin);
958
+ };
959
+
960
+ LiveReload.prototype.analyze = function() {
961
+ var plugin, pluginData, pluginsData, _i, _len, _ref;
962
+ if (!(this.connector.protocol >= 7)) return;
963
+ pluginsData = {};
964
+ _ref = this.plugins;
965
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
966
+ plugin = _ref[_i];
967
+ pluginsData[plugin.constructor.identifier] = pluginData = (typeof plugin.analyze === "function" ? plugin.analyze() : void 0) || {};
968
+ pluginData.version = plugin.constructor.version;
969
+ }
970
+ this.connector.sendCommand({
971
+ command: 'info',
972
+ plugins: pluginsData,
973
+ url: this.window.location.href
974
+ });
975
+ };
977
976
 
978
- })();
977
+ return LiveReload;
978
+
979
+ })();
979
980
 
980
981
  // 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);
993
- }
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);
982
+ var LessPlugin;
983
+ __less = LessPlugin = (function() {
984
+ LessPlugin.identifier = 'less';
985
+ LessPlugin.version = '1.0';
986
+ function LessPlugin(window, host) {
987
+ this.window = window;
988
+ this.host = host;
1010
989
  }
1011
- }
1012
- return _results;
990
+ LessPlugin.prototype.reload = function(path, options) {
991
+ if (this.window.less && this.window.less.refresh) {
992
+ if (path.match(/\.less$/i)) {
993
+ return this.reloadLess(path);
994
+ }
995
+ if (options.originalPath.match(/\.less$/i)) {
996
+ return this.reloadLess(options.originalPath);
997
+ }
998
+ }
999
+ return false;
1000
+ };
1001
+ LessPlugin.prototype.reloadLess = function(path) {
1002
+ var link, links, _i, _len;
1003
+ links = (function() {
1004
+ var _i, _len, _ref, _results;
1005
+ _ref = document.getElementsByTagName('link');
1006
+ _results = [];
1007
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1008
+ link = _ref[_i];
1009
+ if (link.href && link.rel === 'stylesheet/less' || (link.rel.match(/stylesheet/) && link.type.match(/^text\/(x-)?less$/))) {
1010
+ _results.push(link);
1011
+ }
1012
+ }
1013
+ return _results;
1014
+ })();
1015
+ if (links.length === 0) {
1016
+ return false;
1017
+ }
1018
+ for (_i = 0, _len = links.length; _i < _len; _i++) {
1019
+ link = links[_i];
1020
+ link.href = this.host.generateCacheBustUrl(link.href);
1021
+ }
1022
+ this.host.console.log("LiveReload is asking LESS to recompile all stylesheets");
1023
+ this.window.less.refresh(true);
1024
+ return true;
1025
+ };
1026
+ LessPlugin.prototype.analyze = function() {
1027
+ return {
1028
+ disable: !!(this.window.less && this.window.less.refresh)
1029
+ };
1030
+ };
1031
+ return LessPlugin;
1013
1032
  })();
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
- };
1029
- };
1030
- return LessPlugin;
1031
- })();
1032
1033
 
1033
1034
  // 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
- })();
1035
+ var CustomEvents, LiveReload, k;
1036
+ CustomEvents = __customevents;
1037
+ LiveReload = window.LiveReload = new (__livereload.LiveReload)(window);
1038
+ for (k in window) {
1039
+ if (k.match(/^LiveReloadPlugin/)) {
1040
+ LiveReload.addPlugin(window[k]);
1041
+ }
1042
+ }
1043
+ LiveReload.addPlugin(__less);
1044
+ LiveReload.on('shutdown', function() {
1045
+ return delete window.LiveReload;
1046
+ });
1047
+ LiveReload.on('connect', function() {
1048
+ return CustomEvents.fire(document, 'LiveReloadConnect');
1049
+ });
1050
+ LiveReload.on('disconnect', function() {
1051
+ return CustomEvents.fire(document, 'LiveReloadDisconnect');
1052
+ });
1053
+ CustomEvents.bind(document, 'LiveReloadShutDown', function() {
1054
+ return LiveReload.shutDown();
1055
+ });
1056
+ })();