Initial commit
[yaffs-website] / node_modules / livereload-js / lib / options.js
1 (function() {
2   var Options;
3
4   exports.Options = Options = (function() {
5     function Options() {
6       this.https = false;
7       this.host = null;
8       this.port = 35729;
9       this.snipver = null;
10       this.ext = null;
11       this.extver = null;
12       this.mindelay = 1000;
13       this.maxdelay = 60000;
14       this.handshake_timeout = 5000;
15     }
16
17     Options.prototype.set = function(name, value) {
18       if (typeof value === 'undefined') {
19         return;
20       }
21       if (!isNaN(+value)) {
22         value = +value;
23       }
24       return this[name] = value;
25     };
26
27     return Options;
28
29   })();
30
31   Options.extract = function(document) {
32     var element, keyAndValue, m, mm, options, pair, src, _i, _j, _len, _len1, _ref, _ref1;
33     _ref = document.getElementsByTagName('script');
34     for (_i = 0, _len = _ref.length; _i < _len; _i++) {
35       element = _ref[_i];
36       if ((src = element.src) && (m = src.match(/^[^:]+:\/\/(.*)\/z?livereload\.js(?:\?(.*))?$/))) {
37         options = new Options();
38         options.https = src.indexOf("https") === 0;
39         if (mm = m[1].match(/^([^\/:]+)(?::(\d+))?$/)) {
40           options.host = mm[1];
41           if (mm[2]) {
42             options.port = parseInt(mm[2], 10);
43           }
44         }
45         if (m[2]) {
46           _ref1 = m[2].split('&');
47           for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
48             pair = _ref1[_j];
49             if ((keyAndValue = pair.split('=')).length > 1) {
50               options.set(keyAndValue[0].replace(/-/g, '_'), keyAndValue.slice(1).join('='));
51             }
52           }
53         }
54         return options;
55       }
56     }
57     return null;
58   };
59
60 }).call(this);