vendor: 5,152 bytes, lines 1-175
1/* ======================================================================== 2 * Bootstrap: tooltip.js v3.3.4 3 * http://getbootstrap.com/javascript/#tooltip 4 * Inspired by the original jQuery.tipsy by Jason Frame 5 * ======================================================================== 6 * Copyright 2011-2015 Twitter, Inc. 7 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 8 * ======================================================================== 9 Sta in myboot/bootstrap/js/ 10 */ 11 12 13+function ($) { 14 'use strict'; 15 16 // TOOLTIP PUBLIC CLASS DEFINITION 17 // =============================== 18 19 var Tooltip = function (element, options) { 20 this.type = null 21 this.options = null 22 this.enabled = null 23 this.timeout = null 24 this.hoverState = null 25 this.$element = null 26 27 this.init('tooltip', element, options) 28 } 29 30 Tooltip.VERSION = '3.3.4' 31 32 Tooltip.TRANSITION_DURATION = 150 33 34 Tooltip.DEFAULTS = { 35 animation: true, 36 placement: 'top', 37 selector: false, 38 template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>', 39 trigger: 'hover focus', 40 title: '', 41 delay: 0, 42 html: false, 43 container: false, 44 viewport: { 45 selector: 'body', 46 padding: 0 47 } 48 } 49 50 Tooltip.prototype.init = function (type, element, options) { 51 this.enabled = true 52 this.type = type 53 this.$element = $(element) 54 this.options = this.getOptions(options) 55 this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport) 56 57 if (this.$element[0] instanceof document.constructor && !this.options.selector) { 58 throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!') 59 } 60 61 var triggers = this.options.trigger.split(' ') 62 63 for (var i = triggers.length; i--;) { 64 var trigger = triggers[i] 65 66 if (trigger == 'click') { 67 this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) 68 } else if (trigger != 'manual') { 69 var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin' 70 var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout' 71 72 this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) 73 this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) 74 } 75 } 76 77 this.options.selector ? 78 (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : 79 this.fixTitle() 80 } 81 82 Tooltip.prototype.getDefaults = function () { 83 return Tooltip.DEFAULTS 84 } 85 86 Tooltip.prototype.getOptions = function (options) { 87 options = $.extend({}, this.getDefaults(), this.$element.data(), options) 88 89 if (options.delay && typeof options.delay == 'number') { 90 options.delay = { 91 show: options.delay, 92 hide: options.delay 93 } 94 } 95 96 return options 97 } 98 99 Tooltip.prototype.getDelegateOptions = function () { 100 var options = {} 101 var defaults = this.getDefaults() 102 103 this._options && $.each(this._options, function (key, value) { 104 if (defaults[key] != value) options[key] = value 105 }) 106 107 return options 108 } 109 110 Tooltip.prototype.enter = function (obj) { 111 var self = obj instanceof this.constructor ? 112 obj : $(obj.currentTarget).data('bs.' + this.type) 113 114 if (self && self.$tip && self.$tip.is(':visible')) { 115 self.hoverState = 'in' 116 return 117 } 118 119 // MY EDIT 120 if (self && self.options.trigger.indexOf('hover') != -1 && $(window).width() < 780) { 121 // Block tooltip 122 return; 123 } 124 125 if (!self) { 126 self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) 127 $(obj.currentTarget).data('bs.' + this.type, self) 128 } 129 130 clearTimeout(self.timeout) 131 132 self.hoverState = 'in' 133 134 if (!self.options.delay || !self.options.delay.show) return self.show() 135 136 self.timeout = setTimeout(function () { 137 if (self.hoverState == 'in') self.show() 138 }, self.options.delay.show) 139 } 140 141 Tooltip.prototype.leave = function (obj) { 142 var self = obj instanceof this.constructor ? 143 obj : $(obj.currentTarget).data('bs.' + this.type) 144 145 if (!self) { 146 self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) 147 $(obj.currentTarget).data('bs.' + this.type, self) 148 } 149 150 clearTimeout(self.timeout) 151 152 self.hoverState = 'out' 153 154 if (!self.options.delay || !self.options.delay.hide) return self.hide() 155 156 self.timeout = setTimeout(function () { 157 if (self.hoverState == 'out') self.hide() 158 }, self.options.delay.hide) 159 } 160 161 Tooltip.prototype.show = function () { 162 var e = $.Event('show.bs.' + this.type) 163 164 if (this.hasContent() && this.enabled) { 165 this.$element.trigger(e) 166 167 var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0]) 168 if (e.isDefaultPrevented() || !inDom) return 169 var that = this 170 171 var $tip = this.tip() 172 173 var tipId = this.getUID(this.type) 174 175 this.setContent()
vendor: 7,715 bytes, lines 176-381
176 $tip.attr('id', tipId) 177 this.$element.attr('aria-describedby', tipId) 178 179 if (this.options.animation) $tip.addClass('fade') 180 181 var placement = typeof this.options.placement == 'function' ? 182 this.options.placement.call(this, $tip[0], this.$element[0]) : 183 this.options.placement 184 185 var autoToken = /\s?auto?\s?/i 186 var autoPlace = autoToken.test(placement) 187 if (autoPlace) placement = placement.replace(autoToken, '') || 'top' 188 189 $tip 190 .detach() 191 .css({ top: 0, left: 0, display: 'block' }) 192 .addClass(placement) 193 .data('bs.' + this.type, this) 194 195 this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) 196 197 var pos = this.getPosition() 198 var actualWidth = $tip[0].offsetWidth 199 var actualHeight = $tip[0].offsetHeight 200 201 if (autoPlace) { 202 var orgPlacement = placement 203 var $container = this.options.container ? $(this.options.container) : this.$element.parent() 204 var containerDim = this.getPosition($container) 205 206 placement = placement == 'bottom' && pos.bottom + actualHeight > containerDim.bottom ? 'top' : 207 placement == 'top' && pos.top - actualHeight < containerDim.top ? 'bottom' : 208 placement == 'right' && pos.right + actualWidth > containerDim.width ? 'left' : 209 placement == 'left' && pos.left - actualWidth < containerDim.left ? 'right' : 210 placement 211 212 $tip 213 .removeClass(orgPlacement) 214 .addClass(placement) 215 } 216 217 var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) 218 219 this.applyPlacement(calculatedOffset, placement) 220 221 var complete = function () { 222 var prevHoverState = that.hoverState 223 that.$element.trigger('shown.bs.' + that.type) 224 that.hoverState = null 225 226 if (prevHoverState == 'out') that.leave(that) 227 } 228 229 $.support.transition && this.$tip.hasClass('fade') ? 230 $tip 231 .one('bsTransitionEnd', complete) 232 .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : 233 complete() 234 } 235 } 236 237 Tooltip.prototype.applyPlacement = function (offset, placement) { 238 var $tip = this.tip() 239 var width = $tip[0].offsetWidth 240 var height = $tip[0].offsetHeight 241 242 // manually read margins because getBoundingClientRect includes difference 243 var marginTop = parseInt($tip.css('margin-top'), 10) 244 var marginLeft = parseInt($tip.css('margin-left'), 10) 245 246 // we must check for NaN for ie 8/9 247 if (isNaN(marginTop)) marginTop = 0 248 if (isNaN(marginLeft)) marginLeft = 0 249 250 offset.top = offset.top + marginTop 251 offset.left = offset.left + marginLeft 252 253 // $.fn.offset doesn't round pixel values 254 // so we use setOffset directly with our own function B-0 255 $.offset.setOffset($tip[0], $.extend({ 256 using: function (props) { 257 $tip.css({ 258 top: Math.round(props.top), 259 left: Math.round(props.left) 260 }) 261 } 262 }, offset), 0) 263 264 $tip.addClass('in') 265 266 // check to see if placing tip in new offset caused the tip to resize itself 267 var actualWidth = $tip[0].offsetWidth 268 var actualHeight = $tip[0].offsetHeight 269 270 if (placement == 'top' && actualHeight != height) { 271 offset.top = offset.top + height - actualHeight 272 } 273 274 var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight) 275 276 if (delta.left) offset.left += delta.left 277 else offset.top += delta.top 278 279 var isVertical = /top|bottom/.test(placement) 280 var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight 281 var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight' 282 283 $tip.offset(offset) 284 this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical) 285 } 286 287 Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) { 288 this.arrow() 289 .css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%') 290 .css(isVertical ? 'top' : 'left', '') 291 } 292 293 Tooltip.prototype.setContent = function () { 294 var $tip = this.tip() 295 var title = this.getTitle() 296 297 $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) 298 $tip.removeClass('fade in top bottom left right') 299 } 300 301 Tooltip.prototype.hide = function (callback) { 302 var that = this 303 var $tip = $(this.$tip) 304 var e = $.Event('hide.bs.' + this.type) 305 306 function complete() { 307 if (that.hoverState != 'in') $tip.detach() 308 that.$element 309 .removeAttr('aria-describedby') 310 .trigger('hidden.bs.' + that.type) 311 callback && callback() 312 } 313 314 this.$element.trigger(e) 315 316 if (e.isDefaultPrevented()) return 317 318 $tip.removeClass('in') 319 320 $.support.transition && $tip.hasClass('fade') ? 321 $tip 322 .one('bsTransitionEnd', complete) 323 .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) : 324 complete() 325 326 this.hoverState = null 327 328 return this 329 } 330 331 Tooltip.prototype.fixTitle = function () { 332 var $e = this.$element 333 if ($e.attr('title') || typeof ($e.attr('data-original-title')) != 'string') { 334 $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') 335 } 336 } 337 338 Tooltip.prototype.hasContent = function () { 339 return this.getTitle() 340 } 341 342 Tooltip.prototype.getPosition = function ($element) { 343 $element = $element || this.$element 344 345 var el = $element[0] 346 var isBody = el.tagName == 'BODY' 347 348 var elRect = el.getBoundingClientRect() 349 if (elRect.width == null) { 350 // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093 351 elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top }) 352 } 353 var elOffset = isBody ? { top: 0, left: 0 } : $element.offset() 354 var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() } 355 var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null 356 357 return $.extend({}, elRect, scroll, outerDims, elOffset) 358 } 359 360 Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { 361 return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : 362 placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : 363 placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : 364 /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } 365 366 } 367 368 Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) { 369 var delta = { top: 0, left: 0 } 370 if (!this.$viewport) return delta 371 372 var viewportPadding = this.options.viewport && this.options.viewport.padding || 0 373 var viewportDimensions = this.getPosition(this.$viewport) 374 375 if (/right|left/.test(placement)) { 376 var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll 377 var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight 378 if (topEdgeOffset < viewportDimensions.top) { // top overflow 379 delta.top = viewportDimensions.top - topEdgeOffset 380 } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow 381 delta.top = viewportDimensions.top + viewportDimensions.height - bottom
vendor: 2,662 bytes, lines 381-484
381EdgeOffset 382 } 383 } else { 384 var leftEdgeOffset = pos.left - viewportPadding 385 var rightEdgeOffset = pos.left + viewportPadding + actualWidth 386 if (leftEdgeOffset < viewportDimensions.left) { // left overflow 387 delta.left = viewportDimensions.left - leftEdgeOffset 388 } else if (rightEdgeOffset > viewportDimensions.width) { // right overflow 389 delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset 390 } 391 } 392 393 return delta 394 } 395 396 Tooltip.prototype.getTitle = function () { 397 var title 398 var $e = this.$element 399 var o = this.options 400 401 title = $e.attr('data-original-title') 402 || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) 403 404 return title 405 } 406 407 Tooltip.prototype.getUID = function (prefix) { 408 do prefix += ~~(Math.random() * 1000000) 409 while (document.getElementById(prefix)) 410 return prefix 411 } 412 413 Tooltip.prototype.tip = function () { 414 return (this.$tip = this.$tip || $(this.options.template)) 415 } 416 417 Tooltip.prototype.arrow = function () { 418 return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')) 419 } 420 421 Tooltip.prototype.enable = function () { 422 this.enabled = true 423 } 424 425 Tooltip.prototype.disable = function () { 426 this.enabled = false 427 } 428 429 Tooltip.prototype.toggleEnabled = function () { 430 this.enabled = !this.enabled 431 } 432 433 Tooltip.prototype.toggle = function (e) { 434 var self = this 435 if (e) { 436 self = $(e.currentTarget).data('bs.' + this.type) 437 if (!self) { 438 self = new this.constructor(e.currentTarget, this.getDelegateOptions()) 439 $(e.currentTarget).data('bs.' + this.type, self) 440 } 441 } 442 443 self.tip().hasClass('in') ? self.leave(self) : self.enter(self) 444 } 445 446 Tooltip.prototype.destroy = function () { 447 var that = this 448 clearTimeout(this.timeout) 449 this.hide(function () { 450 that.$element.off('.' + that.type).removeData('bs.' + that.type) 451 }) 452 } 453 454 455 // TOOLTIP PLUGIN DEFINITION 456 // ========================= 457 458 function Plugin(option) { 459 return this.each(function () { 460 var $this = $(this) 461 var data = $this.data('bs.tooltip') 462 var options = typeof option == 'object' && option 463 464 if (!data && /destroy|hide/.test(option)) return 465 if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) 466 if (typeof option == 'string') data[option]() 467 }) 468 } 469 470 var old = $.fn.tooltip 471 472 $.fn.tooltip = Plugin 473 $.fn.tooltip.Constructor = Tooltip 474 475 476 // TOOLTIP NO CONFLICT 477 // =================== 478 479 $.fn.tooltip.noConflict = function () { 480 $.fn.tooltip = old 481 return this 482 } 483 484}(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.