re-added widget; fixed tests; use _.throttle instead of depricated custom debounce
This commit is contained in:
parent
7ef70b9090
commit
cc1ac843cc
4 changed files with 107 additions and 0 deletions
|
|
@ -133,6 +133,10 @@
|
|||
.span-24.last{:style=> "#{yield(:break_the_mold)}"}
|
||||
= yield
|
||||
|
||||
- unless @landing_page
|
||||
%a{:id=>"back-to-top", :title=>"Back to top", :href=>"#"}
|
||||
⇧
|
||||
|
||||
%footer
|
||||
.container
|
||||
%ul#footer_nav
|
||||
|
|
|
|||
33
public/javascripts/widgets/back-to-top.js
Normal file
33
public/javascripts/widgets/back-to-top.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(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.throttledScroll, 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;
|
||||
})();
|
||||
|
|
@ -3506,3 +3506,20 @@ a.toggle_selector
|
|||
:position relative
|
||||
:margin
|
||||
:bottom 15px
|
||||
|
||||
#back-to-top
|
||||
:display block
|
||||
:color white
|
||||
:position fixed
|
||||
:z-index 49
|
||||
:right 20px
|
||||
:bottom 20px
|
||||
:opacity 0
|
||||
:font-size 3em
|
||||
:padding 0 11px 0 12px
|
||||
:border-radius 10px
|
||||
:background-color #aaa
|
||||
&:hover
|
||||
:opacity 0.85 !important
|
||||
&:visible
|
||||
:opacity 0.5
|
||||
53
spec/javascripts/widgets/back-to-top-spec.js
Normal file
53
spec/javascripts/widgets/back-to-top-spec.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
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").andReturn(999);
|
||||
|
||||
backToTop.toggleVisibility();
|
||||
|
||||
expect(backToTop.button.hasClass("visible")).toBe(false);
|
||||
|
||||
spy.andReturn(1001);
|
||||
|
||||
backToTop.toggleVisibility();
|
||||
|
||||
expect(backToTop.button.hasClass("visible")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
$.fx.off = false;
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue