Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.blocks/input/__control/input__control.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ block('input').elem('control')(
placeholder : input.placeholder
};

input.autocomplete === false && (attrs.autocomplete = 'off');
input.autocomplete !== true && (attrs.autocomplete = 'off');
this.mods.disabled && (attrs.disabled = 'disabled');

return attrs;
Expand Down
2 changes: 1 addition & 1 deletion common.blocks/input/__control/input__control.bh.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function(bh) {
placeholder : input.placeholder
};

input.autocomplete === false && (attrs.autocomplete = 'off');
input.autocomplete !== true && (attrs.autocomplete = 'off');
json.blockMods.disabled && (attrs.disabled = 'disabled');

ctx.attrs(attrs);
Expand Down
5 changes: 4 additions & 1 deletion common.blocks/input/_has-clear/input_has-clear.bemhtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
block('input').mod('has-clear', true).elem('box')
.content()(function() {
return [this.ctx.content, { elem : 'clear' }];
return [
this.ctx.content,
{ elem : 'clear', mods : { visible : !!this._input.val } }
];
});
7 changes: 6 additions & 1 deletion common.blocks/input/_has-clear/input_has-clear.bh.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module.exports = function(bh) {

bh.match('input_has-clear__box', function(ctx) {
ctx.content([ctx.content(), { elem : 'clear' }], true);
ctx.content(
[
ctx.content(),
{ elem : 'clear', mods : { visible : !!ctx.tParam('_input').val } }
],
true);
});

};
5 changes: 1 addition & 4 deletions common.blocks/input/_has-clear/input_has-clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ provide(Input.decl({ modName : 'has-clear', modVal : true }, {
'js' : {
'inited' : function() {
this.__base.apply(this, arguments);

this
.on('change', this._updateClear)
._updateClear();
this.on('change', this._updateClear);
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions common.blocks/input/_polling/input_polling.bemhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
block('input').mod('polling', true).js()(function() {
return this.extend(applyNext(), { live : false });
});
9 changes: 9 additions & 0 deletions common.blocks/input/_polling/input_polling.bh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function(bh) {

bh.match('input_polling', function(ctx) {
ctx
.applyBase()
.extend(ctx.js(), { live : false });
});

};
3 changes: 3 additions & 0 deletions common.blocks/input/_polling/input_polling.deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
shouldDeps : ['idle', 'tick']
})
50 changes: 50 additions & 0 deletions common.blocks/input/_polling/input_polling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
modules.define('input', ['tick', 'idle'], function(provide, tick, idle, Input) {

var instances = [],
boundToTick,
bindToTick = function() {
boundToTick = true;
tick
.on('tick', update)
.start();
idle
.on({
idle : function() {
tick.un('tick', update);
},
wakeup : function() {
tick.on('tick', update);
}
})
.start();
},
update = function() {
var instance, i = 0;
while(instance = instances[i++]) {
instance.setVal(instance.elem('control').val());
}
};

provide(Input.decl({ modName : 'polling', modVal : true }, {
onSetMod : {
'js' : {
'inited' : function() {
this.__base.apply(this, arguments);

boundToTick || bindToTick();

this._instanceIndex = instances.push(this) - 1;
},

'' : function() {
this.__base.apply(this, arguments);

instances.splice(this._instanceIndex, 1);
var i = this._instanceIndex, instance;
while(instance = instances[i++]) --instance._instanceIndex;
}
}
}
}));

});
9 changes: 7 additions & 2 deletions common.blocks/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ provide(BEMDOM.decl({ block : this.name, baseBlock : Control }, /** @lends input
}

return this;
},

_tryToUpdateVal : function() {
this.setVal(this.elem('control').val());
}
}, {
live : function() {
this.__base.apply(this, arguments);
return false;
return this
.liveBindTo('control', 'input', this.prototype._tryToUpdateVal)
.__base();
}
}));

Expand Down
4 changes: 2 additions & 2 deletions desktop.blocks/input/input.deps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[{
shouldDeps : ['tick', 'idle']
shouldDeps : ['ua']
},
{
tech : 'spec.js',
shouldDeps : { tech : 'js', block : 'dom' }
}]
}]
72 changes: 17 additions & 55 deletions desktop.blocks/input/input.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,31 @@
modules.define('input', ['tick', 'idle'], function(provide, tick, idle, Input) {
modules.define('input', ['ua'], function(provide, ua, Input) {

var instances = [],
boundToTick,
bindToTick = function() {
boundToTick = true;
tick
.on('tick', update)
.start();
idle
.on({
idle : function() {
tick.un('tick', update);
},
wakeup : function() {
tick.on('tick', update);
}
})
.start();
},
update = function() {
var instance, i = 0;
while(instance = instances[i++]) {
instance.setVal(instance.elem('control').val());
}
};

provide(Input.decl({
onSetMod : {
'js' : {
'inited' : function() {
this.__base.apply(this, arguments);

boundToTick || bindToTick();

// сохраняем индекс в массиве инстансов чтобы потом быстро из него удалять
this._instanceIndex = instances.push(this) - 1;
},

'' : function() {
this.__base.apply(this, arguments);

// удаляем из общего массива instances
instances.splice(this._instanceIndex, 1);
// понижаем _instanceIndex всем тем кто был добавлен в instances после нас
var i = this._instanceIndex, instance;
while(instance = instances[i++]) --instance._instanceIndex;
}
}
},
if(!ua.msie || ua.version >= 10) {
provide(Input);
return;
}

provide(Input.decl('input', {
/**
* Нормализация установки фокуса для IE
* @private
* @override
* Normalizes focus for IE
*/
_focus : function() {
var input = this.elem('control')[0];
if(input.createTextRange && !input.selectionStart) {
if(!input.selectionStart) {
var range = input.createTextRange();
range.move('character', input.value.length);
range.select();
} else {
input.focus();
}
}
}, {
live : function() {
this.liveBindTo('keyup cut paste', function() {
// nextTick because when `cut` and `paste` events callbacks are executed, real value is not changed
this.nextTick(this._tryToUpdateVal);
});

return this.__base();
}
}));

});
14 changes: 0 additions & 14 deletions touch.blocks/input/input.js

This file was deleted.