javascript object event

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Toby hinloopen

toby hinloopen

02/03/2009 16:31:00
Quote Anchor link
ik heb een object met daarin een een functie genaamt "resize".
deze functie doet precies wat zn naam zegt: het huidige object "resizen". Nou wordt er in die functie ook een functie opgeroepen, genaamt "on_resize".

Dit is die functie:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?
this.on_resize = function(){
            var
events = new Array();
            this.event = function(func) {
                for(var x=0;events[x];x++);
                events[x] = func;
            }

            for(var x=0;x<events.length;x++) {
                if(events[x]) {
                    events[x]();
                }
            }

            return true;
        }

?>


De bedoeling van deze functie is om events te kunnen toevoegen en verwijderen. Wanneer deze event gestart wordt, moeten alle events gestart worden.

Oftewel, wanneer het object ge-resize-d wordt, wordt de event/functie "on_resize" gestart. In deze functie staat een variable ("events") waarin alle event-functies staan die dynamisch toegevoegd en verwijderd kunnen worden.

voorbeeld:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
var een_event_handler = new jswindow_object.on_resize.event(function() {
//doe iets
});


Wanneer ik dan het object "resize", waarbij de on_resize functie gestart wordt, moeten alle event-handlers die aangemaakt zijn zoals in de bovenstaande code, start worden.

Hopelijk wordt mijn uitleg een beetje gesnapt :P

Hoe dan ook, de bovenstaande code werkt niet. Wanneer ik de event probeer toe te voegen krijg ik een errortje in firebug te zien: "jswindow_object.on_resize.event is not a constructor"

Wanneer ik "new" ervoor weghaal, krijg ik "jswindow_object.on_resize.event is not a function".

wie kan mij helpen?
wat gaat hier fout?

Dit is trouwens de gehele code: (betreffende functie staat op lijn 145)
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?

