rack-livereload 0.3.6 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/js/livereload.js CHANGED
@@ -123,12 +123,17 @@ __protocol.Parser = Parser = (function() {
123
123
  })();
124
124
 
125
125
  // connector
126
+ // Generated by CoffeeScript 1.3.3
126
127
  var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref;
127
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
128
+
128
129
  _ref = __protocol, Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7;
129
- Version = '2.0.3';
130
+
131
+ Version = '2.0.8';
132
+
130
133
  __connector.Connector = Connector = (function() {
134
+
131
135
  function Connector(options, WebSocket, Timer, handlers) {
136
+ var _this = this;
132
137
  this.options = options;
133
138
  this.WebSocket = WebSocket;
134
139
  this.Timer = Timer;
@@ -138,64 +143,66 @@ __connector.Connector = Connector = (function() {
138
143
  this._connectionDesired = false;
139
144
  this.protocol = 0;
140
145
  this.protocolParser = new Parser({
141
- connected: __bind(function(protocol) {
142
- this.protocol = protocol;
143
- this._handshakeTimeout.stop();
144
- this._nextDelay = this.options.mindelay;
145
- this._disconnectionReason = 'broken';
146
- return this.handlers.connected(protocol);
147
- }, this),
148
- error: __bind(function(e) {
149
- this.handlers.error(e);
150
- return this._closeOnError();
151
- }, this),
152
- message: __bind(function(message) {
153
- return this.handlers.message(message);
154
- }, this)
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
+ }
155
160
  });
156
- this._handshakeTimeout = new Timer(__bind(function() {
157
- if (!this._isSocketConnected()) {
161
+ this._handshakeTimeout = new Timer(function() {
162
+ if (!_this._isSocketConnected()) {
158
163
  return;
159
164
  }
160
- this._disconnectionReason = 'handshake-timeout';
161
- return this.socket.close();
162
- }, this));
163
- this._reconnectTimer = new Timer(__bind(function() {
164
- if (!this._connectionDesired) {
165
+ _this._disconnectionReason = 'handshake-timeout';
166
+ return _this.socket.close();
167
+ });
168
+ this._reconnectTimer = new Timer(function() {
169
+ if (!_this._connectionDesired) {
165
170
  return;
166
171
  }
167
- return this.connect();
168
- }, this));
172
+ return _this.connect();
173
+ });
169
174
  this.connect();
170
175
  }
176
+
171
177
  Connector.prototype._isSocketConnected = function() {
172
178
  return this.socket && this.socket.readyState === this.WebSocket.OPEN;
173
179
  };
180
+
174
181
  Connector.prototype.connect = function() {
182
+ var _this = this;
175
183
  this._connectionDesired = true;
176
184
  if (this._isSocketConnected()) {
177
185
  return;
178
186
  }
179
- if (this._reconnectTimer) {
180
- clearTimeout(this._reconnectTimer);
181
- }
187
+ this._reconnectTimer.stop();
182
188
  this._disconnectionReason = 'cannot-connect';
183
189
  this.protocolParser.reset();
184
190
  this.handlers.connecting();
185
191
  this.socket = new this.WebSocket(this._uri);
186
- this.socket.onopen = __bind(function(e) {
187
- return this._onopen(e);
188
- }, this);
189
- this.socket.onclose = __bind(function(e) {
190
- return this._onclose(e);
191
- }, this);
192
- this.socket.onmessage = __bind(function(e) {
193
- return this._onmessage(e);
194
- }, this);
195
- return this.socket.onerror = __bind(function(e) {
196
- return this._onerror(e);
197
- }, this);
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
+ };
198
204
  };
205
+
199
206
  Connector.prototype.disconnect = function() {
200
207
  this._connectionDesired = false;
201
208
  this._reconnectTimer.stop();
@@ -205,6 +212,7 @@ __connector.Connector = Connector = (function() {
205
212
  this._disconnectionReason = 'manual';
206
213
  return this.socket.close();
207
214
  };
215
+
208
216
  Connector.prototype._scheduleReconnection = function() {
209
217
  if (!this._connectionDesired) {
210
218
  return;
@@ -214,20 +222,24 @@ __connector.Connector = Connector = (function() {
214
222
  return this._nextDelay = Math.min(this.options.maxdelay, this._nextDelay * 2);
215
223
  }
216
224
  };
225
+
217
226
  Connector.prototype.sendCommand = function(command) {
218
227
  if (this.protocol == null) {
219
228
  return;
220
229
  }
221
230
  return this._sendCommand(command);
222
231
  };
232
+
223
233
  Connector.prototype._sendCommand = function(command) {
224
234
  return this.socket.send(JSON.stringify(command));
225
235
  };
236
+
226
237
  Connector.prototype._closeOnError = function() {
227
238
  this._handshakeTimeout.stop();
228
239
  this._disconnectionReason = 'error';
229
240
  return this.socket.close();
230
241
  };
242
+
231
243
  Connector.prototype._onopen = function(e) {
232
244
  var hello;
233
245
  this.handlers.socketConnected();
@@ -249,16 +261,21 @@ __connector.Connector = Connector = (function() {
249
261
  this._sendCommand(hello);
250
262
  return this._handshakeTimeout.start(this.options.handshake_timeout);
251
263
  };
264
+
252
265
  Connector.prototype._onclose = function(e) {
253
266
  this.protocol = 0;
254
267
  this.handlers.disconnected(this._disconnectionReason, this._nextDelay);
255
268
  return this._scheduleReconnection();
256
269
  };
270
+
257
271
  Connector.prototype._onerror = function(e) {};
272
+
258
273
  Connector.prototype._onmessage = function(e) {
259
274
  return this.protocolParser.process(e.data);
260
275
  };
276
+
261
277
  return Connector;
278
+
262
279
  })();
263
280
 
264
281
  // timer
@@ -349,375 +366,479 @@ Options.extract = function(document) {
349
366
  };
350
367
 
351
368
  // reloader
352
- var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
353
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
354
- splitUrl = function(url) {
355
- var hash, index, params;
356
- if ((index = url.indexOf('#')) >= 0) {
357
- hash = url.slice(index);
358
- url = url.slice(0, index);
359
- } else {
360
- hash = '';
361
- }
362
- if ((index = url.indexOf('?')) >= 0) {
363
- params = url.slice(index);
364
- url = url.slice(0, index);
365
- } else {
366
- params = '';
367
- }
368
- return {
369
- url: url,
370
- params: params,
371
- hash: hash
372
- };
373
- };
374
- pathFromUrl = function(url) {
375
- var path;
376
- url = splitUrl(url).url;
377
- if (url.indexOf('file://') === 0) {
378
- path = url.replace(/^file:\/\/(localhost)?/, '');
379
- } else {
380
- path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/');
381
- }
382
- return decodeURIComponent(path);
383
- };
384
- pickBestMatch = function(path, objects, pathFunc) {
385
- var bestMatch, object, score, _i, _len;
386
- bestMatch = {
387
- score: 0
388
- };
389
- for (_i = 0, _len = objects.length; _i < _len; _i++) {
390
- object = objects[_i];
391
- score = numberOfMatchingSegments(path, pathFunc(object));
392
- if (score > bestMatch.score) {
393
- bestMatch = {
394
- object: object,
395
- score: score
396
- };
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 = '';
397
380
  }
398
- }
399
- if (bestMatch.score > 0) {
400
- return bestMatch;
401
- } else {
402
- return null;
403
- }
404
- };
405
- numberOfMatchingSegments = function(path1, path2) {
406
- var comps1, comps2, eqCount, len;
407
- path1 = path1.replace(/^\/+/, '').toLowerCase();
408
- path2 = path2.replace(/^\/+/, '').toLowerCase();
409
- if (path1 === path2) {
410
- return 10000;
411
- }
412
- comps1 = path1.split('/').reverse();
413
- comps2 = path2.split('/').reverse();
414
- len = Math.min(comps1.length, comps2.length);
415
- eqCount = 0;
416
- while (eqCount < len && comps1[eqCount] === comps2[eqCount]) {
417
- ++eqCount;
418
- }
419
- return eqCount;
420
- };
421
- pathsMatch = function(path1, path2) {
422
- return numberOfMatchingSegments(path1, path2) > 0;
423
- };
424
- IMAGE_STYLES = [
425
- {
426
- selector: 'background',
427
- styleNames: ['backgroundImage']
428
- }, {
429
- selector: 'border',
430
- styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
431
- }
432
- ];
433
- __reloader.Reloader = Reloader = (function() {
434
- function Reloader(window, console, Timer) {
435
- this.window = window;
436
- this.console = console;
437
- this.Timer = Timer;
438
- this.document = this.window.document;
439
- this.stylesheetGracePeriod = 200;
440
- this.importCacheWaitPeriod = 200;
441
- this.plugins = [];
442
- }
443
- Reloader.prototype.addPlugin = function(plugin) {
444
- return this.plugins.push(plugin);
445
- };
446
- Reloader.prototype.analyze = function(callback) {
447
- return results;
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
+ };
448
392
  };
449
- Reloader.prototype.reload = function(path, options) {
450
- var plugin, _i, _len, _ref;
451
- _ref = this.plugins;
452
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
453
- plugin = _ref[_i];
454
- if (plugin.reload && plugin.reload(path, options)) {
455
- return;
456
- }
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*)?\//, '/');
457
401
  }
458
- if (options.liveCSS) {
459
- if (path.match(/\.css$/i)) {
460
- if (this.reloadStylesheet(path)) {
461
- return;
462
- }
402
+ return decodeURIComponent(path);
403
+ };
404
+
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
417
+ };
463
418
  }
464
419
  }
465
- if (options.liveImg) {
466
- if (path.match(/\.(jpe?g|png|gif)$/i)) {
467
- this.reloadImages(path);
468
- return;
469
- }
420
+ if (bestMatch.score > 0) {
421
+ return bestMatch;
422
+ } else {
423
+ return null;
470
424
  }
471
- return this.reloadPage();
472
- };
473
- Reloader.prototype.reloadPage = function() {
474
- return this.window.document.location.reload();
475
425
  };
476
- Reloader.prototype.reloadImages = function(path) {
477
- var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4, _results;
478
- expando = this.generateUniqueString();
479
- _ref = this.document.images;
480
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
481
- img = _ref[_i];
482
- if (pathsMatch(path, pathFromUrl(img.src))) {
483
- img.src = this.generateCacheBustUrl(img.src, expando);
484
- }
485
- }
486
- if (this.document.querySelectorAll) {
487
- for (_j = 0, _len2 = IMAGE_STYLES.length; _j < _len2; _j++) {
488
- _ref2 = IMAGE_STYLES[_j], selector = _ref2.selector, styleNames = _ref2.styleNames;
489
- _ref3 = this.document.querySelectorAll("[style*=" + selector + "]");
490
- for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
491
- img = _ref3[_k];
492
- this.reloadStyleImages(img.style, styleNames, path, expando);
493
- }
494
- }
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;
495
433
  }
496
- if (this.document.styleSheets) {
497
- _ref4 = this.document.styleSheets;
498
- _results = [];
499
- for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) {
500
- styleSheet = _ref4[_l];
501
- _results.push(this.reloadStylesheetImages(styleSheet, path, expando));
502
- }
503
- return _results;
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;
504
440
  }
441
+ return eqCount;
442
+ };
443
+
444
+ pathsMatch = function(path1, path2) {
445
+ return numberOfMatchingSegments(path1, path2) > 0;
505
446
  };
506
- Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
507
- var rule, rules, styleNames, _i, _j, _len, _len2;
508
- try {
509
- rules = styleSheet != null ? styleSheet.cssRules : void 0;
510
- } catch (e) {
511
447
 
448
+ IMAGE_STYLES = [
449
+ {
450
+ selector: 'background',
451
+ styleNames: ['backgroundImage']
452
+ }, {
453
+ selector: 'border',
454
+ styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
512
455
  }
513
- if (!rules) {
514
- return;
456
+ ];
457
+
458
+ __reloader.Reloader = Reloader = (function() {
459
+
460
+ Reloader.name = 'Reloader';
461
+
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 = [];
515
469
  }
516
- for (_i = 0, _len = rules.length; _i < _len; _i++) {
517
- rule = rules[_i];
518
- switch (rule.type) {
519
- case CSSRule.IMPORT_RULE:
520
- this.reloadStylesheetImages(rule.styleSheet, path, expando);
521
- break;
522
- case CSSRule.STYLE_RULE:
523
- for (_j = 0, _len2 = IMAGE_STYLES.length; _j < _len2; _j++) {
524
- styleNames = IMAGE_STYLES[_j].styleNames;
525
- this.reloadStyleImages(rule.style, styleNames, path, expando);
526
- }
527
- break;
528
- case CSSRule.MEDIA_RULE:
529
- this.reloadStylesheetImages(rule, path, expando);
470
+
471
+ Reloader.prototype.addPlugin = function(plugin) {
472
+ return this.plugins.push(plugin);
473
+ };
474
+
475
+ Reloader.prototype.analyze = function(callback) {
476
+ return results;
477
+ };
478
+
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;
530
484
  }
531
- }
532
- };
533
- Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
534
- var newValue, styleName, value, _i, _len;
535
- for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
536
- styleName = styleNames[_i];
537
- value = style[styleName];
538
- if (typeof value === 'string') {
539
- newValue = value.replace(/\burl\s*\(([^)]*)\)/, __bind(function(match, src) {
540
- if (pathsMatch(path, pathFromUrl(src))) {
541
- return "url(" + (this.generateCacheBustUrl(src, expando)) + ")";
542
- } else {
543
- return match;
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;
544
496
  }
545
- }, this));
546
- if (newValue !== value) {
547
- style[styleName] = newValue;
548
497
  }
549
498
  }
550
- }
551
- };
552
- Reloader.prototype.reloadStylesheet = function(path) {
553
- var imported, link, links, match, style, _i, _j, _k, _len, _len2, _len3, _ref;
554
- links = (function() {
555
- var _i, _len, _ref, _results;
556
- _ref = this.document.getElementsByTagName('link');
557
- _results = [];
558
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
559
- link = _ref[_i];
560
- if (link.rel === 'stylesheet' && !link.__LiveReload_pendingRemoval) {
561
- _results.push(link);
499
+ if (options.liveImg) {
500
+ if (path.match(/\.(jpe?g|png|gif)$/i)) {
501
+ this.reloadImages(path);
502
+ return;
562
503
  }
563
504
  }
564
- return _results;
565
- }).call(this);
566
- imported = [];
567
- _ref = this.document.getElementsByTagName('style');
568
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
569
- style = _ref[_i];
570
- if (style.sheet) {
571
- this.collectImportedStylesheets(style, style.sheet, imported);
505
+ return this.reloadPage();
506
+ };
507
+
508
+ Reloader.prototype.reloadPage = function() {
509
+ return this.window.document.location.reload();
510
+ };
511
+
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
+ }
572
521
  }
573
- }
574
- for (_j = 0, _len2 = links.length; _j < _len2; _j++) {
575
- link = links[_j];
576
- this.collectImportedStylesheets(link, link.sheet, imported);
577
- }
578
- this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets");
579
- match = pickBestMatch(path, links.concat(imported), function(l) {
580
- return pathFromUrl(l.href);
581
- });
582
- if (match) {
583
- if (match.object.rule) {
584
- this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
585
- this.reattachImportedRule(match.object);
586
- } else {
587
- this.console.log("LiveReload is reloading stylesheet: " + match.object.href);
588
- this.reattachStylesheetLink(match.object);
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
+ }
589
531
  }
590
- } else {
591
- this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one");
592
- for (_k = 0, _len3 = links.length; _k < _len3; _k++) {
593
- link = links[_k];
594
- this.reattachStylesheetLink(link);
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));
538
+ }
539
+ return _results;
595
540
  }
