Subversion Repositories HomeAutomation

Rev

Rev 1619 | Rev 1644 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed

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