From cd1d4a80ce3e3937d67c3d62d867fb5e0bd370b4 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 2 Feb 2015 10:25:53 +0100 Subject: [PATCH] Fix Slider, ToTop and Tailing for ember-cli --- assets/scripts/app/utils/slider.coffee | 2 +- assets/scripts/app/utils/tailing.coffee | 37 ++----------------------- assets/scripts/app/utils/to-top.coffee | 34 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 assets/scripts/app/utils/to-top.coffee diff --git a/assets/scripts/app/utils/slider.coffee b/assets/scripts/app/utils/slider.coffee index 46b789f0..6db9eb2c 100644 --- a/assets/scripts/app/utils/slider.coffee +++ b/assets/scripts/app/utils/slider.coffee @@ -17,6 +17,6 @@ Slider.prototype.toggle = -> # TODO gotta force redraws here :/ element = $('') $('#top .profile').append(element) - Em.run.later (-> element.remove()), 10 + Ember.run.later (-> element.remove()), 10 Travis.Slider = Slider diff --git a/assets/scripts/app/utils/tailing.coffee b/assets/scripts/app/utils/tailing.coffee index 39f10452..6162b169 100644 --- a/assets/scripts/app/utils/tailing.coffee +++ b/assets/scripts/app/utils/tailing.coffee @@ -1,37 +1,4 @@ -class Travis.ToTop - # NOTE: I could have probably extract fixed positioning from - # Tailing, but then I would need to parametrize positionElement - # function to make it flexible to handle both cases. In that - # situation I prefer a bit less DRY code over simplicity of - # the calculations. - constructor: (@window, @element_selector, @container_selector) -> - @position = @window.scrollTop() - @window.scroll( $.throttle( 200, @onScroll.bind(this) ) ) - this - - element: -> - $(@element_selector) - container: -> - $(@container_selector) - - onScroll: -> - @positionElement() - - positionElement: -> - element = @element() - container = @container() - return if element.length is 0 - containerHeight = container.outerHeight() - windowHeight = @window.height() - offset = container.offset().top + containerHeight - (@window.scrollTop() + windowHeight) - max = containerHeight - windowHeight - offset = max if offset > max - if offset > 0 - element.css(bottom: offset + 4) - else - element.css(bottom: 2) - -class @Travis.Tailing +class Tailing options: timeout: 200 @@ -93,3 +60,5 @@ class @Travis.Tailing tail.css(top: offset - 2) else tail.css(top: 0) + +Travis.Tailing = Tailing diff --git a/assets/scripts/app/utils/to-top.coffee b/assets/scripts/app/utils/to-top.coffee new file mode 100644 index 00000000..57f9fdf1 --- /dev/null +++ b/assets/scripts/app/utils/to-top.coffee @@ -0,0 +1,34 @@ +class ToTop + # NOTE: I could have probably extract fixed positioning from + # Tailing, but then I would need to parametrize positionElement + # function to make it flexible to handle both cases. In that + # situation I prefer a bit less DRY code over simplicity of + # the calculations. + constructor: (@window, @element_selector, @container_selector) -> + @position = @window.scrollTop() + @window.scroll( $.throttle( 200, @onScroll.bind(this) ) ) + this + + element: -> + $(@element_selector) + container: -> + $(@container_selector) + + onScroll: -> + @positionElement() + + positionElement: -> + element = @element() + container = @container() + return if element.length is 0 + containerHeight = container.outerHeight() + windowHeight = @window.height() + offset = container.offset().top + containerHeight - (@window.scrollTop() + windowHeight) + max = containerHeight - windowHeight + offset = max if offset > max + if offset > 0 + element.css(bottom: offset + 4) + else + element.css(bottom: 2) + +Travis.ToTop = ToTop