function windows_container(element_id) {
    var
minwidth = 49
    var minheight = 20;
    var
parent = this;
    if(!element_id) {
        this.element = document.createElement('div');
        this.element.style.position = 'absolute';
        this.element.style.top = '0px';
        this.element.style.left = '0px';
        this.element.style.width = '0px';
        this.element.style.height = '0px';
        this.element.style.zIndex = '10';
        
        this.local_id = 0;
        while(document.getElementById('windows_container_'+this.local_id)) {
            this.local_id++;
        }

        this.element.id = 'windows_container_'+this.local_id;
        this.local_id = this.element.id;
        document.body.appendChild(this.element);
    }
else {
        this.element = document.getElementById(element_id);
        this.local_id = element_id;
    }

    //variables
    this.windows = new Array();
    
    //events
    this.on_new_window = function(){return true;}
    
    //functions
    this.window = function(title,content,innerDimension) {
        var
current_window = this;
        
        //functions
        this.drag_start = function() {
            if(current_window.positioning==2){
                return false;
            }

            current_window.temp_window_offset = new Array(current_window.element.offsetLeft - mouse_fixed[0],current_window.element.offsetTop - mouse_fixed[1]);
            document_onmouseup.push(function() {
                current_window.temp_window_offset = null;
                document_onmousemove.pop();
                document_onmouseup.pop();
            });

            document_onmousemove.push(function() {
                if(current_window.temp_window_offset) {
                    current_window.set_location(mouse_fixed[0]+current_window.temp_window_offset[0],mouse_fixed[1]+current_window.temp_window_offset[1]);
                }
            });
        }

        
        this.set_location = function(x,y) {
            current_window.element.style.marginLeft = parseInt(x)+'px';    
            current_window.element.style.marginRight = 'auto';            
            current_window.element.style.marginTop = parseInt(y)+'px';
            current_window.element.style.marginBottom = 'auto';
        }

        
        this.set_width = function(width,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            width = Math.max(parseInt(width),minwidth);
            current_window.element.style.width = (width)+'px';
            current_window.content_element.style.width = (width)+'px';
            current_window.content_container.style.width = (width)+'px';
            current_window.title_element.style.width = (width-minwidth)+'px';
        }

        
        this.set_height = function(height,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            height = Math.max(parseInt(height),minheight);
            current_window.element.style.height = (height)+'px';
            current_window.content_element.style.height = (height-minheight)+'px';
            current_window.content_container.style.height = (height-minheight)+'px';
        }

        
        this.set_dimension = function(width,height,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_width(width,1);
            current_window.set_height(height,1);
        }

        
        this.set_innerWidth = function(width,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_width(width,1);            
        }

        
        this.set_innerHeight = function(height,no_event) {    
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_height(height+minheight,1);            
        }

        
        this.set_innerDimension = function(width,height,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_innerWidth(width,1);
            current_window.set_innerHeight(height,1);
        }

        
        this.minimize = function() {
            current_window.positioning = 0;
            current_window.float_position = new Array(
                current_window.element.offsetLeft,
                current_window.element.offsetTop,
                parseInt(current_window.element.style.width),
                parseInt(current_window.element.style.height)
            );

            current_window.content_element.style.display = 'none';
            current_window.set_innerDimension(0,0);
            current_window.set_location(0,body_height() - parseInt(current_window.element.style.height));
        }

        
        this.maximize = function() {
            if(current_window.positioning==0) {
                current_window.content_element.style.display = 'block';
            }

            if(current_window.positioning==1) {
                current_window.float_position = new Array(
                    current_window.element.offsetLeft,
                    current_window.element.offsetTop,
                    parseInt(current_window.element.style.width),
                    parseInt(current_window.element.style.height)
                );

                current_window.set_location(-1,-1);
                current_window.set_dimension(body_width()+2,body_height()+2);    
                current_window.positioning = 2;    
            }
else {
                current_window.set_location(current_window.float_position[0],current_window.float_position[1]);
                current_window.set_dimension(current_window.float_position[2],current_window.float_position[3]);
                current_window.positioning = 1;    
            }
        }

        
        this.destroy = function(no_event) {
            if(!no_event && !current_window.on_destroy()) {return false;}
            this.element.parentNode.removeChild(this.element);
        }

        
        //variables
        this.float_position = new Array(0,0,0,0);
        this.positioning = 1;
        
        //events
        this.on_resize = function(){
            var
events = new Array();
            this.event = function(func) {
                for(var x=0;events[x];x++);
                events[x] = func;
            }

            for(var x=0;x<events.length;x++) {
                if(events[x]) {
                    events[x]();
                }
            }

            return true;
        }

        this.on_destroy = function(){
            var
events = new Array();
            this.event = function(func) {
                for(var x=0;events[x];x++);
                events[x] = func;
            }

            for(var x=0;x<events.length;x++) {
                if(events[x]) {
                    events[x]();
                }
            }

            return true;
        }

        this.on_move = function(){
            var
events = new Array();
            this.event = function(func) {
                for(var x=0;events[x];x++);
                events[x] = func;
            }

            for(var x=0;x<events.length;x++) {
                if(events[x]) {
                    events[x]();
                }
            }

            return true;
        }

        
        this.local_id = 0;
        while(parent.windows[this.local_id]) {
            this.local_id++;
        }

        if(parent.on_new_window(this.local_id,title,content)===false) {//indien "return false" gebruikt is in de "on_new_window" event...
            return false;//stop het maken van een nieuwe window
        }
        parent.windows[this.local_id] = this;
        
        if(!title) {
            title = '';
        }
else {
            title = title.toString();
        }

        if(!content) {
            content = '';
        }
else {
            content = content.toString();
        }

        
        this.element = document.createElement('table');
        this.element.cellSpacing = '0';
        this.element.id = 'window_'+parent.local_id+'_'+this.local_id;
        this.element.className = 'window_inactive';        
        parent.element.appendChild(this.element);
        
        
        this.element.appendChild(document.createElement('tbody'));
        
        
        this.element.childNodes[0].appendChild(document.createElement('tr'));
        this.element.childNodes[0].appendChild(document.createElement('tr'));
        
        
        this.element.childNodes[0].childNodes[0].appendChild(document.createElement('td'));
        this.element.childNodes[0].childNodes[0].appendChild(document.createElement('td'));
        this.element.childNodes[0].childNodes[1].appendChild(document.createElement('td'));
        
        this.element.childNodes[0].childNodes[0].childNodes[0].innerHTML = title;
        this.element.childNodes[0].childNodes[0].childNodes[0].className = 'window_title';
        this.element.childNodes[0].childNodes[0].childNodes[0].onmousedown = function(){current_window.drag_start();return false;};
        this.element.childNodes[0].childNodes[0].childNodes[0].ondblclick = function(){current_window.maximize();return false};
        this.title_element = this.element.childNodes[0].childNodes[0].childNodes[0];
        
        this.element.childNodes[0].childNodes[0].childNodes[1].className = 'window_buttons';
        this.element.childNodes[0].childNodes[0].childNodes[1].appendChild(document.createElement('img'));
        this.element.childNodes[0].childNodes[0].childNodes[1].appendChild(document.createElement('img'));
        this.element.childNodes[0].childNodes[0].childNodes[1].appendChild(document.createElement('img'));
        
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[0].src='img/windows/min.png';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[0].alt='[-]';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[0].onclick=function() {
            current_window.minimize();
            return false;
        };

        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[1].src='img/windows/plus.png';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[1].alt='[+]';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[1].onclick=function() {
            current_window.maximize();
            return false;
        };

        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[2].src='img/windows/blank.png';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[2].alt='[x]';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[2].onclick=function() {
            current_window.destroy();
            return false;
        };

        
        
        this.element.childNodes[0].childNodes[1].childNodes[0].colSpan = '2';
        this.element.childNodes[0].childNodes[1].childNodes[0].className = 'window_content_container';
        this.element.childNodes[0].childNodes[1].childNodes[0].appendChild(document.createElement('div'));
        this.element.childNodes[0].childNodes[1].childNodes[0].childNodes[0].innerHTML = content;
        this.element.childNodes[0].childNodes[1].childNodes[0].childNodes[0].className = 'window_content';
        this.content_element = this.element.childNodes[0].childNodes[1].childNodes[0].childNodes[0];
        this.content_container = this.element.childNodes[0].childNodes[1].childNodes[0];
        
        if(innerDimension) {
            if(typeof(innerDimension)=='object' && (innerDimension instanceof Array) && innerDimension.length == 2) {
                this.set_innerDimension(innerDimension[0],innerDimension[1]);
            }
else if(typeof(innerDimension)=='number') {
                this.set_innerWidth(innerDimension);
            }
else if(typeof(parseInt(innerDimension))=='number') {
                this.set_innerWidth(parseInt(innerDimension));
            }
        }

        this.set_innerDimension(this.content_container.offsetWidth,this.content_container.offsetHeight);
    }
    
}


