Annotation of loncom/html/htmlarea/popupwin.js, revision 1.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>