forked from galen/PHPGoogleMaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventListener.php
70 lines (61 loc) · 1.83 KB
/
EventListener.php
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
<?php
namespace PHPGoogleMaps\Event;
/**
* Event listener class
* This class will listen for events on the map
*
* @link http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener
*
* Example
* This will listen for the idle event(fired when the map loads) and alert the user
* $event = new \PHPGoogleMaps\Event\EventListener( 'idle', 'function(){alert("the map is loaded");}', true );
* $map->addObject( $event );
*/
class EventListener extends \PHPGoogleMaps\Core\MapObject {
/**
* The object to listen to
* This should be the ID of the DOM element to listen to
*
* @var string
*/
protected $object;
/**
* The event to listen for
*
* @var string
*/
protected $event;
/**
* The function to call
* Can be a name of a function that you've defined or a complete function.
* e.g. function(){ alert('Click!') }
*
* @var string
*/
protected $function;
/**
* Once flag
* If true the event listener will be removed after the first firing.
*
* @var boolean
*/
protected $once;
/**
* Constructor
*
* @param MapObjectDecorator|String $object Object to listen to. This should be the ID of the DOM element to listen to.
* @param string $event Event to listen for.
* @param string $function Function to call.
* @param boolean $once Once flag. If true the event listener will be removed after first call.
* @return DOMEventListener
*/
public function __construct( $object, $event, $function, $once=false ) {
if ( $object instanceof \PHPGoogleMaps\Core\MapObject ) {
trigger_error( 'You must pass a MapObjectDecorator to an EventListener. e.g. $decorator = $map->addObject( $object ); $event = new EventListener( $decorator… )', E_USER_ERROR );
}
$this->event = $event;
$this->function = $function;
$this->object = $object;
$this->once = $once;
}
}