Fix Slider, ToTop and Tailing for ember-cli
This commit is contained in:
parent
64323fe4d9
commit
cd1d4a80ce
|
@ -17,6 +17,6 @@ Slider.prototype.toggle = ->
|
||||||
# TODO gotta force redraws here :/
|
# TODO gotta force redraws here :/
|
||||||
element = $('<span></span>')
|
element = $('<span></span>')
|
||||||
$('#top .profile').append(element)
|
$('#top .profile').append(element)
|
||||||
Em.run.later (-> element.remove()), 10
|
Ember.run.later (-> element.remove()), 10
|
||||||
|
|
||||||
Travis.Slider = Slider
|
Travis.Slider = Slider
|
||||||
|
|
|
@ -1,37 +1,4 @@
|
||||||
class Travis.ToTop
|
class Tailing
|
||||||
# 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
|
|
||||||
options:
|
options:
|
||||||
timeout: 200
|
timeout: 200
|
||||||
|
|
||||||
|
@ -93,3 +60,5 @@ class @Travis.Tailing
|
||||||
tail.css(top: offset - 2)
|
tail.css(top: offset - 2)
|
||||||
else
|
else
|
||||||
tail.css(top: 0)
|
tail.css(top: 0)
|
||||||
|
|
||||||
|
Travis.Tailing = Tailing
|
||||||
|
|
34
assets/scripts/app/utils/to-top.coffee
Normal file
34
assets/scripts/app/utils/to-top.coffee
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user