Clean up view.js
This commit is contained in:
parent
9df2cb7290
commit
b9e6f749e2
9 changed files with 55 additions and 68 deletions
|
|
@ -52,6 +52,7 @@ var app = {
|
||||||
this.setupBackboneLinks();
|
this.setupBackboneLinks();
|
||||||
this.setupGlobalViews();
|
this.setupGlobalViews();
|
||||||
this.setupDisabledLinks();
|
this.setupDisabledLinks();
|
||||||
|
this.setupForms();
|
||||||
},
|
},
|
||||||
|
|
||||||
hasPreload : function(prop) {
|
hasPreload : function(prop) {
|
||||||
|
|
@ -143,6 +144,17 @@ var app = {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setupForms: function() {
|
||||||
|
// add placeholder support for old browsers
|
||||||
|
$("input, textarea").placeholder();
|
||||||
|
|
||||||
|
// setup remote forms
|
||||||
|
$(document).on("ajax:success", "form[data-remote]", function() {
|
||||||
|
$(this).clearForm();
|
||||||
|
$(this).focusout();
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ app.views.Base = Backbone.View.extend({
|
||||||
// add avatar fallback if it can't be loaded
|
// add avatar fallback if it can't be loaded
|
||||||
this.$el.find(this.avatars.selector).error(this.avatars.fallback);
|
this.$el.find(this.avatars.selector).error(this.avatars.fallback);
|
||||||
|
|
||||||
|
// add placeholder support for old browsers
|
||||||
|
this.$("input, textarea").placeholder();
|
||||||
|
|
||||||
this.postRenderTemplate();
|
this.postRenderTemplate();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ app.views.CommentStream = app.views.Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
postRenderTemplate : function() {
|
postRenderTemplate : function() {
|
||||||
this.$("textarea").placeholder();
|
|
||||||
this.model.comments.each(this.appendComment, this);
|
this.model.comments.each(this.appendComment, this);
|
||||||
|
|
||||||
// add autoexpanders to new comment textarea
|
// add autoexpanders to new comment textarea
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@
|
||||||
//= require_tree ./helpers
|
//= require_tree ./helpers
|
||||||
//= require_tree ./pages
|
//= require_tree ./pages
|
||||||
//= require_tree ./widgets
|
//= require_tree ./widgets
|
||||||
//= require view
|
|
||||||
//= require aspects-dropdown
|
//= require aspects-dropdown
|
||||||
//= require mentions
|
//= require mentions
|
||||||
//= require bootstrap-tooltip
|
//= require bootstrap-tooltip
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
|
|
||||||
var View = {
|
|
||||||
initialize: function() {
|
|
||||||
/* label placeholders */
|
|
||||||
$("input, textarea").placeholder();
|
|
||||||
|
|
||||||
/* "Toggling" the search input */
|
|
||||||
$(this.search.selector)
|
|
||||||
.blur(this.search.blur)
|
|
||||||
.focus(this.search.focus)
|
|
||||||
|
|
||||||
/* Submit the form when the user hits enter */
|
|
||||||
.keypress(this.search.keyPress);
|
|
||||||
|
|
||||||
$(document).on('ajax:success', 'form[data-remote]', function () {
|
|
||||||
$(this).clearForm();
|
|
||||||
$(this).focusout();
|
|
||||||
});
|
|
||||||
|
|
||||||
/* tag following */
|
|
||||||
$("#new_tag_following .tag_input").bind('focus', function(){
|
|
||||||
$(this).siblings("#tag_following_submit").removeClass('hidden');
|
|
||||||
});
|
|
||||||
|
|
||||||
$('a[rel*=facebox]').facebox();
|
|
||||||
$(document).bind('reveal.facebox', function() {
|
|
||||||
Diaspora.page.directionDetector.updateBinds();
|
|
||||||
});
|
|
||||||
|
|
||||||
/* facebox 'done' buttons */
|
|
||||||
$(document).on('click', "*[rel*=close]", function(){ $.facebox.close(); });
|
|
||||||
},
|
|
||||||
|
|
||||||
search: {
|
|
||||||
blur: function() {
|
|
||||||
$(this).removeClass("active");
|
|
||||||
},
|
|
||||||
focus: function() {
|
|
||||||
$(this).addClass("active");
|
|
||||||
},
|
|
||||||
selector: "#q"
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
$(function() {
|
|
||||||
View.initialize();
|
|
||||||
});
|
|
||||||
// @license-end
|
|
||||||
|
|
@ -1,4 +1,28 @@
|
||||||
describe("app", function() {
|
describe("app", function() {
|
||||||
|
describe("initialize", function() {
|
||||||
|
it("calls several setup functions", function() {
|
||||||
|
spyOn(app.Router.prototype, "initialize");
|
||||||
|
spyOn(app, "setupDummyPreloads");
|
||||||
|
spyOn(app, "setupUser");
|
||||||
|
spyOn(app, "setupHeader");
|
||||||
|
spyOn(app, "setupBackboneLinks");
|
||||||
|
spyOn(app, "setupGlobalViews");
|
||||||
|
spyOn(app, "setupDisabledLinks");
|
||||||
|
spyOn(app, "setupForms");
|
||||||
|
|
||||||
|
app.initialize();
|
||||||
|
|
||||||
|
expect(app.Router.prototype.initialize).toHaveBeenCalled();
|
||||||
|
expect(app.setupDummyPreloads).toHaveBeenCalled();
|
||||||
|
expect(app.setupUser).toHaveBeenCalled();
|
||||||
|
expect(app.setupHeader).toHaveBeenCalled();
|
||||||
|
expect(app.setupBackboneLinks).toHaveBeenCalled();
|
||||||
|
expect(app.setupGlobalViews).toHaveBeenCalled();
|
||||||
|
expect(app.setupDisabledLinks).toHaveBeenCalled();
|
||||||
|
expect(app.setupForms).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("user", function() {
|
describe("user", function() {
|
||||||
it("returns false if the current_user isn't set", function() {
|
it("returns false if the current_user isn't set", function() {
|
||||||
app._user = undefined;
|
app._user = undefined;
|
||||||
|
|
@ -11,4 +35,13 @@ describe("app", function() {
|
||||||
expect(app.user().get("name")).toEqual("alice");
|
expect(app.user().get("name")).toEqual("alice");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("setupForms", function() {
|
||||||
|
it("calls jQuery.placeholder() for inputs", function() {
|
||||||
|
spyOn($.fn, "placeholder");
|
||||||
|
app.setupForms();
|
||||||
|
expect($.fn.placeholder).toHaveBeenCalled();
|
||||||
|
expect($.fn.placeholder.calls.mostRecent().object.selector).toBe("input, textarea");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,6 @@ describe("app.views.CommentStream", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("postRenderTemplate", function(){
|
describe("postRenderTemplate", function(){
|
||||||
it("applies infield labels", function(){
|
|
||||||
spyOn($.fn, "placeholder");
|
|
||||||
this.view.postRenderTemplate();
|
|
||||||
expect($.fn.placeholder).toHaveBeenCalled();
|
|
||||||
expect($.fn.placeholder.calls.mostRecent().object.selector).toBe("textarea");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("autoResizes the new comment textarea", function(){
|
it("autoResizes the new comment textarea", function(){
|
||||||
spyOn($.fn, "autoResize");
|
spyOn($.fn, "autoResize");
|
||||||
this.view.postRenderTemplate();
|
this.view.postRenderTemplate();
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,6 @@ describe("app.views.Base", function(){
|
||||||
expect($.fn.timeago.calls.mostRecent().object.selector).toBe("time");
|
expect($.fn.timeago.calls.mostRecent().object.selector).toBe("time");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("initializes tooltips declared with the view's tooltipSelector property", function(){
|
it("initializes tooltips declared with the view's tooltipSelector property", function(){
|
||||||
this.view.tooltipSelector = ".christopher_columbus, .barrack_obama, .block_user";
|
this.view.tooltipSelector = ".christopher_columbus, .barrack_obama, .block_user";
|
||||||
|
|
||||||
|
|
@ -77,6 +76,13 @@ describe("app.views.Base", function(){
|
||||||
this.view.render();
|
this.view.render();
|
||||||
expect($.fn.tooltip.calls.mostRecent().object.selector).toBe(".christopher_columbus, .barrack_obama, .block_user");
|
expect($.fn.tooltip.calls.mostRecent().object.selector).toBe(".christopher_columbus, .barrack_obama, .block_user");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("applies infield labels", function(){
|
||||||
|
spyOn($.fn, "placeholder");
|
||||||
|
this.view.render();
|
||||||
|
expect($.fn.placeholder).toHaveBeenCalled();
|
||||||
|
expect($.fn.placeholder.calls.mostRecent().object.selector).toBe("input, textarea");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
/* Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
||||||
* licensed under the Affero General Public License version 3 or later. See
|
|
||||||
* the COPYRIGHT file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
describe("View", function() {
|
|
||||||
it("is the object that helps the UI", function() {
|
|
||||||
expect(typeof View === "object").toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
Reference in a new issue