-
-
Notifications
You must be signed in to change notification settings - Fork 79k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tooltip positioning with regards to viewports #14226
Conversation
The getPosition function was simplified with a new function, getViewportBounds, was added to specifically tackle the cases where we’re looking for the viewport bounds. ‘absolute’ and ‘fixed’ tooltips are now matched against the screen where other ones are made to fit inside the viewport element.
Hi, This is my first contribution, hopefully it's a decent one. It fixes #14195 The Tooltip Viewport Example is still working and all unit tests pass. I "hardcoded" some rules concerning the css position for the viewport example to work as it was before, as theoretically the "bottom" tooltip would have room to expand towards the bottom... now I restrict it in screen space like it was before. It's my first JavaScript / web PR, so it's possible that I messed something up... feel free to give me feedback :) If the style / direction I used to fix the problem is "ok", I think I would go further in simplifying / refactoring the getPosition function which is used for many other things than actually getting a position. Thanks! |
And obviously I had to play with whitespaces after running my final 'grunt test'... fixing the file. |
@@ -340,16 +340,40 @@ | |||
|
|||
} | |||
|
|||
Tooltip.prototype.getViewportBounds = function ($viewport) { | |||
if ($viewport.selector == 'body') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use $viewport.is('body')
here.
Remove semi colon Remove temporary variable to hold CSS position Remove extend and explicitly construct top and left elements Use “is” to know if the viewport is a ‘body’
Thank you for your feedback! |
} | ||
|
||
Tooltip.prototype.getScreenSpaceBounds = function () { | ||
return $.extend({}, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking about this $.extend
, the other one was fine, IMO.
Bring back the initial extend Remove the extend that only merges 1 element with an empty one
|
||
Tooltip.prototype.getScreenSpaceBounds = function () { | ||
return $.extend({}, { | ||
top: $('body').scrollTop(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use document.body
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvrebert I wasn't too sure about that one, but based on http://jsperf.com/jquery-body-vs-document-body-selector this seemed like a good option to use $('body')
. Is there a good way to profile performance of jquery / bootstrap or in a case like this it's more a case of project standards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No standard that I know of. It's admittedly a micro-optimization (http://jsperf.com/jquery-body-vs-document-body-selector/2 ). It's ultimately up to @fat to decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mathiasbynens/jsperf.com#158 and http://mrale.ph/blog/2012/12/15/microbenchmarks-fairy-tale.html
I personally prefer $(document.body)
because it's more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing! Since I'm new to all this that's priceless when you guys share information like this!
I have a bunch of meetings in the afternoon, but I definitely wouldn't mind changing it to $(document.body)
later tonight!
Move away from a switch to a regular expression
@@ -340,16 +340,36 @@ | |||
|
|||
} | |||
|
|||
Tooltip.prototype.getViewportBounds = function ($viewport) { | |||
if ($viewport.is('body')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can combine these conditions
if ($viewport.is('body') && /fixed|absolute/.test(this.$element.css('position'))
this is looking pretty good (thanks @hnrch02 for the help) – any chance you could write some new tests @ericmartel for the issues you are fixing? thanks! |
Thanks, will do the changes later tonight! As for the tests, I'll see to add more, but I'm not sure how to handle the scolling in the tests. I'll try to find how to when I get home, but if you have some pointers I'll be more than happy to learn from you guys! |
Reduce access to the DOM and merge conditions on one line
Updated the code and I should be able to write new unit tests for fixed and absolute elements later this week or during the week end. Thanks! :) |
Added a unit test to validate that the computed position didn’t take scrolling into account
I added a new test to handle scrolling, the rest of the code being already covered by existing unit tests |
If that's the case, I believe a lot of tests will have to be updated as a lot of tests about placement and viewport are not using callbacks at the moment. From the results I was getting though, it SEEMED like my tooltip was already created when I was getting the offset values. |
Is this issue about this problem: http://jsbin.com/risupocu/1/ ? |
My pull request doesn't cover auto placement. I suggest you open a new issue, once this pull request is accepted and merge, it should be easy to use the same bounds code to handle auto placement. |
Humm I suspect my Git noobness will show in this commit... I think it should be fine but let me know if I did something wrong. (I almost only use Perforce) |
@ericmartel Much appreciated! @fat Ping. |
Running Sauce cross-browser test: https://travis-ci.org/twbs/bootstrap/jobs/41687000 |
@@ -711,6 +711,42 @@ $(function () { | |||
$styles.remove() | |||
}) | |||
|
|||
test('should not be adjust position when scrolling', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grammar problem: "should not be adjust position" [sic]
@cvrebert thanks Chris for the feedback! I'll most definitely fix the typos. How can I run the Sauce cross-browser tests? Launching grunt was successful but I guess it only runs the unit tests? As for the PR containing wrong commits, it's the first time I try to integrate a branch to update a PR (I'm used to perforce), I'll try to rework the whole thing this week end Thanks |
Using Sauce requires a Sauce account, so there's not an easy way to run the Sauce tests yourself. |
@cvrebert Thanks, I'll read my git book and see what I did wrong :) |
Ok, I read about how to fix this PR... can you guys advise the best way to do so? I believe my best home would be to git revert to my change before merging from master, and then redo the merge (though i'm not sure where I messed during the merge to cause this problem)? Or simply since there's very little change... create a new branch, redo the changes and open a new PR? |
Looking forward to see it merged |
@twbs-savage Retry |
Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED Commit: bc9a3ad (Please note that this is a fully automated comment.) |
@ericmartel I'll just squash the history before merging this. Could you add a commit to fix the rounding problem and address the other minor comments I made? |
@cvrebert sorry I think I missed this comment, let me know if I can do anything else to help! |
Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED Commit: 388064a (Please note that this is a fully automated comment.) |
@cvrebert there seems to be problems with the tests, I doubt it has anything to do with my changelist though :/ Could not connect to Sauce Labs API: Error: read ECONNRESET |
@twbs-savage Retry |
Tests failed. Automated cross-browser testing via Sauce Labs and Travis CI shows that the JavaScript changes in this pull request are: BUSTED Commit: 388064a (Please note that this is a fully automated comment.) |
@cvrebert thanks for the retry, is there a way to get more details than: 13972015-01-05 15:53:17:344 - info: [IOS_SYSLOG_ROW ] Jan 5 07:53:17 itako36176 assertiond[631]: assertion failed: 13F34 12B411: assertiond + 11523 [3F572A0B-7E12-378D-AFEE-EA491BAF2C36]: 0x1 is there a way to extract which assert failed? Thank you very much, I'm sorry if I'm being a burden |
Should be in the screencast on https://saucelabs.com/jobs/fe963a60d91d48a999a3a8e750010755 |
@cvrebert the error seems to come from affix.js, possibly from my bad merge? |
Ah, that might be because this PR is against an older version of |
Superseded by #15494, which is just a rebased version of this PR. |
The getPosition function was simplified with a new function, getViewportBounds, was added to specifically tackle the cases where we’re looking for the viewport bounds. 'absolute' and 'fixed' tooltips are now matched against the screen where other ones are made to fit inside the viewport element. Fixes #14195 Closes #14226
The getPosition function was simplified with a new function,
getViewportBounds, was added to specifically
tackle the cases where we’re looking for the viewport bounds.
‘absolute’ and ‘fixed’ tooltips are now matched against the screen
where other ones are made to fit inside the viewport element.