Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update livereload.js

  • Loading branch information...
commit 6aa86b01479c3aad785e9623f39cfcde2b8615f9 1 parent 8394e4e
@andreyvit andreyvit authored
Showing with 434 additions and 321 deletions.
  1. +434 −321 dist/livereload.js
View
755 dist/livereload.js
@@ -123,11 +123,12 @@ __protocol.Parser = Parser = (function() {
})();
// connector
+// Generated by CoffeeScript 1.3.3
var Connector, PROTOCOL_6, PROTOCOL_7, Parser, Version, _ref;
_ref = __protocol, Parser = _ref.Parser, PROTOCOL_6 = _ref.PROTOCOL_6, PROTOCOL_7 = _ref.PROTOCOL_7;
-Version = '2.0.7';
+Version = '2.0.8';
__connector.Connector = Connector = (function() {
@@ -158,12 +159,16 @@ __connector.Connector = Connector = (function() {
}
});
this._handshakeTimeout = new Timer(function() {
- if (!_this._isSocketConnected()) return;
+ if (!_this._isSocketConnected()) {
+ return;
+ }
_this._disconnectionReason = 'handshake-timeout';
return _this.socket.close();
});
this._reconnectTimer = new Timer(function() {
- if (!_this._connectionDesired) return;
+ if (!_this._connectionDesired) {
+ return;
+ }
return _this.connect();
});
this.connect();
@@ -176,7 +181,9 @@ __connector.Connector = Connector = (function() {
Connector.prototype.connect = function() {
var _this = this;
this._connectionDesired = true;
- if (this._isSocketConnected()) return;
+ if (this._isSocketConnected()) {
+ return;
+ }
this._reconnectTimer.stop();
this._disconnectionReason = 'cannot-connect';
this.protocolParser.reset();
@@ -199,13 +206,17 @@ __connector.Connector = Connector = (function() {
Connector.prototype.disconnect = function() {
this._connectionDesired = false;
this._reconnectTimer.stop();
- if (!this._isSocketConnected()) return;
+ if (!this._isSocketConnected()) {
+ return;
+ }
this._disconnectionReason = 'manual';
return this.socket.close();
};
Connector.prototype._scheduleReconnection = function() {
- if (!this._connectionDesired) return;
+ if (!this._connectionDesired) {
+ return;
+ }
if (!this._reconnectTimer.running) {
this._reconnectTimer.start(this._nextDelay);
return this._nextDelay = Math.min(this.options.maxdelay, this._nextDelay * 2);
@@ -213,7 +224,9 @@ __connector.Connector = Connector = (function() {
};
Connector.prototype.sendCommand = function(command) {
- if (this.protocol == null) return;
+ if (this.protocol == null) {
+ return;
+ }
return this._sendCommand(command);
};
@@ -236,9 +249,15 @@ __connector.Connector = Connector = (function() {
protocols: [PROTOCOL_6, PROTOCOL_7]
};
hello.ver = Version;
- if (this.options.ext) hello.ext = this.options.ext;
- if (this.options.extver) hello.extver = this.options.extver;
- if (this.options.snipver) hello.snipver = this.options.snipver;
+ if (this.options.ext) {
+ hello.ext = this.options.ext;
+ }
+ if (this.options.extver) {
+ hello.extver = this.options.extver;
+ }
+ if (this.options.snipver) {
+ hello.snipver = this.options.snipver;
+ }
this._sendCommand(hello);
return this._handshakeTimeout.start(this.options.handshake_timeout);
};
@@ -347,364 +366,458 @@ Options.extract = function(document) {
};
// reloader
-var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
-
-splitUrl = function(url) {
- var hash, index, params;
- if ((index = url.indexOf('#')) >= 0) {
- hash = url.slice(index);
- url = url.slice(0, index);
- } else {
- hash = '';
- }
- if ((index = url.indexOf('?')) >= 0) {
- params = url.slice(index);
- url = url.slice(0, index);
- } else {
- params = '';
- }
- return {
- url: url,
- params: params,
- hash: hash
+// Generated by CoffeeScript 1.3.1
+(function() {
+ var IMAGE_STYLES, Reloader, numberOfMatchingSegments, pathFromUrl, pathsMatch, pickBestMatch, splitUrl;
+
+ splitUrl = function(url) {
+ var hash, index, params;
+ if ((index = url.indexOf('#')) >= 0) {
+ hash = url.slice(index);
+ url = url.slice(0, index);
+ } else {
+ hash = '';
+ }
+ if ((index = url.indexOf('?')) >= 0) {
+ params = url.slice(index);
+ url = url.slice(0, index);
+ } else {
+ params = '';
+ }
+ return {
+ url: url,
+ params: params,
+ hash: hash
+ };
};
-};
-pathFromUrl = function(url) {
- var path;
- url = splitUrl(url).url;
- if (url.indexOf('file://') === 0) {
- path = url.replace(/^file:\/\/(localhost)?/, '');
- } else {
- path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/');
- }
- return decodeURIComponent(path);
-};
+ pathFromUrl = function(url) {
+ var path;
+ url = splitUrl(url).url;
+ if (url.indexOf('file://') === 0) {
+ path = url.replace(/^file:\/\/(localhost)?/, '');
+ } else {
+ path = url.replace(/^([^:]+:)?\/\/([^:\/]+)(:\d*)?\//, '/');
+ }
+ return decodeURIComponent(path);
+ };
-pickBestMatch = function(path, objects, pathFunc) {
- var bestMatch, object, score, _i, _len;
- bestMatch = {
- score: 0
- };
- for (_i = 0, _len = objects.length; _i < _len; _i++) {
- object = objects[_i];
- score = numberOfMatchingSegments(path, pathFunc(object));
- if (score > bestMatch.score) {
- bestMatch = {
- object: object,
- score: score
- };
+ pickBestMatch = function(path, objects, pathFunc) {
+ var bestMatch, object, score, _i, _len;
+ bestMatch = {
+ score: 0
+ };
+ for (_i = 0, _len = objects.length; _i < _len; _i++) {
+ object = objects[_i];
+ score = numberOfMatchingSegments(path, pathFunc(object));
+ if (score > bestMatch.score) {
+ bestMatch = {
+ object: object,
+ score: score
+ };
+ }
}
- }
- if (bestMatch.score > 0) {
- return bestMatch;
- } else {
- return null;
- }
-};
+ if (bestMatch.score > 0) {
+ return bestMatch;
+ } else {
+ return null;
+ }
+ };
-numberOfMatchingSegments = function(path1, path2) {
- var comps1, comps2, eqCount, len;
- path1 = path1.replace(/^\/+/, '').toLowerCase();
- path2 = path2.replace(/^\/+/, '').toLowerCase();
- if (path1 === path2) return 10000;
- comps1 = path1.split('/').reverse();
- comps2 = path2.split('/').reverse();
- len = Math.min(comps1.length, comps2.length);
- eqCount = 0;
- while (eqCount < len && comps1[eqCount] === comps2[eqCount]) {
- ++eqCount;
- }
- return eqCount;
-};
+ numberOfMatchingSegments = function(path1, path2) {
+ var comps1, comps2, eqCount, len;
+ path1 = path1.replace(/^\/+/, '').toLowerCase();
+ path2 = path2.replace(/^\/+/, '').toLowerCase();
+ if (path1 === path2) {
+ return 10000;
+ }
+ comps1 = path1.split('/').reverse();
+ comps2 = path2.split('/').reverse();
+ len = Math.min(comps1.length, comps2.length);
+ eqCount = 0;
+ while (eqCount < len && comps1[eqCount] === comps2[eqCount]) {
+ ++eqCount;
+ }
+ return eqCount;
+ };
-pathsMatch = function(path1, path2) {
- return numberOfMatchingSegments(path1, path2) > 0;
-};
+ pathsMatch = function(path1, path2) {
+ return numberOfMatchingSegments(path1, path2) > 0;
+ };
-IMAGE_STYLES = [
- {
- selector: 'background',
- styleNames: ['backgroundImage']
- }, {
- selector: 'border',
- styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
- }
-];
+ IMAGE_STYLES = [
+ {
+ selector: 'background',
+ styleNames: ['backgroundImage']
+ }, {
+ selector: 'border',
+ styleNames: ['borderImage', 'webkitBorderImage', 'MozBorderImage']
+ }
+ ];
-__reloader.Reloader = Reloader = (function() {
+ __reloader.Reloader = Reloader = (function() {
- function Reloader(window, console, Timer) {
- this.window = window;
- this.console = console;
- this.Timer = Timer;
- this.document = this.window.document;
- this.stylesheetGracePeriod = 200;
- this.importCacheWaitPeriod = 200;
- this.plugins = [];
- }
+ Reloader.name = 'Reloader';
- Reloader.prototype.addPlugin = function(plugin) {
- return this.plugins.push(plugin);
- };
+ function Reloader(window, console, Timer) {
+ this.window = window;
+ this.console = console;
+ this.Timer = Timer;
+ this.document = this.window.document;
+ this.importCacheWaitPeriod = 200;
+ this.plugins = [];
+ }
- Reloader.prototype.analyze = function(callback) {
- return results;
- };
+ Reloader.prototype.addPlugin = function(plugin) {
+ return this.plugins.push(plugin);
+ };
- Reloader.prototype.reload = function(path, options) {
- var plugin, _i, _len, _ref;
- this.options = options;
- _ref = this.plugins;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- plugin = _ref[_i];
- if (plugin.reload && plugin.reload(path, options)) return;
- }
- if (options.liveCSS) {
- if (path.match(/\.css$/i)) if (this.reloadStylesheet(path)) return;
- }
- if (options.liveImg) {
- if (path.match(/\.(jpe?g|png|gif)$/i)) {
- this.reloadImages(path);
- return;
+ Reloader.prototype.analyze = function(callback) {
+ return results;
+ };
+
+ Reloader.prototype.reload = function(path, options) {
+ var plugin, _base, _i, _len, _ref;
+ this.options = options;
+ if ((_base = this.options).stylesheetReloadTimeout == null) {
+ _base.stylesheetReloadTimeout = 15000;
}
- }
- return this.reloadPage();
- };
+ _ref = this.plugins;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ plugin = _ref[_i];
+ if (plugin.reload && plugin.reload(path, options)) {
+ return;
+ }
+ }
+ if (options.liveCSS) {
+ if (path.match(/\.css$/i)) {
+ if (this.reloadStylesheet(path)) {
+ return;
+ }
+ }
+ }
+ if (options.liveImg) {
+ if (path.match(/\.(jpe?g|png|gif)$/i)) {
+ this.reloadImages(path);
+ return;
+ }
+ }
+ return this.reloadPage();
+ };
- Reloader.prototype.reloadPage = function() {
- return this.window.document.location.reload();
- };
+ Reloader.prototype.reloadPage = function() {
+ return this.window.document.location.reload();
+ };
- Reloader.prototype.reloadImages = function(path) {
- var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len2, _len3, _len4, _ref, _ref2, _ref3, _ref4, _results;
- expando = this.generateUniqueString();
- _ref = this.document.images;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- img = _ref[_i];
- if (pathsMatch(path, pathFromUrl(img.src))) {
- img.src = this.generateCacheBustUrl(img.src, expando);
+ Reloader.prototype.reloadImages = function(path) {
+ var expando, img, selector, styleNames, styleSheet, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3, _results;
+ expando = this.generateUniqueString();
+ _ref = this.document.images;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ img = _ref[_i];
+ if (pathsMatch(path, pathFromUrl(img.src))) {
+ img.src = this.generateCacheBustUrl(img.src, expando);
+ }
}
- }
- if (this.document.querySelectorAll) {
- for (_j = 0, _len2 = IMAGE_STYLES.length; _j < _len2; _j++) {
- _ref2 = IMAGE_STYLES[_j], selector = _ref2.selector, styleNames = _ref2.styleNames;
- _ref3 = this.document.querySelectorAll("[style*=" + selector + "]");
- for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
- img = _ref3[_k];
- this.reloadStyleImages(img.style, styleNames, path, expando);
+ if (this.document.querySelectorAll) {
+ for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
+ _ref1 = IMAGE_STYLES[_j], selector = _ref1.selector, styleNames = _ref1.styleNames;
+ _ref2 = this.document.querySelectorAll("[style*=" + selector + "]");
+ for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
+ img = _ref2[_k];
+ this.reloadStyleImages(img.style, styleNames, path, expando);
+ }
}
}
- }
- if (this.document.styleSheets) {
- _ref4 = this.document.styleSheets;
- _results = [];
- for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) {
- styleSheet = _ref4[_l];
- _results.push(this.reloadStylesheetImages(styleSheet, path, expando));
+ if (this.document.styleSheets) {
+ _ref3 = this.document.styleSheets;
+ _results = [];
+ for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
+ styleSheet = _ref3[_l];
+ _results.push(this.reloadStylesheetImages(styleSheet, path, expando));
+ }
+ return _results;
}
- return _results;
- }
- };
+ };
- Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
- var rule, rules, styleNames, _i, _j, _len, _len2;
- try {
- rules = styleSheet != null ? styleSheet.cssRules : void 0;
- } catch (e) {
+ Reloader.prototype.reloadStylesheetImages = function(styleSheet, path, expando) {
+ var rule, rules, styleNames, _i, _j, _len, _len1;
+ try {
+ rules = styleSheet != null ? styleSheet.cssRules : void 0;
+ } catch (e) {
- }
- if (!rules) return;
- for (_i = 0, _len = rules.length; _i < _len; _i++) {
- rule = rules[_i];
- switch (rule.type) {
- case CSSRule.IMPORT_RULE:
- this.reloadStylesheetImages(rule.styleSheet, path, expando);
- break;
- case CSSRule.STYLE_RULE:
- for (_j = 0, _len2 = IMAGE_STYLES.length; _j < _len2; _j++) {
- styleNames = IMAGE_STYLES[_j].styleNames;
- this.reloadStyleImages(rule.style, styleNames, path, expando);
- }
- break;
- case CSSRule.MEDIA_RULE:
- this.reloadStylesheetImages(rule, path, expando);
}
- }
- };
+ if (!rules) {
+ return;
+ }
+ for (_i = 0, _len = rules.length; _i < _len; _i++) {
+ rule = rules[_i];
+ switch (rule.type) {
+ case CSSRule.IMPORT_RULE:
+ this.reloadStylesheetImages(rule.styleSheet, path, expando);
+ break;
+ case CSSRule.STYLE_RULE:
+ for (_j = 0, _len1 = IMAGE_STYLES.length; _j < _len1; _j++) {
+ styleNames = IMAGE_STYLES[_j].styleNames;
+ this.reloadStyleImages(rule.style, styleNames, path, expando);
+ }
+ break;
+ case CSSRule.MEDIA_RULE:
+ this.reloadStylesheetImages(rule, path, expando);
+ }
+ }
+ };
- Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
- var newValue, styleName, value, _i, _len;
- var _this = this;
- for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
- styleName = styleNames[_i];
- value = style[styleName];
- if (typeof value === 'string') {
- newValue = value.replace(/\burl\s*\(([^)]*)\)/, function(match, src) {
- if (pathsMatch(path, pathFromUrl(src))) {
- return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")";
- } else {
- return match;
+ Reloader.prototype.reloadStyleImages = function(style, styleNames, path, expando) {
+ var newValue, styleName, value, _i, _len,
+ _this = this;
+ for (_i = 0, _len = styleNames.length; _i < _len; _i++) {
+ styleName = styleNames[_i];
+ value = style[styleName];
+ if (typeof value === 'string') {
+ newValue = value.replace(/\burl\s*\(([^)]*)\)/, function(match, src) {
+ if (pathsMatch(path, pathFromUrl(src))) {
+ return "url(" + (_this.generateCacheBustUrl(src, expando)) + ")";
+ } else {
+ return match;
+ }
+ });
+ if (newValue !== value) {
+ style[styleName] = newValue;
}
- });
- if (newValue !== value) style[styleName] = newValue;
+ }
}
- }
- };
+ };
- Reloader.prototype.reloadStylesheet = function(path) {
- var imported, link, links, match, style, _i, _j, _k, _len, _len2, _len3, _ref;
- links = (function() {
- var _i, _len, _ref, _results;
- _ref = this.document.getElementsByTagName('link');
- _results = [];
+ Reloader.prototype.reloadStylesheet = function(path) {
+ var imported, link, links, match, style, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1,
+ _this = this;
+ links = (function() {
+ var _i, _len, _ref, _results;
+ _ref = this.document.getElementsByTagName('link');
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ link = _ref[_i];
+ if (link.rel === 'stylesheet' && !link.__LiveReload_pendingRemoval) {
+ _results.push(link);
+ }
+ }
+ return _results;
+ }).call(this);
+ imported = [];
+ _ref = this.document.getElementsByTagName('style');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- link = _ref[_i];
- if (link.rel === 'stylesheet' && !link.__LiveReload_pendingRemoval) {
- _results.push(link);
+ style = _ref[_i];
+ if (style.sheet) {
+ this.collectImportedStylesheets(style, style.sheet, imported);
}
}
- return _results;
- }).call(this);
- imported = [];
- _ref = this.document.getElementsByTagName('style');
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- style = _ref[_i];
- if (style.sheet) {
- this.collectImportedStylesheets(style, style.sheet, imported);
+ for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
+ link = links[_j];
+ this.collectImportedStylesheets(link, link.sheet, imported);
}
- }
- for (_j = 0, _len2 = links.length; _j < _len2; _j++) {
- link = links[_j];
- this.collectImportedStylesheets(link, link.sheet, imported);
- }
- this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets");
- match = pickBestMatch(path, links.concat(imported), function(l) {
- return pathFromUrl(l.href);
- });
- if (match) {
- if (match.object.rule) {
- this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
- this.reattachImportedRule(match.object);
- } else {
- this.console.log("LiveReload is reloading stylesheet: " + match.object.href);
- this.reattachStylesheetLink(match.object);
+ if (this.window.StyleFix && this.document.querySelectorAll) {
+ _ref1 = this.document.querySelectorAll('style[data-href]');
+ for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
+ style = _ref1[_k];
+ links.push(style);
+ }
}
- } else {
- this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one");
- for (_k = 0, _len3 = links.length; _k < _len3; _k++) {
- link = links[_k];
- this.reattachStylesheetLink(link);
+ this.console.log("LiveReload found " + links.length + " LINKed stylesheets, " + imported.length + " @imported stylesheets");
+ match = pickBestMatch(path, links.concat(imported), function(l) {
+ return pathFromUrl(_this.linkHref(l));
+ });
+ if (match) {
+ if (match.object.rule) {
+ this.console.log("LiveReload is reloading imported stylesheet: " + match.object.href);
+ this.reattachImportedRule(match.object);
+ } else {
+ this.console.log("LiveReload is reloading stylesheet: " + (this.linkHref(match.object)));
+ this.reattachStylesheetLink(match.object);
+ }
+ } else {
+ this.console.log("LiveReload will reload all stylesheets because path '" + path + "' did not match any specific one");
+ for (_l = 0, _len3 = links.length; _l < _len3; _l++) {
+ link = links[_l];
+ this.reattachStylesheetLink(link);
+ }
}
- }
- return true;
- };
+ return true;
+ };
- Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
- var index, rule, rules, _len;
- try {
- rules = styleSheet != null ? styleSheet.cssRules : void 0;
- } catch (e) {
+ Reloader.prototype.collectImportedStylesheets = function(link, styleSheet, result) {
+ var index, rule, rules, _i, _len;
+ try {
+ rules = styleSheet != null ? styleSheet.cssRules : void 0;
+ } catch (e) {
- }
- if (rules && rules.length) {
- for (index = 0, _len = rules.length; index < _len; index++) {
- rule = rules[index];
- switch (rule.type) {
- case CSSRule.CHARSET_RULE:
- continue;
- case CSSRule.IMPORT_RULE:
- result.push({
- link: link,
- rule: rule,
- index: index,
- href: rule.href
- });
- this.collectImportedStylesheets(link, rule.styleSheet, result);
- break;
- default:
- break;
+ }
+ if (rules && rules.length) {
+ for (index = _i = 0, _len = rules.length; _i < _len; index = ++_i) {
+ rule = rules[index];
+ switch (rule.type) {
+ case CSSRule.CHARSET_RULE:
+ continue;
+ case CSSRule.IMPORT_RULE:
+ result.push({
+ link: link,
+ rule: rule,
+ index: index,
+ href: rule.href
+ });
+ this.collectImportedStylesheets(link, rule.styleSheet, result);
+ break;
+ default:
+ break;
+ }
}
}
- }
- };
+ };
- Reloader.prototype.reattachStylesheetLink = function(link) {
- var clone, parent, timer;
- if (link.__LiveReload_pendingRemoval) return;
- link.__LiveReload_pendingRemoval = true;
- clone = link.cloneNode(false);
- clone.href = this.generateCacheBustUrl(link.href);
- parent = link.parentNode;
- if (parent.lastChild === link) {
- parent.appendChild(clone);
- } else {
- parent.insertBefore(clone, link.nextSibling);
- }
- timer = new this.Timer(function() {
- if (link.parentNode) return link.parentNode.removeChild(link);
- });
- return timer.start(this.stylesheetGracePeriod);
- };
+ Reloader.prototype.waitUntilCssLoads = function(clone, func) {
+ var callbackExecuted, executeCallback, poll,
+ _this = this;
+ callbackExecuted = false;
+ executeCallback = function() {
+ if (callbackExecuted) {
+ return;
+ }
+ callbackExecuted = true;
+ return func();
+ };
+ clone.onload = function() {
+ console.log("onload!");
+ _this.knownToSupportCssOnLoad = true;
+ return executeCallback();
+ };
+ if (!this.knownToSupportCssOnLoad) {
+ (poll = function() {
+ if (clone.sheet) {
+ console.log("polling!");
+ return executeCallback();
+ } else {
+ return _this.Timer.start(50, poll);
+ }
+ })();
+ }
+ return this.Timer.start(this.options.stylesheetReloadTimeout, executeCallback);
+ };
- Reloader.prototype.reattachImportedRule = function(_arg) {
- var href, index, link, media, newRule, parent, rule, tempLink;
- var _this = this;
- rule = _arg.rule, index = _arg.index, link = _arg.link;
- parent = rule.parentStyleSheet;
- href = this.generateCacheBustUrl(rule.href);
- media = rule.media.length ? [].join.call(rule.media, ', ') : '';
- newRule = "@import url(\"" + href + "\") " + media + ";";
- rule.__LiveReload_newHref = href;
- tempLink = this.document.createElement("link");
- tempLink.rel = 'stylesheet';
- tempLink.href = href;
- tempLink.__LiveReload_pendingRemoval = true;
- if (link.parentNode) link.parentNode.insertBefore(tempLink, link);
- return this.Timer.start(this.importCacheWaitPeriod, function() {
- if (tempLink.parentNode) tempLink.parentNode.removeChild(tempLink);
- if (rule.__LiveReload_newHref !== href) return;
- parent.insertRule(newRule, index);
- parent.deleteRule(index + 1);
- rule = parent.cssRules[index];
+ Reloader.prototype.linkHref = function(link) {
+ return link.href || link.getAttribute('data-href');
+ };
+
+ Reloader.prototype.reattachStylesheetLink = function(link) {
+ var clone, parent,
+ _this = this;
+ if (link.__LiveReload_pendingRemoval) {
+ return;
+ }
+ link.__LiveReload_pendingRemoval = true;
+ if (link.tagName === 'STYLE') {
+ clone = this.document.createElement('link');
+ clone.rel = 'stylesheet';
+ clone.media = link.media;
+ clone.disabled = link.disabled;
+ } else {
+ clone = link.cloneNode(false);
+ }
+ clone.href = this.generateCacheBustUrl(this.linkHref(link));
+ parent = link.parentNode;
+ if (parent.lastChild === link) {
+ parent.appendChild(clone);
+ } else {
+ parent.insertBefore(clone, link.nextSibling);
+ }
+ return this.waitUntilCssLoads(clone, function() {
+ var additionalWaitingTime;
+ if (/AppleWebKit/.test(navigator.userAgent)) {
+ additionalWaitingTime = 5;
+ } else {
+ additionalWaitingTime = 200;
+ }
+ return _this.Timer.start(additionalWaitingTime, function() {
+ var _ref;
+ if (!link.parentNode) {
+ return;
+ }
+ link.parentNode.removeChild(link);
+ clone.onreadystatechange = null;
+ return (_ref = _this.window.StyleFix) != null ? _ref.link(clone) : void 0;
+ });
+ });
+ };
+
+ Reloader.prototype.reattachImportedRule = function(_arg) {
+ var href, index, link, media, newRule, parent, rule, tempLink,
+ _this = this;
+ rule = _arg.rule, index = _arg.index, link = _arg.link;
+ parent = rule.parentStyleSheet;
+ href = this.generateCacheBustUrl(rule.href);
+ media = rule.media.length ? [].join.call(rule.media, ', ') : '';
+ newRule = "@import url(\"" + href + "\") " + media + ";";
rule.__LiveReload_newHref = href;
- return _this.Timer.start(_this.importCacheWaitPeriod, function() {
- if (rule.__LiveReload_newHref !== href) return;
+ tempLink = this.document.createElement("link");
+ tempLink.rel = 'stylesheet';
+ tempLink.href = href;
+ tempLink.__LiveReload_pendingRemoval = true;
+ if (link.parentNode) {
+ link.parentNode.insertBefore(tempLink, link);
+ }
+ return this.Timer.start(this.importCacheWaitPeriod, function() {
+ if (tempLink.parentNode) {
+ tempLink.parentNode.removeChild(tempLink);
+ }
+ if (rule.__LiveReload_newHref !== href) {
+ return;
+ }
parent.insertRule(newRule, index);
- return parent.deleteRule(index + 1);
+ parent.deleteRule(index + 1);
+ rule = parent.cssRules[index];
+ rule.__LiveReload_newHref = href;
+ return _this.Timer.start(_this.importCacheWaitPeriod, function() {
+ if (rule.__LiveReload_newHref !== href) {
+ return;
+ }
+ parent.insertRule(newRule, index);
+ return parent.deleteRule(index + 1);
+ });
});
- });
- };
+ };
- Reloader.prototype.generateUniqueString = function() {
- return 'livereload=' + Date.now();
- };
+ Reloader.prototype.generateUniqueString = function() {
+ return 'livereload=' + Date.now();
+ };
- Reloader.prototype.generateCacheBustUrl = function(url, expando) {
- var hash, oldParams, params, _ref;
- if (expando == null) expando = this.generateUniqueString();
- _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
- if (this.options.overrideURL) {
- if (url.indexOf(this.options.serverURL) < 0) {
- url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url);
+ Reloader.prototype.generateCacheBustUrl = function(url, expando) {
+ var hash, oldParams, params, _ref;
+ if (expando == null) {
+ expando = this.generateUniqueString();
}
- }
- params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
- return "" + sep + expando;
- });
- if (params === oldParams) {
- if (oldParams.length === 0) {
- params = "?" + expando;
- } else {
- params = "" + oldParams + "&" + expando;
+ _ref = splitUrl(url), url = _ref.url, hash = _ref.hash, oldParams = _ref.params;
+ if (this.options.overrideURL) {
+ if (url.indexOf(this.options.serverURL) < 0) {
+ url = this.options.serverURL + this.options.overrideURL + "?url=" + encodeURIComponent(url);
+ }
}
- }
- return url + params + hash;
- };
+ params = oldParams.replace(/(\?|&)livereload=(\d+)/, function(match, sep) {
+ return "" + sep + expando;
+ });
+ if (params === oldParams) {
+ if (oldParams.length === 0) {
+ params = "?" + expando;
+ } else {
+ params = "" + oldParams + "&" + expando;
+ }
+ }
+ return url + params + hash;
+ };
- return Reloader;
+ return Reloader;
-})();
+ })();
+
+}).call(this);
// livereload
var Connector, LiveReload, Options, Reloader, Timer;
Please sign in to comment.
Something went wrong with that request. Please try again.