diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 5bbe00fb708740ce5175789ae06c138016c5576d..3f862abd2bd820a4883f8f21cd147f9878c77054 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -52,6 +52,7 @@ var app = { this.setupBackboneLinks(); this.setupGlobalViews(); this.setupDisabledLinks(); + this.setupForms(); }, hasPreload : function(prop) { @@ -143,6 +144,17 @@ var app = { 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() { diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index 55ec8fffcfcc5281732a6e50a933e028121036a0..d0dd276b017ce47634e783eae952163fdb0c9894 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -50,6 +50,9 @@ app.views.Base = Backbone.View.extend({ // add avatar fallback if it can't be loaded this.$el.find(this.avatars.selector).error(this.avatars.fallback); + // add placeholder support for old browsers + this.$("input, textarea").placeholder(); + this.postRenderTemplate(); }, diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index 73bc7feda0f165d481f2515805ef54408839d431..5810c07cdc9245ce5fafd83f26e43c0e81ba8d3d 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -26,7 +26,6 @@ app.views.CommentStream = app.views.Base.extend({ }, postRenderTemplate : function() { - this.$("textarea").placeholder(); this.model.comments.each(this.appendComment, this); // add autoexpanders to new comment textarea diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 5fe54a767de7a49e1c5ccdc997f1df243b820d34..beaf399ee7eabeea048c5b36e77bc9e8de559bd3 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -41,7 +41,6 @@ //= require_tree ./helpers //= require_tree ./pages //= require_tree ./widgets -//= require view //= require aspects-dropdown //= require mentions //= require bootstrap-tooltip diff --git a/app/assets/javascripts/view.js b/app/assets/javascripts/view.js deleted file mode 100644 index 8d73197bc876f85b5d1a9514da11cd74e712def0..0000000000000000000000000000000000000000 --- a/app/assets/javascripts/view.js +++ /dev/null @@ -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 diff --git a/spec/javascripts/app/app_spec.js b/spec/javascripts/app/app_spec.js index 2840c1d318ca0744b23e82a537ae7bbca2b1d248..84f4a72f36ac17177d01984fdcdd621b452d56d3 100644 --- a/spec/javascripts/app/app_spec.js +++ b/spec/javascripts/app/app_spec.js @@ -1,4 +1,28 @@ 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() { it("returns false if the current_user isn't set", function() { app._user = undefined; @@ -11,4 +35,13 @@ describe("app", function() { 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"); + }); + }); }); diff --git a/spec/javascripts/app/views/comment_stream_view_spec.js b/spec/javascripts/app/views/comment_stream_view_spec.js index 27cec303fcf64b991c1df7ae0fbde211f05e720f..5028bf0d32bcb13015ac00bb477cd850f9e02235 100644 --- a/spec/javascripts/app/views/comment_stream_view_spec.js +++ b/spec/javascripts/app/views/comment_stream_view_spec.js @@ -14,13 +14,6 @@ describe("app.views.CommentStream", 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(){ spyOn($.fn, "autoResize"); this.view.postRenderTemplate(); diff --git a/spec/javascripts/app/views_spec.js b/spec/javascripts/app/views_spec.js index e33c0585ff9db38dace52e5dbff807a90cab7d21..1204ca4d189147321f75a0965b9f670bbf24aecc 100644 --- a/spec/javascripts/app/views_spec.js +++ b/spec/javascripts/app/views_spec.js @@ -69,7 +69,6 @@ describe("app.views.Base", function(){ expect($.fn.timeago.calls.mostRecent().object.selector).toBe("time"); }); - it("initializes tooltips declared with the view's tooltipSelector property", function(){ this.view.tooltipSelector = ".christopher_columbus, .barrack_obama, .block_user"; @@ -77,6 +76,13 @@ describe("app.views.Base", function(){ this.view.render(); 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"); + }); }); }); }); diff --git a/spec/javascripts/view-spec.js b/spec/javascripts/view-spec.js deleted file mode 100644 index 5542b8fae5738b4f9143401bc67c95ccf0498c82..0000000000000000000000000000000000000000 --- a/spec/javascripts/view-spec.js +++ /dev/null @@ -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(); - }); -});