?>


En dit is mijn main.js scriptje:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<?

var liveOS,window1;
window.onload(function() {
    liveOS = new windows_container();
    window1 = new liveOS.window('hi','test');
    new
window1.on_resize.event(function() {
        alert('hi :D');
    });
});


?>
Gewijzigd op 01/01/1970 01:00:00 door Toby hinloopen
 
PHP hulp

PHP hulp

18/12/2024 09:22:56
 
Jelmer -

Jelmer -

02/03/2009 17:26:00
Quote Anchor link
Die 'new' is op regel 7 van je main.js scriptje niet nodig. New gebruik je alleen wanneer je een nieuw object aan wilt maken. Dat doe je door een functie met 'new' ervoor aan te roepen.

Jij wilt alleen een functie uitvoeren. Dan is 'new' niet nodig.
 
Tom K

Tom K

02/03/2009 17:57:00
Quote Anchor link
ik krijg hierbij:
window.onload is not a function

window.onload werkt zo namenlijk niet. het moet namelijk zo:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
window.onload = function()
{
    liveOS = new windows_container();
    window1 = new liveOS.window('hi','test');
    new window1.on_resize.event(function() {
        alert('hi :D');
    });
}
 
Toby hinloopen

toby hinloopen

02/03/2009 20:07:00
Quote Anchor link
Tom schreef op 02.03.2009 17:57:
ik krijg hierbij:
window.onload is not a function

