Skip to content

Commit

Permalink
Further improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Jan 25, 2015
1 parent a1c6624 commit 3d031f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
9 changes: 5 additions & 4 deletions app/assets/javascripts/visual/push_left_if_necessary.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
document.Fairmondo.push_left_if_necessary = ($target, resetCallback) ->
document.Fairmondo.push_left_if_necessary = ($target) ->
window_width = $(window).width()

# reset target css 'left' before calculating
$target.css 'left', ''

# if element would leave window, give it a negative "left" css
if $target?.offset()?.left + $target.outerWidth() > window_width
$target.css 'left',
"#{window_width - ($target.offset().left + $target.outerWidth())}px"

resetCallback?()
window_width - ($target.offset().left + $target.outerWidth())
39 changes: 15 additions & 24 deletions app/assets/javascripts/visual/touchhover.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,19 @@ $ ->
.not($touchedElement)
.data('touched', false)
)
.on('touchstart', '.TouchHover', (e) ->
$el = $(e.target)
if $el.data('touched')
return true
else
e.preventDefault()
$el.data('touched', true)
)

$('.TouchHover')
.on 'mouseenter', push_left_if_necessary

.on({
'touchstart': (e) ->
$el = $(e.target)
if $el.data('touched')
return true
else
e.preventDefault()
$el.data('touched', true)
'mouseenter touchstart': (e) ->
$container = $(event.target).closest('.TouchHover')
$hidden = $container.children('.TouchHover--hidden')

push_left_if_necessary = (event) ->
$container = $(event.target).closest('.TouchHover')
$hidden = $container.children('.TouchHover--hidden')

document.Fairmondo.push_left_if_necessary $hidden, ->
# turn off the event listener, reset "left" CSS property
$container.on 'mouseleave', null, $hidden, reset_push_left

reset_push_left = (event) ->
# event.target => $item, event.data => $hidden
$(event.target).off 'mouseleave', null, reset_push_left
event.data.css 'left', ''
document.Fairmondo.push_left_if_necessary $hidden
},
'.TouchHover'
)
3 changes: 2 additions & 1 deletion app/assets/stylesheets/modules/_search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ cannot be in controller specific code because it is used by multiple controllers
.Search-filters, .Search-additional {
margin: 0;
padding: 0;
list-style-type: none;
}

.Search-filters {
Expand Down Expand Up @@ -149,7 +150,7 @@ cannot be in controller specific code because it is used by multiple controllers

.Search-filter > ul, .Search-filter > form {
position: absolute;
top: 2.1em;
top: 2em;
left: 0em;
z-index: 1;
width: auto;
Expand Down

0 comments on commit 3d031f2

Please sign in to comment.