Skip to content
Extraits de code Groupes Projets
Valider cc1ac843 rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

re-added widget; fixed tests; use _.throttle instead of depricated custom debounce

parent 7ef70b90
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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
......
(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
\ No newline at end of file
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;
});
});
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter