adding some strings
[moodle-linuxchix.git] / lib / editor / tinymce / jscripts / tiny_mce / tiny_mce_popup.js
blobac5c6870c979b639c56b524c5f1bbae7e67e0b20
1 /**
2  * $RCSfile$
3  * $Revision$
4  * $Date$
5  *
6  * @author Moxiecode
7  * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
8  */
10 var tinyMCE = null, tinyMCELang = null;
12 function TinyMCEPopup() {
15 TinyMCEPopup.prototype.init = function() {
16         var win = window.opener ? window.opener : window.dialogArguments;
17         var inst;
19         if (!win) {
20                 // Try parent
21                 win = parent.parent;
23                 // Try top
24                 if (typeof(win.tinyMCE) == "undefined")
25                         win = top;
26         }
28         window.opener = win;
29         this.windowOpener = win;
30         this.onLoadEval = "";
32         // Setup parent references
33         tinyMCE = win.tinyMCE;
34         tinyMCELang = win.tinyMCELang;
36         if (!tinyMCE) {
37                 alert("tinyMCE object reference not found from popup.");
38                 return;
39         }
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);
45         if (this.isWindow)
46                 window.focus();
48         // Store selection
49         if (this.storeSelection)
50                 inst.selectionBookmark = inst.selection.getBookmark(true);
52         // Setup dir
53         if (tinyMCELang['lang_dir'])
54                 document.dir = tinyMCELang['lang_dir'];
56         // Setup title
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);
66         }
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'];
81         if (dir == "rtl") {
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")
85                                 elms[i].dir = dir;
86                 }
87         }
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);
95         }
98 TinyMCEPopup.prototype.executeOnLoad = function(str) {
99         if (tinyMCE.isOpera)
100                 this.onLoadEval = str;
101         else
102                 eval(str);
105 TinyMCEPopup.prototype.resizeToInnerSize = function() {
106         // Netscape 7.1 workaround
107         if (this.isWindow && tinyMCE.isNS71) {
108                 window.resizeBy(0, 10);
109                 return;
110         }
112         if (this.isWindow) {
113                 var doc = document;
114                 var body = doc.body;
115                 var oldMargin, wrapper, iframe, nodes, dx, dy;
117                 if (body.style.display == 'none')
118                         body.style.display = 'block';
120                 // Remove margin
121                 oldMargin = body.style.margin;
122                 body.style.margin = '0';
124                 // Create wrapper
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);
135                         else
136                                 wrapper.appendChild(nodes[i].cloneNode(true));
138                         nodes[i].parentNode.removeChild(nodes[i]);
139                 }
141                 // Add wrapper
142                 doc.body.appendChild(wrapper);
144                 // Create iframe
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';
152                 // Add iframe
153                 doc.body.appendChild(iframe);
155                 // Measure iframe
156                 iframe = document.getElementById('mcWinIframe');
157                 dx = tinyMCE.getWindowArg('mce_width') - iframe.clientWidth;
158                 dy = tinyMCE.getWindowArg('mce_height') - iframe.clientHeight;
160                 // Resize window
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';
168         }
171 TinyMCEPopup.prototype.resizeToContent = function() {
172         var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
173         var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
175         if (isOpera)
176                 return;
178         if (isMSIE) {
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) {}
188         } else {
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);
196                         window.moveTo(x, y);
197                 }
198         }
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);
213         }
216 TinyMCEPopup.prototype.execCommand = function(command, user_interface, value) {
217         var inst = tinyMCE.selectedInstance;
219         this.restoreSelection();
220         inst.execCommand(command, user_interface, value);
222         // Store selection
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,
234                 document : document,
235                 window : window,
236                 store_selection : false
237         });
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.");
250         else
251                 eval("tinyMCEPopup.windowOpener." + cb + "(element_id, url, type, window);");
254 // Setup global instance
255 var tinyMCEPopup = new TinyMCEPopup();
257 tinyMCEPopup.init();