From b5c6bbbf20e29ff9808c10fac34d70fc5c1c2b14 Mon Sep 17 00:00:00 2001 From: euzuro Date: Sun, 21 May 2006 15:27:36 +0000 Subject: [PATCH] make popup take arguments, allow it to draw itself. tests. git-svn-id: http://svn.openlayers.org/trunk/openlayers@226 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Popup.js | 41 +++++++++++++++++++++++++++++++++++--- tests/test_Popup.html | 44 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index 821c2f0f4f..74dec3d8c1 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -4,15 +4,50 @@ OpenLayers.Popup = Class.create(); OpenLayers.Popup.prototype = { - + /** @type String */ + id: "", + + /** @type DOMElement */ + div: null, + + /** @type OpenLayers.Pixel */ + px: null, + + /** @type OpenLayers.Size*/ + size: null, /** * @constructor + * + * @param {String} id + * @param {OpenLayers.Pixel} px + * @param {OpenLayers.Size} size */ - initialize:function() { + initialize:function(id, px, size) { + this.id = id; + this.px = px; + this.size = size; + }, + + /** + */ + destroy: function() { }, - + + /** + */ + draw: function() { + if (this.div == null) { + this.div = OpenLayers.Util.createDiv(this.id + "_div", + this.px, + this.size + ); + + this.div.style.backgroundColor = "red"; + } + return this.div; + }, diff --git a/tests/test_Popup.html b/tests/test_Popup.html index 1cf04a36bd..d54268f7f8 100644 --- a/tests/test_Popup.html +++ b/tests/test_Popup.html @@ -5,9 +5,49 @@ var popup; function test_01_Popup_constructor (t) { - t.plan( 1 ); - popup = new OpenLayers.Popup(); + t.plan( 6 ); + + var id = "chicken"; + var x = 50; + var y = 100; + var w = 500; + var h = 400; + + + popup = new OpenLayers.Popup(id, + new OpenLayers.Pixel(x, y), + new OpenLayers.Size(w, h)); + t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); + t.eq(popup.id, id, "popup.id set correctly"); + t.eq(popup.px.x, x, "left position of popup.px set correctly"); + t.eq(popup.px.y, y, "top position of popup.px set correctly"); + t.eq(popup.size.w, w, "width position of popup.size set correctly"); + t.eq(popup.size.h, h, "heightposition of popup.size set correctly"); + } + + function test_02_Popup_draw(t) { + + t.plan( 5 ); + + var id = "chicken"; + var x = 50; + var y = 100; + var w = 500; + var h = 400; + + + popup = new OpenLayers.Popup(id, + new OpenLayers.Pixel(x, y), + new OpenLayers.Size(w, h)); + popup.draw(); + + t.eq(popup.div.id, id + "_div", "popup.div.id set correctly"); + t.eq(popup.div.style.left, x + "px", "left position of popup.div set correctly"); + t.eq(popup.div.style.top, y + "px", "top position of popup.div set correctly"); + t.eq(popup.div.style.width, w + "px", "width position of popup.div set correctly"); + t.eq(popup.div.style.height, h + "px", "heightposition of popup.div set correctly"); + }