596
- }
597
- return true;
598
- };
599
- Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
600
- var index, rule, rules, _len;
601
- try {
602
- rules = styleSheet != null ? styleSheet.cssRules : void 0;
603
- } catch (e) {
541
+ };
604
542
 
605
- }
606
- if (rules && rules.length) {
607
- for (index = 0, _len = rules.length; index < _len; index++) {
608
- rule = rules[index];
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];
609
555
  switch (rule.type) {
610
- case CSSRule.CHARSET_RULE:
611
- continue;
612
556
  case CSSRule.IMPORT_RULE:
613
- result.push({
614
- link: link,
615
- rule: rule,
616
- index: index,
617
- href: rule.href
618
- });
619
- this.collectImportedStylesheets(link, rule.styleSheet, result);
557
+ this.reloadStylesheetImages(rule.styleSheet, path, expando);
620
558
  break;
621
- default:
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);
563
+ }
622
564
  break;
565
+ case CSSRule.MEDIA_RULE:
566
+ this.reloadStylesheetImages(rule, path, expando);
623
567
  }
624
568
  }
625
- }
626
- };
627
- Reloader.prototype.reattachStylesheetLink = function(link) {
628
- var clone, parent, timer;
629
- if (link.__LiveReload_pendingRemoval) {
630
- return;
631
- }
632
- link.__LiveReload_pendingRemoval = true;
633
- clone = link.cloneNode(false);
634
- clone.href = this.generateCacheBustUrl(link.href);
635
- parent = link.parentNode;
636
- if (parent.lastChild === link) {
637
- parent.appendChild(clone);
638
- } else {
639
- parent.insertBefore(clone, link.nextSibling);
640
- }
641
- timer = new this.Timer(function() {
642
- if (link.parentNode) {
643
- return link.parentNode.removeChild(link);
569
+ };
570
+
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)) + ")";
581
+ } else {
582
+ return match;
583
+ }
584
+ });
585
+ if (newValue !== value) {
586
+ style[styleName] = newValue;
587
+ }
588
+ }
644
589
  }
