db2708396f3b1f64a4d28ea79a4465c9accf1141
[Packages/TYPO3.CMS.git] / typo3 / js / extjs / iframepanel.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
5 * All rights reserved
6 *
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
17 *
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27
28 /**
29 * iFrame panel
30 *
31 * @author Steffen Kamper
32 */
33
34 Ext.ns('TYPO3');
35
36 TYPO3.iframePanel = Ext.extend(Ext.Panel, {
37 name: 'iframe',
38 iframe: null,
39 src: Ext.isIE && Ext.isSecure ? Ext.SSL_SECURE_URL : 'about:blank',
40 maskMessage: ' ',
41 doMask: true,
42 border: false,
43 // component build
44 initComponent: function() {
45 this.bodyCfg = {
46 tag: 'iframe',
47 frameborder: '0',
48 src: this.src,
49 name: this.name,
50 style: 'float:left;' // this is needed to prevent offset of 2.5 pixel, see #15771
51 }
52 Ext.apply(this, {
53
54 });
55 TYPO3.iframePanel.superclass.initComponent.apply(this, arguments);
56
57 // apply the addListener patch for 'message:tagging'
58 this.addListener = this.on;
59
60 },
61
62 onRender : function() {
63 TYPO3.iframePanel.superclass.onRender.apply(this, arguments);
64 this.maskMessage = ' ';
65 this.iframe = Ext.isIE ? this.body.dom.contentWindow : window.frames[this.name];
66 this.body.dom[Ext.isIE ? 'onreadystatechange' : 'onload'] = this.loadHandler.createDelegate(this);
67 },
68
69 loadHandler: function() {
70 this.src = this.body.dom.src;
71 this.removeMask();
72 },
73
74 getIframe: function() {
75 return this.iframe;
76 },
77 getUrl: function() {
78 return this.body.dom.src;
79 },
80
81 setUrl: function(source) {
82 this.setMask();
83 this.body.dom.src = source;
84 if (this.ownerCt) {
85 if (this.ownerCt.hasLayout) {
86 if (this.ownerCt.layout.setActiveItem) {
87 this.ownerCt.layout.setActiveItem(this.id);
88 }
89 }
90 }
91 },
92 setUrlIfChanged: function(source) {
93 currentSource = this.getUrl();
94 currentSource = currentSource.substr(currentSource.length-source.length);
95
96 // Some modules generate wrong url with unneeded string at the end
97 if (currentSource.substr(currentSource.length-1) == '?' ||
98 currentSource.substr(currentSource.length-1) == '&') {
99 currentSource = currentSource.substr(0,currentSource.length)
100 }
101 if (currentSource.substr(0,1) == '/') {
102 currentSource = currentSource.substr(1);
103 }
104 if (source.substr(source.length-1) == '?' ||
105 source.substr(source.length-1) == '&') {
106 source = source.substr(0,source.length-1)
107 }
108
109 // Check if new uri should be loaded
110 if (source != currentSource) {
111 this.setUrl(source);
112 }
113 },
114 resetUrl: function() {
115 this.setMask();
116 this.body.dom.src = this.src;
117 },
118
119 getIdFromUrl: function() {
120 var url = Ext.urlDecode(this.getUrl().split('?')[1]);
121 return url.id;
122 },
123
124 refresh: function() {
125 if (!this.isVisible()) {
126 return;
127 }
128 this.setMask();
129 this.body.dom.src = this.body.dom.src;
130 },
131
132 /** @private */
133 setMask: function() {
134 if (this.doMask) {
135 this.el.mask(this.maskMessage, 'x-mask-loading-message');
136 this.el.addClass('t3-mask-loading');
137 // add an onClick handler to remove the mask while clicking on the loading message
138 // useful if user cancels loading and wants to access the content again
139 this.el.child('.x-mask-loading-message').on(
140 'click',
141 function() {
142 this.el.unmask();
143 },
144 this
145 );
146 }
147 },
148
149 removeMask: function() {
150 if (this.doMask) {
151 this.el.unmask();
152 }
153 }
154 });
155 Ext.reg('iframePanel', TYPO3.iframePanel);