ccd968ac44044c8254bc59f3e8b63c3e4d65b7a8
[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
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 },
85
86 resetUrl: function() {
87 this.setMask();
88 this.body.dom.src = this.src;
89 },
90
91 getIdFromUrl: function() {
92 var url = Ext.urlDecode(this.getUrl().split('?')[1]);
93 return url.id;
94 },
95
96 refresh: function() {
97 if (!this.isVisible()) {
98 return;
99 }
100 this.setMask();
101 this.body.dom.src = this.body.dom.src;
102 },
103
104 /** @private */
105 setMask: function() {
106 if (this.doMask) {
107 this.el.mask(this.maskMessage, 'x-mask-loading-message');
108 this.el.addClass('t3-mask-loading');
109 // add an onClick handler to remove the mask while clicking on the loading message
110 // useful if user cancels loading and wants to access the content again
111 this.el.child('.x-mask-loading-message').on(
112 'click',
113 function() {
114 this.el.unmask();
115 },
116 this
117 );
118 }
119 },
120
121 removeMask: function() {
122 if (this.doMask) {
123 this.el.unmask();
124 }
125 }
126 });
127 Ext.reg('iframePanel', TYPO3.iframePanel);