/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/popup.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
function POPUP(cb, cbattr) {
 
2
    this.popup_states = new Array();
 
3
    this.popup_callback = new Array();
 
4
    this.popup_rewidth_callback = new Array();
 
5
    this.popup_on_callbacks = new Array();
 
6
    this.popup_off_callbacks = new Array();
 
7
    this.current_height = new Array();
 
8
    this.popups = new Array();
 
9
    this.popups_width = 300;
 
10
    this.num_opened = 0;
 
11
    
 
12
    if (typeof cb != "undefined") this.RegisterCallback(cb,cbattr);
 
13
}
 
14
 
 
15
POPUP.prototype.RegisterOnCallback = function (module, cb, cbattr, call_once) {
 
16
    if (typeof this.popup_on_callbacks[module] == "undefined")
 
17
        this.popup_on_callbacks[module] = new Array();
 
18
        
 
19
    if (typeof call_once == "undefined") call_once = false;
 
20
    
 
21
    this.popup_on_callbacks[module].push({ 'cb': cb, 'cbattr': cbattr, 'once': call_once });
 
22
}
 
23
 
 
24
POPUP.prototype.RegisterOffCallback = function(module, cb, cbattr) {
 
25
    if (typeof this.popup_off_callbacks[module] == "undefined")
 
26
        this.popup_off_callbacks[module] = new Array();
 
27
    
 
28
    this.popup_off_callbacks[module].push({ 'cb': cb, 'cbattr': cbattr });
 
29
}
 
30
 
 
31
POPUP.prototype.RegisterCallback = function(cb, cbattr) {
 
32
        this.popup_callback.push ({ 'cb': cb, 'cbattr': cbattr });
 
33
}
 
34
 
 
35
POPUP.prototype.RegisterReWidthCallback = function(cb, cbattr) {
 
36
        this.popup_rewidth_callback.push ({ 'cb': cb, 'cbattr': cbattr });
 
37
}
 
38
 
 
39
POPUP.prototype.GetEncompasingNode = function(node) {
 
40
//    return node.parentNode.parentNode.parentNode.parentNode.parentNode;
 
41
    return node.parentNode.parentNode.parentNode.parentNode;
 
42
}
 
43
 
 
44
POPUP.prototype.RunReWidthCallbacksFunction = function(self) {
 
45
    return function() {
 
46
        for (var i = 0; i < self.popup_rewidth_callback.length; i++) {
 
47
            var cb = self.popup_rewidth_callback[i];
 
48
            cb.cb(cb.cbattr);
 
49
        }
 
50
    }
 
51
}
 
52
 
 
53
POPUP.prototype.RunReWidthCallbacks = function() {
 
54
    setTimeout(this.RunReWidthCallbacksFunction(this), adei.cfg.parse_delay);
 
55
}
 
56
 
 
57
 
 
58
POPUP.prototype.UpdateGeometry = function(module) {
 
59
    with (this) {
 
60
        var node = document.getElementById("popup_" + module);
 
61
        var switch_node = document.getElementById("popup_switch_" + module);
 
62
 
 
63
            /* Table fills not all available space, we can't fix it by width
 
64
            attribute in HTML since it will prevent hiding. So, fixing here */
 
65
        var tbl_node = this.GetEncompasingNode(node);
 
66
        
 
67
        if (node) {
 
68
            var cur_width_value = tbl_node.offsetWidth;
 
69
            
 
70
            if (cur_width_value > this.popups_width) {
 
71
                this.popups_width = cur_width_value;
 
72
 
 
73
//              for (var popup in this.popup_states) {
 
74
                for (var i = 0; i < this.popups.length; i++) {
 
75
                    var popup = this.popups[i];
 
76
                    if (this.popup_states[popup]) {
 
77
                        var popup_node = document.getElementById("popup_" + popup);
 
78
                        var popup_tbl_node = this.GetEncompasingNode(node);
 
79
                        if (popup_node) {
 
80
//                          if (popup_tbl_node.offsetWidth < this.popups_width) {
 
81
                                domSetMinWidth(popup_node, this.popups_width, false, popup_tbl_node.parentNode);
 
82
//                          }
 
83
                        }
 
84
                    }
 
85
                }
 
86
 
 
87
                if (this.num_opened) { /* otherwise calling in Open */
 
88
                    this.RunReWidthCallbacks();
 
89
                }
 
90
            } else if (cur_width_value < this.popups_width) {
 
91
                domSetMinWidth(node, this.popups_width, false, tbl_node.parentNode);
 
92
            }
 
93
        }
 
94
        
 
95
        if ((node)&&(switch_node)) {
 
96
            var a = switch_node.getElementsByTagName("button")[0];
 
97
            if (a) {
 
98
                var new_height_value = node.parentNode.offsetHeight; // td
 
99
                if (!this.current_height[module]) this.current_height[module] = a.offsetHeight;
 
100
                                
 
101
                if (this.current_height[module] < new_height_value) { 
 
102
                    this.current_height[module] = new_height_value;
 
103
                    domSetMinHeight(a, new_height_value, false, a.parentNode); //td checking
 
104
                }
 
105
            }
 
106
        }
 
107
    }
 
108
}
 
109
 
 
110
 
 
111
POPUP.prototype.Switch = function (module) {
 
112
 with (this) {
 
113
    if (typeof this.popup_states[module] == "undefined") {
 
114
        this.popup_states[module] = 0;
 
115
        this.popups.push(module);
 
116
    }
 
117
 
 
118
    if (popup_states[module]) {
 
119
        domHide("popup_" + module);
 
120
        popup_states[module] = 0;
 
121
 
 
122
        if (typeof this.popup_off_callbacks[module] != "undefined") {
 
123
            for (var i = 0; i < this.popup_off_callbacks[module].length; i++) {
 
124
                var cb = this.popup_off_callbacks[module][i];
 
125
                cb.cb(cb.cbattr, false);
 
126
            }
 
127
        }
 
128
        
 
129
        this.num_opened--;
 
130
 
 
131
        if (!this.num_opened) this.RunReWidthCallbacks();
 
132
    } else {
 
133
        domShow("popup_" + module);
 
134
        this.UpdateGeometry(module);
 
135
        popup_states[module] = 1;
 
136
 
 
137
        if (typeof this.popup_on_callbacks[module] != "undefined") {
 
138
            for (var i = 0; i < this.popup_on_callbacks[module].length; i++) {
 
139
                var cb = this.popup_on_callbacks[module][i];
 
140
                cb.cb(cb.cbattr, true);
 
141
                if (cb.once) {
 
142
                    this.popup_on_callbacks[module].splice(i,1);
 
143
                    i = i - 1;
 
144
                }
 
145
            }
 
146
 
 
147
        }
 
148
 
 
149
 
 
150
        if (!this.num_opened) this.RunReWidthCallbacks();
 
151
        this.num_opened++;
 
152
    }
 
153
    
 
154
    for (var i = 0; i < popup_callback.length; i++) {
 
155
        var cb = popup_callback[i];
 
156
        cb.cb(cb.cbattr);
 
157
    }
 
158
 }
 
159
}
 
160
 
 
161
function popupUpdateGeometryCallback(me, submodule) {
 
162
    me.popup.UpdateGeometry(me.module);
 
163
}
 
164