Subversion Repositories HomeAutomation

Rev

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

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