This commit is contained in:
Oleg Mokhov
2015-06-20 12:26:08 +03:00
committed by mokhov
parent a716969f4e
commit f3546ef3a5
85 changed files with 16682 additions and 1 deletions

View File

@@ -0,0 +1,60 @@
modules.define(
'y-block-event',
[
'inherit'
],
function (
provide,
inherit
) {
/**
* Класс, представляющий событие блока.
*/
var YBlockEvent = inherit({
/**
* @param {String} type Тип события.
* @param {Boolean} [isPropagationStopped=false] Запрещает распространение события.
* @param {Boolean} [isDefaultPrevented=false] Запрещает действие по умолчанию.
*/
__constructor: function (type, isPropagationStopped, isDefaultPrevented) {
this.type = type;
this._isPropagationStopped = Boolean(isPropagationStopped);
this._isDefaultPrevented = Boolean(isDefaultPrevented);
},
/**
* Определяет, прекращено ли распространение события.
*
* @returns {Boolean}
*/
isPropagationStopped: function () {
return this._isPropagationStopped;
},
/**
* Проверяет, отменена ли реакция по умолчанию на событие.
*
* @returns {Boolean}
*/
isDefaultPrevented: function () {
return this._isDefaultPrevented;
},
/**
* Прекращает распространение события.
*/
stopPropagation: function () {
this._isPropagationStopped = true;
},
/**
* Отменяет реакцию по умолчанию на событие.
*/
preventDefault: function () {
this._isDefaultPrevented = true;
}
});
provide(YBlockEvent);
});

View File

@@ -0,0 +1,63 @@
modules.define(
'test',
[
'y-block-event'
],
function (
provide,
YBlockEvent
) {
describe('YBlockEvent', function () {
describe('new YBlockEvent("type")', function () {
var event;
beforeEach(function () {
event = new YBlockEvent('foo');
});
it('should not stop propagation and not stop default action', function () {
event.isPropagationStopped().should.be.false;
event.isDefaultPrevented().should.be.false;
});
it('should have property `type`', function () {
event.type.should.eq('foo');
});
});
describe('new YBlockEvent("type", true, false)', function () {
it('should stop propagation', function () {
var event = new YBlockEvent('type', true, false);
event.isPropagationStopped().should.be.true;
event.isDefaultPrevented().should.be.false;
});
});
describe('new YBlockEvent("type", false, true)', function () {
it('should prevent default action', function () {
var event = new YBlockEvent('type', false, true);
event.isPropagationStopped().should.be.false;
event.isDefaultPrevented().should.be.true;
});
});
describe('preventDefault()', function () {
it('should prevent default action of event', function () {
var event = new YBlockEvent('type');
event.preventDefault();
event.isDefaultPrevented().should.be.true;
});
});
describe('stopPropagation()', function () {
it('should stop propagation of event', function () {
var event = new YBlockEvent('type');
event.stopPropagation();
event.isPropagationStopped().should.be.true;
});
});
});
provide();
});