Menu

[r15]: / includes / htmlarea / popupwin.js  Maximize  Restore  History

Download this file

140 lines (130 with data), 3.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// (c) dynarch.com 2003
// Distributed under the same terms as HTMLArea itself.
function PopupWin(editor, title, handler, initFunction) {
this.editor = editor;
this.handler = handler;
var dlg = window.open("", "__ha_dialog",
"toolbar=no,menubar=no,personalbar=no,width=600,height=600,left=20,top=40" +
"scrollbars=no,resizable=no");
this.window = dlg;
var doc = dlg.document;
this.doc = doc;
var self = this;
var base = document.baseURI || document.URL;
if (base && base.match(/(.*)\/([^\/]+)/)) {
base = RegExp.$1 + "/";
}
if (typeof _editor_url != "undefined" && !/^\//.test(_editor_url)) {
// _editor_url doesn't start with '/' which means it's relative
// FIXME: there's a problem here, it could be http:// which
// doesn't start with slash but it's not relative either.
base += _editor_url;
} else
base = _editor_url;
if (!/\/$/.test(base)) {
// base does not end in slash, add it now
base += '/';
}
this.baseURL = base;
doc.open();
var html = "<html><head><title>" + title + "</title>\n";
// html += "<base href='" + base + "htmlarea.js' />\n";
html += "<style type='text/css'>@import url(" + base + "htmlarea.css);</style></head>\n";
html += "<body class='dialog popupwin' id='--HA-body'></body></html>";
doc.write(html);
doc.close();
// sometimes I Hate Mozilla... ;-(
function init2() {
var body = doc.body;
if (!body) {
setTimeout(init2, 25);
return false;
}
dlg.title = title;
doc.documentElement.style.padding = "0px";
doc.documentElement.style.margin = "0px";
var content = doc.createElement("div");
content.className = "content";
self.content = content;
body.appendChild(content);
self.element = body;
initFunction(self);
dlg.focus();
};
init2();
};
PopupWin.prototype.callHandler = function() {
var tags = ["input", "textarea", "select"];
var params = new Object();
for (var ti in tags) {
var tag = tags[ti];
var els = this.content.getElementsByTagName(tag);
for (var j = 0; j < els.length; ++j) {
var el = els[j];
var val = el.value;
if (el.tagName.toLowerCase() == "input") {
if (el.type == "checkbox") {
val = el.checked;
}
}
params[el.name] = val;
}
}
this.handler(this, params);
return false;
};
PopupWin.prototype.close = function() {
this.window.close();
};
PopupWin.prototype.addButtons = function() {
var self = this;
var div = this.doc.createElement("div");
this.content.appendChild(div);
div.className = "buttons";
for (var i = 0; i < arguments.length; ++i) {
var btn = arguments[i];
var button = this.doc.createElement("button");
div.appendChild(button);
button.innerHTML = HTMLArea.I18N.buttons[btn];
switch (btn) {
case "ok":
button.onclick = function() {
self.callHandler();
self.close();
return false;
};
break;
case "cancel":
button.onclick = function() {
self.close();
return false;
};
break;
}
}
};
PopupWin.prototype.showAtElement = function() {
var self = this;
// Mozilla needs some time to realize what's goin' on..
setTimeout(function() {
var w = self.content.offsetWidth + 4;
var h = self.content.offsetHeight + 4;
// size to content -- that's fuckin' buggy in all fuckin' browsers!!!
// so that we set a larger size for the dialog window and then center
// the element inside... phuck!
// center...
var el = self.content;
var s = el.style;
// s.width = el.offsetWidth + "px";
// s.height = el.offsetHeight + "px";
s.position = "absolute";
s.left = (w - el.offsetWidth) / 2 + "px";
s.top = (h - el.offsetHeight) / 2 + "px";
if (HTMLArea.is_gecko) {
self.window.innerWidth = w;
self.window.innerHeight = h;
} else {
self.window.resizeTo(w + 8, h + 35);
}
}, 25);
};
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.