1 // Some global instances, this will be filled later
\r
2 var tinyMCE = null, tinyMCELang = null;
\r
4 function TinyMCE_Popup() {
\r
7 TinyMCE_Popup.prototype = {
\r
8 findWin : function(w) {
\r
13 while (c && (c = c.parent) != null) {
\r
14 if (typeof(c.tinyMCE) != "undefined")
\r
20 while (c && (c = c.opener) != null) {
\r
21 if (typeof(c.tinyMCE) != "undefined")
\r
26 if (typeof(top.tinyMCE) != "undefined")
\r
33 var win = window.opener ? window.opener : window.dialogArguments, c;
\r
34 var inst, re, title, divElm;
\r
37 win = this.findWin(window);
\r
40 alert("tinyMCE object reference not found from popup.");
\r
44 window.opener = win;
\r
45 this.windowOpener = win;
\r
46 this.onLoadEval = "";
\r
48 // Setup parent references
\r
49 tinyMCE = win.tinyMCE;
\r
50 tinyMCELang = win.tinyMCELang;
\r
52 inst = tinyMCE.selectedInstance;
\r
53 this.isWindow = tinyMCE.getWindowArg('mce_inside_iframe', false) == false;
\r
54 this.storeSelection = (tinyMCE.isRealIE) && !this.isWindow && tinyMCE.getWindowArg('mce_store_selection', true);
\r
60 if (this.storeSelection)
\r
61 inst.selectionBookmark = inst.selection.getBookmark(true);
\r
64 if (tinyMCELang.lang_dir)
\r
65 document.dir = tinyMCELang.lang_dir;
\r
68 re = new RegExp('{|\\\$|}', 'g');
\r
69 title = document.title.replace(re, "");
\r
70 if (typeof(tinyMCELang[title]) != "undefined") {
\r
71 divElm = document.createElement("div");
\r
72 divElm.innerHTML = tinyMCELang[title];
\r
73 document.title = divElm.innerHTML;
\r
75 if (typeof(tinyMCE.setWindowTitle) != 'undefined')
\r
76 tinyMCE.setWindowTitle(window, divElm.innerHTML);
\r
79 // Output Popup CSS class
\r
80 document.write('<link href="' + tinyMCE.getParam("popups_css") + '" rel="stylesheet" type="text/css">');
\r
82 if (tinyMCE.getParam("popups_css_add")) {
\r
83 c = tinyMCE.getParam("popups_css_add");
\r
86 if (c.indexOf('://') == -1 && c.charAt(0) != '/')
\r
87 c = tinyMCE.documentBasePath + "/" + c;
\r
89 document.write('<link href="' + c + '" rel="stylesheet" type="text/css">');
\r
92 tinyMCE.addEvent(window, "load", this.onLoad);
\r
95 onLoad : function() {
\r
96 var dir, i, elms, body = document.body;
\r
98 if (tinyMCE.getWindowArg('mce_replacevariables', true))
\r
99 body.innerHTML = tinyMCE.applyTemplate(body.innerHTML, tinyMCE.windowArgs);
\r
101 dir = tinyMCE.selectedInstance.settings.directionality;
\r
102 if (dir == "rtl" && document.forms && document.forms.length > 0) {
\r
103 elms = document.forms[0].elements;
\r
104 for (i=0; i<elms.length; i++) {
\r
105 if ((elms[i].type == "text" || elms[i].type == "textarea") && elms[i].getAttribute("dir") != "ltr")
\r
110 if (body.style.display == 'none')
\r
111 body.style.display = 'block';
\r
113 // Execute real onload (Opera fix)
\r
114 if (tinyMCEPopup.onLoadEval !== '')
\r
115 eval(tinyMCEPopup.onLoadEval);
\r
118 executeOnLoad : function(str) {
\r
119 if (tinyMCE.isOpera)
\r
120 this.onLoadEval = str;
\r
125 resizeToInnerSize : function() {
\r
126 var i, doc, body, oldMargin, wrapper, iframe, nodes, dx, dy;
\r
128 // Netscape 7.1 workaround
\r
129 if (this.isWindow && tinyMCE.isNS71) {
\r
130 window.resizeBy(0, 10);
\r
134 if (this.isWindow) {
\r
138 if (body.style.display == 'none')
\r
139 body.style.display = 'block';
\r
142 oldMargin = body.style.margin;
\r
143 body.style.margin = '0';
\r
146 wrapper = doc.createElement("div");
\r
147 wrapper.id = 'mcBodyWrapper';
\r
148 wrapper.style.display = 'none';
\r
149 wrapper.style.margin = '0';
\r
151 // Wrap body elements
\r
152 nodes = doc.body.childNodes;
\r
153 for (i=nodes.length-1; i>=0; i--) {
\r
154 if (wrapper.hasChildNodes())
\r
155 wrapper.insertBefore(nodes[i].cloneNode(true), wrapper.firstChild);
\r
157 wrapper.appendChild(nodes[i].cloneNode(true));
\r
159 nodes[i].parentNode.removeChild(nodes[i]);
\r
163 doc.body.appendChild(wrapper);
\r
166 iframe = document.createElement("iframe");
\r
167 iframe.id = "mcWinIframe";
\r
168 iframe.src = document.location.href.toLowerCase().indexOf('https') == -1 ? "about:blank" : tinyMCE.settings.default_document;
\r
169 iframe.width = "100%";
\r
170 iframe.height = "100%";
\r
171 iframe.style.margin = '0';
\r
174 doc.body.appendChild(iframe);
\r
177 iframe = document.getElementById('mcWinIframe');
\r
178 dx = tinyMCE.getWindowArg('mce_width') - iframe.clientWidth;
\r
179 dy = tinyMCE.getWindowArg('mce_height') - iframe.clientHeight;
\r
182 // tinyMCE.debug(tinyMCE.getWindowArg('mce_width') + "," + tinyMCE.getWindowArg('mce_height') + " - " + dx + "," + dy);
\r
183 window.resizeBy(dx, dy);
\r
185 // Hide iframe and show wrapper
\r
186 body.style.margin = oldMargin;
\r
187 iframe.style.display = 'none';
\r
188 wrapper.style.display = 'block';
\r
192 resizeToContent : function() {
\r
193 var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
\r
194 var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
\r
195 var elm, width, height, x, y, dx, dy;
\r
201 try { window.resizeTo(10, 10); } catch (e) {}
\r
203 elm = document.body;
\r
204 width = elm.offsetWidth;
\r
205 height = elm.offsetHeight;
\r
206 dx = (elm.scrollWidth - width) + 4;
\r
207 dy = elm.scrollHeight - height;
\r
209 try { window.resizeBy(dx, dy); } catch (e) {}
\r
211 window.scrollBy(1000, 1000);
\r
212 if (window.scrollX > 0 || window.scrollY > 0) {
\r
213 window.resizeBy(window.innerWidth * 2, window.innerHeight * 2);
\r
214 window.sizeToContent();
\r
215 window.scrollTo(0, 0);
\r
216 x = parseInt(screen.width / 2.0) - (window.outerWidth / 2.0);
\r
217 y = parseInt(screen.height / 2.0) - (window.outerHeight / 2.0);
\r
218 window.moveTo(x, y);
\r
223 getWindowArg : function(name, default_value) {
\r
224 return tinyMCE.getWindowArg(name, default_value);
\r
227 restoreSelection : function() {
\r
230 if (this.storeSelection) {
\r
231 inst = tinyMCE.selectedInstance;
\r
233 inst.getWin().focus();
\r
235 if (inst.selectionBookmark)
\r
236 inst.selection.moveToBookmark(inst.selectionBookmark);
\r
240 execCommand : function(command, user_interface, value) {
\r
241 var inst = tinyMCE.selectedInstance;
\r
243 this.restoreSelection();
\r
244 inst.execCommand(command, user_interface, value);
\r
247 if (this.storeSelection)
\r
248 inst.selectionBookmark = inst.selection.getBookmark(true);
\r
251 close : function() {
\r
252 tinyMCE.closeWindow(window);
\r
255 pickColor : function(e, element_id) {
\r
256 tinyMCE.selectedInstance.execCommand('mceColorPicker', true, {
\r
257 element_id : element_id,
\r
258 document : document,
\r
260 store_selection : false
\r
264 openBrowser : function(element_id, type, option) {
\r
265 var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));
\r
266 var url = document.getElementById(element_id).value;
\r
268 tinyMCE.setWindowArg("window", window);
\r
269 tinyMCE.setWindowArg("document", document);
\r
271 // Call to external callback
\r
272 if (eval('typeof(tinyMCEPopup.windowOpener.' + cb + ')') == "undefined")
\r
273 alert("Callback function: " + cb + " could not be found.");
\r
275 eval("tinyMCEPopup.windowOpener." + cb + "(element_id, url, type, window);");
\r
278 importClass : function(c) {
\r
281 window[c] = function() {};
\r
283 for (n in window.opener[c].prototype)
\r
284 window[c].prototype[n] = window.opener[c].prototype[n];
\r
286 window[c].constructor = window.opener[c].constructor;
\r
291 // Setup global instance
\r
292 var tinyMCEPopup = new TinyMCE_Popup();
\r
294 tinyMCEPopup.init();
\r