Skip to content
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

Add tooltip viewport option, respect bounds of the viewport #12328

Merged
merged 1 commit into from
Mar 23, 2014

Conversation

benogle
Copy link
Contributor

@benogle benogle commented Jan 21, 2014

Currently tooltips do not respect their container. eg. I have a button jammed up against the right side of the page, and place a tooltip on the top, it will stick out of the page.

So I added two new options:

  • viewport: defaults to 'body'. It's the selector the tip should stay inside.
  • viewport: padding: how far, in px should it stay from the edges

With changes from the original at #11593. The tests pass for me in firefox.

@fat: What was the new offset method you mentioned in the other pull?

@cvrebert
Copy link
Collaborator

@benogle The tests are failing on Windows browsers: https://travis-ci.org/twbs/bootstrap/builds/17360227

@benogle
Copy link
Contributor Author

benogle commented Jan 22, 2014

Is there a way to figure out which test actually failed?

@benogle
Copy link
Contributor Author

benogle commented Jan 22, 2014

I get that I can see this, but there's no info on what test actually was the failing one

@cvrebert
Copy link
Collaborator

Yeah, there's not yet an easy way to get more fine-grained test result info from the automated tests. The Sauce guys are working on improving that. For now, you're gonna have to test it manually by opening /js/tests/index.html in a browser.

@benogle
Copy link
Contributor Author

benogle commented Jan 22, 2014

Right... I'm installing a windows VM.

@benogle
Copy link
Contributor Author

benogle commented Jan 22, 2014

Also some notes:

The linter fails

Running "csslint:src" (csslint) task
Linting dist/css/bootstrap.css ...ERROR
[L5678:C1]
>> Unknown @ rule: @-ms-viewport. This rule looks for recoverable syntax errors. (errors)
Warning: Task "csslint:src" failed. Use --force to continue.

Aborted due to warnings.

And when I --force it, it adds the build dir and the concat'd css file, but these things are not in the .gitignore. Should they be?

@cvrebert
Copy link
Collaborator

@benogle Be sure that your copy of csslint is up-to-date. I can't repro that error with [email protected] and [email protected].

/dist/ and its contents are intended to be in git. But don't bother including *.min.* or *.map files in your pull request; that'd only complicate things.

@benogle
Copy link
Contributor Author

benogle commented Jan 22, 2014

Ok, tests pass, and in one commit.

@cvrebert
Copy link
Collaborator

Sauce and BrowserStack tests do indeed pass: https://travis-ci.org/twbs/bootstrap/builds/17381593

@@ -42,6 +46,7 @@
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.$viewport = this.options.viewport.selector ? $(this.options.viewport.selector) : $(this.options.viewport)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you check for this.options.viewport first? …

this.options.viewport && this.options.viewport.selector

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this around to support a null viewport if you dont want it to be constrained.

@fat
Copy link
Member

fat commented Mar 17, 2014

@benogle the offset function was for setting setOffset which allows us to swerve sub pixel rendering https://github.com/twbs/bootstrap/blob/master/js/tooltip.js#L213-L222

@fat
Copy link
Member

fat commented Mar 17, 2014

this looks good to me… small nit with the $viewport condition

@benogle
Copy link
Contributor Author

benogle commented Mar 18, 2014

@fat, I've rebased to current master, and addressed the options.viewport issue.

@fat
Copy link
Member

fat commented Mar 21, 2014

rad

@@ -42,6 +46,9 @@
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.$viewport = !this.options.viewport ? null :
this.options.viewport.selector ? $(this.options.viewport.selector) :
$(this.options.viewport)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll want to line all the = signs up above this declaration. also you can clean up this ternary

this.$element  = $(element)
this.options   = this.getOptions(options)
this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport) 

var viewportDimensions = this.getPosition(this.$viewport)

if (/right|left/.test(placement)) {
var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offsets for all edges for clarity.

@benogle
Copy link
Contributor Author

benogle commented Mar 21, 2014

Alright, alignment and cleanup finished.

@cvrebert
Copy link
Collaborator

Passes Sauce browser tests: https://travis-ci.org/twbs/bootstrap/jobs/21276179

@fat
Copy link
Member

fat commented Mar 23, 2014

lgtm to me – thanks @benogle 💪

@cvrebert
Copy link
Collaborator

@fat So, merge this?

mdo added a commit that referenced this pull request Mar 23, 2014
Add tooltip `viewport` option, respect bounds of the viewport
@mdo mdo merged commit 2b27006 into twbs:master Mar 23, 2014
@mdo
Copy link
Member

mdo commented Mar 23, 2014

😍

@mdo mdo mentioned this pull request Mar 23, 2014
@benogle
Copy link
Contributor Author

benogle commented Mar 24, 2014

🎉

@mdo
Copy link
Member

mdo commented Mar 25, 2014

〽️

@michahell
Copy link

To me it's unclear how to use the viewport property using data attributes. or is it not at all possible ?
for example, is it: data-viewport-selector or data-viewport="{selector:'body', padding: 0}" ?

@julkue
Copy link

julkue commented Aug 18, 2016

I'd expect this to also work with a DOM object instead of a selector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants