/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui

« back to all changes in this revision

Viewing changes to js/module.js

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var currnet_module = null;
 
2
var module_callback = null;
 
3
 
 
4
function MODULE(name, callback, callback_attr) {
 
5
    if (typeof callback == "undefined") callback = null;
 
6
    if (typeof callback_attr == "undefined") callback_attr = null;
 
7
 
 
8
    this.module_name = name;
 
9
    this.current_module = null;
 
10
    this.module_callback = callback;
 
11
    this.attr = callback_attr;
 
12
 
 
13
    this.module_height = 0;
 
14
 
 
15
    this.module = new Array();
 
16
    this.names = new Array();
 
17
    this.geometry_callback = new Array();
 
18
    
 
19
}
 
20
 
 
21
MODULE.prototype.Register = function(module, module_class) {
 
22
    if (module_class) {
 
23
        this.names.push(module);
 
24
        this.module[module] = module_class;
 
25
        return true;
 
26
    }
 
27
    return false;
 
28
}
 
29
 
 
30
MODULE.prototype.RegisterCallback = function(callback, callback_attr) {
 
31
    this.module_callback = callback;
 
32
    this.attr = callback_attr;
 
33
}
 
34
 
 
35
MODULE.prototype.RegisterGeometryCallback = function(cb, cbattr) {
 
36
    this.geometry_callback.push ({ 'cb': cb, 'cbattr': cbattr });
 
37
}
 
38
 
 
39
 
 
40
MODULE.prototype.GetModule = function(m) {
 
41
    return this.module[m];
 
42
}
 
43
 
 
44
MODULE.prototype.GetOpenModule = function() {
 
45
    if (this.current_module)
 
46
        return this.GetModule(this.current_module);
 
47
    return null;
 
48
}
 
49
 
 
50
/*
 
51
MODULE.prototype.SetCurrent = function(module) {
 
52
    with (this) {
 
53
        if (module.length > 0) {
 
54
            current_module = module;
 
55
            UpdateGeometry();    
 
56
        } else current_module = null;
 
57
    }
 
58
}
 
59
*/
 
60
 
 
61
MODULE.prototype.Open = function(mod) {
 
62
    var prefix;
 
63
    
 
64
    if (mod != this.current_module) {
 
65
        this.UpdateGeometry(); // Updating just current height
 
66
        
 
67
        if (this.module_name) prefix = this.module_name + "_";
 
68
        else prefix = "";
 
69
        
 
70
        if (this.current_module) {
 
71
            domHide("module_" + prefix + this.current_module);
 
72
            cssSetClass("module_link_" + prefix + this.current_module, "module_" + prefix + "link");
 
73
        }
 
74
        domShow("module_" + prefix + mod);
 
75
        cssSetClass("module_link_" + prefix + mod, "module_" + prefix + "link_current");
 
76
 
 
77
 
 
78
        this.current_module = mod;
 
79
 
 
80
        if (this.module_callback) this.module_callback(this.attr, this.current_module);
 
81
        this.UpdateGeometry();
 
82
    }
 
83
}
 
84
 
 
85
 
 
86
 
 
87
MODULE.prototype.RunGeometryCallbacks = function() {
 
88
    for (var i = 0; i < this.geometry_callback.length; i++) {
 
89
        var cb = this.geometry_callback[i];
 
90
        cb.cb(cb.cbattr);
 
91
    }
 
92
}
 
93
 
 
94
/*
 
95
The problem: offsetHeight includes 'borders' and style.heigh - not. So insert
 
96
borders inside of the main divs.
 
97
*/
 
98
MODULE.prototype.UpdateGeometry = function() {
 
99
    with (this) {
 
100
        if (module_name) prefix = module_name + "_";
 
101
        else prefix = "";
 
102
        
 
103
        var node = document.getElementById("module_" + prefix + current_module);
 
104
        if (node) {
 
105
            var cur_height_value = node.offsetHeight;
 
106
            var runcb = false;
 
107
            
 
108
            if (node.scrollHeight) {
 
109
                var full_height = node.scrollHeight;
 
110
                if (full_height > cur_height_value) {
 
111
                    if (full_height > module_height) {
 
112
                        module_height = full_height;
 
113
                        runcb = true;
 
114
                    }
 
115
                    cur_height_value = 0;
 
116
                }
 
117
            }
 
118
 
 
119
            if (cur_height_value > module_height) {
 
120
                module_height = cur_height_value;
 
121
 
 
122
                    // We still should increase, window so it could not be decreased back
 
123
                domSetMinHeight(node, module_height);
 
124
                
 
125
                this.RunGeometryCallbacks();
 
126
            } else if (module_height > 0) {
 
127
                domSetMinHeight(node, module_height);
 
128
                this.RunGeometryCallbacks();
 
129
            }
 
130
        }
 
131
    }
 
132
 
 
133
}
 
134
 
 
135
 
 
136
var default_module = new MODULE(null);
 
137
 
 
138
function moduleSetCurrent(module) {
 
139
    default_module.SetCurrent(module);
 
140
}
 
141
 
 
142
function moduleOpen(module) {
 
143
    default_module.Open(module);
 
144
}
 
145
 
 
146
function moduleUpdateGeometry(module) {
 
147
    module.UpdateGeometry();
 
148
}
 
149
 
 
150
 
 
151
function moduleGetElement(module, mclass_name) {
 
152
    if (typeof mclass_name == "undefined")  prefix = "";
 
153
    else prefix = mclass_name + "_";
 
154
 
 
155
    return document.getElementById("module_" + prefix + module);
 
156
}