1 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
3 var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref;
5 _ref = require('./protocol'), Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7;
9 exports.Connector = Connector = (function() {
10 function Connector(options, WebSocket, Timer, handlers) {
11 this.options = options;
12 this.WebSocket = WebSocket;
14 this.handlers = handlers;
15 this._uri = "ws" + (this.options.https ? "s" : "") + "://" + this.options.host + ":" + this.options.port + "/livereload";
16 this._nextDelay = this.options.mindelay;
17 this._connectionDesired = false;
19 this.protocolParser = new Parser({
20 connected: (function(_this) {
21 return function(protocol) {
22 _this.protocol = protocol;
23 _this._handshakeTimeout.stop();
24 _this._nextDelay = _this.options.mindelay;
25 _this._disconnectionReason = 'broken';
26 return _this.handlers.connected(protocol);
29 error: (function(_this) {
31 _this.handlers.error(e);
32 return _this._closeOnError();
35 message: (function(_this) {
36 return function(message) {
37 return _this.handlers.message(message);
41 this._handshakeTimeout = new Timer((function(_this) {
43 if (!_this._isSocketConnected()) {
46 _this._disconnectionReason = 'handshake-timeout';
47 return _this.socket.close();
50 this._reconnectTimer = new Timer((function(_this) {
52 if (!_this._connectionDesired) {
55 return _this.connect();
61 Connector.prototype._isSocketConnected = function() {
62 return this.socket && this.socket.readyState === this.WebSocket.OPEN;
65 Connector.prototype.connect = function() {
66 this._connectionDesired = true;
67 if (this._isSocketConnected()) {
70 this._reconnectTimer.stop();
71 this._disconnectionReason = 'cannot-connect';
72 this.protocolParser.reset();
73 this.handlers.connecting();
74 this.socket = new this.WebSocket(this._uri);
75 this.socket.onopen = (function(_this) {
77 return _this._onopen(e);
80 this.socket.onclose = (function(_this) {
82 return _this._onclose(e);
85 this.socket.onmessage = (function(_this) {
87 return _this._onmessage(e);
90 return this.socket.onerror = (function(_this) {
92 return _this._onerror(e);
97 Connector.prototype.disconnect = function() {
98 this._connectionDesired = false;
99 this._reconnectTimer.stop();
100 if (!this._isSocketConnected()) {
103 this._disconnectionReason = 'manual';
104 return this.socket.close();
107 Connector.prototype._scheduleReconnection = function() {
108 if (!this._connectionDesired) {
111 if (!this._reconnectTimer.running) {
112 this._reconnectTimer.start(this._nextDelay);
113 return this._nextDelay = Math.min(this.options.maxdelay, this._nextDelay * 2);
117 Connector.prototype.sendCommand = function(command) {
118 if (this.protocol == null) {
121 return this._sendCommand(command);
124 Connector.prototype._sendCommand = function(command) {
125 return this.socket.send(JSON.stringify(command));
128 Connector.prototype._closeOnError = function() {
129 this._handshakeTimeout.stop();
130 this._disconnectionReason = 'error';
131 return this.socket.close();
134 Connector.prototype._onopen = function(e) {
136 this.handlers.socketConnected();
137 this._disconnectionReason = 'handshake-failed';
140 protocols: [PROTOCOL_6, PROTOCOL_7]
143 if (this.options.ext) {
144 hello.ext = this.options.ext;
146 if (this.options.extver) {
147 hello.extver = this.options.extver;
149 if (this.options.snipver) {
150 hello.snipver = this.options.snipver;
152 this._sendCommand(hello);
153 return this._handshakeTimeout.start(this.options.handshake_timeout);
156 Connector.prototype._onclose = function(e) {
158 this.handlers.disconnected(this._disconnectionReason, this._nextDelay);
159 return this._scheduleReconnection();
162 Connector.prototype._onerror = function(e) {};
164 Connector.prototype._onmessage = function(e) {
165 return this.protocolParser.process(e.data);
174 },{"./protocol":6}],2:[function(require,module,exports){
179 bind: function(element, eventName, handler) {
180 if (element.addEventListener) {
181 return element.addEventListener(eventName, handler, false);
182 } else if (element.attachEvent) {
183 element[eventName] = 1;
184 return element.attachEvent('onpropertychange', function(event) {
185 if (event.propertyName === eventName) {
190 throw new Error("Attempt to attach custom event " + eventName + " to something which isn't a DOMElement");
193 fire: function(element, eventName) {
195 if (element.addEventListener) {
196 event = document.createEvent('HTMLEvents');
197 event.initEvent(eventName, true, true);
198 return document.dispatchEvent(event);
199 } else if (element.attachEvent) {
200 if (element[eventName]) {
201 return element[eventName]++;
204 throw new Error("Attempt to fire custom event " + eventName + " on something which isn't a DOMElement");
209 exports.bind = CustomEvents.bind;
211 exports.fire = CustomEvents.fire;
215 },{}],3:[function(require,module,exports){
219 module.exports = LessPlugin = (function() {
220 LessPlugin.identifier = 'less';
222 LessPlugin.version = '1.0';
224 function LessPlugin(window, host) {
225 this.window = window;
229 LessPlugin.prototype.reload = function(path, options) {
230 if (this.window.less && this.window.less.refresh) {
231 if (path.match(/\.less$/i)) {
232 return this.reloadLess(path);
234 if (options.originalPath.match(/\.less$/i)) {
235 return this.reloadLess(options.originalPath);
241 LessPlugin.prototype.reloadLess = function(path) {
242 var link, links, _i, _len;
243 links = (function() {
244 var _i, _len, _ref, _results;
245 _ref = document.getElementsByTagName('link');
247 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
249 if (link.href && link.rel.match(/^stylesheet\/less$/i) || (link.rel.match(/stylesheet/i) && link.type.match(/^text\/(x-)?less$/i))) {
255 if (links.length === 0) {
258 for (_i = 0, _len = links.length; _i < _len; _i++) {
260 link.href = this.host.generateCacheBustUrl(link.href);
262 this.host.console.log("LiveReload is asking LESS to recompile all stylesheets");
263 this.window.less.refresh(true);
267 LessPlugin.prototype.analyze = function() {
269 disable: !!(this.window.less && this.window.less.refresh)
279 },{}],4:[function(require,module,exports){
281 var Connector, LiveReload, Options, Reloader, Timer,
282 __hasProp = {}.hasOwnProperty;
284 Connector = require('./connector').Connector;
286 Timer = require('./timer').Timer;
288 Options = require('./options').Options;
290 Reloader = require('./reloader').Reloader;
292 exports.LiveReload = LiveReload = (function() {
293 function LiveReload(window) {
295 this.window = window;
298 this.pluginIdentifiers = {};
299 this.console = this.window.console && this.window.console.log && this.window.console.error ? this.window.location.href.match(/LR-verbose/) ? this.window.console : {
301 error: this.window.console.error.bind(this.window.console)
306 if (!(this.WebSocket = this.window.WebSocket || this.window.MozWebSocket)) {
307 this.console.error("LiveReload disabled because the browser does not seem to support web sockets");
310 if ('LiveReloadOptions' in window) {
311 this.options = new Options();
312 _ref = window['LiveReloadOptions'];
314 if (!__hasProp.call(_ref, k)) continue;
316 this.options.set(k, v);
319 this.options = Options.extract(this.window.document);
321 this.console.error("LiveReload disabled because it could not find its own <SCRIPT> tag");
325 this.reloader = new Reloader(this.window, this.console, Timer);
326 this.connector = new Connector(this.options, this.WebSocket, Timer, {
327 connecting: (function(_this) {
328 return function() {};
330 socketConnected: (function(_this) {
331 return function() {};
333 connected: (function(_this) {
334 return function(protocol) {
336 if (typeof (_base = _this.listeners).connect === "function") {
339 _this.log("LiveReload is connected to " + _this.options.host + ":" + _this.options.port + " (protocol v" + protocol + ").");
340 return _this.analyze();
343 error: (function(_this) {
345 if (e instanceof ProtocolError) {
346 if (typeof console !== "undefined" && console !== null) {
347 return console.log("" + e.message + ".");
350 if (typeof console !== "undefined" && console !== null) {
351 return console.log("LiveReload internal error: " + e.message);
356 disconnected: (function(_this) {
357 return function(reason, nextDelay) {
359 if (typeof (_base = _this.listeners).disconnect === "function") {
363 case 'cannot-connect':
364 return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + ", will retry in " + nextDelay + " sec.");
366 return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + ", reconnecting in " + nextDelay + " sec.");
367 case 'handshake-timeout':
368 return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake timeout), will retry in " + nextDelay + " sec.");
369 case 'handshake-failed':
370 return _this.log("LiveReload cannot connect to " + _this.options.host + ":" + _this.options.port + " (handshake failed), will retry in " + nextDelay + " sec.");
376 return _this.log("LiveReload disconnected from " + _this.options.host + ":" + _this.options.port + " (" + reason + "), reconnecting in " + nextDelay + " sec.");
380 message: (function(_this) {
381 return function(message) {
382 switch (message.command) {
384 return _this.performReload(message);
386 return _this.performAlert(message);
391 this.initialized = true;
394 LiveReload.prototype.on = function(eventName, handler) {
395 return this.listeners[eventName] = handler;
398 LiveReload.prototype.log = function(message) {
399 return this.console.log("" + message);
402 LiveReload.prototype.performReload = function(message) {
404 this.log("LiveReload received reload request: " + (JSON.stringify(message, null, 2)));
405 return this.reloader.reload(message.path, {
406 liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
407 liveImg: (_ref1 = message.liveImg) != null ? _ref1 : true,
408 originalPath: message.originalPath || '',
409 overrideURL: message.overrideURL || '',
410 serverURL: "http://" + this.options.host + ":" + this.options.port
414 LiveReload.prototype.performAlert = function(message) {
415 return alert(message.message);
418 LiveReload.prototype.shutDown = function() {
420 if (!this.initialized) {
423 this.connector.disconnect();
424 this.log("LiveReload disconnected.");
425 return typeof (_base = this.listeners).shutdown === "function" ? _base.shutdown() : void 0;
428 LiveReload.prototype.hasPlugin = function(identifier) {
429 return !!this.pluginIdentifiers[identifier];
432 LiveReload.prototype.addPlugin = function(pluginClass) {
434 if (!this.initialized) {
437 if (this.hasPlugin(pluginClass.identifier)) {
440 this.pluginIdentifiers[pluginClass.identifier] = true;
441 plugin = new pluginClass(this.window, {
443 _reloader: this.reloader,
444 _connector: this.connector,
445 console: this.console,
447 generateCacheBustUrl: (function(_this) {
448 return function(url) {
449 return _this.reloader.generateCacheBustUrl(url);
453 this.plugins.push(plugin);
454 this.reloader.addPlugin(plugin);
457 LiveReload.prototype.analyze = function() {
458 var plugin, pluginData, pluginsData, _i, _len, _ref;
459 if (!this.initialized) {
462 if (!(this.connector.protocol >= 7)) {
467 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
469 pluginsData[plugin.constructor.identifier] = pluginData = (typeof plugin.analyze === "function" ? plugin.analyze() : void 0) || {};
470 pluginData.version = plugin.constructor.version;
472 this.connector.sendCommand({
474 plugins: pluginsData,
475 url: this.window.location.href
485 },{"./connector":1,"./options":5,"./reloader":7,"./timer":9}],5:[function(require,module,exports){
489 exports.Options = Options = (function() {
497 this.mindelay = 1000;
498 this.maxdelay = 60000;
499 this.handshake_timeout = 5000;
502 Options.prototype.set = function(name, value) {
503 if (typeof value === 'undefined') {
506 if (!isNaN(+value)) {
509 return this[name] = value;
516 Options.extract = function(document) {
517 var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len1, _ref, _ref1;
518 _ref = document.getElementsByTagName('script');
519 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
521 if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) {
522 options = new Options();
523 options.https = src.indexOf("https") === 0;
524 if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?$/)) {
525 options.host = mm[1];
527 options.port = parseInt(mm[2], 10);
531 _ref1 = m[2].split('&');
532 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
534 if ((keyAndValue = pair.split('=')).length > 1) {
535 options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('='));
547 },{}],6:[function(require,module,exports){
549 var PROTOCOL_6, PROTOCOL_7, Parser, ProtocolError,
550 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
552 exports.PROTOCOL_6 = PROTOCOL_6 = 'http://livereload.com/protocols/official-6';
554 exports.PROTOCOL_7 = PROTOCOL_7 = 'http://livereload.com/protocols/official-7';
556 exports.ProtocolError = ProtocolError = (function() {
557 function ProtocolError(reason, data) {
558 this.message = "LiveReload protocol error (" + reason + ") after receiving data: \"" + data + "\".";
561 return ProtocolError;
565 exports.Parser = Parser = (function() {
566 function Parser(handlers) {
567 this.handlers = handlers;
571 Parser.prototype.reset = function() {
572 return this.protocol = null;
575 Parser.prototype.process = function(data) {
576 var command, e, message, options, _ref;
578 if (this.protocol == null) {
579 if (data.match(/^!!ver:([\d.]+)$/)) {
581 } else if (message = this._parseMessage(data, ['hello'])) {
582 if (!message.protocols.length) {
583 throw new ProtocolError("no protocols specified in handshake message");
584 } else if (__indexOf.call(message.protocols, PROTOCOL_7) >= 0) {
586 } else if (__indexOf.call(message.protocols, PROTOCOL_6) >= 0) {
589 throw new ProtocolError("no supported protocols found");
592 return this.handlers.connected(this.protocol);
593 } else if (this.protocol === 6) {
594 message = JSON.parse(data);
595 if (!message.length) {
596 throw new ProtocolError("protocol 6 messages must be arrays");
598 command = message[0], options = message[1];
599 if (command !== 'refresh') {
600 throw new ProtocolError("unknown protocol 6 command");
602 return this.handlers.message({
605 liveCSS: (_ref = options.apply_css_live) != null ? _ref : true
608 message = this._parseMessage(data, ['reload', 'alert']);
609 return this.handlers.message(message);
613 if (e instanceof ProtocolError) {
614 return this.handlers.error(e);
621 Parser.prototype._parseMessage = function(data, validCommands) {
622 var e, message, _ref;
624 message = JSON.parse(data);
627 throw new ProtocolError('unparsable JSON', data);
629 if (!message.command) {
630 throw new ProtocolError('missing "command" key', data);
632 if (_ref = message.command, __indexOf.call(validCommands, _ref) < 0) {
633 throw new ProtocolError("invalid command '" + message.command + "', only valid commands are: " + (validCommands.join(', ')) + ")", data);
644 },{}],7:[function(require,module,exports){
646 var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
648 splitUrl = function(url) {
649 var hash, index, params;
650 if ((index = url.indexOf('#')) >= 0) {
651 hash = url.slice(index);
652 url = url.slice(0, index);
656 if ((index = url.indexOf('?')) >= 0) {
657 params = url.slice(index);
658 url = url.slice(0, index);
669 pathFromUrl = function(url) {
671 url = splitUrl(url).url;
672 if (url.indexOf('file://') === 0) {
673 path = url.replace(/^file:\/\/(localhost)?/, '');
675 path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/');
677 return decodeURIComponent(path);
680 pickBestMatch = function(path, objects, pathFunc) {
681 var bestMatch, object, score, _i, _len;
685 for (_i = 0, _len = objects.length; _i < _len; _i++) {
686 object = objects[_i];
687 score = numberOfMatchingSegments(path, pathFunc(object));
688 if (score > bestMatch.score) {
695 if (bestMatch.score > 0) {
702 numberOfMatchingSegments = function(path1, path2) {
703 var comps1, comps2, eqCount, len;
704 path1 = path1.replace(/^\/+/, '').toLowerCase();
705 path2 = path2.replace(/^\/+/, '').toLowerCase();
706 if (path1 === path2) {
709 comps1 = path1.split('/').reverse();
710 comps2 = path2.split('/').reverse();
711 len = Math.min(comps1.length, comps2.length);
713 while (eqCount < len && comps1[eqCount] === comps2[eqCount]) {
719 pathsMatch = function(path1, path2) {
720 return numberOfMatchingSegments(path1, path2) > 0;
725 selector: 'background',
726 styleNames: ['backgroundImage']
729 styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
733 exports.Reloader = Reloader = (function() {
734 function Reloader(window, console, Timer) {
735 this.window = window;
736 this.console = console;
738 this.document = this.window.document;
739 this.importCacheWaitPeriod = 200;
743 Reloader.prototype.addPlugin = function(plugin) {
744 return this.plugins.push(plugin);
747 Reloader.prototype.analyze = function(callback) {
751 Reloader.prototype.reload = function(path, options) {
752 var plugin, _base, _i, _len, _ref;
753 this.options = options;
754 if ((_base = this.options).stylesheetReloadTimeout == null) {
755 _base.stylesheetReloadTimeout = 15000;
758 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
760 if (plugin.reload && plugin.reload(path, options)) {
764 if (options.liveCSS) {
765 if (path.match(/\.css$/i)) {
766 if (this.reloadStylesheet(path)) {
771 if (options.liveImg) {
772 if (path.match(/\.(jpe?g|png|gif)$/i)) {
773 this.reloadImages(path);
777 return this.reloadPage();
780 Reloader.prototype.reloadPage = function() {
781 return this.window.document.location.reload();
784 Reloader.prototype.reloadImages = function(path) {
785 var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results;
786 expando = this.generateUniqueString();
787 _ref = this.document.images;
788 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
790 if (pathsMatch(path, pathFromUrl(img.src))) {
791 img.src = this.generateCacheBustUrl(img.src, expando);
794 if (this.document.querySelectorAll) {
795 for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
796 _ref1 = IMAGE_STYLES[_j], selector = _ref1.selector, styleNames = _ref1.styleNames;
797 _ref2 = this.document.querySelectorAll("[style*=" + selector + "]");
798 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
800 this.reloadStyleImages(img.style, styleNames, path, expando);
804 if (this.document.styleSheets) {
805 _ref3 = this.document.styleSheets;
807 for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
808 styleSheet = _ref3[_l];
809 _results.push(this.reloadStylesheetImages(styleSheet, path, expando));
815 Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
816 var e, rule, rules, styleNames, _i, _j, _len, _len1;
818 rules = styleSheet != null ? styleSheet.cssRules : void 0;
825 for (_i = 0, _len = rules.length; _i < _len; _i++) {
828 case CSSRule.IMPORT_RULE:
829 this.reloadStylesheetImages(rule.styleSheet, path, expando);
831 case CSSRule.STYLE_RULE:
832 for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
833 styleNames = IMAGE_STYLES[_j].styleNames;
834 this.reloadStyleImages(rule.style, styleNames, path, expando);
837 case CSSRule.MEDIA_RULE:
838 this.reloadStylesheetImages(rule, path, expando);
843 Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
844 var newValue, styleName, value, _i, _len;
845 for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
846 styleName = styleNames[_i];
847 value = style[styleName];
848 if (typeof value === 'string') {
849 newValue = value.replace(/\burl\s*\(([^)]*)\)/, (function(_this) {
850 return function(match, src) {
851 if (pathsMatch(path, pathFromUrl(src))) {
852 return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")";
858 if (newValue !== value) {
859 style[styleName] = newValue;
865 Reloader.prototype.reloadStylesheet = function(path) {
866 var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1;
867 links = (function() {
868 var _i, _len, _ref, _results;
869 _ref = this.document.getElementsByTagName('link');
871 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
873 if (link.rel.match(/^stylesheet$/i) && !link.__LiveReload_pendingRemoval) {
880 _ref = this.document.getElementsByTagName('style');
881 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
884 this.collectImportedStylesheets(style, style.sheet, imported);
887 for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
889 this.collectImportedStylesheets(link, link.sheet, imported);
891 if (this.window.StyleFix && this.document.querySelectorAll) {
892 _ref1 = this.document.querySelectorAll('style[data-href]');
893 for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
898 this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets");
899 match = pickBestMatch(path, links.concat(imported), (function(_this) {
901 return pathFromUrl(_this.linkHref(l));
905 if (match.object.rule) {
906 this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
907 this.reattachImportedRule(match.object);
909 this.console.log("LiveReload is reloading stylesheet: " + (this.linkHref(match.object)));
910 this.reattachStylesheetLink(match.object);
913 this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one");
914 for (_l = 0, _len3 = links.length; _l < _len3; _l++) {
916 this.reattachStylesheetLink(link);
922 Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
923 var e, index, rule, rules, _i, _len;
925 rules = styleSheet != null ? styleSheet.cssRules : void 0;
929 if (rules && rules.length) {
930 for (index = _i = 0, _len = rules.length; _i < _len; index = ++_i) {
933 case CSSRule.CHARSET_RULE:
935 case CSSRule.IMPORT_RULE:
942 this.collectImportedStylesheets(link, rule.styleSheet, result);
951 Reloader.prototype.waitUntilCssLoads = function(clone, func) {
952 var callbackExecuted, executeCallback, poll;
953 callbackExecuted = false;
954 executeCallback = (function(_this) {
956 if (callbackExecuted) {
959 callbackExecuted = true;
963 clone.onload = (function(_this) {
965 _this.console.log("LiveReload: the new stylesheet has finished loading");
966 _this.knownToSupportCssOnLoad = true;
967 return executeCallback();
970 if (!this.knownToSupportCssOnLoad) {
971 (poll = (function(_this) {
974 _this.console.log("LiveReload is polling until the new CSS finishes loading...");
975 return executeCallback();
977 return _this.Timer.start(50, poll);
982 return this.Timer.start(this.options.stylesheetReloadTimeout, executeCallback);
985 Reloader.prototype.linkHref = function(link) {
986 return link.href || link.getAttribute('data-href');
989 Reloader.prototype.reattachStylesheetLink = function(link) {
991 if (link.__LiveReload_pendingRemoval) {
994 link.__LiveReload_pendingRemoval = true;
995 if (link.tagName === 'STYLE') {
996 clone = this.document.createElement('link');
997 clone.rel = 'stylesheet';
998 clone.media = link.media;
999 clone.disabled = link.disabled;
1001 clone = link.cloneNode(false);
1003 clone.href = this.generateCacheBustUrl(this.linkHref(link));
1004 parent = link.parentNode;
1005 if (parent.lastChild === link) {
1006 parent.appendChild(clone);
1008 parent.insertBefore(clone, link.nextSibling);
1010 return this.waitUntilCssLoads(clone, (function(_this) {
1012 var additionalWaitingTime;
1013 if (/AppleWebKit/.test(navigator.userAgent)) {
1014 additionalWaitingTime = 5;
1016 additionalWaitingTime = 200;
1018 return _this.Timer.start(additionalWaitingTime, function() {
1020 if (!link.parentNode) {
1023 link.parentNode.removeChild(link);
1024 clone.onreadystatechange = null;
1025 return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0;
1031 Reloader.prototype.reattachImportedRule = function(_arg) {
1032 var href, index, link, media, newRule, parent, rule, tempLink;
1033 rule = _arg.rule, index = _arg.index, link = _arg.link;
1034 parent = rule.parentStyleSheet;
1035 href = this.generateCacheBustUrl(rule.href);
1036 media = rule.media.length ? [].join.call(rule.media, ', ') : '';
1037 newRule = "@import url(\"" + href + "\") " + media + ";";
1038 rule.__LiveReload_newHref = href;
1039 tempLink = this.document.createElement("link");
1040 tempLink.rel = 'stylesheet';
1041 tempLink.href = href;
1042 tempLink.__LiveReload_pendingRemoval = true;
1043 if (link.parentNode) {
1044 link.parentNode.insertBefore(tempLink, link);
1046 return this.Timer.start(this.importCacheWaitPeriod, (function(_this) {
1048 if (tempLink.parentNode) {
1049 tempLink.parentNode.removeChild(tempLink);
1051 if (rule.__LiveReload_newHref !== href) {
1054 parent.insertRule(newRule, index);
1055 parent.deleteRule(index + 1);
1056 rule = parent.cssRules[index];
1057 rule.__LiveReload_newHref = href;
1058 return _this.Timer.start(_this.importCacheWaitPeriod, function() {
1059 if (rule.__LiveReload_newHref !== href) {
1062 parent.insertRule(newRule, index);
1063 return parent.deleteRule(index + 1);
1069 Reloader.prototype.generateUniqueString = function() {
1070 return 'livereload=' + Date.now();
1073 Reloader.prototype.generateCacheBustUrl = function(url, expando) {
1074 var hash, oldParams, originalUrl, params, _ref;
1075 if (expando == null) {
1076 expando = this.generateUniqueString();
1078 _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
1079 if (this.options.overrideURL) {
1080 if (url.indexOf(this.options.serverURL) < 0) {
1082 url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url);
1083 this.console.log("LiveReload is overriding source URL " + originalUrl + " with " + url);
1086 params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
1087 return "" + sep + expando;
1089 if (params === oldParams) {
1090 if (oldParams.length === 0) {
1091 params = "?" + expando;
1093 params = "" + oldParams + "&" + expando;
1096 return url + params + hash;
1105 },{}],8:[function(require,module,exports){
1107 var CustomEvents, LiveReload, k;
1109 CustomEvents = require('./customevents');
1111 LiveReload = window.LiveReload = new (require('./livereload').LiveReload)(window);
1114 if (k.match(/^LiveReloadPlugin/)) {
1115 LiveReload.addPlugin(window[k]);
1119 LiveReload.addPlugin(require('./less'));
1121 LiveReload.on('shutdown', function() {
1122 return delete window.LiveReload;
1125 LiveReload.on('connect', function() {
1126 return CustomEvents.fire(document, 'LiveReloadConnect');
1129 LiveReload.on('disconnect', function() {
1130 return CustomEvents.fire(document, 'LiveReloadDisconnect');
1133 CustomEvents.bind(document, 'LiveReloadShutDown', function() {
1134 return LiveReload.shutDown();
1139 },{"./customevents":2,"./less":3,"./livereload":4}],9:[function(require,module,exports){
1143 exports.Timer = Timer = (function() {
1144 function Timer(func) {
1146 this.running = false;
1148 this._handler = (function(_this) {
1150 _this.running = false;
1152 return _this.func();
1157 Timer.prototype.start = function(timeout) {
1159 clearTimeout(this.id);
1161 this.id = setTimeout(this._handler, timeout);
1162 return this.running = true;
1165 Timer.prototype.stop = function() {
1167 clearTimeout(this.id);
1168 this.running = false;
1169 return this.id = null;
1177 Timer.start = function(timeout, func) {
1178 return setTimeout(func, timeout);