| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | (function() { |
| 2 | var LessPlugin; |
| 3 | |
| 4 | module.exports = LessPlugin = (function() { |
| 5 | LessPlugin.identifier = 'less'; |
| 6 | |
| 7 | LessPlugin.version = '1.0'; |
| 8 | |
| 9 | function LessPlugin(window, host) { |
| 10 | this.window = window; |
| 11 | this.host = host; |
| 12 | } |
| 13 | |
| 14 | LessPlugin.prototype.reload = function(path, options) { |
| 15 | if (this.window.less && this.window.less.refresh) { |
| 16 | if (path.match(/\.less$/i)) { |
| 17 | return this.reloadLess(path); |
| 18 | } |
| 19 | if (options.originalPath.match(/\.less$/i)) { |
| 20 | return this.reloadLess(options.originalPath); |
| 21 | } |
| 22 | } |
| 23 | return false; |
| 24 | }; |
| 25 | |
| 26 | LessPlugin.prototype.reloadLess = function(path) { |
| 27 | var i, len, link, links; |
| 28 | links = (function() { |
| 29 | var i, len, ref, results; |
| 30 | ref = document.getElementsByTagName('link'); |
| 31 | results = []; |
| 32 | for (i = 0, len = ref.length; i < len; i++) { |
| 33 | link = ref[i]; |
| 34 | if (link.href && link.rel.match(/^stylesheet\/less$/i) || (link.rel.match(/stylesheet/i) && link.type.match(/^text\/(x-)?less$/i))) { |
| 35 | results.push(link); |
| 36 | } |
| 37 | } |
| 38 | return results; |
| 39 | })(); |
| 40 | if (links.length === 0) { |
| 41 | return false; |
| 42 | } |
| 43 | for (i = 0, len = links.length; i < len; i++) { |
| 44 | link = links[i]; |
| 45 | link.href = this.host.generateCacheBustUrl(link.href); |
| 46 | } |
| 47 | this.host.console.log("LiveReload is asking LESS to recompile all stylesheets"); |
| 48 | this.window.less.refresh(true); |
| 49 | return true; |
| 50 | }; |
| 51 | |
| 52 | LessPlugin.prototype.analyze = function() { |
| 53 | return { |
| 54 | disable: !!(this.window.less && this.window.less.refresh) |
| 55 | }; |
| 56 | }; |
| 57 | |
| 58 | return LessPlugin; |
| 59 | |
| 60 | })(); |
| 61 | |
| 62 | }).call(this); |