window.onload werkt zo namenlijk niet. het moet namelijk zo:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
window.onload = function()
{
    liveOS = new windows_container();
    window1 = new liveOS.window('hi','test');
    new window1.on_resize.event(function() {
        alert('hi :D');
    });
}


dat is een klein omzetten-voor-plaatsing-op-forum foutje. Ik heb een aangepaste onload functie voor meerdere events.
Gewijzigd op 01/01/1970 01:00:00 door toby hinloopen
 
Toby hinloopen

toby hinloopen

02/03/2009 20:12:00
Quote Anchor link
Jelmer schreef op 02.03.2009 17:26:
Die 'new' is op regel 7 van je main.js scriptje niet nodig. New gebruik je alleen wanneer je een nieuw object aan wilt maken. Dat doe je door een functie met 'new' ervoor aan te roepen.

Jij wilt alleen een functie uitvoeren. Dan is 'new' niet nodig.

a: ik wil wel een object aanmaken omdat ik die event ook wil kunnen stoppen.
zoals hier:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
<?
var custom_event = new window1.on_resize.event(function(){....});
custom_event.exec();//om handmatig de event te triggeren
custom_event.destroy();//om de event te verwijderen
?>

alleen die 2 functies moet ik nog maken.

b: als ik "new" weghaal krijg ik opnieuw een error, maar dan is de error "window1.on_resize.event is not a function"
Gewijzigd op 01/01/1970 01:00:00 door toby hinloopen
 
Toby hinloopen

toby hinloopen

02/03/2009 20:38:00
Quote Anchor link
fixed:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?
        this.on_resize = function(){
            current_event = current_window.on_resize;
            if(current_event.handlers===undefined) {
                current_event.handlers = new Array();
            }

            current_event.add_handler = function(func) {
                for(var x=0;current_event.handlers[x];x++);
                current_event.handlers[x] = func;
                this.handler_id = x;
                this.exec = current_event.handlers[x];
                this.destroy = function() {
                    current_event.handlers[x] = null;
                }
            }

            for(var x=0;x<current_event.handlers.length;x++) {
                if(current_event.handlers[x]) {
                    if(current_event.handlers[x]()===false) {
                        return false;
                    }
                }
            }

            return true;
        }

?>


