Initial commit
[yaffs-website] / node_modules / livereload-js / lib / less.js
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 link, links, _i, _len;
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);