mirror of
https://github.com/flarum/framework.git
synced 2025-01-08 19:53:39 +08:00
27 lines
566 B
JavaScript
27 lines
566 B
JavaScript
|
import Ember from 'ember';
|
||
|
|
||
|
/**
|
||
|
An extension of Ember's text field with an option to set up an auto-growing
|
||
|
text input.
|
||
|
*/
|
||
|
export default Ember.TextField.extend({
|
||
|
autoGrow: false,
|
||
|
|
||
|
didInsertElement: function() {
|
||
|
if (this.get('autoGrow')) {
|
||
|
var component = this;
|
||
|
this.$().on('input', function() {
|
||
|
var empty = !$(this).val();
|
||
|
if (empty) {
|
||
|
$(this).val(component.get('placeholder'));
|
||
|
}
|
||
|
$(this).css('width', 0);
|
||
|
$(this).width($(this)[0].scrollWidth);
|
||
|
if (empty) {
|
||
|
$(this).val('');
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|