MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / lib / editor / htmlarea / popupwin.js
blobe5fad1a61701036e3f8a7930a3790412901455e7
1 // $Id$
2 function PopupWin(editor, title, handler, initFunction) {
3 this.editor = editor;
4 this.handler = handler;
5 var dlg = window.open("", "__ha_dialog",
6 "toolbar=no,menubar=no,personalbar=no,width=600,height=600," +
7 "scrollbars=no,resizable=no");
8 this.window = dlg;
9 var doc = dlg.document;
10 this.doc = doc;
11 var self = this;
13 var base = document.baseURI || document.URL;
14 if (base && base.match(/(.*)\/([^\/]+)/)) {
15 base = RegExp.$1 + "/";
17 this.baseURL = base;
19 doc.open();
20 var html = "<html><head><title>" + title + "</title>\n";
21 // html += "<base href='" + base + "htmlarea.js' />\n";
22 //html += "<style type='text/css'>@import url(" + base + "htmlarea.css);</style></head>\n";
23 html += "<style type='text/css'>@import url(../htmlarea.css);</style></head>\n";
24 html += "<body class='dialog popupwin' id='--HA-body'></body></html>";
25 doc.write(html);
26 doc.close();
28 // sometimes I Hate Mozilla... ;-(
29 function init2() {
30 var body = doc.body;
31 if (!body) {
32 setTimeout(init2, 25);
33 return false;
35 dlg.title = title;
36 doc.documentElement.style.padding = "0px";
37 doc.documentElement.style.margin = "0px";
38 var content = doc.createElement("div");
39 content.className = "content";
40 self.content = content;
41 body.appendChild(content);
42 self.element = body;
43 initFunction(self);
44 dlg.focus();
46 init2();
49 PopupWin.prototype.callHandler = function() {
50 var tags = ["input", "textarea", "select"];
51 var params = new Object();
52 for (var ti in tags) {
53 var tag = tags[ti];
54 var els = this.content.getElementsByTagName(tag);
55 for (var j = 0; j < els.length; ++j) {
56 var el = els[j];
57 var val = el.value;
58 if (el.tagName.toLowerCase() == "input") {
59 if (el.type == "checkbox") {
60 val = el.checked;
63 params[el.name] = val;
66 this.handler(this, params);
67 return false;
70 PopupWin.prototype.close = function() {
71 this.window.close();
74 PopupWin.prototype.addButtons = function() {
75 var self = this;
76 var div = this.doc.createElement("div");
77 this.content.appendChild(div);
78 div.className = "buttons";
79 for (var i = 0; i < arguments.length; ++i) {
80 var btn = arguments[i];
81 var button = this.doc.createElement("button");
82 div.appendChild(button);
83 button.innerHTML = HTMLArea.I18N.buttons[btn];
84 switch (btn) {
85 case "ok":
86 button.onclick = function() {
87 self.callHandler();
88 self.close();
89 return false;
91 break;
92 case "cancel":
93 button.onclick = function() {
94 self.close();
95 return false;
97 break;
102 PopupWin.prototype.showAtElement = function() {
103 var self = this;
104 // Mozilla needs some time to realize what's goin' on..
105 setTimeout(function() {
106 var w = self.content.offsetWidth + 4;
107 var h = self.content.offsetHeight + 4;
108 // size to content -- that's phuckin' buggy in all phuckin' browsers!!!
109 // so that we set a larger size for the dialog window and then center
110 // the element inside... phuck!
112 // center...
113 var el = self.content;
114 var s = el.style;
115 // s.width = el.offsetWidth + "px";
116 // s.height = el.offsetHeight + "px";
117 s.position = "absolute";
118 s.left = (w - el.offsetWidth) / 2 + "px";
119 s.top = (h - el.offsetHeight) / 2 + "px";
120 if (HTMLArea.is_gecko) {
121 self.window.innerWidth = w;
122 self.window.innerHeight = h;
123 } else {
124 self.window.resizeTo(w + 8, h + 35);
126 }, 25);