From a2943d8a1dca97f75da0ae5a2debd2f1e598de47 Mon Sep 17 00:00:00 2001 From: Andrey Tarantsov Date: Sat, 19 Nov 2011 01:47:55 +0700 Subject: [PATCH] Update livereload.js --- dist/livereload.js | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/dist/livereload.js b/dist/livereload.js index 80c5eaa..eb98ab3 100644 --- a/dist/livereload.js +++ b/dist/livereload.js @@ -812,9 +812,9 @@ __livereload.LiveReload = LiveReload = (function() { _connector: this.connector, console: this.console, Timer: Timer, - generateCacheBustUrl: function(url) { + generateCacheBustUrl: __bind(function(url) { return this.reloader.generateCacheBustUrl(url); - } + }, this) }); this.plugins.push(plugin); this.reloader.addPlugin(plugin); @@ -850,14 +850,41 @@ __less = LessPlugin = (function() { this.host = host; } LessPlugin.prototype.reload = function(path, options) { - console.log([path, options]); - if ((path.match(/\.less$/i) || options.originalPath.match(/\.less$/i)) && this.window.less && this.window.less.refresh) { - this.host.console.log("LiveReload is asking LESS to recompile all stylesheets"); - this.window.less.refresh(true); - return true; + if (this.window.less && this.window.less.refresh) { + if (path.match(/\.less$/i)) { + return this.reloadLess(path); + } + if (options.originalPath.match(/\.less$/i)) { + return this.reloadLess(options.originalPath); + } } return false; }; + LessPlugin.prototype.reloadLess = function(path) { + var link, links, _i, _len; + links = (function() { + var _i, _len, _ref, _results; + _ref = document.getElementsByTagName('link'); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + link = _ref[_i]; + if (link.href && link.rel === 'stylesheet/less' || (link.rel.match(/stylesheet/) && link.type.match(/^text\/(x-)?less$/))) { + _results.push(link); + } + } + return _results; + })(); + if (links.length === 0) { + return false; + } + for (_i = 0, _len = links.length; _i < _len; _i++) { + link = links[_i]; + link.href = this.host.generateCacheBustUrl(link.href); + } + this.host.console.log("LiveReload is asking LESS to recompile all stylesheets"); + this.window.less.refresh(true); + return true; + }; LessPlugin.prototype.analyze = function() { return { disable: !!(this.window.less && this.window.less.refresh)