trigger = $trigger; $this->function = $function; $this->encapsulate_function = $encapsulate_function; $this->setType($type); } /** * * Sets the type of event, by default Google Event * @param string $type * @throws CException */ public function setType( $type ){ if( $type !== self::TYPE_EVENT_DEFAULT && $type !== self::TYPE_EVENT_DEFAULT_ONCE && $type !== self::TYPE_EVENT_DOM && $type !== self::TYPE_EVENT_DOM_ONCE ) throw new CException( Yii::t('EGMap', 'Unrecognized Event type') ); $this->type = $type; } /** * * Returns type of event * @return string */ public function getType( ){ return $this->type; } /** * @return string $trigger action that will trigger the event */ public function getTrigger() { return $this->trigger; } /** * @return string $function the javascript function to be executed */ public function getFunction() { if (!$this->encapsulate_function) return $this->function; else return 'function() {'.$this->function.'}'; } /** * returns the javascript code for attaching a Google event to a javascript_object * * @param string $js_object_name * @return string * @author Fabrice Bernhard * @since 2011-07-02 Johnatan added Once support */ public function getEventJs($js_object_name, $once=false) { $once = ($once)?'Once':''; return 'google.maps.event.addListener'.$once.'('.$js_object_name.', "'.$this->getTrigger().'", '.$this->getFunction().');'.PHP_EOL; } /** * returns the javascript code for attaching a dom event to a javascript_object * * @param string $js_object_name * @return string * @author Fabrice Bernhard * @since 2011-07-02 Johnatan */ public function getDomEventJs($js_object_name, $once=false) { $once = ($once)?'Once':''; return 'google.maps.event.addDomListener'.$once.'('.$js_object_name.', "'.$this->getTrigger().'", '.$this->getFunction().');'.PHP_EOL; } /** * returns the javascript code for attaching a Google event or a dom event to a javascript_object * * @param string $js_object_name * @return string of event type * @author Antonio Ramirez * @since 2011-07-02 Johnatan added Once Support */ public function toJs( $js_object_name ){ switch ($this->type) { case self::TYPE_EVENT_DEFAULT_ONCE: return $this->getEventJs($js_object_name, true); case self::TYPE_EVENT_DOM: return $this->getDomEventJs($js_object_name); case self::TYPE_EVENT_DOM_ONCE: return $this->getDomEventJs($js_object_name, true); case self::TYPE_EVENT_DEFAULT: default: return $this->getEventJs($js_object_name); } } }