From e0650821337e7372f434e0c0a05ea39b2bfdb6c5 Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Sat, 7 Jan 2012 06:40:18 +0800 Subject: [PATCH] Add property to info window to allow to close the info windows if an other is opened --- Model/Overlays/InfoWindow.php | 28 +++++++++++++++++++++++++ Tests/Model/Overlays/InfoWindowTest.php | 14 +++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Model/Overlays/InfoWindow.php b/Model/Overlays/InfoWindow.php index a5393ad3..3cec2ec3 100644 --- a/Model/Overlays/InfoWindow.php +++ b/Model/Overlays/InfoWindow.php @@ -44,6 +44,11 @@ class InfoWindow extends AbstractOptionsAsset implements IExtendable * @var string Event which opens the info window */ protected $openEvent = MouseEvent::CLICK; + + /** + * @var boolean TRUE if the info window closes when one is opened else FALSE + */ + protected $autoClose = false; /** * Create an info window @@ -247,4 +252,27 @@ public function setOpenEvent($openEvent) else throw new \InvalidArgumentException(sprintf('The only available open event are : %s', implode(', ', MouseEvent::getMouseEvents()))); } + + /** + * Gets the auto close flag + * + * @return boolean TRUE if all opened info windows close when one is opened else FALSE + */ + public function isAutoClose() + { + return $this->autoClose; + } + + /** + * Sets the auto close flag + * + * @param boolean $autoClose TRUE if all opened info windows close when one is opened else FALSE + */ + public function setAutoClose($autoClose) + { + if(is_bool($autoClose)) + $this->autoClose = $autoClose; + else + throw new \InvalidArgumentException('The info window auto close flag must be a boolean value.'); + } } diff --git a/Tests/Model/Overlays/InfoWindowTest.php b/Tests/Model/Overlays/InfoWindowTest.php index 8ec64713..6c81e4f4 100644 --- a/Tests/Model/Overlays/InfoWindowTest.php +++ b/Tests/Model/Overlays/InfoWindowTest.php @@ -38,12 +38,26 @@ public function testDefaultValues() { parent::testDefaultValues(); + $this->assertFalse(self::$object->isAutoClose()); $this->assertNull(self::$object->getPosition()); $this->assertNull(self::$object->getPixelOffset()); $this->assertEquals(self::$object->getContent(), '

Default content

'); $this->assertFalse(self::$object->isOpen()); $this->assertTrue(self::$object->isAutoOpen()); $this->assertEquals(self::$object->getOpenEvent(), 'click'); + $this->assertFalse(self::$object->isAutoClose()); + } + + /** + * Checks the auto close getter & setter + */ + public function testAutoClose() + { + self::$object->setAutoClose(true); + $this->assertTrue(self::$object->isAutoClose()); + + self::$object->setAutoClose(false); + $this->assertFalse(self::$object->isAutoClose()); } /**