Gehele code:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?
function windows_container(element_id) {
    var
minwidth = 49
    var minheight = 20;
    var
parent = this;
    if(!element_id) {
        this.element = document.createElement('div');
        this.element.style.position = 'absolute';
        this.element.style.top = '0px';
        this.element.style.left = '0px';
        this.element.style.width = '0px';
        this.element.style.height = '0px';
        this.element.style.zIndex = '10';
        
        this.local_id = 0;
        while(document.getElementById('windows_container_'+this.local_id)) {
            this.local_id++;
        }

        this.element.id = 'windows_container_'+this.local_id;
        this.local_id = this.element.id;
        document.body.appendChild(this.element);
    }
else {
        this.element = document.getElementById(element_id);
        this.local_id = element_id;
    }

    //variables
    this.windows = new Array();
    
    //events
    this.on_new_window = function(){return true;}
    
    //functions
    this.window = function(title,content,innerDimension) {
        var
current_window = this;
        
        //functions
        this.drag_start = function() {
            if(current_window.positioning==2){
                return false;
            }

            current_window.temp_window_offset = new Array(current_window.element.offsetLeft - mouse_fixed[0],current_window.element.offsetTop - mouse_fixed[1]);
            document_onmouseup.push(function() {
                current_window.temp_window_offset = null;
                document_onmousemove.pop();
                document_onmouseup.pop();
            });

            document_onmousemove.push(function() {
                if(current_window.temp_window_offset) {
                    current_window.set_location(mouse_fixed[0]+current_window.temp_window_offset[0],mouse_fixed[1]+current_window.temp_window_offset[1]);
                }
            });
        }

        
        this.set_location = function(x,y) {
            current_window.element.style.marginLeft = parseInt(x)+'px';    
            current_window.element.style.marginRight = 'auto';            
            current_window.element.style.marginTop = parseInt(y)+'px';
            current_window.element.style.marginBottom = 'auto';
        }

        
        this.set_width = function(width,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            width = Math.max(parseInt(width),minwidth);
            current_window.element.style.width = (width)+'px';
            current_window.content_element.style.width = (width)+'px';
            current_window.content_container.style.width = (width)+'px';
            current_window.title_element.style.width = (width-minwidth)+'px';
        }

        
        this.set_height = function(height,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            height = Math.max(parseInt(height),minheight);
            current_window.element.style.height = (height)+'px';
            current_window.content_element.style.height = (height-minheight)+'px';
            current_window.content_container.style.height = (height-minheight)+'px';
        }

        
        this.set_dimension = function(width,height,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_width(width,1);
            current_window.set_height(height,1);
        }

        
        this.set_innerWidth = function(width,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_width(width,1);            
        }

        
        this.set_innerHeight = function(height,no_event) {    
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_height(height+minheight,1);            
        }

        
        this.set_innerDimension = function(width,height,no_event) {
            if(!no_event && !current_window.on_resize()) {return false;}
            current_window.set_innerWidth(width,1);
            current_window.set_innerHeight(height,1);
        }

        
        this.minimize = function() {
            current_window.positioning = 0;
            current_window.float_position = new Array(
                current_window.element.offsetLeft,
                current_window.element.offsetTop,
                parseInt(current_window.element.style.width),
                parseInt(current_window.element.style.height)
            );

            current_window.content_element.style.display = 'none';
            current_window.set_innerDimension(0,0);
            current_window.set_location(0,body_height() - parseInt(current_window.element.style.height));
        }

        
        this.maximize = function() {
            if(current_window.positioning==0) {
                current_window.content_element.style.display = 'block';
            }

            if(current_window.positioning==1) {
                current_window.float_position = new Array(
                    current_window.element.offsetLeft,
                    current_window.element.offsetTop,
                    parseInt(current_window.element.style.width),
                    parseInt(current_window.element.style.height)
                );

                current_window.set_location(-1,-1);
                current_window.set_dimension(body_width()+2,body_height()+2);    
                current_window.positioning = 2;    
            }
else {
                current_window.set_location(current_window.float_position[0],current_window.float_position[1]);
                current_window.set_dimension(current_window.float_position[2],current_window.float_position[3]);
                current_window.positioning = 1;    
            }
        }

        
        this.destroy = function(no_event) {
            if(!no_event && !current_window.on_destroy()) {return false;}
            this.element.parentNode.removeChild(this.element);
        }

        
        //variables
        this.float_position = new Array(0,0,0,0);
        this.positioning = 1;
        
        //events
        this.on_resize = function(){
            current_event = current_window.on_resize;
            if(current_event.handlers===undefined) {
                current_event.handlers = new Array();
            }

            current_event.add_handler = function(func) {
                for(var x=0;current_event.handlers[x];x++);
                current_event.handlers[x] = func;
                this.handler_id = x;
                this.exec = current_event.handlers[x];
                this.destroy = function() {
                    current_event.handlers[x] = null;
                }
            }

            for(var x=0;x<current_event.handlers.length;x++) {
                if(current_event.handlers[x]) {
                    if(current_event.handlers[x]()===false) {
                        return false;
                    }
                }
            }

            return true;
        }

        this.on_destroy = function(){
            var
events = new Array();
            this.event = function(func) {
                for(var x=0;events[x];x++);
                events[x] = func;
            }

            for(var x=0;x<events.length;x++) {
                if(events[x]) {
                    events[x]();
                }
            }

            return true;
        }

        this.on_move = function(){
            var
events = new Array();
            this.event = function(func) {
                for(var x=0;events[x];x++);
                events[x] = func;
            }

            for(var x=0;x<events.length;x++) {
                if(events[x]) {
                    events[x]();
                }
            }

            return true;
        }

        
        this.local_id = 0;
        while(parent.windows[this.local_id]) {
            this.local_id++;
        }

        if(parent.on_new_window(this.local_id,title,content)===false) {//indien "return false" gebruikt is in de "on_new_window" event...
            return false;//stop het maken van een nieuwe window
        }
        parent.windows[this.local_id] = this;
        
        if(!title) {
            title = '';
        }
else {
            title = title.toString();
        }

        if(!content) {
            content = '';
        }
else {
            content = content.toString();
        }

        
        this.element = document.createElement('table');
        this.element.cellSpacing = '0';
        this.element.id = 'window_'+parent.local_id+'_'+this.local_id;
        this.element.className = 'window_inactive';        
        parent.element.appendChild(this.element);
        
        
        this.element.appendChild(document.createElement('tbody'));
        
        
        this.element.childNodes[0].appendChild(document.createElement('tr'));
        this.element.childNodes[0].appendChild(document.createElement('tr'));
        
        
        this.element.childNodes[0].childNodes[0].appendChild(document.createElement('td'));
        this.element.childNodes[0].childNodes[0].appendChild(document.createElement('td'));
        this.element.childNodes[0].childNodes[1].appendChild(document.createElement('td'));
        
        this.element.childNodes[0].childNodes[0].childNodes[0].innerHTML = title;
        this.element.childNodes[0].childNodes[0].childNodes[0].className = 'window_title';
        this.element.childNodes[0].childNodes[0].childNodes[0].onmousedown = function(){current_window.drag_start();return false;};
        this.element.childNodes[0].childNodes[0].childNodes[0].ondblclick = function(){current_window.maximize();return false};
        this.title_element = this.element.childNodes[0].childNodes[0].childNodes[0];
        
        this.element.childNodes[0].childNodes[0].childNodes[1].className = 'window_buttons';
        this.element.childNodes[0].childNodes[0].childNodes[1].appendChild(document.createElement('img'));
        this.element.childNodes[0].childNodes[0].childNodes[1].appendChild(document.createElement('img'));
        this.element.childNodes[0].childNodes[0].childNodes[1].appendChild(document.createElement('img'));
        
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[0].src='img/windows/min.png';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[0].alt='[-]';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[0].onclick=function() {
            current_window.minimize();
            return false;
        };

        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[1].src='img/windows/plus.png';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[1].alt='[+]';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[1].onclick=function() {
            current_window.maximize();
            return false;
        };

        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[2].src='img/windows/blank.png';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[2].alt='[x]';
        this.element.childNodes[0].childNodes[0].childNodes[1].childNodes[2].onclick=function() {
            current_window.destroy();
            return false;
        };

        
        
        this.element.childNodes[0].childNodes[1].childNodes[0].colSpan = '2';
        this.element.childNodes[0].childNodes[1].childNodes[0].className = 'window_content_container';
        this.element.childNodes[0].childNodes[1].childNodes[0].appendChild(document.createElement('div'));
        this.element.childNodes[0].childNodes[1].childNodes[0].childNodes[0].innerHTML = content;
        this.element.childNodes[0].childNodes[1].childNodes[0].childNodes[0].className = 'window_content';
        this.content_element = this.element.childNodes[0].childNodes[1].childNodes[0].childNodes[0];
        this.content_container = this.element.childNodes[0].childNodes[1].childNodes[0];
        
        if(innerDimension) {
            if(typeof(innerDimension)=='object' && (innerDimension instanceof Array) && innerDimension.length == 2) {
                this.set_innerDimension(innerDimension[0],innerDimension[1]);
            }
else if(typeof(innerDimension)=='number') {
                this.set_innerWidth(innerDimension);
            }
else if(typeof(parseInt(innerDimension))=='number') {
                this.set_innerWidth(parseInt(innerDimension));
            }
        }

        this.set_innerDimension(this.content_container.offsetWidth,this.content_container.offsetHeight);
    }
    
}


?>


main.js:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?

var window_onload = new Array();
window.onload=function(e) {
    for(var x=0;x<window_onload.length;x++) {
        window_onload[x](e);
    }
}

var
liveOS,window1;
window_onload.push(function() {
    liveOS = new windows_container();
    window1 = new liveOS.window('hi','test');
    new
window1.on_resize.add_handler(function() {
        alert('hi :D');
    });
    new
window1.on_resize.add_handler(function() {
        alert('hi2 :D');
    });
    
});


?>


Het probleem was dat "on_resize" een functie was een geen object, maar ik het gebruikte als object.
Gewijzigd op 01/01/1970 01:00:00 door toby hinloopen
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.