Merge pull request #6255 from fredj/translate_cursor

Don't reset the css cursor if it's not needed
This commit is contained in:
Frédéric Junod
2016-12-22 09:20:00 +01:00
committed by GitHub
2 changed files with 49 additions and 17 deletions

View File

@@ -171,7 +171,8 @@ ol.interaction.Translate.handleMoveEvent_ = function(event) {
// Change the cursor to grab/grabbing if hovering any of the features managed // Change the cursor to grab/grabbing if hovering any of the features managed
// by the interaction // by the interaction
if (this.featuresAtPixel_(event.pixel, event.map)) { if (this.featuresAtPixel_(event.pixel, event.map)) {
this.previousCursor_ = elem.style.cursor; this.previousCursor_ = this.previousCursor_ !== undefined ?
this.previousCursor_ : elem.style.cursor;
// WebKit browsers don't support the grab icons without a prefix // WebKit browsers don't support the grab icons without a prefix
elem.style.cursor = this.lastCoordinate_ ? elem.style.cursor = this.lastCoordinate_ ?
'-webkit-grabbing' : '-webkit-grab'; '-webkit-grabbing' : '-webkit-grab';
@@ -179,9 +180,8 @@ ol.interaction.Translate.handleMoveEvent_ = function(event) {
// Thankfully, attempting to set the standard ones will silently fail, // Thankfully, attempting to set the standard ones will silently fail,
// keeping the prefixed icons // keeping the prefixed icons
elem.style.cursor = this.lastCoordinate_ ? 'grabbing' : 'grab'; elem.style.cursor = this.lastCoordinate_ ? 'grabbing' : 'grab';
} else { } else if (this.previousCursor_ !== undefined) {
elem.style.cursor = this.previousCursor_ !== undefined ? elem.style.cursor = this.previousCursor_;
this.previousCursor_ : '';
this.previousCursor_ = undefined; this.previousCursor_ = undefined;
} }
}; };

View File

@@ -203,4 +203,36 @@ describe('ol.interaction.Translate', function() {
validateEvents(events, [features[0]]); validateEvents(events, [features[0]]);
}); });
}); });
describe('changes css cursor', function() {
var element, translate;
beforeEach(function() {
translate = new ol.interaction.Translate();
map.addInteraction(translate);
element = map.getTargetElement();
});
it('changes css cursor', function() {
expect(element.style.cursor).to.eql('');
simulateEvent('pointermove', 10, 20);
expect(element.style.cursor).to.match(/grab$/);
simulateEvent('pointerdown', 10, 20);
expect(element.style.cursor).to.match(/grabbing$/);
simulateEvent('pointerup', 10, 20);
expect(element.style.cursor).to.match(/grab$/);
});
it('respects existing cursor value', function() {
element.style.cursor = 'pointer';
simulateEvent('pointermove', 0, 0);
expect(element.style.cursor).to.eql('pointer');
});
});
}); });