diff --git a/Changelog.md b/Changelog.md index bfe7235c20d52f98fe057e2bd665f263cff55e25..3d1bf968f0167cf32bed33e95baf6c38b5fa0130 100644 --- a/Changelog.md +++ b/Changelog.md @@ -77,6 +77,7 @@ With the port to Bootstrap 3, app/views/terms/default.haml has a new structure. * 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/app.js b/app/assets/javascripts/app/app.js index 24b35469dc91182b7716e79718626bec7b8fd483..216d71bcd3c4d1f416b55b6535720b065810247c 100644 --- a/app/assets/javascripts/app/app.js +++ b/app/assets/javascripts/app/app.js @@ -108,6 +108,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 0000000000000000000000000000000000000000..66c516475575c137a36d09fbd898c2257023e026 --- /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/app/views/hovercard_view.js b/app/assets/javascripts/app/views/hovercard_view.js index 41b5f587ae665b7730511df7847b099284cafaaf..1d070096e7b11464246475590215584cd445367d 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 73ff4369412579140e2b6584a4ad1dac3b54931f..8aacf6e36e1fb008b5d266a044c04fda79ef788d 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"), @@ -92,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 4810a8a691224904604d2cca8951651e676bcfd4..7d20a491f5004deb910d9286bf9443066ebc2b6f 100644 --- a/app/assets/javascripts/view.js +++ b/app/assets/javascripts/view.js @@ -1,17 +1,9 @@ // @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(); - /* 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(); @@ -21,39 +13,7 @@ var View = { $("#new_tag_following .tag_input").bind('focus', function(){ $(this).siblings("#tag_following_submit").removeClass('hidden'); }); - - $(document.body).click(this.dropdowns.removeFocus); - - $("a.new_aspect").click(function(){ - $("input#aspect_name").focus(); - }); - - /* 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'); - } - }); }, - - 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/back-to-top.js b/app/assets/javascripts/widgets/back-to-top.js deleted file mode 100644 index bde326774ee22bebff488912907d92838fdb3c0e..0000000000000000000000000000000000000000 --- 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/app/assets/javascripts/widgets/stream.js b/app/assets/javascripts/widgets/stream.js deleted file mode 100644 index a126af0e1901dabaf23f3c1ba49d30d2da8201ff..0000000000000000000000000000000000000000 --- 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 6462b31d02e58217859569cb1a6066220be0aebe..9738542e4ac2da8a4744906ebb5b8a5e4b667905 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -743,37 +743,6 @@ form p.checkbox_select { } } -#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; - } -} - form#update_profile_form { select { padding: 3px; diff --git a/app/views/shared/_right_sections.html.haml b/app/views/shared/_right_sections.html.haml index dc1ec229ddb793aa29b04764b7611d8d452653b8..e8fd5b013d8fd28f84129b2da158882b83e23048 100644 --- a/app/views/shared/_right_sections.html.haml +++ b/app/views/shared/_right_sections.html.haml @@ -84,7 +84,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 06ccd99ed391cc7deb45b850f2e6102fe7fc8919..54a986ae11ad7d82919ccb3115f80aa30577ee15 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 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 0000000000000000000000000000000000000000..8cfed56967506d2a44396f12fb574d5e84162332 --- /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 35543969a4e39d40e2ec5bf4581ea066bbafe3b8..0000000000000000000000000000000000000000 --- 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; - }); -});