Enable autosize for all textareas

This commit is contained in:
Steffen van Bergerem 2016-02-06 12:14:35 +01:00
parent 0c34452840
commit 3f72b231d4
9 changed files with 42 additions and 13 deletions

View file

@ -144,6 +144,9 @@ var app = {
// add placeholder support for old browsers
$("input, textarea").placeholder();
// init autosize plugin
autosize($("textarea"));
// setup remote forms
$(document).on("ajax:success", "form[data-remote]", function() {
$(this).clearForm();

View file

@ -53,6 +53,9 @@ app.views.Base = Backbone.View.extend({
// add placeholder support for old browsers
this.$("input, textarea").placeholder();
// init autosize plugin
autosize(this.$("textarea"));
this.postRenderTemplate();
},

View file

@ -30,7 +30,7 @@ app.views.CommentStream = app.views.Base.extend({
// add autoexpanders to new comment textarea
this.$("textarea").val(this.textareaValue);
autosize(this.$("textarea"));
autosize.update(this.$("textarea"));
},
presenter: function(){

View file

@ -94,9 +94,6 @@ app.views.Publisher = Backbone.View.extend({
this.viewPollCreator.render();
});
// init autosize plugin
autosize(this.inputEl);
this.initSubviews();
this.checkSubmitAvailability();
return this;

View file

@ -37,6 +37,9 @@ $(document).ready(function(){
.toggleClass('inactive');
};
// init autosize plugin
autosize($("textarea"));
/* Drawer menu */
$("#menu-badge").bind("tap click", function(evt){
evt.preventDefault();

View file

@ -38,6 +38,4 @@ $(document).ready(function(){
evt.preventDefault();
$("#new_status_message").submit();
});
autosize($("#status_message_text"));
});

View file

@ -45,6 +45,13 @@ describe("app", function() {
expect($.fn.placeholder).toHaveBeenCalled();
expect($.fn.placeholder.calls.mostRecent().object.selector).toBe("input, textarea");
});
it("initializes autosize for textareas", function(){
spyOn(window, "autosize");
app.setupForms();
expect(window.autosize).toHaveBeenCalled();
expect(window.autosize.calls.mostRecent().args[0].selector).toBe("textarea");
});
});
describe("setupAjaxErrorRedirect", function() {

View file

@ -15,10 +15,10 @@ describe("app.views.CommentStream", function(){
describe("postRenderTemplate", function(){
it("autoResizes the new comment textarea", function(){
spyOn(window, "autosize");
spyOn(window.autosize, "update");
this.view.postRenderTemplate();
expect(window.autosize).toHaveBeenCalled();
expect(window.autosize.calls.mostRecent().args[0].selector).toBe("textarea");
expect(window.autosize.update).toHaveBeenCalled();
expect(window.autosize.update.calls.mostRecent().args[0].selector).toBe("textarea");
});
});

View file

@ -1,10 +1,12 @@
describe("app.views.Base", function(){
beforeEach(function(){
var StaticTemplateClass = app.views.Base.extend({ templateName : "static-text" });
this.model = new Backbone.Model({text : "model attributes are in the default presenter"});
this.view = new StaticTemplateClass({model: this.model});
});
describe("#render", function(){
beforeEach(function(){
var staticTemplateClass = app.views.Base.extend({ templateName : "static-text" });
this.model = new Backbone.Model({text : "model attributes are in the default presenter"});
this.view = new staticTemplateClass({model: this.model});
this.view.render();
});
@ -85,4 +87,20 @@ describe("app.views.Base", function(){
});
});
});
describe("#renderTemplate", function(){
it("calls jQuery.placeholder() for inputs", function() {
spyOn($.fn, "placeholder");
this.view.renderTemplate();
expect($.fn.placeholder).toHaveBeenCalled();
expect($.fn.placeholder.calls.mostRecent().object.selector).toBe("input, textarea");
});
it("initializes autosize for textareas", function(){
spyOn(window, "autosize");
this.view.renderTemplate();
expect(window.autosize).toHaveBeenCalled();
expect(window.autosize.calls.mostRecent().args[0].selector).toBe("textarea");
});
});
});