DomController.prototype._setEvents = function() {
var that = this;
this._domView.addLeftMouseDownToFieldListener(function() {
that._domView.setFaceType("danger-face")
});
this._domView.addLeftMouseUpToFieldListener(function(x, y) {
that.open(x, y);
that._domView.setFaceType("cool-face");
});
this._domView.addRightMouseDownToFieldListener(this.toggleFlag.bind(this));
this._domView.addClickToFaceListener(this.reset.bind(this));
this._domView.preventContextMenuOnField();
};
DomView.prototype.setFaceType = function(type) {
if (!this._face) {
throw new DomViewException("Нет ссылки на элемент.");
} else if (this._getFaceType()) {
this.removeFaceType();
}
this._face.classList.add(type);
};
DomView.prototype.addLeftMouseUpToFieldListener = function(func) {
this._field.addEventListener("mouseup", function(event) {
var target = event.target;
if (event.which == 1) {
func(+target.dataset.x, +target.dataset.y);
}
});
};
//Поменять смайлик как в классическом сапере
DomView.prototype.addLeftMouseDownToFieldListener = function(func) {
this._field.addEventListener("mousedown", function(event) {
var target = event.target;
if (event.which == 1) {
func(+target.dataset.x, +target.dataset.y);
}
});
};
//Установка флажков
DomView.prototype.addRightMouseDownToFieldListener = function(func) {
this._field.addEventListener("mousedown", function(event) {
var target = event.target;
if (event.which == 3) {
func(+target.dataset.x, +target.dataset.y);
}
});
};
DomView.prototype.addClickToFaceListener = function(func) {
this._face.addEventListener("click", function(event) {
func();
});
};