Sha256: 7a5c0124bdff2993d252bb138ac3c05093179d35e042aa4e61ae82cfe903aa26

Contents?: true

Size: 1.66 KB

Versions: 39

Compression:

Stored size: 1.66 KB

Contents

GMaps.prototype.on = function(event_name, handler) {
  return GMaps.on(event_name, this, handler);
};

GMaps.prototype.off = function(event_name) {
  GMaps.off(event_name, this);
};

GMaps.custom_events = ['marker_added', 'marker_removed', 'polyline_added', 'polyline_removed', 'polygon_added', 'polygon_removed', 'geolocated', 'geolocation_failed'];

GMaps.on = function(event_name, object, handler) {
  if (GMaps.custom_events.indexOf(event_name) == -1) {
    if(object instanceof GMaps) object = object.map; 
    return google.maps.event.addListener(object, event_name, handler);
  }
  else {
    var registered_event = {
      handler : handler,
      eventName : event_name
    };

    object.registered_events[event_name] = object.registered_events[event_name] || [];
    object.registered_events[event_name].push(registered_event);

    return registered_event;
  }
};

GMaps.off = function(event_name, object) {
  if (GMaps.custom_events.indexOf(event_name) == -1) {
    if(object instanceof GMaps) object = object.map; 
    google.maps.event.clearListeners(object, event_name);
  }
  else {
    object.registered_events[event_name] = [];
  }
};

GMaps.fire = function(event_name, object, scope) {
  if (GMaps.custom_events.indexOf(event_name) == -1) {
    google.maps.event.trigger(object, event_name, Array.prototype.slice.apply(arguments).slice(2));
  }
  else {
    if(event_name in scope.registered_events) {
      var firing_events = scope.registered_events[event_name];

      for(var i = 0; i < firing_events.length; i++) {
        (function(handler, scope, object) {
          handler.apply(scope, [object]);
        })(firing_events[i]['handler'], scope, object);
      }
    }
  }
};

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
wbase-0.3.20 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.19 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.18 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.17 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.16 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.15 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.14 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.13 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.12 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.11 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.10 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.9 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.8 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.7 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.6 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.5 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.4 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.3 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.2 lib/vendor/admin/gmaps/lib/gmaps.events.js
wbase-0.3.1 lib/vendor/admin/gmaps/lib/gmaps.events.js