Subversion Repositories HomeAutomation

Rev

Rev 1619 | Rev 1644 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1619 Rev 1625
1
 
1
 
2
var global_legacy = false;
2
var global_legacy = false;
3
 
3
 
4
LoadScript("common/json.js");
4
LoadScript("common/json.js");
5
 
5
 
6
function Start(legacy)
6
function Start(legacy)
7
{
7
{
8
    global_legacy = legacy;
8
    global_legacy = legacy;
-
 
9
   
-
 
10
    LoadScript("common/alias.js");
-
 
11
    LoadScript("common/irrecord.js");
9
   
12
   
10
    if (global_legacy)
13
    if (global_legacy)
11
    {
14
    {
12
        LoadScript("legacy/System/Base.js");
15
        LoadScript("legacy/System/Base.js");
13
        LoadScript("legacy/System/Startup.js");
16
        LoadScript("legacy/System/Startup.js");
14
        LoadScript("legacy/Autostart.js");
17
        LoadScript("legacy/Autostart.js");
15
       
18
       
16
        autostart();
19
        autostart();
17
    }
20
    }
18
    else
21
    else
19
    {
22
    {
20
        LoadScript("user/autostart.js");
23
        LoadScript("user/autostart.js");
21
    }
24
    }
22
}
25
}
23
 
26
 
24
function Extend(descendant, parent)
27
function Extend(descendant, parent)
25
{
28
{
26
    var s_constructor = parent.toString();
29
    var s_constructor = parent.toString();
27
    var a_match = s_constructor.match(/\s*function (.*)\(/);
30
    var a_match = s_constructor.match(/\s*function (.*)\(/);
28
   
31
   
29
    if (a_match != null)
32
    if (a_match != null)
30
    {
33
    {
31
        descendant.prototype[a_match[1]] = parent;
34
        descendant.prototype[a_match[1]] = parent;
32
    }
35
    }
33
   
36
   
34
    for (var m in parent.prototype)
37
    for (var m in parent.prototype)
35
    {
38
    {
36
        descendant.prototype[m] = parent.prototype[m];
39
        descendant.prototype[m] = parent.prototype[m];
37
    }
40
    }
38
}
41
}
39
 
42
 
40
function ArrayContains(array, item)
43
function ArrayContains(array, item)
41
{
44
{
42
    for (var n in array)
45
    for (var n in array)
43
    {
46
    {
44
        if (array[n] == item)
47
        if (array[n] == item)
45
        {
48
        {
46
            return true;
49
            return true;
47
        }
50
        }
48
    }
51
    }
49
   
52
   
50
    return false;
53
    return false;
51
}
54
}
52
 
55
 
53
String.prototype.ltrim = function(charlist)
56
String.prototype.ltrim = function(charlist)
54
{
57
{
55
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
58
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
56
    var re = new RegExp('^[' + charlist + ']+', 'g');
59
    var re = new RegExp('^[' + charlist + ']+', 'g');
57
    return this.replace(re, '');
60
    return this.replace(re, '');
58
}
61
}
59
 
62
 
60
String.prototype.rtrim = function(charlist)
63
String.prototype.rtrim = function(charlist)
61
{
64
{
62
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
65
    charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
63
    var re = new RegExp('[' + charlist + ']+$', 'g');
66
    var re = new RegExp('[' + charlist + ']+$', 'g');
64
    return this.replace(re, '');
67
    return this.replace(re, '');
65
}
68
}
66
 
69
 
67
String.prototype.trim = function(charlist)
70
String.prototype.trim = function(charlist)
68
{
71
{
69
    var str = this.ltrim(charlist);
72
    var str = this.ltrim(charlist);
70
    return str.rtrim(charlist);
73
    return str.rtrim(charlist);
71
}
74
}
72
 
75
 
73
function EventBase()
76
function EventBase()
74
{
77
{
75
    this.callbacks_ = new Array();
78
    this.callbacks_ = new Array();
76
}
79
}
77
 
80
 
78
EventBase.prototype.callbacks_ = null;
81
EventBase.prototype.callbacks_ = null;
79
 
82
 
80
EventBase.prototype.Bind = function(event_name, callback)
83
EventBase.prototype.Bind = function(event_name, callback)
81
{
84
{
82
    if (typeof this.callbacks_[event_name] == 'undefined')
85
    if (typeof this.callbacks_[event_name] == 'undefined')
83
    {
86
    {
84
        this.callbacks_[event_name] = new Array();
87
        this.callbacks_[event_name] = new Array();
85
    }
88
    }
86
   
89
   
87
    this.callbacks_[event_name].push(callback);
90
    this.callbacks_[event_name].push(callback);
88
}
91
}
89
 
92
 
90
EventBase.prototype.Trigger = function(event_name)
93
EventBase.prototype.Trigger = function(event_name)
91
{
94
{
92
    if (typeof this.callbacks_[event_name] != 'undefined')
95
    if (typeof this.callbacks_[event_name] != 'undefined')
93
    {
96
    {
94
        for (var n = 0; n < this.callbacks_[event_name].length; n++)
97
        for (var n = 0; n < this.callbacks_[event_name].length; n++)
95
        {
98
        {
96
            this.callbacks_[event_name][n].apply(null, Array.prototype.slice.call(arguments, 0));
99
            this.callbacks_[event_name][n].apply(null, Array.prototype.slice.call(arguments, 0));
97
        }
100
        }
98
    }
101
    }
99
}
102
}
100
 
103