1704 lines
56 KiB
JavaScript
1704 lines
56 KiB
JavaScript
/* ========================================================================
|
|
* bootstrap-tour - v0.12.0
|
|
* http://bootstraptour.com
|
|
* ========================================================================
|
|
* Copyright 2012-2015 Ulrich Sossou
|
|
*
|
|
* ========================================================================
|
|
* Licensed under the MIT License (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* https://opensource.org/licenses/MIT
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* ========================================================================
|
|
*/
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: transition.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#transitions
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
|
|
// ============================================================
|
|
|
|
function transitionEnd() {
|
|
var el = document.createElement('bootstrap')
|
|
|
|
var transEndEventNames = {
|
|
WebkitTransition : 'webkitTransitionEnd',
|
|
MozTransition : 'transitionend',
|
|
OTransition : 'oTransitionEnd otransitionend',
|
|
transition : 'transitionend'
|
|
}
|
|
|
|
for (var name in transEndEventNames) {
|
|
if (el.style[name] !== undefined) {
|
|
return { end: transEndEventNames[name] }
|
|
}
|
|
}
|
|
|
|
return false // explicit for ie8 ( ._.)
|
|
}
|
|
|
|
// http://blog.alexmaccaw.com/css-transitions
|
|
$.fn.emulateTransitionEnd = function (duration) {
|
|
var called = false
|
|
var $el = this
|
|
$(this).one('bsTransitionEnd', function () { called = true })
|
|
var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
|
|
setTimeout(callback, duration)
|
|
return this
|
|
}
|
|
|
|
$(function () {
|
|
$.support.transition = transitionEnd()
|
|
|
|
if (!$.support.transition) return
|
|
|
|
$.event.special.bsTransitionEnd = {
|
|
bindType: $.support.transition.end,
|
|
delegateType: $.support.transition.end,
|
|
handle: function (e) {
|
|
if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments)
|
|
}
|
|
}
|
|
})
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: tooltip.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#tooltip
|
|
* Inspired by the original jQuery.tipsy by Jason Frame
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// TOOLTIP PUBLIC CLASS DEFINITION
|
|
// ===============================
|
|
|
|
var Tooltip = function (element, options) {
|
|
this.type = null
|
|
this.options = null
|
|
this.enabled = null
|
|
this.timeout = null
|
|
this.hoverState = null
|
|
this.$element = null
|
|
this.inState = null
|
|
|
|
this.init('tooltip', element, options)
|
|
}
|
|
|
|
Tooltip.VERSION = '3.3.7'
|
|
|
|
Tooltip.TRANSITION_DURATION = 150
|
|
|
|
Tooltip.DEFAULTS = {
|
|
animation: true,
|
|
placement: 'top',
|
|
selector: false,
|
|
template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
|
|
trigger: 'hover focus',
|
|
title: '',
|
|
delay: 0,
|
|
html: false,
|
|
container: false,
|
|
viewport: {
|
|
selector: 'body',
|
|
padding: 0
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.init = function (type, element, options) {
|
|
this.enabled = true
|
|
this.type = type
|
|
this.$element = $(element)
|
|
this.options = this.getOptions(options)
|
|
this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport))
|
|
this.inState = { click: false, hover: false, focus: false }
|
|
|
|
if (this.$element[0] instanceof document.constructor && !this.options.selector) {
|
|
throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!')
|
|
}
|
|
|
|
var triggers = this.options.trigger.split(' ')
|
|
|
|
for (var i = triggers.length; i--;) {
|
|
var trigger = triggers[i]
|
|
|
|
if (trigger == 'click') {
|
|
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
|
|
} else if (trigger != 'manual') {
|
|
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
|
|
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
|
|
|
|
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
|
|
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
|
|
}
|
|
}
|
|
|
|
this.options.selector ?
|
|
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
|
|
this.fixTitle()
|
|
}
|
|
|
|
Tooltip.prototype.getDefaults = function () {
|
|
return Tooltip.DEFAULTS
|
|
}
|
|
|
|
Tooltip.prototype.getOptions = function (options) {
|
|
options = $.extend({}, this.getDefaults(), this.$element.data(), options)
|
|
|
|
if (options.delay && typeof options.delay == 'number') {
|
|
options.delay = {
|
|
show: options.delay,
|
|
hide: options.delay
|
|
}
|
|
}
|
|
|
|
return options
|
|
}
|
|
|
|
Tooltip.prototype.getDelegateOptions = function () {
|
|
var options = {}
|
|
var defaults = this.getDefaults()
|
|
|
|
this._options && $.each(this._options, function (key, value) {
|
|
if (defaults[key] != value) options[key] = value
|
|
})
|
|
|
|
return options
|
|
}
|
|
|
|
Tooltip.prototype.enter = function (obj) {
|
|
var self = obj instanceof this.constructor ?
|
|
obj : $(obj.currentTarget).data('bs.' + this.type)
|
|
|
|
if (!self) {
|
|
self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
|
|
$(obj.currentTarget).data('bs.' + this.type, self)
|
|
}
|
|
|
|
if (obj instanceof $.Event) {
|
|
self.inState[obj.type == 'focusin' ? 'focus' : 'hover'] = true
|
|
}
|
|
|
|
if (self.tip().hasClass('in') || self.hoverState == 'in') {
|
|
self.hoverState = 'in'
|
|
return
|
|
}
|
|
|
|
clearTimeout(self.timeout)
|
|
|
|
self.hoverState = 'in'
|
|
|
|
if (!self.options.delay || !self.options.delay.show) return self.show()
|
|
|
|
self.timeout = setTimeout(function () {
|
|
if (self.hoverState == 'in') self.show()
|
|
}, self.options.delay.show)
|
|
}
|
|
|
|
Tooltip.prototype.isInStateTrue = function () {
|
|
for (var key in this.inState) {
|
|
if (this.inState[key]) return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
Tooltip.prototype.leave = function (obj) {
|
|
var self = obj instanceof this.constructor ?
|
|
obj : $(obj.currentTarget).data('bs.' + this.type)
|
|
|
|
if (!self) {
|
|
self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
|
|
$(obj.currentTarget).data('bs.' + this.type, self)
|
|
}
|
|
|
|
if (obj instanceof $.Event) {
|
|
self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false
|
|
}
|
|
|
|
if (self.isInStateTrue()) return
|
|
|
|
clearTimeout(self.timeout)
|
|
|
|
self.hoverState = 'out'
|
|
|
|
if (!self.options.delay || !self.options.delay.hide) return self.hide()
|
|
|
|
self.timeout = setTimeout(function () {
|
|
if (self.hoverState == 'out') self.hide()
|
|
}, self.options.delay.hide)
|
|
}
|
|
|
|
Tooltip.prototype.show = function () {
|
|
var e = $.Event('show.bs.' + this.type)
|
|
|
|
if (this.hasContent() && this.enabled) {
|
|
this.$element.trigger(e)
|
|
|
|
var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0])
|
|
if (e.isDefaultPrevented() || !inDom) return
|
|
var that = this
|
|
|
|
var $tip = this.tip()
|
|
|
|
var tipId = this.getUID(this.type)
|
|
|
|
this.setContent()
|
|
$tip.attr('id', tipId)
|
|
this.$element.attr('aria-describedby', tipId)
|
|
|
|
if (this.options.animation) $tip.addClass('fade')
|
|
|
|
var placement = typeof this.options.placement == 'function' ?
|
|
this.options.placement.call(this, $tip[0], this.$element[0]) :
|
|
this.options.placement
|
|
|
|
var autoToken = /\s?auto?\s?/i
|
|
var autoPlace = autoToken.test(placement)
|
|
if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
|
|
|
|
$tip
|
|
.detach()
|
|
.css({ top: 0, left: 0, display: 'block' })
|
|
.addClass(placement)
|
|
.data('bs.' + this.type, this)
|
|
|
|
this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
|
|
this.$element.trigger('inserted.bs.' + this.type)
|
|
|
|
var pos = this.getPosition()
|
|
var actualWidth = $tip[0].offsetWidth
|
|
var actualHeight = $tip[0].offsetHeight
|
|
|
|
if (autoPlace) {
|
|
var orgPlacement = placement
|
|
var viewportDim = this.getPosition(this.$viewport)
|
|
|
|
placement = placement == 'bottom' && pos.bottom + actualHeight > viewportDim.bottom ? 'top' :
|
|
placement == 'top' && pos.top - actualHeight < viewportDim.top ? 'bottom' :
|
|
placement == 'right' && pos.right + actualWidth > viewportDim.width ? 'left' :
|
|
placement == 'left' && pos.left - actualWidth < viewportDim.left ? 'right' :
|
|
placement
|
|
|
|
$tip
|
|
.removeClass(orgPlacement)
|
|
.addClass(placement)
|
|
}
|
|
|
|
var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
|
|
|
|
this.applyPlacement(calculatedOffset, placement)
|
|
|
|
var complete = function () {
|
|
var prevHoverState = that.hoverState
|
|
that.$element.trigger('shown.bs.' + that.type)
|
|
that.hoverState = null
|
|
|
|
if (prevHoverState == 'out') that.leave(that)
|
|
}
|
|
|
|
$.support.transition && this.$tip.hasClass('fade') ?
|
|
$tip
|
|
.one('bsTransitionEnd', complete)
|
|
.emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
|
|
complete()
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.applyPlacement = function (offset, placement) {
|
|
var $tip = this.tip()
|
|
var width = $tip[0].offsetWidth
|
|
var height = $tip[0].offsetHeight
|
|
|
|
// manually read margins because getBoundingClientRect includes difference
|
|
var marginTop = parseInt($tip.css('margin-top'), 10)
|
|
var marginLeft = parseInt($tip.css('margin-left'), 10)
|
|
|
|
// we must check for NaN for ie 8/9
|
|
if (isNaN(marginTop)) marginTop = 0
|
|
if (isNaN(marginLeft)) marginLeft = 0
|
|
|
|
offset.top += marginTop
|
|
offset.left += marginLeft
|
|
|
|
// $.fn.offset doesn't round pixel values
|
|
// so we use setOffset directly with our own function B-0
|
|
$.offset.setOffset($tip[0], $.extend({
|
|
using: function (props) {
|
|
$tip.css({
|
|
top: Math.round(props.top),
|
|
left: Math.round(props.left)
|
|
})
|
|
}
|
|
}, offset), 0)
|
|
|
|
$tip.addClass('in')
|
|
|
|
// check to see if placing tip in new offset caused the tip to resize itself
|
|
var actualWidth = $tip[0].offsetWidth
|
|
var actualHeight = $tip[0].offsetHeight
|
|
|
|
if (placement == 'top' && actualHeight != height) {
|
|
offset.top = offset.top + height - actualHeight
|
|
}
|
|
|
|
var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
|
|
|
|
if (delta.left) offset.left += delta.left
|
|
else offset.top += delta.top
|
|
|
|
var isVertical = /top|bottom/.test(placement)
|
|
var arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
|
|
var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'
|
|
|
|
$tip.offset(offset)
|
|
this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical)
|
|
}
|
|
|
|
Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) {
|
|
this.arrow()
|
|
.css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%')
|
|
.css(isVertical ? 'top' : 'left', '')
|
|
}
|
|
|
|
Tooltip.prototype.setContent = function () {
|
|
var $tip = this.tip()
|
|
var title = this.getTitle()
|
|
|
|
$tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
|
|
$tip.removeClass('fade in top bottom left right')
|
|
}
|
|
|
|
Tooltip.prototype.hide = function (callback) {
|
|
var that = this
|
|
var $tip = $(this.$tip)
|
|
var e = $.Event('hide.bs.' + this.type)
|
|
|
|
function complete() {
|
|
if (that.hoverState != 'in') $tip.detach()
|
|
if (that.$element) { // TODO: Check whether guarding this code with this `if` is really necessary.
|
|
that.$element
|
|
.removeAttr('aria-describedby')
|
|
.trigger('hidden.bs.' + that.type)
|
|
}
|
|
callback && callback()
|
|
}
|
|
|
|
this.$element.trigger(e)
|
|
|
|
if (e.isDefaultPrevented()) return
|
|
|
|
$tip.removeClass('in')
|
|
|
|
$.support.transition && $tip.hasClass('fade') ?
|
|
$tip
|
|
.one('bsTransitionEnd', complete)
|
|
.emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
|
|
complete()
|
|
|
|
this.hoverState = null
|
|
|
|
return this
|
|
}
|
|
|
|
Tooltip.prototype.fixTitle = function () {
|
|
var $e = this.$element
|
|
if ($e.attr('title') || typeof $e.attr('data-original-title') != 'string') {
|
|
$e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.hasContent = function () {
|
|
return this.getTitle()
|
|
}
|
|
|
|
Tooltip.prototype.getPosition = function ($element) {
|
|
$element = $element || this.$element
|
|
|
|
var el = $element[0]
|
|
var isBody = el.tagName == 'BODY'
|
|
|
|
var elRect = el.getBoundingClientRect()
|
|
if (elRect.width == null) {
|
|
// width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093
|
|
elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top })
|
|
}
|
|
var isSvg = window.SVGElement && el instanceof window.SVGElement
|
|
// Avoid using $.offset() on SVGs since it gives incorrect results in jQuery 3.
|
|
// See https://github.com/twbs/bootstrap/issues/20280
|
|
var elOffset = isBody ? { top: 0, left: 0 } : (isSvg ? null : $element.offset())
|
|
var scroll = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() }
|
|
var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null
|
|
|
|
return $.extend({}, elRect, scroll, outerDims, elOffset)
|
|
}
|
|
|
|
Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
|
|
return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } :
|
|
placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
|
|
placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
|
|
/* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
|
|
|
|
}
|
|
|
|
Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) {
|
|
var delta = { top: 0, left: 0 }
|
|
if (!this.$viewport) return delta
|
|
|
|
var viewportPadding = this.options.viewport && this.options.viewport.padding || 0
|
|
var viewportDimensions = this.getPosition(this.$viewport)
|
|
|
|
if (/right|left/.test(placement)) {
|
|
var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll
|
|
var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight
|
|
if (topEdgeOffset < viewportDimensions.top) { // top overflow
|
|
delta.top = viewportDimensions.top - topEdgeOffset
|
|
} else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
|
|
delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset
|
|
}
|
|
} else {
|
|
var leftEdgeOffset = pos.left - viewportPadding
|
|
var rightEdgeOffset = pos.left + viewportPadding + actualWidth
|
|
if (leftEdgeOffset < viewportDimensions.left) { // left overflow
|
|
delta.left = viewportDimensions.left - leftEdgeOffset
|
|
} else if (rightEdgeOffset > viewportDimensions.right) { // right overflow
|
|
delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
|
|
}
|
|
}
|
|
|
|
return delta
|
|
}
|
|
|
|
Tooltip.prototype.getTitle = function () {
|
|
var title
|
|
var $e = this.$element
|
|
var o = this.options
|
|
|
|
title = $e.attr('data-original-title')
|
|
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
|
|
|
|
return title
|
|
}
|
|
|
|
Tooltip.prototype.getUID = function (prefix) {
|
|
do prefix += ~~(Math.random() * 1000000)
|
|
while (document.getElementById(prefix))
|
|
return prefix
|
|
}
|
|
|
|
Tooltip.prototype.tip = function () {
|
|
if (!this.$tip) {
|
|
this.$tip = $(this.options.template)
|
|
if (this.$tip.length != 1) {
|
|
throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!')
|
|
}
|
|
}
|
|
return this.$tip
|
|
}
|
|
|
|
Tooltip.prototype.arrow = function () {
|
|
return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow'))
|
|
}
|
|
|
|
Tooltip.prototype.enable = function () {
|
|
this.enabled = true
|
|
}
|
|
|
|
Tooltip.prototype.disable = function () {
|
|
this.enabled = false
|
|
}
|
|
|
|
Tooltip.prototype.toggleEnabled = function () {
|
|
this.enabled = !this.enabled
|
|
}
|
|
|
|
Tooltip.prototype.toggle = function (e) {
|
|
var self = this
|
|
if (e) {
|
|
self = $(e.currentTarget).data('bs.' + this.type)
|
|
if (!self) {
|
|
self = new this.constructor(e.currentTarget, this.getDelegateOptions())
|
|
$(e.currentTarget).data('bs.' + this.type, self)
|
|
}
|
|
}
|
|
|
|
if (e) {
|
|
self.inState.click = !self.inState.click
|
|
if (self.isInStateTrue()) self.enter(self)
|
|
else self.leave(self)
|
|
} else {
|
|
self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
|
|
}
|
|
}
|
|
|
|
Tooltip.prototype.destroy = function () {
|
|
var that = this
|
|
clearTimeout(this.timeout)
|
|
this.hide(function () {
|
|
that.$element.off('.' + that.type).removeData('bs.' + that.type)
|
|
if (that.$tip) {
|
|
that.$tip.detach()
|
|
}
|
|
that.$tip = null
|
|
that.$arrow = null
|
|
that.$viewport = null
|
|
that.$element = null
|
|
})
|
|
}
|
|
|
|
|
|
// TOOLTIP PLUGIN DEFINITION
|
|
// =========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.tooltip')
|
|
var options = typeof option == 'object' && option
|
|
|
|
if (!data && /destroy|hide/.test(option)) return
|
|
if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.tooltip
|
|
|
|
$.fn.tooltip = Plugin
|
|
$.fn.tooltip.Constructor = Tooltip
|
|
|
|
|
|
// TOOLTIP NO CONFLICT
|
|
// ===================
|
|
|
|
$.fn.tooltip.noConflict = function () {
|
|
$.fn.tooltip = old
|
|
return this
|
|
}
|
|
|
|
}(jQuery);
|
|
|
|
/* ========================================================================
|
|
* Bootstrap: popover.js v3.3.7
|
|
* http://getbootstrap.com/javascript/#popovers
|
|
* ========================================================================
|
|
* Copyright 2011-2016 Twitter, Inc.
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
* ======================================================================== */
|
|
|
|
|
|
+function ($) {
|
|
'use strict';
|
|
|
|
// POPOVER PUBLIC CLASS DEFINITION
|
|
// ===============================
|
|
|
|
var Popover = function (element, options) {
|
|
this.init('popover', element, options)
|
|
}
|
|
|
|
if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
|
|
|
|
Popover.VERSION = '3.3.7'
|
|
|
|
Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, {
|
|
placement: 'right',
|
|
trigger: 'click',
|
|
content: '',
|
|
template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
|
|
})
|
|
|
|
|
|
// NOTE: POPOVER EXTENDS tooltip.js
|
|
// ================================
|
|
|
|
Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
|
|
|
|
Popover.prototype.constructor = Popover
|
|
|
|
Popover.prototype.getDefaults = function () {
|
|
return Popover.DEFAULTS
|
|
}
|
|
|
|
Popover.prototype.setContent = function () {
|
|
var $tip = this.tip()
|
|
var title = this.getTitle()
|
|
var content = this.getContent()
|
|
|
|
$tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
|
|
$tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events
|
|
this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
|
|
](content)
|
|
|
|
$tip.removeClass('fade top bottom left right in')
|
|
|
|
// IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
|
|
// this manually by checking the contents.
|
|
if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
|
|
}
|
|
|
|
Popover.prototype.hasContent = function () {
|
|
return this.getTitle() || this.getContent()
|
|
}
|
|
|
|
Popover.prototype.getContent = function () {
|
|
var $e = this.$element
|
|
var o = this.options
|
|
|
|
return $e.attr('data-content')
|
|
|| (typeof o.content == 'function' ?
|
|
o.content.call($e[0]) :
|
|
o.content)
|
|
}
|
|
|
|
Popover.prototype.arrow = function () {
|
|
return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
|
|
}
|
|
|
|
|
|
// POPOVER PLUGIN DEFINITION
|
|
// =========================
|
|
|
|
function Plugin(option) {
|
|
return this.each(function () {
|
|
var $this = $(this)
|
|
var data = $this.data('bs.popover')
|
|
var options = typeof option == 'object' && option
|
|
|
|
if (!data && /destroy|hide/.test(option)) return
|
|
if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
|
|
if (typeof option == 'string') data[option]()
|
|
})
|
|
}
|
|
|
|
var old = $.fn.popover
|
|
|
|
$.fn.popover = Plugin
|
|
$.fn.popover.Constructor = Popover
|
|
|
|
|
|
// POPOVER NO CONFLICT
|
|
// ===================
|
|
|
|
$.fn.popover.noConflict = function () {
|
|
$.fn.popover = old
|
|
return this
|
|
}
|
|
|
|
}(jQuery);
|
|
|
|
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
|
|
|
(function(window, factory) {
|
|
if (typeof define === 'function' && define.amd) {
|
|
return define(['jquery'], function(jQuery) {
|
|
return window.Tour = factory(jQuery);
|
|
});
|
|
} else if (typeof exports === 'object') {
|
|
return module.exports = factory(require('jquery'));
|
|
} else {
|
|
return window.Tour = factory(window.jQuery);
|
|
}
|
|
})(window, function($) {
|
|
var Tour, document;
|
|
document = window.document;
|
|
Tour = (function() {
|
|
function Tour(options) {
|
|
this._showPopoverAndOverlay = bind(this._showPopoverAndOverlay, this);
|
|
var storage;
|
|
try {
|
|
storage = window.localStorage;
|
|
} catch (error) {
|
|
storage = false;
|
|
}
|
|
this._options = $.extend({
|
|
name: 'tour',
|
|
steps: [],
|
|
container: 'body',
|
|
autoscroll: true,
|
|
keyboard: true,
|
|
storage: storage,
|
|
debug: false,
|
|
backdrop: false,
|
|
backdropContainer: 'body',
|
|
backdropPadding: 0,
|
|
redirect: true,
|
|
orphan: false,
|
|
duration: false,
|
|
delay: false,
|
|
basePath: '',
|
|
template: '<div class="popover" role="tooltip"> <div class="arrow"></div> <h3 class="popover-title"></h3> <div class="popover-content"></div> <div class="popover-navigation"> <div class="btn-group"> <button class="btn btn-sm btn-default" data-role="prev">« Prev</button> <button class="btn btn-sm btn-default" data-role="next">Next »</button> <button class="btn btn-sm btn-default" data-role="pause-resume" data-pause-text="Pause" data-resume-text="Resume">Pause</button> </div> <button class="btn btn-sm btn-default" data-role="end">End tour</button> </div> </div>',
|
|
afterSetState: function(key, value) {},
|
|
afterGetState: function(key, value) {},
|
|
afterRemoveState: function(key) {},
|
|
onStart: function(tour) {},
|
|
onEnd: function(tour) {},
|
|
onShow: function(tour) {},
|
|
onShown: function(tour) {},
|
|
onHide: function(tour) {},
|
|
onHidden: function(tour) {},
|
|
onNext: function(tour) {},
|
|
onPrev: function(tour) {},
|
|
onPause: function(tour, duration) {},
|
|
onResume: function(tour, duration) {},
|
|
onRedirectError: function(tour) {}
|
|
}, options);
|
|
this._force = false;
|
|
this._inited = false;
|
|
this._current = null;
|
|
this.backdrops = [];
|
|
this;
|
|
}
|
|
|
|
Tour.prototype.addSteps = function(steps) {
|
|
var j, len, step;
|
|
for (j = 0, len = steps.length; j < len; j++) {
|
|
step = steps[j];
|
|
this.addStep(step);
|
|
}
|
|
return this;
|
|
};
|
|
|
|
Tour.prototype.addStep = function(step) {
|
|
this._options.steps.push(step);
|
|
return this;
|
|
};
|
|
|
|
Tour.prototype.getStep = function(i) {
|
|
if (this._options.steps[i] != null) {
|
|
return $.extend({
|
|
id: "step-" + i,
|
|
path: '',
|
|
host: '',
|
|
placement: 'right',
|
|
title: '',
|
|
content: '<p></p>',
|
|
next: i === this._options.steps.length - 1 ? -1 : i + 1,
|
|
prev: i - 1,
|
|
animation: true,
|
|
container: this._options.container,
|
|
autoscroll: this._options.autoscroll,
|
|
backdrop: this._options.backdrop,
|
|
backdropContainer: this._options.backdropContainer,
|
|
backdropPadding: this._options.backdropPadding,
|
|
redirect: this._options.redirect,
|
|
reflexElement: this._options.steps[i].element,
|
|
backdropElement: this._options.steps[i].element,
|
|
orphan: this._options.orphan,
|
|
duration: this._options.duration,
|
|
delay: this._options.delay,
|
|
template: this._options.template,
|
|
onShow: this._options.onShow,
|
|
onShown: this._options.onShown,
|
|
onHide: this._options.onHide,
|
|
onHidden: this._options.onHidden,
|
|
onNext: this._options.onNext,
|
|
onPrev: this._options.onPrev,
|
|
onPause: this._options.onPause,
|
|
onResume: this._options.onResume,
|
|
onRedirectError: this._options.onRedirectError
|
|
}, this._options.steps[i]);
|
|
}
|
|
};
|
|
|
|
Tour.prototype.init = function(force) {
|
|
this._force = force;
|
|
if (this.ended()) {
|
|
this._debug('Tour ended, init prevented.');
|
|
return this;
|
|
}
|
|
this.setCurrentStep();
|
|
this._initMouseNavigation();
|
|
this._initKeyboardNavigation();
|
|
this._onResize((function(_this) {
|
|
return function() {
|
|
return _this.showStep(_this._current);
|
|
};
|
|
})(this));
|
|
this._onScroll((function(_this) {
|
|
return function() {
|
|
return _this._showPopoverAndOverlay(_this._current);
|
|
};
|
|
})(this));
|
|
if (this._current !== null) {
|
|
this.showStep(this._current);
|
|
}
|
|
this._inited = true;
|
|
return this;
|
|
};
|
|
|
|
Tour.prototype.start = function(force) {
|
|
var promise;
|
|
if (force == null) {
|
|
force = false;
|
|
}
|
|
if (!this._inited) {
|
|
this.init(force);
|
|
}
|
|
if (this._current === null) {
|
|
promise = this._makePromise(this._options.onStart != null ? this._options.onStart(this) : void 0);
|
|
this._callOnPromiseDone(promise, this.showStep, 0);
|
|
}
|
|
return this;
|
|
};
|
|
|
|
Tour.prototype.next = function() {
|
|
var promise;
|
|
promise = this.hideStep(this._current, this._current + 1);
|
|
return this._callOnPromiseDone(promise, this._showNextStep);
|
|
};
|
|
|
|
Tour.prototype.prev = function() {
|
|
var promise;
|
|
promise = this.hideStep(this._current, this._current - 1);
|
|
return this._callOnPromiseDone(promise, this._showPrevStep);
|
|
};
|
|
|
|
Tour.prototype.goTo = function(i) {
|
|
var promise;
|
|
promise = this.hideStep(this._current, i);
|
|
return this._callOnPromiseDone(promise, this.showStep, i);
|
|
};
|
|
|
|
Tour.prototype.end = function() {
|
|
var endHelper, promise;
|
|
endHelper = (function(_this) {
|
|
return function(e) {
|
|
$(document).off("click.tour-" + _this._options.name);
|
|
$(document).off("keyup.tour-" + _this._options.name);
|
|
$(window).off("resize.tour-" + _this._options.name);
|
|
$(window).off("scroll.tour-" + _this._options.name);
|
|
_this._setState('end', 'yes');
|
|
_this._inited = false;
|
|
_this._force = false;
|
|
_this._clearTimer();
|
|
if (_this._options.onEnd != null) {
|
|
return _this._options.onEnd(_this);
|
|
}
|
|
};
|
|
})(this);
|
|
promise = this.hideStep(this._current);
|
|
return this._callOnPromiseDone(promise, endHelper);
|
|
};
|
|
|
|
Tour.prototype.ended = function() {
|
|
return !this._force && !!this._getState('end');
|
|
};
|
|
|
|
Tour.prototype.restart = function() {
|
|
this._removeState('current_step');
|
|
this._removeState('end');
|
|
this._removeState('redirect_to');
|
|
return this.start();
|
|
};
|
|
|
|
Tour.prototype.pause = function() {
|
|
var step;
|
|
step = this.getStep(this._current);
|
|
if (!(step && step.duration)) {
|
|
return this;
|
|
}
|
|
this._paused = true;
|
|
this._duration -= new Date().getTime() - this._start;
|
|
window.clearTimeout(this._timer);
|
|
this._debug("Paused/Stopped step " + (this._current + 1) + " timer (" + this._duration + " remaining).");
|
|
if (step.onPause != null) {
|
|
return step.onPause(this, this._duration);
|
|
}
|
|
};
|
|
|
|
Tour.prototype.resume = function() {
|
|
var step;
|
|
step = this.getStep(this._current);
|
|
if (!(step && step.duration)) {
|
|
return this;
|
|
}
|
|
this._paused = false;
|
|
this._start = new Date().getTime();
|
|
this._duration = this._duration || step.duration;
|
|
this._timer = window.setTimeout((function(_this) {
|
|
return function() {
|
|
if (_this._isLast()) {
|
|
return _this.next();
|
|
} else {
|
|
return _this.end();
|
|
}
|
|
};
|
|
})(this), this._duration);
|
|
this._debug("Started step " + (this._current + 1) + " timer with duration " + this._duration);
|
|
if ((step.onResume != null) && this._duration !== step.duration) {
|
|
return step.onResume(this, this._duration);
|
|
}
|
|
};
|
|
|
|
Tour.prototype.hideStep = function(i, iNext) {
|
|
var hideDelay, hideStepHelper, promise, step;
|
|
step = this.getStep(i);
|
|
if (!step) {
|
|
return;
|
|
}
|
|
this._clearTimer();
|
|
promise = this._makePromise(step.onHide != null ? step.onHide(this, i) : void 0);
|
|
hideStepHelper = (function(_this) {
|
|
return function(e) {
|
|
var $element, next_step;
|
|
$element = $(step.element);
|
|
if (!($element.data('bs.popover') || $element.data('popover'))) {
|
|
$element = $('body');
|
|
}
|
|
$element.popover('destroy').removeClass("tour-" + _this._options.name + "-element tour-" + _this._options.name + "-" + i + "-element").removeData('bs.popover');
|
|
if (step.reflex) {
|
|
$(step.reflexElement).removeClass('tour-step-element-reflex').off((_this._reflexEvent(step.reflex)) + ".tour-" + _this._options.name);
|
|
}
|
|
if (step.backdrop) {
|
|
next_step = (iNext != null) && _this.getStep(iNext);
|
|
if (!next_step || !next_step.backdrop || next_step.backdropElement !== step.backdropElement) {
|
|
_this._hideOverlayElement(step);
|
|
}
|
|
}
|
|
if (step.onHidden != null) {
|
|
return step.onHidden(_this);
|
|
}
|
|
};
|
|
})(this);
|
|
hideDelay = step.delay.hide || step.delay;
|
|
if ({}.toString.call(hideDelay) === '[object Number]' && hideDelay > 0) {
|
|
this._debug("Wait " + hideDelay + " milliseconds to hide the step " + (this._current + 1));
|
|
window.setTimeout((function(_this) {
|
|
return function() {
|
|
return _this._callOnPromiseDone(promise, hideStepHelper);
|
|
};
|
|
})(this), hideDelay);
|
|
} else {
|
|
this._callOnPromiseDone(promise, hideStepHelper);
|
|
}
|
|
return promise;
|
|
};
|
|
|
|
Tour.prototype.showStep = function(i) {
|
|
var path, promise, showDelay, showStepHelper, skipToPrevious, step;
|
|
if (this.ended()) {
|
|
this._debug('Tour ended, showStep prevented.');
|
|
return this;
|
|
}
|
|
step = this.getStep(i);
|
|
if (!step) {
|
|
return;
|
|
}
|
|
skipToPrevious = i < this._current;
|
|
promise = this._makePromise(step.onShow != null ? step.onShow(this, i) : void 0);
|
|
this.setCurrentStep(i);
|
|
path = (function() {
|
|
switch ({}.toString.call(step.path)) {
|
|
case '[object Function]':
|
|
return step.path();
|
|
case '[object String]':
|
|
return this._options.basePath + step.path;
|
|
default:
|
|
return step.path;
|
|
}
|
|
}).call(this);
|
|
if (step.redirect && this._isRedirect(step.host, path, document.location)) {
|
|
this._redirect(step, i, path);
|
|
if (!this._isJustPathHashDifferent(step.host, path, document.location)) {
|
|
return;
|
|
}
|
|
}
|
|
showStepHelper = (function(_this) {
|
|
return function(e) {
|
|
if (_this._isOrphan(step)) {
|
|
if (step.orphan === false) {
|
|
_this._debug("Skip the orphan step " + (_this._current + 1) + ".\nOrphan option is false and the element does not exist or is hidden.");
|
|
if (skipToPrevious) {
|
|
_this._showPrevStep();
|
|
} else {
|
|
_this._showNextStep();
|
|
}
|
|
return;
|
|
}
|
|
_this._debug("Show the orphan step " + (_this._current + 1) + ". Orphans option is true.");
|
|
}
|
|
if (step.autoscroll) {
|
|
_this._scrollIntoView(i);
|
|
} else {
|
|
_this._showPopoverAndOverlay(i);
|
|
}
|
|
if (step.duration) {
|
|
return _this.resume();
|
|
}
|
|
};
|
|
})(this);
|
|
showDelay = step.delay.show || step.delay;
|
|
if ({}.toString.call(showDelay) === '[object Number]' && showDelay > 0) {
|
|
this._debug("Wait " + showDelay + " milliseconds to show the step " + (this._current + 1));
|
|
window.setTimeout((function(_this) {
|
|
return function() {
|
|
return _this._callOnPromiseDone(promise, showStepHelper);
|
|
};
|
|
})(this), showDelay);
|
|
} else {
|
|
this._callOnPromiseDone(promise, showStepHelper);
|
|
}
|
|
return promise;
|
|
};
|
|
|
|
Tour.prototype.getCurrentStep = function() {
|
|
return this._current;
|
|
};
|
|
|
|
Tour.prototype.setCurrentStep = function(value) {
|
|
if (value != null) {
|
|
this._current = value;
|
|
this._setState('current_step', value);
|
|
} else {
|
|
this._current = this._getState('current_step');
|
|
this._current = this._current === null ? null : parseInt(this._current, 10);
|
|
}
|
|
return this;
|
|
};
|
|
|
|
Tour.prototype.redraw = function() {
|
|
return this._showOverlayElement(this.getStep(this.getCurrentStep()));
|
|
};
|
|
|
|
Tour.prototype._setState = function(key, value) {
|
|
var e, keyName;
|
|
if (this._options.storage) {
|
|
keyName = this._options.name + "_" + key;
|
|
try {
|
|
this._options.storage.setItem(keyName, value);
|
|
} catch (error) {
|
|
e = error;
|
|
if (e.code === DOMException.QUOTA_EXCEEDED_ERR) {
|
|
this._debug('LocalStorage quota exceeded. State storage failed.');
|
|
}
|
|
}
|
|
return this._options.afterSetState(keyName, value);
|
|
} else {
|
|
if (this._state == null) {
|
|
this._state = {};
|
|
}
|
|
return this._state[key] = value;
|
|
}
|
|
};
|
|
|
|
Tour.prototype._removeState = function(key) {
|
|
var keyName;
|
|
if (this._options.storage) {
|
|
keyName = this._options.name + "_" + key;
|
|
this._options.storage.removeItem(keyName);
|
|
return this._options.afterRemoveState(keyName);
|
|
} else {
|
|
if (this._state != null) {
|
|
return delete this._state[key];
|
|
}
|
|
}
|
|
};
|
|
|
|
Tour.prototype._getState = function(key) {
|
|
var keyName, value;
|
|
if (this._options.storage) {
|
|
keyName = this._options.name + "_" + key;
|
|
value = this._options.storage.getItem(keyName);
|
|
} else {
|
|
if (this._state != null) {
|
|
value = this._state[key];
|
|
}
|
|
}
|
|
if (value === void 0 || value === 'null') {
|
|
value = null;
|
|
}
|
|
this._options.afterGetState(key, value);
|
|
return value;
|
|
};
|
|
|
|
Tour.prototype._showNextStep = function() {
|
|
var promise, showNextStepHelper, step;
|
|
step = this.getStep(this._current);
|
|
showNextStepHelper = (function(_this) {
|
|
return function(e) {
|
|
return _this.showStep(step.next);
|
|
};
|
|
})(this);
|
|
promise = this._makePromise(step.onNext != null ? step.onNext(this) : void 0);
|
|
return this._callOnPromiseDone(promise, showNextStepHelper);
|
|
};
|
|
|
|
Tour.prototype._showPrevStep = function() {
|
|
var promise, showPrevStepHelper, step;
|
|
step = this.getStep(this._current);
|
|
showPrevStepHelper = (function(_this) {
|
|
return function(e) {
|
|
return _this.showStep(step.prev);
|
|
};
|
|
})(this);
|
|
promise = this._makePromise(step.onPrev != null ? step.onPrev(this) : void 0);
|
|
return this._callOnPromiseDone(promise, showPrevStepHelper);
|
|
};
|
|
|
|
Tour.prototype._debug = function(text) {
|
|
if (this._options.debug) {
|
|
return window.console.log("Bootstrap Tour '" + this._options.name + "' | " + text);
|
|
}
|
|
};
|
|
|
|
Tour.prototype._isRedirect = function(host, path, location) {
|
|
var currentPath;
|
|
if ((host != null) && host !== '' && (({}.toString.call(host) === '[object RegExp]' && !host.test(location.origin)) || ({}.toString.call(host) === '[object String]' && this._isHostDifferent(host, location)))) {
|
|
return true;
|
|
}
|
|
currentPath = [location.pathname, location.search, location.hash].join('');
|
|
return (path != null) && path !== '' && (({}.toString.call(path) === '[object RegExp]' && !path.test(currentPath)) || ({}.toString.call(path) === '[object String]' && this._isPathDifferent(path, currentPath)));
|
|
};
|
|
|
|
Tour.prototype._isHostDifferent = function(host, location) {
|
|
switch ({}.toString.call(host)) {
|
|
case '[object RegExp]':
|
|
return !host.test(location.origin);
|
|
case '[object String]':
|
|
return this._getProtocol(host) !== this._getProtocol(location.href) || this._getHost(host) !== this._getHost(location.href);
|
|
default:
|
|
return true;
|
|
}
|
|
};
|
|
|
|
Tour.prototype._isPathDifferent = function(path, currentPath) {
|
|
return this._getPath(path) !== this._getPath(currentPath) || !this._equal(this._getQuery(path), this._getQuery(currentPath)) || !this._equal(this._getHash(path), this._getHash(currentPath));
|
|
};
|
|
|
|
Tour.prototype._isJustPathHashDifferent = function(host, path, location) {
|
|
var currentPath;
|
|
if ((host != null) && host !== '') {
|
|
if (this._isHostDifferent(host, location)) {
|
|
return false;
|
|
}
|
|
}
|
|
currentPath = [location.pathname, location.search, location.hash].join('');
|
|
if ({}.toString.call(path) === '[object String]') {
|
|
return this._getPath(path) === this._getPath(currentPath) && this._equal(this._getQuery(path), this._getQuery(currentPath)) && !this._equal(this._getHash(path), this._getHash(currentPath));
|
|
}
|
|
return false;
|
|
};
|
|
|
|
Tour.prototype._redirect = function(step, i, path) {
|
|
var href;
|
|
if ($.isFunction(step.redirect)) {
|
|
return step.redirect.call(this, path);
|
|
} else {
|
|
href = {}.toString.call(step.host) === '[object String]' ? "" + step.host + path : path;
|
|
this._debug("Redirect to " + href);
|
|
if (this._getState('redirect_to') === ("" + i)) {
|
|
this._debug("Error redirection loop to " + path);
|
|
this._removeState('redirect_to');
|
|
if (step.onRedirectError != null) {
|
|
return step.onRedirectError(this);
|
|
}
|
|
} else {
|
|
this._setState('redirect_to', "" + i);
|
|
return document.location.href = href;
|
|
}
|
|
}
|
|
};
|
|
|
|
Tour.prototype._isOrphan = function(step) {
|
|
return (step.element == null) || !$(step.element).length || $(step.element).is(':hidden') && ($(step.element)[0].namespaceURI !== 'http://www.w3.org/2000/svg');
|
|
};
|
|
|
|
Tour.prototype._isLast = function() {
|
|
return this._current < this._options.steps.length - 1;
|
|
};
|
|
|
|
Tour.prototype._showPopoverAndOverlay = function(i) {
|
|
var step;
|
|
if (this.getCurrentStep() !== i || this.ended()) {
|
|
return;
|
|
}
|
|
step = this.getStep(i);
|
|
if (step.backdrop) {
|
|
this._showOverlayElement(step);
|
|
}
|
|
this._showPopover(step, i);
|
|
if (step.onShown != null) {
|
|
step.onShown(this);
|
|
}
|
|
return this._debug("Step " + (this._current + 1) + " of " + this._options.steps.length);
|
|
};
|
|
|
|
Tour.prototype._showPopover = function(step, i) {
|
|
var $element, $tip, isOrphan, options, shouldAddSmart;
|
|
$(".tour-" + this._options.name).remove();
|
|
options = $.extend({}, this._options);
|
|
isOrphan = this._isOrphan(step);
|
|
step.template = this._template(step, i);
|
|
if (isOrphan) {
|
|
step.element = 'body';
|
|
step.placement = 'top';
|
|
}
|
|
$element = $(step.element);
|
|
$element.addClass("tour-" + this._options.name + "-element tour-" + this._options.name + "-" + i + "-element");
|
|
if (step.options) {
|
|
$.extend(options, step.options);
|
|
}
|
|
if (step.reflex && !isOrphan) {
|
|
$(step.reflexElement).addClass('tour-step-element-reflex').off((this._reflexEvent(step.reflex)) + ".tour-" + this._options.name).on((this._reflexEvent(step.reflex)) + ".tour-" + this._options.name, (function(_this) {
|
|
return function() {
|
|
if (_this._isLast()) {
|
|
return _this.next();
|
|
} else {
|
|
return _this.end();
|
|
}
|
|
};
|
|
})(this));
|
|
}
|
|
shouldAddSmart = step.smartPlacement === true && step.placement.search(/auto/i) === -1;
|
|
$element.popover({
|
|
placement: shouldAddSmart ? "auto " + step.placement : step.placement,
|
|
trigger: 'manual',
|
|
title: step.title,
|
|
content: step.content,
|
|
html: true,
|
|
animation: step.animation,
|
|
container: step.container,
|
|
template: step.template,
|
|
selector: step.element
|
|
}).popover('show');
|
|
$tip = $element.data('bs.popover') ? $element.data('bs.popover').tip() : $element.data('popover').tip();
|
|
$tip.attr('id', step.id);
|
|
if ($element.css('position') === 'fixed') {
|
|
$tip.css('position', 'fixed');
|
|
}
|
|
this._reposition($tip, step);
|
|
if (isOrphan) {
|
|
return this._center($tip);
|
|
}
|
|
};
|
|
|
|
Tour.prototype._template = function(step, i) {
|
|
var $navigation, $next, $prev, $resume, $template, template;
|
|
template = step.template;
|
|
if (this._isOrphan(step) && {}.toString.call(step.orphan) !== '[object Boolean]') {
|
|
template = step.orphan;
|
|
}
|
|
$template = $.isFunction(template) ? $(template(i, step)) : $(template);
|
|
$navigation = $template.find('.popover-navigation');
|
|
$prev = $navigation.find('[data-role="prev"]');
|
|
$next = $navigation.find('[data-role="next"]');
|
|
$resume = $navigation.find('[data-role="pause-resume"]');
|
|
if (this._isOrphan(step)) {
|
|
$template.addClass('orphan');
|
|
}
|
|
$template.addClass("tour-" + this._options.name + " tour-" + this._options.name + "-" + i);
|
|
if (step.reflex) {
|
|
$template.addClass("tour-" + this._options.name + "-reflex");
|
|
}
|
|
if (step.prev < 0) {
|
|
$prev.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
|
|
}
|
|
if (step.next < 0) {
|
|
$next.addClass('disabled').prop('disabled', true).prop('tabindex', -1);
|
|
}
|
|
if (!step.duration) {
|
|
$resume.remove();
|
|
}
|
|
return $template.clone().wrap('<div>').parent().html();
|
|
};
|
|
|
|
Tour.prototype._reflexEvent = function(reflex) {
|
|
if ({}.toString.call(reflex) === '[object Boolean]') {
|
|
return 'click';
|
|
} else {
|
|
return reflex;
|
|
}
|
|
};
|
|
|
|
Tour.prototype._reposition = function($tip, step) {
|
|
var offsetBottom, offsetHeight, offsetRight, offsetWidth, originalLeft, originalTop, tipOffset;
|
|
offsetWidth = $tip[0].offsetWidth;
|
|
offsetHeight = $tip[0].offsetHeight;
|
|
tipOffset = $tip.offset();
|
|
originalLeft = tipOffset.left;
|
|
originalTop = tipOffset.top;
|
|
offsetBottom = $(document).outerHeight() - tipOffset.top - $tip.outerHeight();
|
|
if (offsetBottom < 0) {
|
|
tipOffset.top = tipOffset.top + offsetBottom;
|
|
}
|
|
offsetRight = $('html').outerWidth() - tipOffset.left - $tip.outerWidth();
|
|
if (offsetRight < 0) {
|
|
tipOffset.left = tipOffset.left + offsetRight;
|
|
}
|
|
if (tipOffset.top < 0) {
|
|
tipOffset.top = 0;
|
|
}
|
|
if (tipOffset.left < 0) {
|
|
tipOffset.left = 0;
|
|
}
|
|
$tip.offset(tipOffset);
|
|
if (step.placement === 'bottom' || step.placement === 'top') {
|
|
if (originalLeft !== tipOffset.left) {
|
|
return this._replaceArrow($tip, (tipOffset.left - originalLeft) * 2, offsetWidth, 'left');
|
|
}
|
|
} else {
|
|
if (originalTop !== tipOffset.top) {
|
|
return this._replaceArrow($tip, (tipOffset.top - originalTop) * 2, offsetHeight, 'top');
|
|
}
|
|
}
|
|
};
|
|
|
|
Tour.prototype._center = function($tip) {
|
|
return $tip.css('top', $(window).outerHeight() / 2 - $tip.outerHeight() / 2);
|
|
};
|
|
|
|
Tour.prototype._replaceArrow = function($tip, delta, dimension, position) {
|
|
return $tip.find('.arrow').css(position, delta ? 50 * (1 - delta / dimension) + '%' : '');
|
|
};
|
|
|
|
Tour.prototype._scrollIntoView = function(i) {
|
|
var $element, $window, counter, height, offsetTop, scrollTop, step, windowHeight;
|
|
step = this.getStep(i);
|
|
$element = $(step.element);
|
|
if (!$element.length) {
|
|
return this._showPopoverAndOverlay(i);
|
|
}
|
|
$window = $(window);
|
|
offsetTop = $element.offset().top;
|
|
height = $element.outerHeight();
|
|
windowHeight = $window.height();
|
|
scrollTop = 0;
|
|
switch (step.placement) {
|
|
case 'top':
|
|
scrollTop = Math.max(0, offsetTop - (windowHeight / 2));
|
|
break;
|
|
case 'left':
|
|
case 'right':
|
|
scrollTop = Math.max(0, (offsetTop + height / 2) - (windowHeight / 2));
|
|
break;
|
|
case 'bottom':
|
|
scrollTop = Math.max(0, (offsetTop + height) - (windowHeight / 2));
|
|
}
|
|
this._debug("Scroll into view. ScrollTop: " + scrollTop + ". Element offset: " + offsetTop + ". Window height: " + windowHeight + ".");
|
|
counter = 0;
|
|
return $('body, html').stop(true, true).animate({
|
|
scrollTop: Math.ceil(scrollTop)
|
|
}, (function(_this) {
|
|
return function() {
|
|
if (++counter === 2) {
|
|
_this._showPopoverAndOverlay(i);
|
|
return _this._debug("Scroll into view.\nAnimation end element offset: " + ($element.offset().top) + ".\nWindow height: " + ($window.height()) + ".");
|
|
}
|
|
};
|
|
})(this));
|
|
};
|
|
|
|
Tour.prototype._onResize = function(callback, timeout) {
|
|
return $(window).on("resize.tour-" + this._options.name, function() {
|
|
clearTimeout(timeout);
|
|
return timeout = setTimeout(callback, 100);
|
|
});
|
|
};
|
|
|
|
Tour.prototype._onScroll = function(callback, timeout) {
|
|
return $(window).on("scroll.tour-" + this._options.name, function() {
|
|
clearTimeout(timeout);
|
|
return timeout = setTimeout(callback, 100);
|
|
});
|
|
};
|
|
|
|
Tour.prototype._initMouseNavigation = function() {
|
|
var _this;
|
|
_this = this;
|
|
return $(document).off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='prev']").off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='next']").off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='end']").off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='pause-resume']").on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='next']", (function(_this) {
|
|
return function(e) {
|
|
e.preventDefault();
|
|
return _this.next();
|
|
};
|
|
})(this)).on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='prev']", (function(_this) {
|
|
return function(e) {
|
|
e.preventDefault();
|
|
if (_this._current > 0) {
|
|
return _this.prev();
|
|
}
|
|
};
|
|
})(this)).on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='end']", (function(_this) {
|
|
return function(e) {
|
|
e.preventDefault();
|
|
return _this.end();
|
|
};
|
|
})(this)).on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='pause-resume']", function(e) {
|
|
var $this;
|
|
e.preventDefault();
|
|
$this = $(this);
|
|
$this.text(_this._paused ? $this.data('pause-text') : $this.data('resume-text'));
|
|
if (_this._paused) {
|
|
return _this.resume();
|
|
} else {
|
|
return _this.pause();
|
|
}
|
|
});
|
|
};
|
|
|
|
Tour.prototype._initKeyboardNavigation = function() {
|
|
if (!this._options.keyboard) {
|
|
return;
|
|
}
|
|
return $(document).on("keyup.tour-" + this._options.name, (function(_this) {
|
|
return function(e) {
|
|
if (!e.which) {
|
|
return;
|
|
}
|
|
switch (e.which) {
|
|
case 39:
|
|
e.preventDefault();
|
|
if (_this._isLast()) {
|
|
return _this.next();
|
|
} else {
|
|
return _this.end();
|
|
}
|
|
break;
|
|
case 37:
|
|
e.preventDefault();
|
|
if (_this._current > 0) {
|
|
return _this.prev();
|
|
}
|
|
}
|
|
};
|
|
})(this));
|
|
};
|
|
|
|
Tour.prototype._makePromise = function(result) {
|
|
if (result && $.isFunction(result.then)) {
|
|
return result;
|
|
} else {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
Tour.prototype._callOnPromiseDone = function(promise, cb, arg) {
|
|
if (promise) {
|
|
return promise.then((function(_this) {
|
|
return function(e) {
|
|
return cb.call(_this, arg);
|
|
};
|
|
})(this));
|
|
} else {
|
|
return cb.call(this, arg);
|
|
}
|
|
};
|
|
|
|
Tour.prototype._showBackground = function(step, data) {
|
|
var $backdrop, base, height, j, len, pos, ref, results, width;
|
|
height = $(document).height();
|
|
width = $(document).width();
|
|
ref = ['top', 'bottom', 'left', 'right'];
|
|
results = [];
|
|
for (j = 0, len = ref.length; j < len; j++) {
|
|
pos = ref[j];
|
|
$backdrop = (base = this.backdrops)[pos] != null ? base[pos] : base[pos] = $('<div>', {
|
|
"class": "tour-backdrop " + pos
|
|
});
|
|
$(step.backdropContainer).append($backdrop);
|
|
switch (pos) {
|
|
case 'top':
|
|
results.push($backdrop.height(data.offset.top > 0 ? data.offset.top : 0).width(width).offset({
|
|
top: 0,
|
|
left: 0
|
|
}));
|
|
break;
|
|
case 'bottom':
|
|
results.push($backdrop.offset({
|
|
top: data.offset.top + data.height,
|
|
left: 0
|
|
}).height(height - (data.offset.top + data.height)).width(width));
|
|
break;
|
|
case 'left':
|
|
results.push($backdrop.offset({
|
|
top: data.offset.top,
|
|
left: 0
|
|
}).height(data.height).width(data.offset.left > 0 ? data.offset.left : 0));
|
|
break;
|
|
case 'right':
|
|
results.push($backdrop.offset({
|
|
top: data.offset.top,
|
|
left: data.offset.left + data.width
|
|
}).height(data.height).width(width - (data.offset.left + data.width)));
|
|
break;
|
|
default:
|
|
results.push(void 0);
|
|
}
|
|
}
|
|
return results;
|
|
};
|
|
|
|
Tour.prototype._showOverlayElement = function(step) {
|
|
var $backdropElement, elementData;
|
|
$backdropElement = $(step.backdropElement);
|
|
if ($backdropElement.length === 0) {
|
|
elementData = {
|
|
width: 0,
|
|
height: 0,
|
|
offset: {
|
|
top: 0,
|
|
left: 0
|
|
}
|
|
};
|
|
} else {
|
|
elementData = {
|
|
width: $backdropElement.innerWidth(),
|
|
height: $backdropElement.innerHeight(),
|
|
offset: $backdropElement.offset()
|
|
};
|
|
$backdropElement.addClass('tour-step-backdrop');
|
|
if (step.backdropPadding) {
|
|
elementData = this._applyBackdropPadding(step.backdropPadding, elementData);
|
|
}
|
|
}
|
|
return this._showBackground(step, elementData);
|
|
};
|
|
|
|
Tour.prototype._hideOverlayElement = function(step) {
|
|
var $backdrop, pos, ref;
|
|
$(step.backdropElement).removeClass('tour-step-backdrop');
|
|
ref = this.backdrops;
|
|
for (pos in ref) {
|
|
$backdrop = ref[pos];
|
|
if ($backdrop && $backdrop.remove !== void 0) {
|
|
$backdrop.remove();
|
|
}
|
|
}
|
|
return this.backdrops = [];
|
|
};
|
|
|
|
Tour.prototype._applyBackdropPadding = function(padding, data) {
|
|
if (typeof padding === 'object') {
|
|
if (padding.top == null) {
|
|
padding.top = 0;
|
|
}
|
|
if (padding.right == null) {
|
|
padding.right = 0;
|
|
}
|
|
if (padding.bottom == null) {
|
|
padding.bottom = 0;
|
|
}
|
|
if (padding.left == null) {
|
|
padding.left = 0;
|
|
}
|
|
data.offset.top = data.offset.top - padding.top;
|
|
data.offset.left = data.offset.left - padding.left;
|
|
data.width = data.width + padding.left + padding.right;
|
|
data.height = data.height + padding.top + padding.bottom;
|
|
} else {
|
|
data.offset.top = data.offset.top - padding;
|
|
data.offset.left = data.offset.left - padding;
|
|
data.width = data.width + (padding * 2);
|
|
data.height = data.height + (padding * 2);
|
|
}
|
|
return data;
|
|
};
|
|
|
|
Tour.prototype._clearTimer = function() {
|
|
window.clearTimeout(this._timer);
|
|
this._timer = null;
|
|
return this._duration = null;
|
|
};
|
|
|
|
Tour.prototype._getProtocol = function(url) {
|
|
url = url.split('://');
|
|
if (url.length > 1) {
|
|
return url[0];
|
|
} else {
|
|
return 'http';
|
|
}
|
|
};
|
|
|
|
Tour.prototype._getHost = function(url) {
|
|
url = url.split('//');
|
|
url = url.length > 1 ? url[1] : url[0];
|
|
return url.split('/')[0];
|
|
};
|
|
|
|
Tour.prototype._getPath = function(path) {
|
|
return path.replace(/\/?$/, '').split('?')[0].split('#')[0];
|
|
};
|
|
|
|
Tour.prototype._getQuery = function(path) {
|
|
return this._getParams(path, '?');
|
|
};
|
|
|
|
Tour.prototype._getHash = function(path) {
|
|
return this._getParams(path, '#');
|
|
};
|
|
|
|
Tour.prototype._getParams = function(path, start) {
|
|
var j, len, param, params, paramsObject;
|
|
params = path.split(start);
|
|
if (params.length === 1) {
|
|
return {};
|
|
}
|
|
params = params[1].split('&');
|
|
paramsObject = {};
|
|
for (j = 0, len = params.length; j < len; j++) {
|
|
param = params[j];
|
|
param = param.split('=');
|
|
paramsObject[param[0]] = param[1] || '';
|
|
}
|
|
return paramsObject;
|
|
};
|
|
|
|
Tour.prototype._equal = function(obj1, obj2) {
|
|
var j, k, len, obj1Keys, obj2Keys, v;
|
|
if ({}.toString.call(obj1) === '[object Object]' && {}.toString.call(obj2) === '[object Object]') {
|
|
obj1Keys = Object.keys(obj1);
|
|
obj2Keys = Object.keys(obj2);
|
|
if (obj1Keys.length !== obj2Keys.length) {
|
|
return false;
|
|
}
|
|
for (k in obj1) {
|
|
v = obj1[k];
|
|
if (!this._equal(obj2[k], v)) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
} else if ({}.toString.call(obj1) === '[object Array]' && {}.toString.call(obj2) === '[object Array]') {
|
|
if (obj1.length !== obj2.length) {
|
|
return false;
|
|
}
|
|
for (k = j = 0, len = obj1.length; j < len; k = ++j) {
|
|
v = obj1[k];
|
|
if (!this._equal(v, obj2[k])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
} else {
|
|
return obj1 === obj2;
|
|
}
|
|
};
|
|
|
|
return Tour;
|
|
|
|
})();
|
|
return Tour;
|
|
});
|