Merge pull request #694 from fredj/backbone-model

Change ol.Object event name syntax
This commit is contained in:
Frédéric Junod
2013-05-31 04:33:51 -07:00
10 changed files with 46 additions and 46 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ var marker = new ol.Overlay({
// bind the marker position to the device location. // bind the marker position to the device location.
marker.bindTo('position', geolocation); marker.bindTo('position', geolocation);
geolocation.addEventListener('accuracy_changed', function() { geolocation.on('change:accuracy', function() {
$(marker.getElement()).tooltip({ $(marker.getElement()).tooltip({
title: this.getAccuracy() + 'm from this point' title: this.getAccuracy() + 'm from this point'
}); });
+1 -1
View File
@@ -29,7 +29,7 @@ var geolocation = new ol.Geolocation({
tracking: true tracking: true
}); });
geolocation.bindTo('projection', view); geolocation.bindTo('projection', view);
geolocation.once('position_changed', function() { geolocation.once('change:position', function() {
view.setCenter(geolocation.getPosition()); view.setCenter(geolocation.getPosition());
view.setResolution(2.388657133911758); view.setResolution(2.388657133911758);
}); });
+2 -2
View File
@@ -34,10 +34,10 @@ ol.dom.Input = function(target) {
this.handleInputChanged_, false, this); this.handleInputChanged_, false, this);
goog.events.listen(this, goog.events.listen(this,
ol.Object.getChangedEventType(ol.dom.InputProperty.VALUE), ol.Object.getChangeEventType(ol.dom.InputProperty.VALUE),
this.handleValueChanged_, false, this); this.handleValueChanged_, false, this);
goog.events.listen(this, goog.events.listen(this,
ol.Object.getChangedEventType(ol.dom.InputProperty.CHECKED), ol.Object.getChangeEventType(ol.dom.InputProperty.CHECKED),
this.handleCheckedChanged_, false, this); this.handleCheckedChanged_, false, this);
}; };
goog.inherits(ol.dom.Input, ol.Object); goog.inherits(ol.dom.Input, ol.Object);
+2 -2
View File
@@ -60,10 +60,10 @@ ol.Geolocation = function(opt_options) {
this.watchId_ = undefined; this.watchId_ = undefined;
goog.events.listen( goog.events.listen(
this, ol.Object.getChangedEventType(ol.GeolocationProperty.PROJECTION), this, ol.Object.getChangeEventType(ol.GeolocationProperty.PROJECTION),
this.handleProjectionChanged_, false, this); this.handleProjectionChanged_, false, this);
goog.events.listen( goog.events.listen(
this, ol.Object.getChangedEventType(ol.GeolocationProperty.TRACKING), this, ol.Object.getChangeEventType(ol.GeolocationProperty.TRACKING),
this.handleTrackingChanged_, false, this); this.handleTrackingChanged_, false, this);
if (goog.isDef(options.projection)) { if (goog.isDef(options.projection)) {
+5 -5
View File
@@ -307,13 +307,13 @@ ol.Map = function(options) {
*/ */
this.layersListenerKeys_ = null; this.layersListenerKeys_ = null;
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.LAYERS), goog.events.listen(this, ol.Object.getChangeEventType(ol.MapProperty.LAYERS),
this.handleLayersChanged_, false, this); this.handleLayersChanged_, false, this);
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.VIEW), goog.events.listen(this, ol.Object.getChangeEventType(ol.MapProperty.VIEW),
this.handleViewChanged_, false, this); this.handleViewChanged_, false, this);
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.SIZE), goog.events.listen(this, ol.Object.getChangeEventType(ol.MapProperty.SIZE),
this.handleSizeChanged_, false, this); this.handleSizeChanged_, false, this);
goog.events.listen(this, ol.Object.getChangedEventType(ol.MapProperty.TARGET), goog.events.listen(this, ol.Object.getChangeEventType(ol.MapProperty.TARGET),
this.handleTargetChanged_, false, this); this.handleTargetChanged_, false, this);
// setValues will trigger the rendering of the map if the map // setValues will trigger the rendering of the map if the map
@@ -727,7 +727,7 @@ ol.Map.prototype.handleViewChanged_ = function() {
var view = this.getView(); var view = this.getView();
if (goog.isDefAndNotNull(view)) { if (goog.isDefAndNotNull(view)) {
this.viewPropertyListenerKey_ = goog.events.listen( this.viewPropertyListenerKey_ = goog.events.listen(
view, ol.ObjectEventType.CHANGED, view, ol.ObjectEventType.CHANGE,
this.handleViewPropertyChanged_, false, this); this.handleViewPropertyChanged_, false, this);
} }
this.render(); this.render();
+10 -10
View File
@@ -18,7 +18,7 @@ goog.require('goog.object');
* @enum {string} * @enum {string}
*/ */
ol.ObjectEventType = { ol.ObjectEventType = {
CHANGED: 'changed' CHANGE: 'change'
}; };
@@ -57,7 +57,7 @@ goog.inherits(ol.Object, goog.events.EventTarget);
* @private * @private
* @type {Object.<string, string>} * @type {Object.<string, string>}
*/ */
ol.Object.changedEventTypeCache_ = {}; ol.Object.changeEventTypeCache_ = {};
/** /**
@@ -95,12 +95,12 @@ ol.Object.getAccessors = function(obj) {
/** /**
* @param {string} key Key. * @param {string} key Key.
* @return {string} Changed name. * @return {string} Change name.
*/ */
ol.Object.getChangedEventType = function(key) { ol.Object.getChangeEventType = function(key) {
return ol.Object.changedEventTypeCache_.hasOwnProperty(key) ? return ol.Object.changeEventTypeCache_.hasOwnProperty(key) ?
ol.Object.changedEventTypeCache_[key] : ol.Object.changeEventTypeCache_[key] :
(ol.Object.changedEventTypeCache_[key] = key.toLowerCase() + '_changed'); (ol.Object.changeEventTypeCache_[key] = 'change:' + key.toLowerCase());
}; };
@@ -146,7 +146,7 @@ ol.Object.prototype.bindTo =
function(key, target, opt_targetKey, opt_noNotify) { function(key, target, opt_targetKey, opt_noNotify) {
var targetKey = opt_targetKey || key; var targetKey = opt_targetKey || key;
this.unbind(key); this.unbind(key);
var eventType = ol.Object.getChangedEventType(targetKey); var eventType = ol.Object.getChangeEventType(targetKey);
var listeners = ol.Object.getListeners(this); var listeners = ol.Object.getListeners(this);
listeners[key] = goog.events.listen(target, eventType, function() { listeners[key] = goog.events.listen(target, eventType, function() {
this.notifyInternal_(key); this.notifyInternal_(key);
@@ -217,9 +217,9 @@ ol.Object.prototype.notify = function(key) {
* @private * @private
*/ */
ol.Object.prototype.notifyInternal_ = function(key) { ol.Object.prototype.notifyInternal_ = function(key) {
var eventType = ol.Object.getChangedEventType(key); var eventType = ol.Object.getChangeEventType(key);
this.dispatchEvent(eventType); this.dispatchEvent(eventType);
this.dispatchEvent(ol.ObjectEventType.CHANGED); this.dispatchEvent(ol.ObjectEventType.CHANGE);
}; };
+4 -4
View File
@@ -69,20 +69,20 @@ ol.Overlay = function(options) {
}; };
goog.events.listen( goog.events.listen(
this, ol.Object.getChangedEventType(ol.OverlayProperty.ELEMENT), this, ol.Object.getChangeEventType(ol.OverlayProperty.ELEMENT),
this.handleElementChanged, false, this); this.handleElementChanged, false, this);
goog.events.listen( goog.events.listen(
this, ol.Object.getChangedEventType(ol.OverlayProperty.MAP), this, ol.Object.getChangeEventType(ol.OverlayProperty.MAP),
this.handleMapChanged, false, this); this.handleMapChanged, false, this);
goog.events.listen( goog.events.listen(
this, ol.Object.getChangedEventType(ol.OverlayProperty.POSITION), this, ol.Object.getChangeEventType(ol.OverlayProperty.POSITION),
this.handlePositionChanged, false, this); this.handlePositionChanged, false, this);
goog.events.listen( goog.events.listen(
this, this,
ol.Object.getChangedEventType(ol.OverlayProperty.POSITIONING), ol.Object.getChangeEventType(ol.OverlayProperty.POSITIONING),
this.handlePositioningChanged, false, this); this.handlePositioningChanged, false, this);
if (goog.isDef(options.element)) { if (goog.isDef(options.element)) {
+6 -6
View File
@@ -43,30 +43,30 @@ ol.renderer.Layer = function(mapRenderer, layer) {
this.layer_ = layer; this.layer_ = layer;
goog.events.listen(this.layer_, goog.events.listen(this.layer_,
ol.Object.getChangedEventType(ol.layer.LayerProperty.BRIGHTNESS), ol.Object.getChangeEventType(ol.layer.LayerProperty.BRIGHTNESS),
this.handleLayerBrightnessChange, false, this); this.handleLayerBrightnessChange, false, this);
goog.events.listen(this.layer_, goog.events.listen(this.layer_,
ol.Object.getChangedEventType(ol.layer.LayerProperty.CONTRAST), ol.Object.getChangeEventType(ol.layer.LayerProperty.CONTRAST),
this.handleLayerContrastChange, false, this); this.handleLayerContrastChange, false, this);
goog.events.listen(this.layer_, goog.events.listen(this.layer_,
ol.Object.getChangedEventType(ol.layer.LayerProperty.HUE), ol.Object.getChangeEventType(ol.layer.LayerProperty.HUE),
this.handleLayerHueChange, false, this); this.handleLayerHueChange, false, this);
goog.events.listen(this.layer_, goog.events.EventType.LOAD, goog.events.listen(this.layer_, goog.events.EventType.LOAD,
this.handleLayerLoad, false, this); this.handleLayerLoad, false, this);
goog.events.listen(this.layer_, goog.events.listen(this.layer_,
ol.Object.getChangedEventType(ol.layer.LayerProperty.OPACITY), ol.Object.getChangeEventType(ol.layer.LayerProperty.OPACITY),
this.handleLayerOpacityChange, false, this); this.handleLayerOpacityChange, false, this);
goog.events.listen(this.layer_, goog.events.listen(this.layer_,
ol.Object.getChangedEventType(ol.layer.LayerProperty.SATURATION), ol.Object.getChangeEventType(ol.layer.LayerProperty.SATURATION),
this.handleLayerSaturationChange, false, this); this.handleLayerSaturationChange, false, this);
goog.events.listen(this.layer_, goog.events.listen(this.layer_,
ol.Object.getChangedEventType(ol.layer.LayerProperty.VISIBLE), ol.Object.getChangeEventType(ol.layer.LayerProperty.VISIBLE),
this.handleLayerVisibleChange, false, this); this.handleLayerVisibleChange, false, this);
}; };
+5 -5
View File
@@ -195,30 +195,30 @@ describe('ol.collection', function() {
}); });
}); });
describe('length_changed event', function() { describe('change:length event', function() {
var collection, cb; var collection, cb;
beforeEach(function() { beforeEach(function() {
collection = new ol.Collection([0, 1, 2]); collection = new ol.Collection([0, 1, 2]);
cb = sinon.spy(); cb = sinon.spy();
goog.events.listen(collection, 'length_changed', cb); goog.events.listen(collection, 'change:length', cb);
}); });
describe('insertAt', function() { describe('insertAt', function() {
it('triggers length_changed event', function() { it('triggers change:length event', function() {
collection.insertAt(2, 3); collection.insertAt(2, 3);
expect(cb).to.be.called(); expect(cb).to.be.called();
}); });
}); });
describe('removeAt', function() { describe('removeAt', function() {
it('triggers length_changed event', function() { it('triggers change:length event', function() {
collection.removeAt(0); collection.removeAt(0);
expect(cb).to.be.called(); expect(cb).to.be.called();
}); });
}); });
describe('setAt', function() { describe('setAt', function() {
it('does not trigger length_changed event', function() { it('does not trigger change:length event', function() {
collection.setAt(1, 1); collection.setAt(1, 1);
expect(cb).to.not.be.called(); expect(cb).to.not.be.called();
}); });
+10 -10
View File
@@ -103,15 +103,15 @@ describe('ol.Object', function() {
beforeEach(function() { beforeEach(function() {
listener1 = sinon.spy(); listener1 = sinon.spy();
goog.events.listen(o, 'k_changed', listener1); goog.events.listen(o, 'change:k', listener1);
listener2 = sinon.spy(); listener2 = sinon.spy();
goog.events.listen(o, 'changed', listener2); goog.events.listen(o, 'change', listener2);
var o2 = new ol.Object(); var o2 = new ol.Object();
o2.bindTo('k', o); o2.bindTo('k', o);
listener3 = sinon.spy(); listener3 = sinon.spy();
goog.events.listen(o2, 'k_changed', listener3); goog.events.listen(o2, 'change:k', listener3);
}); });
it('dispatches events', function() { it('dispatches events', function() {
@@ -136,15 +136,15 @@ describe('ol.Object', function() {
beforeEach(function() { beforeEach(function() {
listener1 = sinon.spy(); listener1 = sinon.spy();
goog.events.listen(o, 'k_changed', listener1); goog.events.listen(o, 'change:k', listener1);
listener2 = sinon.spy(); listener2 = sinon.spy();
goog.events.listen(o, 'changed', listener2); goog.events.listen(o, 'change', listener2);
o2 = new ol.Object(); o2 = new ol.Object();
o2.bindTo('k', o); o2.bindTo('k', o);
listener3 = sinon.spy(); listener3 = sinon.spy();
goog.events.listen(o2, 'k_changed', listener3); goog.events.listen(o2, 'change:k', listener3);
}); });
it('dispatches events to object', function() { it('dispatches events to object', function() {
@@ -288,10 +288,10 @@ describe('ol.Object', function() {
o2.bindTo('k2', o, 'k1'); o2.bindTo('k2', o, 'k1');
listener1 = sinon.spy(); listener1 = sinon.spy();
goog.events.listen(o, 'k1_changed', listener1); goog.events.listen(o, 'change:k1', listener1);
listener2 = sinon.spy(); listener2 = sinon.spy();
goog.events.listen(o2, 'k2_changed', listener2); goog.events.listen(o2, 'change:k2', listener2);
}); });
it('sets the expected properties', function() { it('sets the expected properties', function() {
@@ -460,9 +460,9 @@ describe('ol.Object', function() {
beforeEach(function() { beforeEach(function() {
listener1 = sinon.spy(); listener1 = sinon.spy();
goog.events.listen(o, 'k_changed', listener1); goog.events.listen(o, 'change:k', listener1);
listener2 = sinon.spy(); listener2 = sinon.spy();
goog.events.listen(o, 'K_changed', listener2); goog.events.listen(o, 'change:K', listener2);
}); });
it('dispatches the expected event', function() { it('dispatches the expected event', function() {