645
- });
646
- return timer.start(this.stylesheetGracePeriod);
647
- };
648
- Reloader.prototype.reattachImportedRule = function(_arg) {
649
- var href, index, link, media, newRule, parent, rule, tempLink;
650
- rule = _arg.rule, index = _arg.index, link = _arg.link;
651
- parent = rule.parentStyleSheet;
652
- href = this.generateCacheBustUrl(rule.href);
653
- media = rule.media.length ? [].join.call(rule.media, ', ') : '';
654
- newRule = "@import url(\"" + href + "\") " + media + ";";
655
- rule.__LiveReload_newHref = href;
656
- tempLink = this.document.createElement("link");
657
- tempLink.rel = 'stylesheet';
658
- tempLink.href = href;
659
- tempLink.__LiveReload_pendingRemoval = true;
660
- if (link.parentNode) {
661
- link.parentNode.insertBefore(tempLink, link);
662
- }
663
- return this.Timer.start(this.importCacheWaitPeriod, __bind(function() {
664
- if (tempLink.parentNode) {
665
- tempLink.parentNode.removeChild(tempLink);
666
- }
667
- if (rule.__LiveReload_newHref !== href) {
590
+ };
591
+
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
+ };
647
+
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
+ };
676
+
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
+ };
705
+
706
+ Reloader.prototype.linkHref = function(link) {
707
+ return link.href || link.getAttribute('data-href');
708
+ };
709
+
710
+ Reloader.prototype.reattachStylesheetLink = function(link) {
711
+ var clone, parent,
712
+ _this = this;
713
+ if (link.__LiveReload_pendingRemoval) {
668
714
  return;
669
715
  }
670
- parent.insertRule(newRule, index);
671
- parent.deleteRule(index + 1);
672
- rule = parent.cssRules[index];
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
+ };
750
+
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 + ";";
673
759
  rule.__LiveReload_newHref = href;
674
- return this.Timer.start(this.importCacheWaitPeriod, __bind(function() {
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
+ }
675
771
  if (rule.__LiveReload_newHref !== href) {
676
772
  return;
677
773
  }
678
774
  parent.insertRule(newRule, index);
679
- return parent.deleteRule(index + 1);
680
- }, this));
681
- }, this));
682
- };
683
- Reloader.prototype.generateUniqueString = function() {
684
- return 'livereload=' + Date.now();
685
- };
686
- Reloader.prototype.generateCacheBustUrl = function(url, expando) {
687
- var hash, oldParams, params, _ref;
688
- if (expando == null) {
689
- expando = this.generateUniqueString();
690
- }
691
- _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
692
- params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
693
- return "" + sep + expando;
694
- });
695
- if (params === oldParams) {
696
- if (oldParams.length === 0) {
697
- params = "?" + expando;
698
- } else {
699
- params = "" + oldParams + "&" + expando;
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
+ };
787
+
788
+ Reloader.prototype.generateUniqueString = function() {
789
+ return 'livereload=' + Date.now();
790
+ };
791
+
792
+ Reloader.prototype.generateCacheBustUrl = function(url, expando) {
793
+ var hash, oldParams, params, _ref;
794
+ if (expando == null) {
795
+ expando = this.generateUniqueString();
700
796
  }
701
- }
702
- return url + params + hash;
703
- };
704
- return Reloader;
705
- })();
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
+ };
815
+
816
+ return Reloader;
817
+
818
+ })();
819
+
820
+ }).call(this);
706
821
 
