From 0df09267390f693d8a14aab81e9a502eb80d1f21 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 2 Aug 2015 03:46:55 +0200 Subject: [PATCH 1/3] Convert BackToTop to a backbone view --- app/assets/javascripts/app/app.js | 1 + .../javascripts/app/views/back_to_top_view.js | 26 +++++++++ app/assets/javascripts/diaspora.js | 1 - app/assets/javascripts/widgets/back-to-top.js | 36 ------------- .../app/views/back_to_top_view_spec.js | 29 ++++++++++ spec/javascripts/widgets/back-to-top-spec.js | 53 ------------------- 6 files changed, 56 insertions(+), 90 deletions(-) create mode 100644 app/assets/javascripts/app/views/back_to_top_view.js delete mode 100644 app/assets/javascripts/widgets/back-to-top.js create mode 100644 spec/javascripts/app/views/back_to_top_view_spec.js delete mode 100644 spec/javascripts/widgets/back-to-top-spec.js diff --git a/app/assets/javascripts/app/app.js b/app/assets/javascripts/app/app.js index 11f5dd367..841a0cbd2 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -115,6 +115,7 @@ var app = { new app.views.AspectMembership({el: this}); }); app.sidebar = new app.views.Sidebar(); + app.backToTop = new app.views.BackToTop(); }, /* mixpanel wrapper function */ diff --git a/app/assets/javascripts/app/views/back_to_top_view.js b/app/assets/javascripts/app/views/back_to_top_view.js new file mode 100644 index 000000000..66c516475 --- /dev/null +++ b/app/assets/javascripts/app/views/back_to_top_view.js @@ -0,0 +1,26 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +app.views.BackToTop = Backbone.View.extend({ + events: { + "click #back-to-top": "backToTop" + }, + + initialize: function() { + var throttledScroll = _.throttle(this.toggleVisibility, 250); + $(window).scroll(throttledScroll); + }, + + backToTop: function(evt) { + evt.preventDefault(); + $("html, body").animate({scrollTop: 0}); + }, + + toggleVisibility: function() { + if($("html, body").scrollTop() > 1000) { + $("#back-to-top").addClass("visible"); + } else { + $("#back-to-top").removeClass("visible"); + } + } +}); +// @license-end diff --git a/app/assets/javascripts/diaspora.js b/app/assets/javascripts/diaspora.js index 054905786..b4a70e1f4 100644 --- a/app/assets/javascripts/diaspora.js +++ b/app/assets/javascripts/diaspora.js @@ -68,7 +68,6 @@ Diaspora.BasePage = function(body) { $.extend(this, Diaspora.BaseWidget); $.extend(this, { - backToTop: this.instantiate("BackToTop", body.find("#back-to-top")), directionDetector: this.instantiate("DirectionDetector"), events: function() { return Diaspora.page.eventsContainer.data("events"); }, flashMessages: this.instantiate("FlashMessages"), diff --git a/app/assets/javascripts/widgets/back-to-top.js b/app/assets/javascripts/widgets/back-to-top.js deleted file mode 100644 index bde326774..000000000 --- a/app/assets/javascripts/widgets/back-to-top.js +++ /dev/null @@ -1,36 +0,0 @@ -// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later - -(function() { - var BackToTop = function() { - var self = this; - - this.subscribe("widget/ready", function(evt, button) { - $.extend(self, { - button: button, - body: $("html, body"), - window: $(window) - }); - - self.button.click(self.backToTop); - - var throttledScroll = _.throttle($.proxy(self.toggleVisibility, self), 250); - self.window.scroll(throttledScroll); - }); - - this.backToTop = function(evt) { - evt.preventDefault(); - self.body.animate({scrollTop: 0}); - }; - - this.toggleVisibility = function() { - self.button[ - (self.body.scrollTop() > 1000) ? - 'addClass' : - 'removeClass' - ]('visible'); - }; - }; - - Diaspora.Widgets.BackToTop = BackToTop; -})(); -// @license-end diff --git a/spec/javascripts/app/views/back_to_top_view_spec.js b/spec/javascripts/app/views/back_to_top_view_spec.js new file mode 100644 index 000000000..8cfed5696 --- /dev/null +++ b/spec/javascripts/app/views/back_to_top_view_spec.js @@ -0,0 +1,29 @@ +describe("app.views.BackToTop", function() { + beforeEach(function() { + spec.loadFixture("aspects_index"); + this.view = new app.views.BackToTop(); + }); + + describe("backToTop", function() { + it("scrolls to the top of the page", function() { + var spy = spyOn($.fn, "animate"); + this.view.backToTop($.Event()); + expect(spy).toHaveBeenCalledWith({scrollTop: 0}); + }); + }); + + describe("toggleVisibility", function() { + it("toggles the button visibility depending on the scroll position", function() { + expect($("#back-to-top")).not.toHaveClass("visible"); + var spy = spyOn($.fn, "scrollTop").and.returnValue(1000); + this.view.toggleVisibility(); + expect($("#back-to-top")).not.toHaveClass("visible"); + spy.and.returnValue(1001); + this.view.toggleVisibility(); + expect($("#back-to-top")).toHaveClass("visible"); + spy.and.returnValue(1000); + this.view.toggleVisibility(); + expect($("#back-to-top")).not.toHaveClass("visible"); + }); + }); +}); diff --git a/spec/javascripts/widgets/back-to-top-spec.js b/spec/javascripts/widgets/back-to-top-spec.js deleted file mode 100644 index 35543969a..000000000 --- a/spec/javascripts/widgets/back-to-top-spec.js +++ /dev/null @@ -1,53 +0,0 @@ -describe("Diaspora.Widgets.BackToTop", function() { - var backToTop; - beforeEach(function() { - spec.loadFixture("aspects_index"); - backToTop = Diaspora.BaseWidget.instantiate("BackToTop", $("#back-to-top")); - $.fx.off = true; - }); - - describe("integration", function() { - beforeEach(function() { - backToTop = new Diaspora.Widgets.BackToTop(); - - spyOn(backToTop, "backToTop"); - spyOn(backToTop, "toggleVisibility"); - - backToTop.publish("widget/ready", [$("#back-to-top")]); - }); - - it("calls backToTop when the button is clicked", function() { - backToTop.button.click(); - - expect(backToTop.backToTop).toHaveBeenCalled(); - }); - }); - - describe("backToTop", function() { - it("animates scrollTop to 0", function() { - backToTop.backToTop($.Event()); - - expect($("body").scrollTop()).toEqual(0); - }); - }); - - describe("toggleVisibility", function() { - it("adds a visibility class to the button", function() { - var spy = spyOn(backToTop.body, "scrollTop").and.returnValue(999); - - backToTop.toggleVisibility(); - - expect(backToTop.button.hasClass("visible")).toBe(false); - - spy.and.returnValue(1001); - - backToTop.toggleVisibility(); - - expect(backToTop.button.hasClass("visible")).toBe(true); - }); - }); - - afterEach(function() { - $.fx.off = false; - }); -}); From 3c370ea56ee8d13ba7cfd5461654a13c80f8bc06 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 2 Aug 2015 03:47:42 +0200 Subject: [PATCH 2/3] Remove unused js code (stream widget and dropdowns) closes #6279 --- Changelog.md | 1 + .../javascripts/app/views/hovercard_view.js | 2 - app/assets/javascripts/diaspora.js | 5 --- app/assets/javascripts/view.js | 40 ------------------- app/assets/javascripts/widgets/stream.js | 36 ----------------- app/assets/stylesheets/mobile/mobile.scss | 31 -------------- app/views/shared/_right_sections.html.haml | 2 +- features/support/user_cuke_helpers.rb | 4 +- 8 files changed, 4 insertions(+), 117 deletions(-) delete mode 100644 app/assets/javascripts/widgets/stream.js diff --git a/Changelog.md b/Changelog.md index a4e0c325a..934b29edc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ * Extract CommentService from CommentsController [#6307](https://github.com/diaspora/diaspora/pull/6307) * Extract user/profile discovery into the diaspora\_federation-rails gem [#6310](https://github.com/diaspora/diaspora/pull/6310) * Refactor PostPresenter [#6315](https://github.com/diaspora/diaspora/pull/6315) +* Convert BackToTop to a backbone view [#6279](https://github.com/diaspora/diaspora/pull/6279) ## Bug fixes * Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212) diff --git a/app/assets/javascripts/app/views/hovercard_view.js b/app/assets/javascripts/app/views/hovercard_view.js index 41b5f587a..1d070096e 100644 --- a/app/assets/javascripts/app/views/hovercard_view.js +++ b/app/assets/javascripts/app/views/hovercard_view.js @@ -21,7 +21,6 @@ app.views.Hovercard = app.views.Base.extend({ // cache some element references this.avatar = this.$('.avatar'); this.avatarLink = this.$("a.person_avatar"); - this.dropdown = this.$('.dropdown_list'); this.dropdown_container = this.$('#hovercard_dropdown_container'); this.hashtags = this.$('.hashtags'); this.person_link = this.$('a.person'); @@ -120,7 +119,6 @@ app.views.Hovercard = app.views.Base.extend({ this.person_link.attr('href', person.url); this.person_link.text(person.name); this.person_handle.text(person.handle); - this.dropdown.attr('data-person-id', person.id); // set hashtags this.hashtags.empty(); diff --git a/app/assets/javascripts/diaspora.js b/app/assets/javascripts/diaspora.js index b4a70e1f4..157a6ab5e 100644 --- a/app/assets/javascripts/diaspora.js +++ b/app/assets/javascripts/diaspora.js @@ -91,11 +91,6 @@ Diaspora.page.publish("page/ready", [$(document.body)]); }; - // temp hack to check if backbone is enabled for the page - Diaspora.backboneEnabled = function(){ - return window.app && window.app.stream !== undefined; - }; - window.Diaspora = Diaspora; })(); diff --git a/app/assets/javascripts/view.js b/app/assets/javascripts/view.js index 508da666d..8d73197bc 100644 --- a/app/assets/javascripts/view.js +++ b/app/assets/javascripts/view.js @@ -1,9 +1,6 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later var View = { initialize: function() { - /* Buttons */ - $("input:submit").addClass("button"); - /* label placeholders */ $("input, textarea").placeholder(); @@ -15,11 +12,6 @@ var View = { /* Submit the form when the user hits enter */ .keypress(this.search.keyPress); - /* Dropdowns */ - $(document) - .on('click', this.dropdowns.selector, this.dropdowns.click) - .on('keypress', this.dropdowns.selector, this.dropdowns.click); - $(document).on('ajax:success', 'form[data-remote]', function () { $(this).clearForm(); $(this).focusout(); @@ -30,30 +22,13 @@ var View = { $(this).siblings("#tag_following_submit").removeClass('hidden'); }); - $(document.body).click(this.dropdowns.removeFocus); - $('a[rel*=facebox]').facebox(); $(document).bind('reveal.facebox', function() { Diaspora.page.directionDetector.updateBinds(); }); - $("a.new_aspect").click(function(){ - $("input#aspect_name").focus(); - }); - /* facebox 'done' buttons */ $(document).on('click', "*[rel*=close]", function(){ $.facebox.close(); }); - - /* notification routing */ - $("#notification").delegate('.hard_object_link', 'click', function(evt){ - var post = $("#"+ $(this).attr('data-ref')), - lastComment = post.find('.comment.posted').last(); - - if(post.length > 0){ - evt.preventDefault(); - $('html, body').animate({scrollTop: parseInt(lastComment.offset().top)-80 }, 'fast'); - } - }); }, search: { @@ -65,21 +40,6 @@ var View = { }, selector: "#q" }, - - dropdowns: { - click: function(evt) { - $(this).parent('.dropdown').toggleClass("active"); - evt.preventDefault(); - }, - removeFocus: function(evt) { - var $target = $(evt.target); - if(!$target.is('.dropdown_list *') && !$target.is('.dropdown.active > .toggle')) { - $(View.dropdowns.selector).parent().removeClass("active"); - } - }, - selector: ".dropdown > .toggle", - parentSelector: ".dropdown > .wrapper" - } }; $(function() { diff --git a/app/assets/javascripts/widgets/stream.js b/app/assets/javascripts/widgets/stream.js deleted file mode 100644 index a126af0e1..000000000 --- a/app/assets/javascripts/widgets/stream.js +++ /dev/null @@ -1,36 +0,0 @@ -// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later - -(function() { - var Stream = function() { - var self = this; - - this.subscribe("widget/ready", function(evt, stream) { - if( Diaspora.backboneEnabled() ){ return } - - $.extend(self, { - stream: $(stream), - mainStream: $(stream).find('#main_stream'), - headerTitle: $(stream).find('#aspect_stream_header > h3') - }); - }); - - this.globalSubscribe("stream/reloaded stream/scrolled", function() { - self.publish("widget/ready", self.stream); - }); - - this.empty = function() { - self.mainStream.empty(); - self.headerTitle.text(Diaspora.I18n.t('stream.no_aspects')); - }; - - this.setHeaderTitle = function(newTitle) { - self.headerTitle.text(newTitle); - }; - }; - - if(!Diaspora.backboneEnabled()) { - Diaspora.Widgets.Stream = Stream; - } -})(); -// @license-end - diff --git a/app/assets/stylesheets/mobile/mobile.scss b/app/assets/stylesheets/mobile/mobile.scss index d6d056beb..183995e01 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -943,37 +943,6 @@ form p.checkbox_select { padding-left: 120px; } -#file-upload.button { - @include button-gradient($light-grey); - border-radius: 3px; - box-shadow: 0 1px 1px #cfcfcf; - @include transition(border); - - display: inline-block; - - font { - style: normal; - size: 12px; - } - color: #505050; - - padding: 4px 9px; - - min-height: 10px; - - border: 1px solid; - - cursor: pointer; - white-space: normal; - - &:hover { - @include button-gradient-hover-no-saturation($light-grey); - color: #505050; - text-decoration: none; - border: 1px solid; - } -} - #settings_nav { font-size: 1em; diff --git a/app/views/shared/_right_sections.html.haml b/app/views/shared/_right_sections.html.haml index feb135beb..13f0e7d10 100644 --- a/app/views/shared/_right_sections.html.haml +++ b/app/views/shared/_right_sections.html.haml @@ -90,7 +90,7 @@ %p = t('aspects.index.help.contact_podmin') %p - = link_to t('aspects.index.help.mail_podmin'), "mailto:#{AppConfig.admins.podmin_email}", :class => "button" + = link_to t("aspects.index.help.mail_podmin"), "mailto:#{AppConfig.admins.podmin_email}" .section .title diff --git a/features/support/user_cuke_helpers.rb b/features/support/user_cuke_helpers.rb index 20603dde8..fb8b339f8 100644 --- a/features/support/user_cuke_helpers.rb +++ b/features/support/user_cuke_helpers.rb @@ -90,7 +90,7 @@ module UserCukeHelpers # submit forgot password form to get reset password link def submit_forgot_password_form - find("#new_user input.button").click + find("#new_user input.btn").click end # fill the reset password form @@ -101,7 +101,7 @@ module UserCukeHelpers # submit reset password form def submit_reset_password_form - find(".button").click + find(".btn").click end def confirm_not_signed_up From 8816c7bc8416c422022628797698f1153923e3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Tue, 25 Aug 2015 01:14:48 +0200 Subject: [PATCH 3/3] Bump Rails to 4.2.4 --- Gemfile | 2 +- Gemfile.lock | 66 ++++++++++++++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Gemfile b/Gemfile index 18348e693..4cd6e22ee 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem "rails", "4.2.3" +gem "rails", "4.2.4" # Legacy Rails features, remove me! # responders (class level) diff --git a/Gemfile.lock b/Gemfile.lock index 2332bd4f7..57622e046 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,40 +3,40 @@ GEM remote: https://rails-assets.org/ specs: CFPropertyList (2.3.1) - actionmailer (4.2.3) - actionpack (= 4.2.3) - actionview (= 4.2.3) - activejob (= 4.2.3) + actionmailer (4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.3) - actionview (= 4.2.3) - activesupport (= 4.2.3) + actionpack (4.2.4) + actionview (= 4.2.4) + activesupport (= 4.2.4) rack (~> 1.6) rack-test (~> 0.6.2) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.3) - activesupport (= 4.2.3) + actionview (4.2.4) + activesupport (= 4.2.4) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) active_model_serializers (0.9.3) activemodel (>= 3.2) - activejob (4.2.3) - activesupport (= 4.2.3) + activejob (4.2.4) + activesupport (= 4.2.4) globalid (>= 0.3.0) - activemodel (4.2.3) - activesupport (= 4.2.3) + activemodel (4.2.4) + activesupport (= 4.2.4) builder (~> 3.1) - activerecord (4.2.3) - activemodel (= 4.2.3) - activesupport (= 4.2.3) + activerecord (4.2.4) + activemodel (= 4.2.4) + activesupport (= 4.2.4) arel (~> 6.0) activerecord-import (0.10.0) activerecord (>= 3.0) - activesupport (4.2.3) + activesupport (4.2.4) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -312,7 +312,7 @@ GEM ruby-progressbar (~> 1.4) gherkin (2.12.2) multi_json (~> 1.3) - globalid (0.3.5) + globalid (0.3.6) activesupport (>= 4.1.0) gon (6.0.1) actionpack (>= 3.0) @@ -409,7 +409,7 @@ GEM multi_json (~> 1.10) logging-rails (0.5.0) logging (>= 1.8) - loofah (2.0.2) + loofah (2.0.3) nokogiri (>= 1.5.9) lumberjack (1.0.9) macaddr (1.7.1) @@ -508,16 +508,16 @@ GEM rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.3) - actionmailer (= 4.2.3) - actionpack (= 4.2.3) - actionview (= 4.2.3) - activejob (= 4.2.3) - activemodel (= 4.2.3) - activerecord (= 4.2.3) - activesupport (= 4.2.3) + rails (4.2.4) + actionmailer (= 4.2.4) + actionpack (= 4.2.4) + actionview (= 4.2.4) + activejob (= 4.2.4) + activemodel (= 4.2.4) + activerecord (= 4.2.4) + activesupport (= 4.2.4) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.3) + railties (= 4.2.4) sprockets-rails rails-assets-colorbox (1.6.3) rails-assets-jquery (>= 1.3.2) @@ -560,7 +560,7 @@ GEM rails-assets-perfect-scrollbar (0.6.4) rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.6) + rails-dom-testing (1.0.7) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) @@ -586,9 +586,9 @@ GEM remotipart (~> 1.0) safe_yaml (~> 1.0) sass-rails (>= 4.0, < 6) - railties (4.2.3) - actionpack (= 4.2.3) - activesupport (= 4.2.3) + railties (4.2.4) + actionpack (= 4.2.4) + activesupport (= 4.2.4) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.0.0) @@ -823,7 +823,7 @@ DEPENDENCIES rack-protection (= 1.5.3) rack-rewrite (= 1.5.1) rack-ssl (= 1.4.1) - rails (= 4.2.3) + rails (= 4.2.4) rails-assets-diaspora_jsxc (~> 0.1.4.alpha, < 0.1.4.develop)! rails-assets-highlightjs (= 8.6.0)! rails-assets-jakobmattsson--jquery-elastic (= 1.6.11)!