var ResizeIframe = {
2 wrapperId : "tinc_content",
3
4 /**
5 * Resizes an iframe sId including oDoc to oDoc's content size.
6 * Can be called top-down, i.e. from the including iframe (or it's parents) or bottom-up, i.e. from the included document.
7 * In the latter case the iframe element is retrieved programmatically.
8 *
9 * @param oDoc Included page's document object
10 * @param sId ID of including iframe
11 */
12 resize : function ( oDoc, sId )
13 {
14 try
15 {
16 if ( typeof oDoc == "undefined" ) return;
17
18 if ( typeof sId != "undefined" )
19 {
20 var iframe = oDoc.getElementById( sId );
21 var iframeDoc = iframe.contentWindow.document;
22 } else {
23 var iframeDoc = oDoc;
24 var iframeWindow = iframeDoc.parentWindow || iframeDoc.defaultView;
25 var iframe = iframeWindow.frameElement;
26 }
27 var wrapper = iframeDoc.getElementById( this.wrapperId );
28
29 // make sure we only resize once
30 if ( iframeDoc.isIntegrated == true ) { return; }
31
32 // switch on transparency for iframe
33 iframeDoc.body.style.backgroundColor = "transparent";
34 iframe.allowTransparency = "true";
35
36 iframeDoc.body.style.padding = "0px";
37 iframeDoc.body.style.border = "none";
38
39 var tabs = iframeDoc.getElementsByTagName( "table" )
40 if ( tabs[0] && tabs[0].className == "dborder" )
41 {
42 wrapper.setAttribute( "wfx:overridewidth", "true" );
43 } else if ( iframeDoc.forms[0] && iframeDoc.forms[0].elements["formname"] )
44 {
45 wrapper.setAttribute( "wfx:overridewidth", "true" );
46 }
47
48 if ( window.addEventListener )
49 {
50 var gcs = iframeDoc.defaultView.getComputedStyle( iframeDoc.body, null);
51 var v_margin = parseInt( gcs.getPropertyValue( "margin-top" ) ) + parseInt( gcs.getPropertyValue( "margin-bottom" ) );
52 var h_margin = parseInt( gcs.getPropertyValue( "margin-left" ) ) + parseInt( gcs.getPropertyValue( "margin-right" ) );
53 var wrapper_width = wrapper.offsetWidth;
54
55 var flex = wrapper.getAttribute( "wfx:overridewidth" );
56 if ( flex == "true" )
57 {
58 wrapper.style.width = "100%";
59 } else {
60 iframe.style.width = wrapper_width + h_margin + "px";
61 }
62
63 // Setting the top padding of the wrapper avoids wrong calculation of the height due to collapsing margins behavior
64 wrapper.style.paddingTop = "1px";
65
66 height = wrapper.offsetHeight + v_margin ;
67 }
68 else if ( window.attachEvent )
69 {
70 iframeDoc.body.style.margin = "0px";
71 var wrapper_width = wrapper.offsetWidth;
72
73 var flex = wrapper.getAttribute( "wfx:overridewidth" );
74 if ( flex == "true" )
75 {
76 wrapper.style.width = "100%";
77 } else {
78 iframe.style.width = wrapper_width + "px";
79 }
80
81 height = wrapper.offsetHeight;
82 }
83
84 if ( iframe.scrolling != "yes" ) { height += 20; }
85
86 iframe.style.height = height + "px";
87 iframeDoc.isIntegrated = true;
88 } catch ( ex )
89 {
90 return;
91 }
92
93 WfxExtrasProcessor.process( oDoc, sId );
94 }
95}
96
97var WfxExtrasProcessor = {
98 process : function ( oDoc, sId)
99 {
100 if ( typeof oDoc == "undefined" ) return;
101
102 if ( typeof sId != "undefined" )
103 {
104 var iframe = oDoc.getElementById( sId );
105 var iframeDoc = iframe.contentWindow.document;
106 } else {
107 var iframeDoc = oDoc;
108 var iframeWindow = iframeDoc.parentWindow || iframeDoc.defaultView;
109 var iframe = iframeWindow.frameElement;
110 }
111
112 // let non-tinc links load in the parent document. this might need some adjustment
113 var links = iframeDoc.getElementsByTagName( "a" );
114 for ( var i = 0; i < links.length; i++ )
115 {
116 if ( links[i].href.indexOf( "/tinc" ) == -1 ) links[i].target = "_parent";
117 }
118
119 // Special case: WebElements forms might do redirection to another page after submission. That's indicated by a non-empty
120 // 'redirectionEnabled' attribute of a submit button.
121 var inputs = iframeDoc.getElementsByTagName( "input" );
122 for ( var i = 0; i < inputs.length; i++ )
123 {
124 var input = inputs[i];
125 if ( input.getAttribute("redirection") != null && input.getAttribute("redirection") != '' )
126 input.form.target = "_parent";
127 }
128 }
129}
130 
