Custom popup positioning

This is used to make the userlist popup show up to the right
This commit is contained in:
Guangcong Luo
2013-05-16 14:52:05 -05:00
parent 966a6bbd01
commit e9b621e29d
2 changed files with 38 additions and 23 deletions

View File

@@ -81,8 +81,12 @@
clickUsername: function(e) {
e.stopPropagation();
e.preventDefault();
var position;
if (e.currentTarget.className === 'userbutton username') {
position = 'right';
}
var name = $(e.currentTarget).data('name');
app.addPopup(UserPopup, {name: name, sourceEl: e.currentTarget});
app.addPopup(UserPopup, {name: name, sourceEl: e.currentTarget, position: position});
},
clickLink: function(e) {
if (e.cmdKey || e.metaKey || e.ctrlKey) return;
@@ -805,13 +809,6 @@
if (!users.length) {
buf += this.noNamedUsersOnline;
}
if (this.room.userCount.unregistered) {
buf += '<li id="userlist-unregistered" style="height:auto;padding-top:5px;padding-bottom:5px">';
buf += '<span style="font-size:10pt;display:block;text-align:center;padding-bottom:5px;font-style:italic">Due to lag, <span id="usercount-unregistered">' + this.room.userCount.unregistered + '</span> unregistered users are hidden.</span>';
buf += ' <button>Challenge an unregistered user</button>';
buf += '<div style="clear:both"></div>';
buf += '</li>';
}
if (this.room.userCount.guests) {
buf += '<li id="userlist-guests" style="text-align:center;padding:2px 0"><small>(<span id="usercount-guests">' + this.room.userCount.guests + '</span> guest' + (this.room.userCount.guests == 1 ? '' : 's') + ')</small></li>';
}

View File

@@ -1353,6 +1353,8 @@
if (data && data.sourceEl) {
this.sourceEl = data.sourceEl = $(data.sourceEl);
}
if (data.type) this.type = data.type;
if (data.position) this.position = data.position;
Backbone.View.apply(this, arguments);
@@ -1369,25 +1371,41 @@
var room = $(window).height();
var height = $el.outerHeight();
var width = $el.outerWidth();
var sourceHeight = this.sourceEl.outerHeight();
if (room > offset.top + sourceHeight + height + 5 &&
(offset.top + sourceHeight < room * 2/3 || offset.top + sourceHeight + 200 < room)) {
$el.css('top', offset.top + sourceHeight);
} else if (height + 5 <= offset.top) {
$el.css('bottom', room - offset.top);
} else if (height + 10 < room) {
$el.css('bottom', 5);
if (this.position === 'right') {
if (room > offset.top + height + 5 &&
(offset.top < room * 2/3 || offset.top + 200 < room)) {
$el.css('top', offset.top);
} else {
$el.css('bottom', room - offset.top - sourceHeight);
}
$el.css('left', offset.left + this.sourceEl.outerWidth());
} else {
$el.css('top', 0);
if (room > offset.top + sourceHeight + height + 5 &&
(offset.top + sourceHeight < room * 2/3 || offset.top + sourceHeight + 200 < room)) {
$el.css('top', offset.top + sourceHeight);
} else if (height + 5 <= offset.top) {
$el.css('bottom', room - offset.top);
} else if (height + 10 < room) {
$el.css('bottom', 5);
} else {
$el.css('top', 0);
}
room = $(window).width() - offset.left;
if (room < width + 10) {
$el.css('right', 10);
} else {
$el.css('left', offset.left);
}
}
room = $(window).width() - offset.left;
var outerWidth = $el.outerWidth();
if (room < outerWidth + 10) {
$el.css('right', 10);
} else {
$el.css('left', offset.left);
}
$el.detach();
$measurer.remove();
}