Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Hover Bubble: add .anchor-right-fixed positioning mode.
Browse files Browse the repository at this point in the history
Like anchor-right but using fixed positioning and clamped to the window
dimensions.
  • Loading branch information
spladug committed Apr 1, 2013
1 parent e66b621 commit 2d68088
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 19 additions & 1 deletion r2/r2/public/static/js/ui.js
Expand Up @@ -165,6 +165,17 @@ r.ui.Bubble = Backbone.View.extend({
right: parentPos.right + offsetX,
top: parentPos.top + offsetY - bodyOffset.top
})
} else if (this.$el.is('.anchor-right-fixed')) {
offsetX = 32
offsetY = 0

parentPos.top -= $(document).scrollTop()
parentPos.left -= $(document).scrollLeft()

this.$el.css({
top: r.utils.clamp(parentPos.top - offsetY, 0, $(window).height() - this.$el.outerHeight()),
left: r.utils.clamp(parentPos.left - offsetX - this.$el.width(), 0, $(window).width())
})
}
},

Expand All @@ -178,9 +189,13 @@ r.ui.Bubble = Backbone.View.extend({

$('body').append(this.$el)

this.$el.css('visibility', 'hidden').show()
this.render()
this.position()
this.$el.css('opacity', 1).show()
this.$el.css({
'opacity': 1,
'visibility': 'visible'
})

var isSwitch = this.options.group && this.options.group.current && this.options.group.current != this
if (isSwitch) {
Expand Down Expand Up @@ -228,6 +243,9 @@ r.ui.Bubble = Backbone.View.extend({
} else if (this.$el.is('.anchor-right')) {
animProp = 'right'
animOffset = '-=5'
} else if (this.$el.is('.anchor-right-fixed')) {
animProp = 'right'
animOffset = '-=5'
}
var curOffset = this.$el.css(animProp)

Expand Down
4 changes: 4 additions & 0 deletions r2/r2/public/static/js/utils.js
@@ -1,4 +1,8 @@
r.utils = {
clamp: function(val, min, max) {
return Math.max(min, Math.min(max, val))
},

staticURL: function (item) {
return r.config.static_root + '/' + item
},
Expand Down

0 comments on commit 2d68088

Please sign in to comment.