Debian Codegraph @

debian/missing-sources/livereload.js/less.js

raw
1 class LessPlugin {
2 constructor (window, host) {
3 this.window = window;
4 this.host = host;
5 }
6
7 reload (path, options) {
8 if (this.window.less && this.window.less.refresh) {
9 if (path.match(/\.less$/i)) {
10 return this.reloadLess(path);
11 }
12
13 if (options.originalPath.match(/\.less$/i)) {
14 return this.reloadLess(options.originalPath);
15 }
16 }
17
18 return false;
19 }
20
21 reloadLess (path) {
22 let link;
23 const links = ((() => {
24 const result = [];
25 for (link of Array.from(document.getElementsByTagName('link'))) {
26 if ((link.href && link.rel.match(/^stylesheet\/less$/i)) || (link.rel.match(/stylesheet/i) && link.type.match(/^text\/(x-)?less$/i))) {
27 result.push(link);
28 }
29 }
30 return result;
31 })());
32
33 if (links.length === 0) {
34 return false;
35 }
36
37 for (link of Array.from(links)) {
38 link.href = this.host.generateCacheBustUrl(link.href);
39 }
40
41 this.host.console.log('LiveReload is asking LESS to recompile all stylesheets');
42 this.window.less.refresh(true);
43
44 return true;
45 }
46
47 analyze () {
48 return {
49 disable: !!(this.window.less && this.window.less.refresh)
50 };
51 }
52 };
53
54 LessPlugin.identifier = 'less';
55 LessPlugin.version = '1.0';
56
57 module.exports = LessPlugin;