0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-21 18:54:30 +01:00

clean up styles

This commit is contained in:
fat 2013-02-05 22:29:59 -08:00
parent 5e4db94c24
commit 4814281540
9 changed files with 151 additions and 101 deletions

View File

@ -5290,7 +5290,6 @@ input[type="submit"].btn.btn-mini {
position: absolute; position: absolute;
z-index: 1030; z-index: 1030;
display: block; display: block;
padding: 5px;
font-size: 11px; font-size: 11px;
line-height: 1.4; line-height: 1.4;
opacity: 0; opacity: 0;
@ -5304,18 +5303,22 @@ input[type="submit"].btn.btn-mini {
} }
.tooltip.top { .tooltip.top {
padding: 5px 0;
margin-top: -3px; margin-top: -3px;
} }
.tooltip.right { .tooltip.right {
padding: 0 5px;
margin-left: 3px; margin-left: 3px;
} }
.tooltip.bottom { .tooltip.bottom {
padding: 5px 0;
margin-top: 3px; margin-top: 3px;
} }
.tooltip.left { .tooltip.left {
padding: 0 5px;
margin-left: -3px; margin-left: -3px;
} }

View File

@ -152,13 +152,56 @@
break break
} }
this.applyPlacement(tp, placement)
this.$element.trigger('shown')
}
}
, applyPlacement: function(offset, placement){
var $tip = this.tip()
, width = $tip[0].offsetWidth
, height = $tip[0].offsetHeight
, actualWidth
, actualHeight
, delta
, replace
$tip $tip
.offset(tp) .offset(offset)
.addClass(placement) .addClass(placement)
.addClass('in') .addClass('in')
this.$element.trigger('shown') actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight
if (placement == 'top' && actualHeight != height) {
offset.top = offset.top + height - actualHeight
replace = true
} }
if (placement == 'bottom' || placement == 'top') {
delta = 0
if (offset.left < 0){
delta = offset.left * -2
offset.left = 0
$tip.offset(offset)
actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight
}
this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
} else {
this.replaceArrow(actualHeight - height, actualHeight, 'top')
}
if (replace) $tip.offset(offset)
}
, replaceArrow: function(delta, dimension, position){
this
.arrow()
.css(position, delta ? (50 * (1 - delta / dimension) + "%") : '')
} }
, setContent: function () { , setContent: function () {
@ -233,6 +276,10 @@
return this.$tip = this.$tip || $(this.options.template) return this.$tip = this.$tip || $(this.options.template)
} }
, arrow: function(){
return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow")
}
, validate: function () { , validate: function () {
if (!this.$element[0].parentNode) { if (!this.$element[0].parentNode) {
this.hide() this.hide()

View File

@ -1194,13 +1194,56 @@
break break
} }
this.applyPlacement(tp, placement)
this.$element.trigger('shown')
}
}
, applyPlacement: function(offset, placement){
var $tip = this.tip()
, width = $tip[0].offsetWidth
, height = $tip[0].offsetHeight
, actualWidth
, actualHeight
, delta
, replace
$tip $tip
.offset(tp) .offset(offset)
.addClass(placement) .addClass(placement)
.addClass('in') .addClass('in')
this.$element.trigger('shown') actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight
if (placement == 'top' && actualHeight != height) {
offset.top = offset.top + height - actualHeight
replace = true
} }
if (placement == 'bottom' || placement == 'top') {
delta = 0
if (offset.left < 0){
delta = offset.left * -2
offset.left = 0
$tip.offset(offset)
actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight
}
this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
} else {
this.replaceArrow(actualHeight - height, actualHeight, 'top')
}
if (replace) $tip.offset(offset)
}
, replaceArrow: function(delta, dimension, position){
this
.arrow()
.css(position, delta ? (50 * (1 - delta / dimension) + "%") : '')
} }
, setContent: function () { , setContent: function () {
@ -1275,6 +1318,10 @@
return this.$tip = this.$tip || $(this.options.template) return this.$tip = this.$tip || $(this.options.template)
} }
, arrow: function(){
return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow")
}
, validate: function () { , validate: function () {
if (!this.$element[0].parentNode) { if (!this.$element[0].parentNode) {
this.hide() this.hide()

File diff suppressed because one or more lines are too long

View File

@ -153,24 +153,18 @@
} }
this.applyPlacement(tp, placement) this.applyPlacement(tp, placement)
this.$element.trigger('shown') this.$element.trigger('shown')
} }
} }
, applyPlacement: function(offset, placement){ , applyPlacement: function(offset, placement){
var $tip var $tip = this.tip()
, width , width = $tip[0].offsetWidth
, height , height = $tip[0].offsetHeight
, actualWidth , actualWidth
, actualHeight , actualHeight
, delta , delta
, replace = false , replace
$tip = this.tip()
width = $tip[0].offsetWidth
height = $tip[0].offsetHeight
$tip $tip
.offset(offset) .offset(offset)
@ -180,38 +174,34 @@
actualWidth = $tip[0].offsetWidth actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight actualHeight = $tip[0].offsetHeight
if (placement == "top" && actualHeight != height){ if (placement == 'top' && actualHeight != height) {
offset.top = offset.top + height - actualHeight offset.top = offset.top + height - actualHeight
replace = true replace = true
} }
if (placement == "bottom" || placement == "top"){ if (placement == 'bottom' || placement == 'top') {
delta = 0 delta = 0
if (offset.left < 0){ if (offset.left < 0){
delta = -offset.left * 2 delta = offset.left * -2
offset.left = 0 offset.left = 0
$tip.offset(offset) $tip.offset(offset)
actualWidth = $tip[0].offsetWidth actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight actualHeight = $tip[0].offsetHeight
} }
this.replaceArrow(delta - width + actualWidth, actualWidth, "left") this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
} else { } else {
this.replaceArrow(actualHeight - height, actualHeight, "top") this.replaceArrow(actualHeight - height, actualHeight, 'top')
} }
if (replace) $tip.offset(offset) if (replace) $tip.offset(offset)
} }
, replaceArrow: function(delta, dimension, position){ , replaceArrow: function(delta, dimension, position){
var $arrow = this.arrow() this
.arrow()
if (delta !== 0){ .css(position, delta ? (50 * (1 - delta / dimension) + "%") : '')
$arrow.css(position, 50 * (1 - delta / dimension) + "%")
}else{
$arrow.css(position, "")
}
} }
, setContent: function () { , setContent: function () {

View File

@ -29,9 +29,6 @@
<script src="../../js/bootstrap-typeahead.js"></script> <script src="../../js/bootstrap-typeahead.js"></script>
<script src="../../js/bootstrap-affix.js"></script> <script src="../../js/bootstrap-affix.js"></script>
<!-- Needed for testing -->
<link rel="stylesheet" type="text/css" href="unit/bootstrap-tooltip.css" />
<!-- unit tests --> <!-- unit tests -->
<script src="unit/bootstrap-transition.js"></script> <script src="unit/bootstrap-transition.js"></script>
<script src="unit/bootstrap-alert.js"></script> <script src="unit/bootstrap-alert.js"></script>

View File

@ -1,13 +0,0 @@
.tooltip{
position: absolute;
}
.tooltip-inner{
max-width: 200px;
}
.tooltip.top .tooltip-arrow{
position: absolute;
}

View File

@ -291,25 +291,4 @@ $(function () {
container.remove() container.remove()
}, 100) }, 100)
}) })
test("arrow should point to element", function(){
var container = $("<div />").appendTo("body")
.css({position: "absolute", bottom: 0, left: 0, textAlign: "right", width: 300, height: 300})
, p = $("<p style='margin-top:200px' />").appendTo(container)
, tooltiped = $("<a href='#' title='very very very very very very very long tooltip'>Hover me</a>")
.css({marginTop: 200})
.appendTo(p)
.tooltip({placement: "top", animate: false})
.tooltip("show")
stop()
setTimeout(function(){
var arrow = container.find(".tooltip-arrow")
start()
ok(Math.abs(arrow.offset().left - tooltiped.offset().left - tooltiped.outerWidth()/2) <= 1)
container.remove()
}, 100)
})
}) })