7 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
10 var tinyMCE
= null, tinyMCELang
= null;
12 function TinyMCEPopup() {
15 TinyMCEPopup
.prototype.init = function() {
16 var win
= window
.opener
? window
.opener
: window
.dialogArguments
;
24 if (typeof(win
.tinyMCE
) == "undefined")
29 this.windowOpener
= win
;
32 // Setup parent references
33 tinyMCE
= win
.tinyMCE
;
34 tinyMCELang
= win
.tinyMCELang
;
37 alert("tinyMCE object reference not found from popup.");
41 inst
= tinyMCE
.selectedInstance
;
42 this.isWindow
= tinyMCE
.getWindowArg('mce_inside_iframe', false) == false;
43 this.storeSelection
= (tinyMCE
.isMSIE
&& !tinyMCE
.isOpera
) && !this.isWindow
&& tinyMCE
.getWindowArg('mce_store_selection', true);
49 if (this.storeSelection
)
50 inst
.selectionBookmark
= inst
.selection
.getBookmark(true);
53 if (tinyMCELang
['lang_dir'])
54 document
.dir
= tinyMCELang
['lang_dir'];
57 var re
= new RegExp('{|\\\$|}', 'g');
58 var title
= document
.title
.replace(re
, "");
59 if (typeof tinyMCELang
[title
] != "undefined") {
60 var divElm
= document
.createElement("div");
61 divElm
.innerHTML
= tinyMCELang
[title
];
62 document
.title
= divElm
.innerHTML
;
64 if (tinyMCE
.setWindowTitle
!= null)
65 tinyMCE
.setWindowTitle(window
, divElm
.innerHTML
);
68 // Output Popup CSS class
69 document
.write('<link href="' + tinyMCE
.getParam("popups_css") + '" rel="stylesheet" type="text/css">');
71 tinyMCE
.addEvent(window
, "load", this.onLoad
);
74 TinyMCEPopup
.prototype.onLoad = function() {
75 var body
= document
.body
;
77 if (tinyMCE
.getWindowArg('mce_replacevariables', true))
78 body
.innerHTML
= tinyMCE
.applyTemplate(body
.innerHTML
, tinyMCE
.windowArgs
);
80 var dir
= tinyMCE
.selectedInstance
.settings
['directionality'];
82 var elms
= document
.forms
[0].elements
;
83 for (var i
=0; i
<elms
.length
; i
++) {
84 if ((elms
[i
].type
== "text" || elms
[i
].type
== "textarea") && elms
[i
].getAttribute("dir") != "ltr")
89 if (body
.style
.display
== 'none')
90 body
.style
.display
= 'block';
92 // Execute real onload (Opera fix)
93 if (tinyMCEPopup
.onLoadEval
!= "") {
94 eval(tinyMCEPopup
.onLoadEval
);
98 TinyMCEPopup
.prototype.executeOnLoad = function(str
) {
100 this.onLoadEval
= str
;
105 TinyMCEPopup
.prototype.resizeToInnerSize = function() {
106 // Netscape 7.1 workaround
107 if (this.isWindow
&& tinyMCE
.isNS71
) {
108 window
.resizeBy(0, 10);
115 var oldMargin
, wrapper
, iframe
, nodes
, dx
, dy
;
117 if (body
.style
.display
== 'none')
118 body
.style
.display
= 'block';
121 oldMargin
= body
.style
.margin
;
122 body
.style
.margin
= '0';
125 wrapper
= doc
.createElement("div");
126 wrapper
.id
= 'mcBodyWrapper';
127 wrapper
.style
.display
= 'none';
128 wrapper
.style
.margin
= '0';
130 // Wrap body elements
131 nodes
= doc
.body
.childNodes
;
132 for (var i
=nodes
.length
-1; i
>=0; i
--) {
133 if (wrapper
.hasChildNodes())
134 wrapper
.insertBefore(nodes
[i
].cloneNode(true), wrapper
.firstChild
);
136 wrapper
.appendChild(nodes
[i
].cloneNode(true));
138 nodes
[i
].parentNode
.removeChild(nodes
[i
]);
142 doc
.body
.appendChild(wrapper
);
145 iframe
= document
.createElement("iframe");
146 iframe
.id
= "mcWinIframe";
147 iframe
.src
= document
.location
.href
.toLowerCase().indexOf('https') == -1 ? "about:blank" : tinyMCE
.settings
['default_document'];
148 iframe
.width
= "100%";
149 iframe
.height
= "100%";
150 iframe
.style
.margin
= '0';
153 doc
.body
.appendChild(iframe
);
156 iframe
= document
.getElementById('mcWinIframe');
157 dx
= tinyMCE
.getWindowArg('mce_width') - iframe
.clientWidth
;
158 dy
= tinyMCE
.getWindowArg('mce_height') - iframe
.clientHeight
;
161 // tinyMCE.debug(tinyMCE.getWindowArg('mce_width') + "," + tinyMCE.getWindowArg('mce_height') + " - " + dx + "," + dy);
162 window
.resizeBy(dx
, dy
);
164 // Hide iframe and show wrapper
165 body
.style
.margin
= oldMargin
;
166 iframe
.style
.display
= 'none';
167 wrapper
.style
.display
= 'block';
171 TinyMCEPopup
.prototype.resizeToContent = function() {
172 var isMSIE
= (navigator
.appName
== "Microsoft Internet Explorer");
173 var isOpera
= (navigator
.userAgent
.indexOf("Opera") != -1);
179 try { window
.resizeTo(10, 10); } catch (e
) {}
181 var elm
= document
.body
;
182 var width
= elm
.offsetWidth
;
183 var height
= elm
.offsetHeight
;
184 var dx
= (elm
.scrollWidth
- width
) + 4;
185 var dy
= elm
.scrollHeight
- height
;
187 try { window
.resizeBy(dx
, dy
); } catch (e
) {}
189 window
.scrollBy(1000, 1000);
190 if (window
.scrollX
> 0 || window
.scrollY
> 0) {
191 window
.resizeBy(window
.innerWidth
* 2, window
.innerHeight
* 2);
192 window
.sizeToContent();
193 window
.scrollTo(0, 0);
194 var x
= parseInt(screen
.width
/ 2.0) - (window
.outerWidth
/ 2.0);
195 var y
= parseInt(screen
.height
/ 2.0) - (window
.outerHeight
/ 2.0);
201 TinyMCEPopup
.prototype.getWindowArg = function(name
, default_value
) {
202 return tinyMCE
.getWindowArg(name
, default_value
);
205 TinyMCEPopup
.prototype.restoreSelection = function() {
206 if (this.storeSelection
) {
207 var inst
= tinyMCE
.selectedInstance
;
209 inst
.getWin().focus();
211 if (inst
.selectionBookmark
)
212 inst
.selection
.moveToBookmark(inst
.selectionBookmark
);
216 TinyMCEPopup
.prototype.execCommand = function(command
, user_interface
, value
) {
217 var inst
= tinyMCE
.selectedInstance
;
219 this.restoreSelection();
220 inst
.execCommand(command
, user_interface
, value
);
223 if (this.storeSelection
)
224 inst
.selectionBookmark
= inst
.selection
.getBookmark(true);
227 TinyMCEPopup
.prototype.close = function() {
228 tinyMCE
.closeWindow(window
);
231 TinyMCEPopup
.prototype.pickColor = function(e
, element_id
) {
232 tinyMCE
.selectedInstance
.execCommand('mceColorPicker', true, {
233 element_id
: element_id
,
236 store_selection
: false
240 TinyMCEPopup
.prototype.openBrowser = function(element_id
, type
, option
) {
241 var cb
= tinyMCE
.getParam(option
, tinyMCE
.getParam("file_browser_callback"));
242 var url
= document
.getElementById(element_id
).value
;
244 tinyMCE
.setWindowArg("window", window
);
245 tinyMCE
.setWindowArg("document", document
);
247 // Call to external callback
248 if (eval('typeof(tinyMCEPopup.windowOpener.' + cb
+ ')') == "undefined")
249 alert("Callback function: " + cb
+ " could not be found.");
251 eval("tinyMCEPopup.windowOpener." + cb
+ "(element_id, url, type, window);");
254 // Setup global instance
255 var tinyMCEPopup
= new TinyMCEPopup();