707
822
  // livereload
708
823
  var Connector, LiveReload, Options, Reloader, Timer;
709
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
824
+
710
825
  Connector = __connector.Connector;
826
+
711
827
  Timer = __timer.Timer;
828
+
712
829
  Options = __options.Options;
830
+
713
831
  Reloader = __reloader.Reloader;
832
+
714
833
  __livereload.LiveReload = LiveReload = (function() {
834
+
715
835
  function LiveReload(window) {
836
+ var _this = this;
716
837
  this.window = window;
717
838
  this.listeners = {};
718
839
  this.plugins = [];
719
840
  this.pluginIdentifiers = {};
720
- this.console = this.window.console && this.window.console.log && this.window.console.error ? this.window.console : {
841
+ this.console = this.window.location.href.match(/LR-verbose/) && this.window.console && this.window.console.log && this.window.console.error ? this.window.console : {
721
842
  log: function() {},
722
843
  error: function() {}
723
844
  };
@@ -731,87 +852,95 @@ __livereload.LiveReload = LiveReload = (function() {
731
852
  }
732
853
  this.reloader = new Reloader(this.window, this.console, Timer);
733
854
  this.connector = new Connector(this.options, this.WebSocket, Timer, {
734
- connecting: __bind(function() {}, this),
735
- socketConnected: __bind(function() {}, this),
736
- connected: __bind(function(protocol) {
855
+ connecting: function() {},
856
+ socketConnected: function() {},
857
+ connected: function(protocol) {
737
858
  var _base;
738
- if (typeof (_base = this.listeners).connect === "function") {
859
+ if (typeof (_base = _this.listeners).connect === "function") {
739
860
  _base.connect();
740
861
  }
741
- this.log("LiveReload is connected to " + this.options.host + ":" + this.options.port + " (protocol v" + protocol + ").");
742
- return this.analyze();
743
- }, this),
744
- error: __bind(function(e) {
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) {
745
866
  if (e instanceof ProtocolError) {
746
867
  return console.log("" + e.message + ".");
747
868
  } else {
748
869
  return console.log("LiveReload internal error: " + e.message);
749
870
  }
750
- }, this),
751
- disconnected: __bind(function(reason, nextDelay) {
871
+ },
872
+ disconnected: function(reason, nextDelay) {
752
873
  var _base;
753
- if (typeof (_base = this.listeners).disconnect === "function") {
874
+ if (typeof (_base = _this.listeners).disconnect === "function") {
754
875
  _base.disconnect();
755
876
  }
756
877
  switch (reason) {
757
878
  case 'cannot-connect':
758
- return this.log("LiveReload cannot connect to " + this.options.host + ":" + this.options.port + ", will retry in " + nextDelay + " sec.");
879
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + ", will retry in " + nextDelay + " sec.");
759
880
  case 'broken':
760
- return this.log("LiveReload disconnected from " + this.options.host + ":" + this.options.port + ", reconnecting in " + nextDelay + " sec.");
881
+ return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + ", reconnecting in " + nextDelay + " sec.");
761
882
  case 'handshake-timeout':
762
- return this.log("LiveReload cannot connect to " + this.options.host + ":" + this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec.");
883
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec.");
763
884
  case 'handshake-failed':
764
- return this.log("LiveReload cannot connect to " + this.options.host + ":" + this.options.port + " (handshake failed), will retry in " + nextDelay + " sec.");
885
+ return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake failed), will retry in " + nextDelay + " sec.");
765
886
  case 'manual':
766
887
  break;
767
888
  case 'error':
768
889
  break;
769
890
  default:
770
- return this.log("LiveReload disconnected from " + this.options.host + ":" + this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec.");
891
+ return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec.");
771
892
  }
772
- }, this),
773
- message: __bind(function(message) {
893
+ },
894
+ message: function(message) {
774
895
  switch (message.command) {
775
896
  case 'reload':
776
- return this.performReload(message);
897
+ return _this.performReload(message);
777
898
  case 'alert':
778
- return this.performAlert(message);
899
+ return _this.performAlert(message);
779
900
  }
780
- }, this)
901
+ }
781
902
  });
782
903
  }
904
+
783
905
  LiveReload.prototype.on = function(eventName, handler) {
784
906
  return this.listeners[eventName] = handler;
785
907
  };
908
+
786
909
  LiveReload.prototype.log = function(message) {
787
910
  return this.console.log("" + message);
788
911
  };
912
+
789
913
  LiveReload.prototype.performReload = function(message) {
790
914
  var _ref, _ref2;
791
915
  this.log("LiveReload received reload request for " + message.path + ".");
792
916
  return this.reloader.reload(message.path, {
793
917
  liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
794
918
  liveImg: (_ref2 = message.liveImg) != null ? _ref2 : true,
795
- originalPath: message.originalPath || ''
919
+ originalPath: message.originalPath || '',
920
+ overrideURL: message.overrideURL || '',
921
+ serverURL: "http://" + this.options.host + ":" + this.options.port
796
922
  });
797
923
  };
924
+
798
925
  LiveReload.prototype.performAlert = function(message) {
799
926
  return alert(message.message);
800
927
  };
928
+
801
929
  LiveReload.prototype.shutDown = function() {
802
930
  var _base;
803
931
  this.connector.disconnect();
804
932
  this.log("LiveReload disconnected.");
805
933
  return typeof (_base = this.listeners).shutdown === "function" ? _base.shutdown() : void 0;
806
934
  };
935
+
807
936
  LiveReload.prototype.hasPlugin = function(identifier) {
808
937
  return !!this.pluginIdentifiers[identifier];
809
938
  };
939
+
810
940
  LiveReload.prototype.addPlugin = function(pluginClass) {
811
941
  var plugin;
812
- if (this.hasPlugin(pluginClass.identifier)) {
813
- return;
814
- }
942
+ var _this = this;
943
+ if (this.hasPlugin(pluginClass.identifier)) return;
815
944
  this.pluginIdentifiers[pluginClass.identifier] = true;
816
945
  plugin = new pluginClass(this.window, {
817
946
  _livereload: this,
@@ -819,18 +948,17 @@ __livereload.LiveReload = LiveReload = (function() {
819
948
  _connector: this.connector,
820
949
  console: this.console,
821
950
  Timer: Timer,
822
- generateCacheBustUrl: __bind(function(url) {
823
- return this.reloader.generateCacheBustUrl(url);
824
- }, this)
951
+ generateCacheBustUrl: function(url) {
952
+ return _this.reloader.generateCacheBustUrl(url);
953
+ }
825
954
  });
826
955
  this.plugins.push(plugin);
827
956
  this.reloader.addPlugin(plugin);
828
957
  };
958
+
829
959
  LiveReload.prototype.analyze = function() {
830
960
  var plugin, pluginData, pluginsData, _i, _len, _ref;
831
- if (!(this.connector.protocol >= 7)) {
832
- return;
833
- }
961
+ if (!(this.connector.protocol >= 7)) return;
834
962
  pluginsData = {};
835
963
  _ref = this.plugins;
836
964
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -844,7 +972,9 @@ __livereload.LiveReload = LiveReload = (function() {
844
972
  url: this.window.location.href
845
973
  });
846
974
  };
975
+
847
976
  return LiveReload;
977
+
848
978
  })();
849
979
 
850
980
  // less
@@ -901,13 +1031,12 @@ __less = LessPlugin = (function() {
901
1031
  })();
902
1032
 
903
1033
  // startup
904
- var CustomEvents, LiveReload, k, v;
1034
+ var CustomEvents, LiveReload, k;
905
1035
  CustomEvents = __customevents;
906
1036
  LiveReload = window.LiveReload = new (__livereload.LiveReload)(window);
907
1037
  for (k in window) {
908
- v = window[k];
909
1038
  if (k.match(/^LiveReloadPlugin/)) {
910
- LiveReload.addPlugin(v);
1039
+ LiveReload.addPlugin(window[k]);
911
1040
  }
912
1041
  }
913
1042
  LiveReload.addPlugin(__less);