Skip to content

Commit 2ae8520

Browse files
committed
Updated bootstrap-tooltip.js from 2.2.2 to 2.3.2
1 parent af430f1 commit 2ae8520

File tree

2 files changed

+105
-32
lines changed

2 files changed

+105
-32
lines changed

core/src/main/resources/org/apache/spark/ui/static/bootstrap-tooltip.js

Lines changed: 104 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* ===========================================================
2-
* bootstrap-tooltip.js v2.2.2
3-
* http://twitter.github.com/bootstrap/javascript.html#tooltips
2+
* bootstrap-tooltip.js v2.3.2
3+
* http://getbootstrap.com/2.3.2/javascript.html#tooltips
44
* Inspired by the original jQuery.tipsy by Jason Frame
55
* ===========================================================
6-
* Copyright 2012 Twitter, Inc.
6+
* Copyright 2013 Twitter, Inc.
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
99
* you may not use this file except in compliance with the License.
@@ -38,19 +38,27 @@
3838
, init: function (type, element, options) {
3939
var eventIn
4040
, eventOut
41+
, triggers
42+
, trigger
43+
, i
4144

4245
this.type = type
4346
this.$element = $(element)
4447
this.options = this.getOptions(options)
4548
this.enabled = true
4649

47-
if (this.options.trigger == 'click') {
48-
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
49-
} else if (this.options.trigger != 'manual') {
50-
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
51-
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
52-
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
53-
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
50+
triggers = this.options.trigger.split(' ')
51+
52+
for (i = triggers.length; i--;) {
53+
trigger = triggers[i]
54+
if (trigger == 'click') {
55+
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
56+
} else if (trigger != 'manual') {
57+
eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
58+
eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
59+
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
60+
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
61+
}
5462
}
5563

5664
this.options.selector ?
@@ -59,7 +67,7 @@
5967
}
6068

6169
, getOptions: function (options) {
62-
options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
70+
options = $.extend({}, $.fn[this.type].defaults, this.$element.data(), options)
6371

6472
if (options.delay && typeof options.delay == 'number') {
6573
options.delay = {
@@ -72,7 +80,15 @@
7280
}
7381

7482
, enter: function (e) {
75-
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
83+
var defaults = $.fn[this.type].defaults
84+
, options = {}
85+
, self
86+
87+
this._options && $.each(this._options, function (key, value) {
88+
if (defaults[key] != value) options[key] = value
89+
}, this)
90+
91+
self = $(e.currentTarget)[this.type](options).data(this.type)
7692

7793
if (!self.options.delay || !self.options.delay.show) return self.show()
7894

@@ -97,14 +113,16 @@
97113

98114
, show: function () {
99115
var $tip
100-
, inside
101116
, pos
102117
, actualWidth
103118
, actualHeight
104119
, placement
105120
, tp
121+
, e = $.Event('show')
106122

107123
if (this.hasContent() && this.enabled) {
124+
this.$element.trigger(e)
125+
if (e.isDefaultPrevented()) return
108126
$tip = this.tip()
109127
this.setContent()
110128

@@ -116,19 +134,18 @@
116134
this.options.placement.call(this, $tip[0], this.$element[0]) :
117135
this.options.placement
118136

119-
inside = /in/.test(placement)
120-
121137
$tip
122138
.detach()
123139
.css({ top: 0, left: 0, display: 'block' })
124-
.insertAfter(this.$element)
125140

126-
pos = this.getPosition(inside)
141+
this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
142+
143+
pos = this.getPosition()
127144

128145
actualWidth = $tip[0].offsetWidth
129146
actualHeight = $tip[0].offsetHeight
130147

131-
switch (inside ? placement.split(' ')[1] : placement) {
148+
switch (placement) {
132149
case 'bottom':
133150
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
134151
break
@@ -143,11 +160,56 @@
143160
break
144161
}
145162

146-
$tip
147-
.offset(tp)
148-
.addClass(placement)
149-
.addClass('in')
163+
this.applyPlacement(tp, placement)
164+
this.$element.trigger('shown')
165+
}
166+
}
167+
168+
, applyPlacement: function(offset, placement){
169+
var $tip = this.tip()
170+
, width = $tip[0].offsetWidth
171+
, height = $tip[0].offsetHeight
172+
, actualWidth
173+
, actualHeight
174+
, delta
175+
, replace
176+
177+
$tip
178+
.offset(offset)
179+
.addClass(placement)
180+
.addClass('in')
181+
182+
actualWidth = $tip[0].offsetWidth
183+
actualHeight = $tip[0].offsetHeight
184+
185+
if (placement == 'top' && actualHeight != height) {
186+
offset.top = offset.top + height - actualHeight
187+
replace = true
188+
}
189+
190+
if (placement == 'bottom' || placement == 'top') {
191+
delta = 0
192+
193+
if (offset.left < 0){
194+
delta = offset.left * -2
195+
offset.left = 0
196+
$tip.offset(offset)
197+
actualWidth = $tip[0].offsetWidth
198+
actualHeight = $tip[0].offsetHeight
199+
}
200+
201+
this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
202+
} else {
203+
this.replaceArrow(actualHeight - height, actualHeight, 'top')
150204
}
205+
206+
if (replace) $tip.offset(offset)
207+
}
208+
209+
, replaceArrow: function(delta, dimension, position){
210+
this
211+
.arrow()
212+
.css(position, delta ? (50 * (1 - delta / dimension) + "%") : '')
151213
}
152214

153215
, setContent: function () {
@@ -161,6 +223,10 @@
161223
, hide: function () {
162224
var that = this
163225
, $tip = this.tip()
226+
, e = $.Event('hide')
227+
228+
this.$element.trigger(e)
229+
if (e.isDefaultPrevented()) return
164230

165231
$tip.removeClass('in')
166232

@@ -179,6 +245,8 @@
179245
removeWithAnimation() :
180246
$tip.detach()
181247

248+
this.$element.trigger('hidden')
249+
182250
return this
183251
}
184252

@@ -193,11 +261,12 @@
193261
return this.getTitle()
194262
}
195263

196-
, getPosition: function (inside) {
197-
return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
198-
width: this.$element[0].offsetWidth
199-
, height: this.$element[0].offsetHeight
200-
})
264+
, getPosition: function () {
265+
var el = this.$element[0]
266+
return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : {
267+
width: el.offsetWidth
268+
, height: el.offsetHeight
269+
}, this.$element.offset())
201270
}
202271

203272
, getTitle: function () {
@@ -215,6 +284,10 @@
215284
return this.$tip = this.$tip || $(this.options.template)
216285
}
217286

287+
, arrow: function(){
288+
return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow")
289+
}
290+
218291
, validate: function () {
219292
if (!this.$element[0].parentNode) {
220293
this.hide()
@@ -236,8 +309,8 @@
236309
}
237310

238311
, toggle: function (e) {
239-
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
240-
self[self.tip().hasClass('in') ? 'hide' : 'show']()
312+
var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this
313+
self.tip().hasClass('in') ? self.hide() : self.show()
241314
}
242315

243316
, destroy: function () {
@@ -269,10 +342,11 @@
269342
, placement: 'top'
270343
, selector: false
271344
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
272-
, trigger: 'hover'
345+
, trigger: 'hover focus'
273346
, title: ''
274347
, delay: 0
275348
, html: false
349+
, container: false
276350
}
277351

278352

@@ -285,4 +359,3 @@
285359
}
286360

287361
}(window.jQuery);
288-

core/src/main/scala/org/apache/spark/ui/jobs/StagePage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ private[ui] class StagePage(parent: StagesTab) extends WebUIPage("stage") {
573573
| 'className': 'task task-assignment-timeline-object ${classNameByStatus}',
574574
| 'group': '${executorId}',
575575
| 'content': '<div class="task-assignment-timeline-content"' +
576-
| 'data-toggle="tooltip" data-placement="right" data-html="true"' +
576+
| 'data-toggle="tooltip" data-placement="right" data-html="true" data-container="body"' +
577577
| 'data-title="${taskIdWithIndexAndAttempt}<br>Status: ${taskInfo.status}<br>' +
578578
| 'Launch Time: ${UIUtils.formatDate(new Date(launchTime))}' +
579579
| '${

0 commit comments

Comments
 (0)