/[webpac]/trunk2/out/js/iframe.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk2/out/js/iframe.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 578 - (hide annotations)
Mon Nov 1 22:15:20 2004 UTC (19 years, 5 months ago) by dpavlin
File MIME type: application/javascript
File size: 1700 byte(s)
better hight calculation (with fixed additional height +20 which should be
removed), don't reload iframe if url is same as existing iframe.src

1 dpavlin 575 // load iframe and resize it
2     // written by Dobrica Pavlinusic <dpavlin@rot13.org>
3     // based on great hints from Robert Avilov
4    
5     var iframe_id_cache = Array();
6    
7     function iframe_id(name) {
8     if (! iframe_id_cache[name]) {
9     iframe_id_cache[name] = self.document.getElementById(name);
10     }
11     return iframe_id_cache[name];
12     }
13    
14    
15     function iframe_doc(name) {
16     if (iframe_id(name).contentDocument) return iframe_id(name).contentDocument;
17     if (iframe_id(name).contentWindow) {
18     try {
19     return iframe_id(name).contentWindow.document;
20     } catch (e) {};
21     }
22     if (iframe_id(name).document) return iframe_id(name).document;
23     return null;
24     }
25    
26     function iframe_height(name) {
27    
28     var doc = iframe_doc(name);
29    
30     if (doc.body) {
31     var h = -1;
32 dpavlin 578 var h1 = -1;
33 dpavlin 575
34     if (doc.body.scrollHeight) {
35 dpavlin 578 h1 = parseInt(doc.body.scrollHeight) || -1;
36     //alert(name+" scrollHeight "+h1);
37     if (h1 > h) h = h1;
38 dpavlin 575 }
39 dpavlin 578 if (doc.body.clientHeight) {
40     h1 = parseInt(doc.body.clientHeight) || -1;
41     //alert(name+" clientHeight "+h1);
42     if (h1 > h) h = h1;
43 dpavlin 575 }
44    
45 dpavlin 578 /*
46     var elm = document.getElementById(name);
47     if (elm) {
48     elm.style.height = 'auto';
49     h1 = elm.offsetHeight;
50     alert(name+" offsetHeight "+h1);
51     if (h1 > h) h = h1;
52     }
53     */
54 dpavlin 575
55 dpavlin 578 return h + 20;
56    
57 dpavlin 575 }
58     return 50;
59     }
60    
61     function iframe_resize(name) {
62    
63 dpavlin 578 var el=iframe_id(name);
64    
65     if (! el || ! el.src) return;
66    
67     el.style.height = String(iframe_height(name)+'px');
68 dpavlin 575 }
69    
70     function iframe_load(name,url) {
71    
72     if (! name || ! url) return false;
73    
74 dpavlin 578 var el=iframe_id(name);
75 dpavlin 575
76 dpavlin 578 if (! el) alert("can't find element "+name);
77    
78     // is there src, and is src same?
79     if (el.src && el.src.substr(el.src.length - url.length) == url) return false;
80    
81     el.style.height = '0px';
82     el.src = url;
83    
84 dpavlin 575 return false;
85     }
86    

  ViewVC Help
Powered by ViewVC 1.1.26