1 | /* ======================================================================== |
---|
2 | * bootstrap-tour - v0.10.1 |
---|
3 | * http://bootstraptour.com |
---|
4 | * ======================================================================== |
---|
5 | * Copyright 2012-2013 Ulrich Sossou |
---|
6 | * |
---|
7 | * ======================================================================== |
---|
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
9 | * you may not use this file except in compliance with the License. |
---|
10 | * You may obtain a copy of the License at |
---|
11 | * |
---|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
13 | * |
---|
14 | * Unless required by applicable law or agreed to in writing, software |
---|
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
17 | * See the License for the specific language governing permissions and |
---|
18 | * limitations under the License. |
---|
19 | * ======================================================================== |
---|
20 | */ |
---|
21 | |
---|
22 | /* ======================================================================== |
---|
23 | * Bootstrap: tooltip.js v3.2.0 |
---|
24 | * http://getbootstrap.com/javascript/#tooltip |
---|
25 | * Inspired by the original jQuery.tipsy by Jason Frame |
---|
26 | * ======================================================================== |
---|
27 | * Copyright 2011-2014 Twitter, Inc. |
---|
28 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) |
---|
29 | * ======================================================================== */ |
---|
30 | |
---|
31 | |
---|
32 | +function ($) { |
---|
33 | 'use strict'; |
---|
34 | |
---|
35 | // TOOLTIP PUBLIC CLASS DEFINITION |
---|
36 | // =============================== |
---|
37 | |
---|
38 | var Tooltip = function (element, options) { |
---|
39 | this.type = |
---|
40 | this.options = |
---|
41 | this.enabled = |
---|
42 | this.timeout = |
---|
43 | this.hoverState = |
---|
44 | this.$element = null |
---|
45 | |
---|
46 | this.init('tooltip', element, options) |
---|
47 | } |
---|
48 | |
---|
49 | Tooltip.VERSION = '3.2.0' |
---|
50 | |
---|
51 | Tooltip.DEFAULTS = { |
---|
52 | animation: true, |
---|
53 | placement: 'top', |
---|
54 | selector: false, |
---|
55 | template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>', |
---|
56 | trigger: 'hover focus', |
---|
57 | title: '', |
---|
58 | delay: 0, |
---|
59 | html: false, |
---|
60 | container: false, |
---|
61 | viewport: { |
---|
62 | selector: 'body', |
---|
63 | padding: 0 |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | Tooltip.prototype.init = function (type, element, options) { |
---|
68 | this.enabled = true |
---|
69 | this.type = type |
---|
70 | this.$element = $(element) |
---|
71 | this.options = this.getOptions(options) |
---|
72 | this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport) |
---|
73 | |
---|
74 | var triggers = this.options.trigger.split(' ') |
---|
75 | |
---|
76 | for (var i = triggers.length; i--;) { |
---|
77 | var trigger = triggers[i] |
---|
78 | |
---|
79 | if (trigger == 'click') { |
---|
80 | this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this)) |
---|
81 | } else if (trigger != 'manual') { |
---|
82 | var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin' |
---|
83 | var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout' |
---|
84 | |
---|
85 | this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this)) |
---|
86 | this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this)) |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | this.options.selector ? |
---|
91 | (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) : |
---|
92 | this.fixTitle() |
---|
93 | } |
---|
94 | |
---|
95 | Tooltip.prototype.getDefaults = function () { |
---|
96 | return Tooltip.DEFAULTS |
---|
97 | } |
---|
98 | |
---|
99 | Tooltip.prototype.getOptions = function (options) { |
---|
100 | options = $.extend({}, this.getDefaults(), this.$element.data(), options) |
---|
101 | |
---|
102 | if (options.delay && typeof options.delay == 'number') { |
---|
103 | options.delay = { |
---|
104 | show: options.delay, |
---|
105 | hide: options.delay |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | return options |
---|
110 | } |
---|
111 | |
---|
112 | Tooltip.prototype.getDelegateOptions = function () { |
---|
113 | var options = {} |
---|
114 | var defaults = this.getDefaults() |
---|
115 | |
---|
116 | this._options && $.each(this._options, function (key, value) { |
---|
117 | if (defaults[key] != value) options[key] = value |
---|
118 | }) |
---|
119 | |
---|
120 | return options |
---|
121 | } |
---|
122 | |
---|
123 | Tooltip.prototype.enter = function (obj) { |
---|
124 | var self = obj instanceof this.constructor ? |
---|
125 | obj : $(obj.currentTarget).data('bs.' + this.type) |
---|
126 | |
---|
127 | if (!self) { |
---|
128 | self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) |
---|
129 | $(obj.currentTarget).data('bs.' + this.type, self) |
---|
130 | } |
---|
131 | |
---|
132 | clearTimeout(self.timeout) |
---|
133 | |
---|
134 | self.hoverState = 'in' |
---|
135 | |
---|
136 | if (!self.options.delay || !self.options.delay.show) return self.show() |
---|
137 | |
---|
138 | self.timeout = setTimeout(function () { |
---|
139 | if (self.hoverState == 'in') self.show() |
---|
140 | }, self.options.delay.show) |
---|
141 | } |
---|
142 | |
---|
143 | Tooltip.prototype.leave = function (obj) { |
---|
144 | var self = obj instanceof this.constructor ? |
---|
145 | obj : $(obj.currentTarget).data('bs.' + this.type) |
---|
146 | |
---|
147 | if (!self) { |
---|
148 | self = new this.constructor(obj.currentTarget, this.getDelegateOptions()) |
---|
149 | $(obj.currentTarget).data('bs.' + this.type, self) |
---|
150 | } |
---|
151 | |
---|
152 | clearTimeout(self.timeout) |
---|
153 | |
---|
154 | self.hoverState = 'out' |
---|
155 | |
---|
156 | if (!self.options.delay || !self.options.delay.hide) return self.hide() |
---|
157 | |
---|
158 | self.timeout = setTimeout(function () { |
---|
159 | if (self.hoverState == 'out') self.hide() |
---|
160 | }, self.options.delay.hide) |
---|
161 | } |
---|
162 | |
---|
163 | Tooltip.prototype.show = function () { |
---|
164 | var e = $.Event('show.bs.' + this.type) |
---|
165 | |
---|
166 | if (this.hasContent() && this.enabled) { |
---|
167 | this.$element.trigger(e) |
---|
168 | |
---|
169 | var inDom = $.contains(document.documentElement, this.$element[0]) |
---|
170 | if (e.isDefaultPrevented() || !inDom) return |
---|
171 | var that = this |
---|
172 | |
---|
173 | var $tip = this.tip() |
---|
174 | |
---|
175 | var tipId = this.getUID(this.type) |
---|
176 | |
---|
177 | this.setContent() |
---|
178 | $tip.attr('id', tipId) |
---|
179 | this.$element.attr('aria-describedby', tipId) |
---|
180 | |
---|
181 | if (this.options.animation) $tip.addClass('fade') |
---|
182 | |
---|
183 | var placement = typeof this.options.placement == 'function' ? |
---|
184 | this.options.placement.call(this, $tip[0], this.$element[0]) : |
---|
185 | this.options.placement |
---|
186 | |
---|
187 | var autoToken = /\s?auto?\s?/i |
---|
188 | var autoPlace = autoToken.test(placement) |
---|
189 | if (autoPlace) placement = placement.replace(autoToken, '') || 'top' |
---|
190 | |
---|
191 | $tip |
---|
192 | .detach() |
---|
193 | .css({ top: 0, left: 0, display: 'block' }) |
---|
194 | .addClass(placement) |
---|
195 | .data('bs.' + this.type, this) |
---|
196 | |
---|
197 | this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) |
---|
198 | |
---|
199 | var pos = this.getPosition() |
---|
200 | var actualWidth = $tip[0].offsetWidth |
---|
201 | var actualHeight = $tip[0].offsetHeight |
---|
202 | |
---|
203 | if (autoPlace) { |
---|
204 | var orgPlacement = placement |
---|
205 | var $parent = this.$element.parent() |
---|
206 | var parentDim = this.getPosition($parent) |
---|
207 | |
---|
208 | placement = placement == 'bottom' && pos.top + pos.height + actualHeight - parentDim.scroll > parentDim.height ? 'top' : |
---|
209 | placement == 'top' && pos.top - parentDim.scroll - actualHeight < 0 ? 'bottom' : |
---|
210 | placement == 'right' && pos.right + actualWidth > parentDim.width ? 'left' : |
---|
211 | placement == 'left' && pos.left - actualWidth < parentDim.left ? 'right' : |
---|
212 | placement |
---|
213 | |
---|
214 | $tip |
---|
215 | .removeClass(orgPlacement) |
---|
216 | .addClass(placement) |
---|
217 | } |
---|
218 | |
---|
219 | var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight) |
---|
220 | |
---|
221 | this.applyPlacement(calculatedOffset, placement) |
---|
222 | |
---|
223 | var complete = function () { |
---|
224 | that.$element.trigger('shown.bs.' + that.type) |
---|
225 | that.hoverState = null |
---|
226 | } |
---|
227 | |
---|
228 | $.support.transition && this.$tip.hasClass('fade') ? |
---|
229 | $tip |
---|
230 | .one('bsTransitionEnd', complete) |
---|
231 | .emulateTransitionEnd(150) : |
---|
232 | complete() |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | Tooltip.prototype.applyPlacement = function (offset, placement) { |
---|
237 | var $tip = this.tip() |
---|
238 | var width = $tip[0].offsetWidth |
---|
239 | var height = $tip[0].offsetHeight |
---|
240 | |
---|
241 | // manually read margins because getBoundingClientRect includes difference |
---|
242 | var marginTop = parseInt($tip.css('margin-top'), 10) |
---|
243 | var marginLeft = parseInt($tip.css('margin-left'), 10) |
---|
244 | |
---|
245 | // we must check for NaN for ie 8/9 |
---|
246 | if (isNaN(marginTop)) marginTop = 0 |
---|
247 | if (isNaN(marginLeft)) marginLeft = 0 |
---|
248 | |
---|
249 | offset.top = offset.top + marginTop |
---|
250 | offset.left = offset.left + marginLeft |
---|
251 | |
---|
252 | // $.fn.offset doesn't round pixel values |
---|
253 | // so we use setOffset directly with our own function B-0 |
---|
254 | $.offset.setOffset($tip[0], $.extend({ |
---|
255 | using: function (props) { |
---|
256 | $tip.css({ |
---|
257 | top: Math.round(props.top), |
---|
258 | left: Math.round(props.left) |
---|
259 | }) |
---|
260 | } |
---|
261 | }, offset), 0) |
---|
262 | |
---|
263 | $tip.addClass('in') |
---|
264 | |
---|
265 | // check to see if placing tip in new offset caused the tip to resize itself |
---|
266 | var actualWidth = $tip[0].offsetWidth |
---|
267 | var actualHeight = $tip[0].offsetHeight |
---|
268 | |
---|
269 | if (placement == 'top' && actualHeight != height) { |
---|
270 | offset.top = offset.top + height - actualHeight |
---|
271 | } |
---|
272 | |
---|
273 | var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight) |
---|
274 | |
---|
275 | if (delta.left) offset.left += delta.left |
---|
276 | else offset.top += delta.top |
---|
277 | |
---|
278 | var arrowDelta = delta.left ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight |
---|
279 | var arrowPosition = delta.left ? 'left' : 'top' |
---|
280 | var arrowOffsetPosition = delta.left ? 'offsetWidth' : 'offsetHeight' |
---|
281 | |
---|
282 | $tip.offset(offset) |
---|
283 | this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], arrowPosition) |
---|
284 | } |
---|
285 | |
---|
286 | Tooltip.prototype.replaceArrow = function (delta, dimension, position) { |
---|
287 | this.arrow().css(position, delta ? (50 * (1 - delta / dimension) + '%') : '') |
---|
288 | } |
---|
289 | |
---|
290 | Tooltip.prototype.setContent = function () { |
---|
291 | var $tip = this.tip() |
---|
292 | var title = this.getTitle() |
---|
293 | |
---|
294 | $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title) |
---|
295 | $tip.removeClass('fade in top bottom left right') |
---|
296 | } |
---|
297 | |
---|
298 | Tooltip.prototype.hide = function () { |
---|
299 | var that = this |
---|
300 | var $tip = this.tip() |
---|
301 | var e = $.Event('hide.bs.' + this.type) |
---|
302 | |
---|
303 | this.$element.removeAttr('aria-describedby') |
---|
304 | |
---|
305 | function complete() { |
---|
306 | if (that.hoverState != 'in') $tip.detach() |
---|
307 | that.$element.trigger('hidden.bs.' + that.type) |
---|
308 | } |
---|
309 | |
---|
310 | this.$element.trigger(e) |
---|
311 | |
---|
312 | if (e.isDefaultPrevented()) return |
---|
313 | |
---|
314 | $tip.removeClass('in') |
---|
315 | |
---|
316 | $.support.transition && this.$tip.hasClass('fade') ? |
---|
317 | $tip |
---|
318 | .one('bsTransitionEnd', complete) |
---|
319 | .emulateTransitionEnd(150) : |
---|
320 | complete() |
---|
321 | |
---|
322 | this.hoverState = null |
---|
323 | |
---|
324 | return this |
---|
325 | } |
---|
326 | |
---|
327 | Tooltip.prototype.fixTitle = function () { |
---|
328 | var $e = this.$element |
---|
329 | if ($e.attr('title') || typeof ($e.attr('data-original-title')) != 'string') { |
---|
330 | $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | Tooltip.prototype.hasContent = function () { |
---|
335 | return this.getTitle() |
---|
336 | } |
---|
337 | |
---|
338 | Tooltip.prototype.getPosition = function ($element) { |
---|
339 | $element = $element || this.$element |
---|
340 | var el = $element[0] |
---|
341 | var isBody = el.tagName == 'BODY' |
---|
342 | return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : null, { |
---|
343 | scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop(), |
---|
344 | width: isBody ? $(window).width() : $element.outerWidth(), |
---|
345 | height: isBody ? $(window).height() : $element.outerHeight() |
---|
346 | }, isBody ? { top: 0, left: 0 } : $element.offset()) |
---|
347 | } |
---|
348 | |
---|
349 | Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { |
---|
350 | return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } : |
---|
351 | placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } : |
---|
352 | placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } : |
---|
353 | /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width } |
---|
354 | |
---|
355 | } |
---|
356 | |
---|
357 | Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) { |
---|
358 | var delta = { top: 0, left: 0 } |
---|
359 | if (!this.$viewport) return delta |
---|
360 | |
---|
361 | var viewportPadding = this.options.viewport && this.options.viewport.padding || 0 |
---|
362 | var viewportDimensions = this.getPosition(this.$viewport) |
---|
363 | |
---|
364 | if (/right|left/.test(placement)) { |
---|
365 | var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll |
---|
366 | var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight |
---|
367 | if (topEdgeOffset < viewportDimensions.top) { // top overflow |
---|
368 | delta.top = viewportDimensions.top - topEdgeOffset |
---|
369 | } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow |
---|
370 | delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset |
---|
371 | } |
---|
372 | } else { |
---|
373 | var leftEdgeOffset = pos.left - viewportPadding |
---|
374 | var rightEdgeOffset = pos.left + viewportPadding + actualWidth |
---|
375 | if (leftEdgeOffset < viewportDimensions.left) { // left overflow |
---|
376 | delta.left = viewportDimensions.left - leftEdgeOffset |
---|
377 | } else if (rightEdgeOffset > viewportDimensions.width) { // right overflow |
---|
378 | delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | return delta |
---|
383 | } |
---|
384 | |
---|
385 | Tooltip.prototype.getTitle = function () { |
---|
386 | var title |
---|
387 | var $e = this.$element |
---|
388 | var o = this.options |
---|
389 | |
---|
390 | title = $e.attr('data-original-title') |
---|
391 | || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title) |
---|
392 | |
---|
393 | return title |
---|
394 | } |
---|
395 | |
---|
396 | Tooltip.prototype.getUID = function (prefix) { |
---|
397 | do prefix += ~~(Math.random() * 1000000) |
---|
398 | while (document.getElementById(prefix)) |
---|
399 | return prefix |
---|
400 | } |
---|
401 | |
---|
402 | Tooltip.prototype.tip = function () { |
---|
403 | return (this.$tip = this.$tip || $(this.options.template)) |
---|
404 | } |
---|
405 | |
---|
406 | Tooltip.prototype.arrow = function () { |
---|
407 | return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')) |
---|
408 | } |
---|
409 | |
---|
410 | Tooltip.prototype.validate = function () { |
---|
411 | if (!this.$element[0].parentNode) { |
---|
412 | this.hide() |
---|
413 | this.$element = null |
---|
414 | this.options = null |
---|
415 | } |
---|
416 | } |
---|
417 | |
---|
418 | Tooltip.prototype.enable = function () { |
---|
419 | this.enabled = true |
---|
420 | } |
---|
421 | |
---|
422 | Tooltip.prototype.disable = function () { |
---|
423 | this.enabled = false |
---|
424 | } |
---|
425 | |
---|
426 | Tooltip.prototype.toggleEnabled = function () { |
---|
427 | this.enabled = !this.enabled |
---|
428 | } |
---|
429 | |
---|
430 | Tooltip.prototype.toggle = function (e) { |
---|
431 | var self = this |
---|
432 | if (e) { |
---|
433 | self = $(e.currentTarget).data('bs.' + this.type) |
---|
434 | if (!self) { |
---|
435 | self = new this.constructor(e.currentTarget, this.getDelegateOptions()) |
---|
436 | $(e.currentTarget).data('bs.' + this.type, self) |
---|
437 | } |
---|
438 | } |
---|
439 | |
---|
440 | self.tip().hasClass('in') ? self.leave(self) : self.enter(self) |
---|
441 | } |
---|
442 | |
---|
443 | Tooltip.prototype.destroy = function () { |
---|
444 | clearTimeout(this.timeout) |
---|
445 | this.hide().$element.off('.' + this.type).removeData('bs.' + this.type) |
---|
446 | } |
---|
447 | |
---|
448 | |
---|
449 | // TOOLTIP PLUGIN DEFINITION |
---|
450 | // ========================= |
---|
451 | |
---|
452 | function Plugin(option) { |
---|
453 | return this.each(function () { |
---|
454 | var $this = $(this) |
---|
455 | var data = $this.data('bs.tooltip') |
---|
456 | var options = typeof option == 'object' && option |
---|
457 | |
---|
458 | if (!data && option == 'destroy') return |
---|
459 | if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options))) |
---|
460 | if (typeof option == 'string') data[option]() |
---|
461 | }) |
---|
462 | } |
---|
463 | |
---|
464 | var old = $.fn.tooltip |
---|
465 | |
---|
466 | $.fn.tooltip = Plugin |
---|
467 | $.fn.tooltip.Constructor = Tooltip |
---|
468 | |
---|
469 | |
---|
470 | // TOOLTIP NO CONFLICT |
---|
471 | // =================== |
---|
472 | |
---|
473 | $.fn.tooltip.noConflict = function () { |
---|
474 | $.fn.tooltip = old |
---|
475 | return this |
---|
476 | } |
---|
477 | |
---|
478 | }(jQuery); |
---|
479 | |
---|
480 | /* ======================================================================== |
---|
481 | * Bootstrap: popover.js v3.2.0 |
---|
482 | * http://getbootstrap.com/javascript/#popovers |
---|
483 | * ======================================================================== |
---|
484 | * Copyright 2011-2014 Twitter, Inc. |
---|
485 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) |
---|
486 | * ======================================================================== */ |
---|
487 | |
---|
488 | |
---|
489 | +function ($) { |
---|
490 | 'use strict'; |
---|
491 | |
---|
492 | // POPOVER PUBLIC CLASS DEFINITION |
---|
493 | // =============================== |
---|
494 | |
---|
495 | var Popover = function (element, options) { |
---|
496 | this.init('popover', element, options) |
---|
497 | } |
---|
498 | |
---|
499 | if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js') |
---|
500 | |
---|
501 | Popover.VERSION = '3.2.0' |
---|
502 | |
---|
503 | Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, { |
---|
504 | placement: 'right', |
---|
505 | trigger: 'click', |
---|
506 | content: '', |
---|
507 | template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>' |
---|
508 | }) |
---|
509 | |
---|
510 | |
---|
511 | // NOTE: POPOVER EXTENDS tooltip.js |
---|
512 | // ================================ |
---|
513 | |
---|
514 | Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype) |
---|
515 | |
---|
516 | Popover.prototype.constructor = Popover |
---|
517 | |
---|
518 | Popover.prototype.getDefaults = function () { |
---|
519 | return Popover.DEFAULTS |
---|
520 | } |
---|
521 | |
---|
522 | Popover.prototype.setContent = function () { |
---|
523 | var $tip = this.tip() |
---|
524 | var title = this.getTitle() |
---|
525 | var content = this.getContent() |
---|
526 | |
---|
527 | $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title) |
---|
528 | $tip.find('.popover-content').empty()[ // we use append for html objects to maintain js events |
---|
529 | this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text' |
---|
530 | ](content) |
---|
531 | |
---|
532 | $tip.removeClass('fade top bottom left right in') |
---|
533 | |
---|
534 | // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do |
---|
535 | // this manually by checking the contents. |
---|
536 | if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide() |
---|
537 | } |
---|
538 | |
---|
539 | Popover.prototype.hasContent = function () { |
---|
540 | return this.getTitle() || this.getContent() |
---|
541 | } |
---|
542 | |
---|
543 | Popover.prototype.getContent = function () { |
---|
544 | var $e = this.$element |
---|
545 | var o = this.options |
---|
546 | |
---|
547 | return $e.attr('data-content') |
---|
548 | || (typeof o.content == 'function' ? |
---|
549 | o.content.call($e[0]) : |
---|
550 | o.content) |
---|
551 | } |
---|
552 | |
---|
553 | Popover.prototype.arrow = function () { |
---|
554 | return (this.$arrow = this.$arrow || this.tip().find('.arrow')) |
---|
555 | } |
---|
556 | |
---|
557 | Popover.prototype.tip = function () { |
---|
558 | if (!this.$tip) this.$tip = $(this.options.template) |
---|
559 | return this.$tip |
---|
560 | } |
---|
561 | |
---|
562 | |
---|
563 | // POPOVER PLUGIN DEFINITION |
---|
564 | // ========================= |
---|
565 | |
---|
566 | function Plugin(option) { |
---|
567 | return this.each(function () { |
---|
568 | var $this = $(this) |
---|
569 | var data = $this.data('bs.popover') |
---|
570 | var options = typeof option == 'object' && option |
---|
571 | |
---|
572 | if (!data && option == 'destroy') return |
---|
573 | if (!data) $this.data('bs.popover', (data = new Popover(this, options))) |
---|
574 | if (typeof option == 'string') data[option]() |
---|
575 | }) |
---|
576 | } |
---|
577 | |
---|
578 | var old = $.fn.popover |
---|
579 | |
---|
580 | $.fn.popover = Plugin |
---|
581 | $.fn.popover.Constructor = Popover |
---|
582 | |
---|
583 | |
---|
584 | // POPOVER NO CONFLICT |
---|
585 | // =================== |
---|
586 | |
---|
587 | $.fn.popover.noConflict = function () { |
---|
588 | $.fn.popover = old |
---|
589 | return this |
---|
590 | } |
---|
591 | |
---|
592 | }(jQuery); |
---|
593 | |
---|
594 | (function($, window) { |
---|
595 | var Tour, document; |
---|
596 | document = window.document; |
---|
597 | Tour = (function() { |
---|
598 | function Tour(options) { |
---|
599 | var storage; |
---|
600 | try { |
---|
601 | storage = window.localStorage; |
---|
602 | } catch (_error) { |
---|
603 | storage = false; |
---|
604 | } |
---|
605 | this._options = $.extend({ |
---|
606 | name: 'tour', |
---|
607 | steps: [], |
---|
608 | container: 'body', |
---|
609 | autoscroll: true, |
---|
610 | keyboard: true, |
---|
611 | storage: storage, |
---|
612 | debug: false, |
---|
613 | backdrop: false, |
---|
614 | backdropPadding: 0, |
---|
615 | redirect: true, |
---|
616 | orphan: false, |
---|
617 | duration: false, |
---|
618 | delay: false, |
---|
619 | basePath: '', |
---|
620 | 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>', |
---|
621 | afterSetState: function(key, value) {}, |
---|
622 | afterGetState: function(key, value) {}, |
---|
623 | afterRemoveState: function(key) {}, |
---|
624 | onStart: function(tour) {}, |
---|
625 | onEnd: function(tour) {}, |
---|
626 | onShow: function(tour) {}, |
---|
627 | onShown: function(tour) {}, |
---|
628 | onHide: function(tour) {}, |
---|
629 | onHidden: function(tour) {}, |
---|
630 | onNext: function(tour) {}, |
---|
631 | onPrev: function(tour) {}, |
---|
632 | onPause: function(tour, duration) {}, |
---|
633 | onResume: function(tour, duration) {} |
---|
634 | }, options); |
---|
635 | this._force = false; |
---|
636 | this._inited = false; |
---|
637 | this.backdrop = { |
---|
638 | overlay: null, |
---|
639 | $element: null, |
---|
640 | $background: null, |
---|
641 | backgroundShown: false, |
---|
642 | overlayElementShown: false |
---|
643 | }; |
---|
644 | this; |
---|
645 | } |
---|
646 | |
---|
647 | Tour.prototype.addSteps = function(steps) { |
---|
648 | var step, _i, _len; |
---|
649 | for (_i = 0, _len = steps.length; _i < _len; _i++) { |
---|
650 | step = steps[_i]; |
---|
651 | this.addStep(step); |
---|
652 | } |
---|
653 | return this; |
---|
654 | }; |
---|
655 | |
---|
656 | Tour.prototype.addStep = function(step) { |
---|
657 | this._options.steps.push(step); |
---|
658 | return this; |
---|
659 | }; |
---|
660 | |
---|
661 | Tour.prototype.getStep = function(i) { |
---|
662 | if (this._options.steps[i] != null) { |
---|
663 | return $.extend({ |
---|
664 | id: "step-" + i, |
---|
665 | path: '', |
---|
666 | placement: 'right', |
---|
667 | title: '', |
---|
668 | content: '<p></p>', |
---|
669 | next: i === this._options.steps.length - 1 ? -1 : i + 1, |
---|
670 | prev: i - 1, |
---|
671 | animation: true, |
---|
672 | container: this._options.container, |
---|
673 | autoscroll: this._options.autoscroll, |
---|
674 | backdrop: this._options.backdrop, |
---|
675 | backdropPadding: this._options.backdropPadding, |
---|
676 | redirect: this._options.redirect, |
---|
677 | orphan: this._options.orphan, |
---|
678 | duration: this._options.duration, |
---|
679 | delay: this._options.delay, |
---|
680 | template: this._options.template, |
---|
681 | onShow: this._options.onShow, |
---|
682 | onShown: this._options.onShown, |
---|
683 | onHide: this._options.onHide, |
---|
684 | onHidden: this._options.onHidden, |
---|
685 | onNext: this._options.onNext, |
---|
686 | onPrev: this._options.onPrev, |
---|
687 | onPause: this._options.onPause, |
---|
688 | onResume: this._options.onResume |
---|
689 | }, this._options.steps[i]); |
---|
690 | } |
---|
691 | }; |
---|
692 | |
---|
693 | Tour.prototype.init = function(force) { |
---|
694 | this._force = force; |
---|
695 | if (this.ended()) { |
---|
696 | this._debug('Tour ended, init prevented.'); |
---|
697 | return this; |
---|
698 | } |
---|
699 | this.setCurrentStep(); |
---|
700 | this._initMouseNavigation(); |
---|
701 | this._initKeyboardNavigation(); |
---|
702 | this._onResize((function(_this) { |
---|
703 | return function() { |
---|
704 | return _this.showStep(_this._current); |
---|
705 | }; |
---|
706 | })(this)); |
---|
707 | if (this._current !== null) { |
---|
708 | this.showStep(this._current); |
---|
709 | } |
---|
710 | this._inited = true; |
---|
711 | return this; |
---|
712 | }; |
---|
713 | |
---|
714 | Tour.prototype.start = function(force) { |
---|
715 | var promise; |
---|
716 | if (force == null) { |
---|
717 | force = false; |
---|
718 | } |
---|
719 | if (!this._inited) { |
---|
720 | this.init(force); |
---|
721 | } |
---|
722 | if (this._current === null) { |
---|
723 | promise = this._makePromise(this._options.onStart != null ? this._options.onStart(this) : void 0); |
---|
724 | this._callOnPromiseDone(promise, this.showStep, 0); |
---|
725 | } |
---|
726 | return this; |
---|
727 | }; |
---|
728 | |
---|
729 | Tour.prototype.next = function() { |
---|
730 | var promise; |
---|
731 | promise = this.hideStep(this._current); |
---|
732 | return this._callOnPromiseDone(promise, this._showNextStep); |
---|
733 | }; |
---|
734 | |
---|
735 | Tour.prototype.prev = function() { |
---|
736 | var promise; |
---|
737 | promise = this.hideStep(this._current); |
---|
738 | return this._callOnPromiseDone(promise, this._showPrevStep); |
---|
739 | }; |
---|
740 | |
---|
741 | Tour.prototype.goTo = function(i) { |
---|
742 | var promise; |
---|
743 | promise = this.hideStep(this._current); |
---|
744 | return this._callOnPromiseDone(promise, this.showStep, i); |
---|
745 | }; |
---|
746 | |
---|
747 | Tour.prototype.end = function() { |
---|
748 | var endHelper, promise; |
---|
749 | endHelper = (function(_this) { |
---|
750 | return function(e) { |
---|
751 | $(document).off("click.tour-" + _this._options.name); |
---|
752 | $(document).off("keyup.tour-" + _this._options.name); |
---|
753 | $(window).off("resize.tour-" + _this._options.name); |
---|
754 | _this._setState('end', 'yes'); |
---|
755 | _this._inited = false; |
---|
756 | _this._force = false; |
---|
757 | _this._clearTimer(); |
---|
758 | if (_this._options.onEnd != null) { |
---|
759 | return _this._options.onEnd(_this); |
---|
760 | } |
---|
761 | }; |
---|
762 | })(this); |
---|
763 | promise = this.hideStep(this._current); |
---|
764 | return this._callOnPromiseDone(promise, endHelper); |
---|
765 | }; |
---|
766 | |
---|
767 | Tour.prototype.ended = function() { |
---|
768 | return !this._force && !!this._getState('end'); |
---|
769 | }; |
---|
770 | |
---|
771 | Tour.prototype.restart = function() { |
---|
772 | this._removeState('current_step'); |
---|
773 | this._removeState('end'); |
---|
774 | return this.start(); |
---|
775 | }; |
---|
776 | |
---|
777 | Tour.prototype.pause = function() { |
---|
778 | var step; |
---|
779 | step = this.getStep(this._current); |
---|
780 | if (!(step && step.duration)) { |
---|
781 | return this; |
---|
782 | } |
---|
783 | this._paused = true; |
---|
784 | this._duration -= new Date().getTime() - this._start; |
---|
785 | window.clearTimeout(this._timer); |
---|
786 | this._debug("Paused/Stopped step " + (this._current + 1) + " timer (" + this._duration + " remaining)."); |
---|
787 | if (step.onPause != null) { |
---|
788 | return step.onPause(this, this._duration); |
---|
789 | } |
---|
790 | }; |
---|
791 | |
---|
792 | Tour.prototype.resume = function() { |
---|
793 | var step; |
---|
794 | step = this.getStep(this._current); |
---|
795 | if (!(step && step.duration)) { |
---|
796 | return this; |
---|
797 | } |
---|
798 | this._paused = false; |
---|
799 | this._start = new Date().getTime(); |
---|
800 | this._duration = this._duration || step.duration; |
---|
801 | this._timer = window.setTimeout((function(_this) { |
---|
802 | return function() { |
---|
803 | if (_this._isLast()) { |
---|
804 | return _this.next(); |
---|
805 | } else { |
---|
806 | return _this.end(); |
---|
807 | } |
---|
808 | }; |
---|
809 | })(this), this._duration); |
---|
810 | this._debug("Started step " + (this._current + 1) + " timer with duration " + this._duration); |
---|
811 | if ((step.onResume != null) && this._duration !== step.duration) { |
---|
812 | return step.onResume(this, this._duration); |
---|
813 | } |
---|
814 | }; |
---|
815 | |
---|
816 | Tour.prototype.hideStep = function(i) { |
---|
817 | var hideStepHelper, promise, step; |
---|
818 | step = this.getStep(i); |
---|
819 | if (!step) { |
---|
820 | return; |
---|
821 | } |
---|
822 | this._clearTimer(); |
---|
823 | promise = this._makePromise(step.onHide != null ? step.onHide(this, i) : void 0); |
---|
824 | hideStepHelper = (function(_this) { |
---|
825 | return function(e) { |
---|
826 | var $element; |
---|
827 | $element = $(step.element); |
---|
828 | if (!($element.data('bs.popover') || $element.data('popover'))) { |
---|
829 | $element = $('body'); |
---|
830 | } |
---|
831 | $element.popover('destroy').removeClass("tour-" + _this._options.name + "-element tour-" + _this._options.name + "-" + i + "-element"); |
---|
832 | if (step.reflex) { |
---|
833 | $element.removeClass('tour-step-element-reflex').off("" + (_this._reflexEvent(step.reflex)) + ".tour-" + _this._options.name); |
---|
834 | } |
---|
835 | if (step.backdrop) { |
---|
836 | _this._hideBackdrop(); |
---|
837 | } |
---|
838 | if (step.onHidden != null) { |
---|
839 | return step.onHidden(_this); |
---|
840 | } |
---|
841 | }; |
---|
842 | })(this); |
---|
843 | this._callOnPromiseDone(promise, hideStepHelper); |
---|
844 | return promise; |
---|
845 | }; |
---|
846 | |
---|
847 | Tour.prototype.showStep = function(i) { |
---|
848 | var promise, showStepHelper, skipToPrevious, step; |
---|
849 | if (this.ended()) { |
---|
850 | this._debug('Tour ended, showStep prevented.'); |
---|
851 | return this; |
---|
852 | } |
---|
853 | step = this.getStep(i); |
---|
854 | if (!step) { |
---|
855 | return; |
---|
856 | } |
---|
857 | skipToPrevious = i < this._current; |
---|
858 | promise = this._makePromise(step.onShow != null ? step.onShow(this, i) : void 0); |
---|
859 | showStepHelper = (function(_this) { |
---|
860 | return function(e) { |
---|
861 | var current_path, path, showPopoverAndOverlay; |
---|
862 | _this.setCurrentStep(i); |
---|
863 | path = (function() { |
---|
864 | switch ({}.toString.call(step.path)) { |
---|
865 | case '[object Function]': |
---|
866 | return step.path(); |
---|
867 | case '[object String]': |
---|
868 | return this._options.basePath + step.path; |
---|
869 | default: |
---|
870 | return step.path; |
---|
871 | } |
---|
872 | }).call(_this); |
---|
873 | current_path = document.location.href; |
---|
874 | if (_this._isRedirect(path, current_path)) { |
---|
875 | if ({}.toString.call(path) === "[object RegExp]") { |
---|
876 | _this._redirect(step, path); |
---|
877 | } |
---|
878 | else { |
---|
879 | path = document.location.protocol+'//'+path; |
---|
880 | _this._redirect(step, path); |
---|
881 | } |
---|
882 | return; |
---|
883 | } |
---|
884 | if (_this._isOrphan(step)) { |
---|
885 | if (!step.orphan) { |
---|
886 | _this._debug("Skip the orphan step " + (_this._current + 1) + ".\nOrphan option is false and the element does not exist or is hidden."); |
---|
887 | if (skipToPrevious) { |
---|
888 | _this._showPrevStep(); |
---|
889 | } else { |
---|
890 | _this._showNextStep(); |
---|
891 | } |
---|
892 | return; |
---|
893 | } |
---|
894 | _this._debug("Show the orphan step " + (_this._current + 1) + ". Orphans option is true."); |
---|
895 | } |
---|
896 | if (step.title === "" & step.content === "") { |
---|
897 | if (skipToPrevious) { |
---|
898 | _this._showPrevStep(); |
---|
899 | } else { |
---|
900 | _this._showNextStep(); |
---|
901 | } |
---|
902 | return; |
---|
903 | } |
---|
904 | if (step.backdrop) { |
---|
905 | _this._showBackdrop(!_this._isOrphan(step) ? step.element : void 0); |
---|
906 | } |
---|
907 | showPopoverAndOverlay = function() { |
---|
908 | if (_this.getCurrentStep() !== i) { |
---|
909 | return; |
---|
910 | } |
---|
911 | if ((step.element != null) && step.backdrop) { |
---|
912 | _this._showOverlayElement(step); |
---|
913 | } |
---|
914 | _this._showPopover(step, i); |
---|
915 | if (step.onShown != null) { |
---|
916 | step.onShown(_this); |
---|
917 | } |
---|
918 | return _this._debug("Step " + (_this._current + 1) + " of " + _this._options.steps.length); |
---|
919 | }; |
---|
920 | if (step.autoscroll) { |
---|
921 | _this._scrollIntoView(step.element, showPopoverAndOverlay); |
---|
922 | } else { |
---|
923 | showPopoverAndOverlay(); |
---|
924 | } |
---|
925 | if (step.duration) { |
---|
926 | return _this.resume(); |
---|
927 | } |
---|
928 | }; |
---|
929 | })(this); |
---|
930 | if (step.delay) { |
---|
931 | this._debug("Wait " + step.delay + " milliseconds to show the step " + (this._current + 1)); |
---|
932 | window.setTimeout((function(_this) { |
---|
933 | return function() { |
---|
934 | return _this._callOnPromiseDone(promise, showStepHelper); |
---|
935 | }; |
---|
936 | })(this), step.delay); |
---|
937 | } else { |
---|
938 | this._callOnPromiseDone(promise, showStepHelper); |
---|
939 | } |
---|
940 | return promise; |
---|
941 | }; |
---|
942 | |
---|
943 | Tour.prototype.getCurrentStep = function() { |
---|
944 | return this._current; |
---|
945 | }; |
---|
946 | |
---|
947 | Tour.prototype.setCurrentStep = function(value) { |
---|
948 | if (value != null) { |
---|
949 | this._current = value; |
---|
950 | this._setState('current_step', value); |
---|
951 | } else { |
---|
952 | this._current = this._getState('current_step'); |
---|
953 | this._current = this._current === null ? null : parseInt(this._current, 10); |
---|
954 | } |
---|
955 | return this; |
---|
956 | }; |
---|
957 | |
---|
958 | Tour.prototype._setState = function(key, value) { |
---|
959 | var e, keyName; |
---|
960 | if (this._options.storage) { |
---|
961 | keyName = "" + this._options.name + "_" + key; |
---|
962 | try { |
---|
963 | this._options.storage.setItem(keyName, value); |
---|
964 | } catch (_error) { |
---|
965 | e = _error; |
---|
966 | if (e.code === DOMException.QUOTA_EXCEEDED_ERR) { |
---|
967 | this._debug('LocalStorage quota exceeded. State storage failed.'); |
---|
968 | } |
---|
969 | } |
---|
970 | return this._options.afterSetState(keyName, value); |
---|
971 | } else { |
---|
972 | if (this._state == null) { |
---|
973 | this._state = {}; |
---|
974 | } |
---|
975 | return this._state[key] = value; |
---|
976 | } |
---|
977 | }; |
---|
978 | |
---|
979 | Tour.prototype._removeState = function(key) { |
---|
980 | var keyName; |
---|
981 | if (this._options.storage) { |
---|
982 | keyName = "" + this._options.name + "_" + key; |
---|
983 | this._options.storage.removeItem(keyName); |
---|
984 | return this._options.afterRemoveState(keyName); |
---|
985 | } else { |
---|
986 | if (this._state != null) { |
---|
987 | return delete this._state[key]; |
---|
988 | } |
---|
989 | } |
---|
990 | }; |
---|
991 | |
---|
992 | Tour.prototype._getState = function(key) { |
---|
993 | var keyName, value; |
---|
994 | if (this._options.storage) { |
---|
995 | keyName = "" + this._options.name + "_" + key; |
---|
996 | value = this._options.storage.getItem(keyName); |
---|
997 | } else { |
---|
998 | if (this._state != null) { |
---|
999 | value = this._state[key]; |
---|
1000 | } |
---|
1001 | } |
---|
1002 | if (value === void 0 || value === 'null') { |
---|
1003 | value = null; |
---|
1004 | } |
---|
1005 | this._options.afterGetState(key, value); |
---|
1006 | return value; |
---|
1007 | }; |
---|
1008 | |
---|
1009 | Tour.prototype._showNextStep = function() { |
---|
1010 | var promise, showNextStepHelper, step; |
---|
1011 | step = this.getStep(this._current); |
---|
1012 | showNextStepHelper = (function(_this) { |
---|
1013 | return function(e) { |
---|
1014 | return _this.showStep(step.next); |
---|
1015 | }; |
---|
1016 | })(this); |
---|
1017 | promise = this._makePromise(step.onNext != null ? step.onNext(this) : void 0); |
---|
1018 | return this._callOnPromiseDone(promise, showNextStepHelper); |
---|
1019 | }; |
---|
1020 | |
---|
1021 | Tour.prototype._showPrevStep = function() { |
---|
1022 | var promise, showPrevStepHelper, step; |
---|
1023 | step = this.getStep(this._current); |
---|
1024 | showPrevStepHelper = (function(_this) { |
---|
1025 | return function(e) { |
---|
1026 | return _this.showStep(step.prev); |
---|
1027 | }; |
---|
1028 | })(this); |
---|
1029 | promise = this._makePromise(step.onPrev != null ? step.onPrev(this) : void 0); |
---|
1030 | return this._callOnPromiseDone(promise, showPrevStepHelper); |
---|
1031 | }; |
---|
1032 | |
---|
1033 | Tour.prototype._debug = function(text) { |
---|
1034 | if (this._options.debug) { |
---|
1035 | return window.console.log("Bootstrap Tour '" + this._options.name + "' | " + text); |
---|
1036 | } |
---|
1037 | }; |
---|
1038 | |
---|
1039 | Tour.prototype._isRedirect = function(path, currentPath) { |
---|
1040 | return (path != null) && path !== '' && (({}.toString.call(path) === '[object RegExp]' && !path.test(currentPath)) || ({}.toString.call(path) === '[object String]' && path !== currentPath.replace("http://", "").replace("https://", ""))); |
---|
1041 | }; |
---|
1042 | |
---|
1043 | Tour.prototype._redirect = function(step, path) { |
---|
1044 | if ($.isFunction(step.redirect)) { |
---|
1045 | return step.redirect.call(this, path); |
---|
1046 | } else if (step.redirect === true) { |
---|
1047 | this._debug("Redirect to " + path); |
---|
1048 | return document.location.href = path; |
---|
1049 | } |
---|
1050 | }; |
---|
1051 | |
---|
1052 | Tour.prototype._isOrphan = function(step) { |
---|
1053 | return (step.element == null) || !$(step.element).length || $(step.element).is(':hidden') && ($(step.element)[0].namespaceURI !== 'http://www.w3.org/2000/svg'); |
---|
1054 | }; |
---|
1055 | |
---|
1056 | Tour.prototype._isLast = function() { |
---|
1057 | return this._current < this._options.steps.length - 1; |
---|
1058 | }; |
---|
1059 | |
---|
1060 | Tour.prototype._showPopover = function(step, i) { |
---|
1061 | var $element, $tip, isOrphan, options; |
---|
1062 | $(".tour-" + this._options.name).remove(); |
---|
1063 | options = $.extend({}, this._options); |
---|
1064 | isOrphan = this._isOrphan(step); |
---|
1065 | step.template = this._template(step, i); |
---|
1066 | if (isOrphan) { |
---|
1067 | step.element = 'body'; |
---|
1068 | step.placement = 'top'; |
---|
1069 | } |
---|
1070 | $element = $(step.element); |
---|
1071 | $element.addClass("tour-" + this._options.name + "-element tour-" + this._options.name + "-" + i + "-element"); |
---|
1072 | if (step.options) { |
---|
1073 | $.extend(options, step.options); |
---|
1074 | } |
---|
1075 | if (step.reflex && !isOrphan) { |
---|
1076 | $element.addClass('tour-step-element-reflex'); |
---|
1077 | $element.off("" + (this._reflexEvent(step.reflex)) + ".tour-" + this._options.name); |
---|
1078 | $element.on("" + (this._reflexEvent(step.reflex)) + ".tour-" + this._options.name, (function(_this) { |
---|
1079 | return function() { |
---|
1080 | if (_this._isLast()) { |
---|
1081 | return _this.next(); |
---|
1082 | } else { |
---|
1083 | return _this.end(); |
---|
1084 | } |
---|
1085 | }; |
---|
1086 | })(this)); |
---|
1087 | } |
---|
1088 | $element.popover({ |
---|
1089 | placement: step.placement, |
---|
1090 | trigger: 'manual', |
---|
1091 | title: step.title, |
---|
1092 | content: step.content, |
---|
1093 | html: true, |
---|
1094 | animation: step.animation, |
---|
1095 | container: step.container, |
---|
1096 | template: step.template, |
---|
1097 | selector: step.element |
---|
1098 | }).popover('show'); |
---|
1099 | $tip = $element.data('bs.popover') ? $element.data('bs.popover').tip() : $element.data('popover').tip(); |
---|
1100 | $tip.attr('id', step.id); |
---|
1101 | this._reposition($tip, step); |
---|
1102 | if (isOrphan) { |
---|
1103 | return this._center($tip); |
---|
1104 | } |
---|
1105 | }; |
---|
1106 | |
---|
1107 | Tour.prototype._template = function(step, i) { |
---|
1108 | var $navigation, $next, $prev, $resume, $template; |
---|
1109 | $template = $.isFunction(step.template) ? $(step.template(i, step)) : $(step.template); |
---|
1110 | $navigation = $template.find('.popover-navigation'); |
---|
1111 | $prev = $navigation.find('[data-role="prev"]'); |
---|
1112 | $next = $navigation.find('[data-role="next"]'); |
---|
1113 | $resume = $navigation.find('[data-role="pause-resume"]'); |
---|
1114 | if (this._isOrphan(step)) { |
---|
1115 | $template.addClass('orphan'); |
---|
1116 | } |
---|
1117 | $template.addClass("tour-" + this._options.name + " tour-" + this._options.name + "-" + i); |
---|
1118 | if (step.prev < 0) { |
---|
1119 | $prev.addClass('disabled'); |
---|
1120 | } |
---|
1121 | if (step.next < 0) { |
---|
1122 | $next.addClass('disabled'); |
---|
1123 | } |
---|
1124 | if (!step.duration) { |
---|
1125 | $resume.remove(); |
---|
1126 | } |
---|
1127 | return $template.clone().wrap('<div>').parent().html(); |
---|
1128 | }; |
---|
1129 | |
---|
1130 | Tour.prototype._reflexEvent = function(reflex) { |
---|
1131 | if ({}.toString.call(reflex) === '[object Boolean]') { |
---|
1132 | return 'click'; |
---|
1133 | } else { |
---|
1134 | return reflex; |
---|
1135 | } |
---|
1136 | }; |
---|
1137 | |
---|
1138 | Tour.prototype._reposition = function($tip, step) { |
---|
1139 | var offsetBottom, offsetHeight, offsetRight, offsetWidth, originalLeft, originalTop, tipOffset; |
---|
1140 | offsetWidth = $tip[0].offsetWidth; |
---|
1141 | offsetHeight = $tip[0].offsetHeight; |
---|
1142 | tipOffset = $tip.offset(); |
---|
1143 | originalLeft = tipOffset.left; |
---|
1144 | originalTop = tipOffset.top; |
---|
1145 | offsetBottom = $(document).outerHeight() - tipOffset.top - $tip.outerHeight(); |
---|
1146 | if (offsetBottom < 0) { |
---|
1147 | tipOffset.top = tipOffset.top + offsetBottom; |
---|
1148 | } |
---|
1149 | offsetRight = $('html').outerWidth() - tipOffset.left - $tip.outerWidth(); |
---|
1150 | if (offsetRight < 0) { |
---|
1151 | tipOffset.left = tipOffset.left + offsetRight; |
---|
1152 | } |
---|
1153 | if (tipOffset.top < 0) { |
---|
1154 | tipOffset.top = 0; |
---|
1155 | } |
---|
1156 | if (tipOffset.left < 0) { |
---|
1157 | tipOffset.left = 0; |
---|
1158 | } |
---|
1159 | $tip.offset(tipOffset); |
---|
1160 | if (step.placement === 'bottom' || step.placement === 'top') { |
---|
1161 | if (originalLeft !== tipOffset.left) { |
---|
1162 | return this._replaceArrow($tip, (tipOffset.left - originalLeft) * 2, offsetWidth, 'left'); |
---|
1163 | } |
---|
1164 | } else { |
---|
1165 | if (originalTop !== tipOffset.top) { |
---|
1166 | return this._replaceArrow($tip, (tipOffset.top - originalTop) * 2, offsetHeight, 'top'); |
---|
1167 | } |
---|
1168 | } |
---|
1169 | }; |
---|
1170 | |
---|
1171 | Tour.prototype._center = function($tip) { |
---|
1172 | return $tip.css('top', $(window).outerHeight() / 2 - $tip.outerHeight() / 2); |
---|
1173 | }; |
---|
1174 | |
---|
1175 | Tour.prototype._replaceArrow = function($tip, delta, dimension, position) { |
---|
1176 | return $tip.find('.arrow').css(position, delta ? 50 * (1 - delta / dimension) + '%' : ''); |
---|
1177 | }; |
---|
1178 | |
---|
1179 | Tour.prototype._scrollIntoView = function(element, callback) { |
---|
1180 | var $element, $window, counter, offsetTop, scrollTop, windowHeight; |
---|
1181 | $element = $(element); |
---|
1182 | if (!$element.length) { |
---|
1183 | return callback(); |
---|
1184 | } |
---|
1185 | $window = $(window); |
---|
1186 | offsetTop = $element.offset().top; |
---|
1187 | windowHeight = $window.height(); |
---|
1188 | scrollTop = Math.max(0, offsetTop - (windowHeight / 2)); |
---|
1189 | this._debug("Scroll into view. ScrollTop: " + scrollTop + ". Element offset: " + offsetTop + ". Window height: " + windowHeight + "."); |
---|
1190 | counter = 0; |
---|
1191 | return $('body, html').stop(true, true).animate({ |
---|
1192 | scrollTop: Math.ceil(scrollTop) |
---|
1193 | }, (function(_this) { |
---|
1194 | return function() { |
---|
1195 | if (++counter === 2) { |
---|
1196 | callback(); |
---|
1197 | return _this._debug("Scroll into view.\nAnimation end element offset: " + ($element.offset().top) + ".\nWindow height: " + ($window.height()) + "."); |
---|
1198 | } |
---|
1199 | }; |
---|
1200 | })(this)); |
---|
1201 | }; |
---|
1202 | |
---|
1203 | Tour.prototype._onResize = function(callback, timeout) { |
---|
1204 | return $(window).on("resize.tour-" + this._options.name, function() { |
---|
1205 | clearTimeout(timeout); |
---|
1206 | return timeout = setTimeout(callback, 100); |
---|
1207 | }); |
---|
1208 | }; |
---|
1209 | |
---|
1210 | Tour.prototype._initMouseNavigation = function() { |
---|
1211 | var _this; |
---|
1212 | _this = this; |
---|
1213 | 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) { |
---|
1214 | return function(e) { |
---|
1215 | e.preventDefault(); |
---|
1216 | return _this.next(); |
---|
1217 | }; |
---|
1218 | })(this)).on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='prev']", (function(_this) { |
---|
1219 | return function(e) { |
---|
1220 | e.preventDefault(); |
---|
1221 | return _this.prev(); |
---|
1222 | }; |
---|
1223 | })(this)).on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='end']", (function(_this) { |
---|
1224 | return function(e) { |
---|
1225 | e.preventDefault(); |
---|
1226 | return _this.end(); |
---|
1227 | }; |
---|
1228 | })(this)).on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role='pause-resume']", function(e) { |
---|
1229 | var $this; |
---|
1230 | e.preventDefault(); |
---|
1231 | $this = $(this); |
---|
1232 | $this.text(_this._paused ? $this.data('pause-text') : $this.data('resume-text')); |
---|
1233 | if (_this._paused) { |
---|
1234 | return _this.resume(); |
---|
1235 | } else { |
---|
1236 | return _this.pause(); |
---|
1237 | } |
---|
1238 | }); |
---|
1239 | }; |
---|
1240 | |
---|
1241 | Tour.prototype._initKeyboardNavigation = function() { |
---|
1242 | if (!this._options.keyboard) { |
---|
1243 | return; |
---|
1244 | } |
---|
1245 | return $(document).on("keyup.tour-" + this._options.name, (function(_this) { |
---|
1246 | return function(e) { |
---|
1247 | if (!e.which) { |
---|
1248 | return; |
---|
1249 | } |
---|
1250 | switch (e.which) { |
---|
1251 | case 39: |
---|
1252 | e.preventDefault(); |
---|
1253 | if (_this._isLast()) { |
---|
1254 | return _this.next(); |
---|
1255 | } else { |
---|
1256 | return _this.end(); |
---|
1257 | } |
---|
1258 | break; |
---|
1259 | case 37: |
---|
1260 | e.preventDefault(); |
---|
1261 | if (_this._current > 0) { |
---|
1262 | return _this.prev(); |
---|
1263 | } |
---|
1264 | break; |
---|
1265 | case 27: |
---|
1266 | e.preventDefault(); |
---|
1267 | return _this.end(); |
---|
1268 | } |
---|
1269 | }; |
---|
1270 | })(this)); |
---|
1271 | }; |
---|
1272 | |
---|
1273 | Tour.prototype._makePromise = function(result) { |
---|
1274 | if (result && $.isFunction(result.then)) { |
---|
1275 | return result; |
---|
1276 | } else { |
---|
1277 | return null; |
---|
1278 | } |
---|
1279 | }; |
---|
1280 | |
---|
1281 | Tour.prototype._callOnPromiseDone = function(promise, cb, arg) { |
---|
1282 | if (promise) { |
---|
1283 | return promise.then((function(_this) { |
---|
1284 | return function(e) { |
---|
1285 | return cb.call(_this, arg); |
---|
1286 | }; |
---|
1287 | })(this)); |
---|
1288 | } else { |
---|
1289 | return cb.call(this, arg); |
---|
1290 | } |
---|
1291 | }; |
---|
1292 | |
---|
1293 | Tour.prototype._showBackdrop = function(element) { |
---|
1294 | if (this.backdrop.backgroundShown) { |
---|
1295 | return; |
---|
1296 | } |
---|
1297 | this.backdrop = $('<div>', { |
---|
1298 | "class": 'tour-backdrop' |
---|
1299 | }); |
---|
1300 | this.backdrop.backgroundShown = true; |
---|
1301 | return $('body').append(this.backdrop); |
---|
1302 | }; |
---|
1303 | |
---|
1304 | Tour.prototype._hideBackdrop = function() { |
---|
1305 | this._hideOverlayElement(); |
---|
1306 | return this._hideBackground(); |
---|
1307 | }; |
---|
1308 | |
---|
1309 | Tour.prototype._hideBackground = function() { |
---|
1310 | if (this.backdrop) { |
---|
1311 | this.backdrop.remove(); |
---|
1312 | this.backdrop.overlay = null; |
---|
1313 | return this.backdrop.backgroundShown = false; |
---|
1314 | } |
---|
1315 | }; |
---|
1316 | |
---|
1317 | Tour.prototype._showOverlayElement = function(step) { |
---|
1318 | var $element, elementData; |
---|
1319 | $element = $(step.element); |
---|
1320 | if (!$element || $element.length === 0 || this.backdrop.overlayElementShown) { |
---|
1321 | return; |
---|
1322 | } |
---|
1323 | this.backdrop.overlayElementShown = true; |
---|
1324 | this.backdrop.$element = $element.addClass('tour-step-backdrop'); |
---|
1325 | this.backdrop.$background = $('<div>', { |
---|
1326 | "class": 'tour-step-background' |
---|
1327 | }); |
---|
1328 | elementData = { |
---|
1329 | width: $element.innerWidth(), |
---|
1330 | height: $element.innerHeight(), |
---|
1331 | offset: $element.offset() |
---|
1332 | }; |
---|
1333 | this.backdrop.$background.appendTo('body'); |
---|
1334 | if (step.backdropPadding) { |
---|
1335 | elementData = this._applyBackdropPadding(step.backdropPadding, elementData); |
---|
1336 | } |
---|
1337 | return this.backdrop.$background.width(elementData.width).height(elementData.height).offset(elementData.offset); |
---|
1338 | }; |
---|
1339 | |
---|
1340 | Tour.prototype._hideOverlayElement = function() { |
---|
1341 | if (!this.backdrop.overlayElementShown) { |
---|
1342 | return; |
---|
1343 | } |
---|
1344 | this.backdrop.$element.removeClass('tour-step-backdrop'); |
---|
1345 | this.backdrop.$background.remove(); |
---|
1346 | this.backdrop.$element = null; |
---|
1347 | this.backdrop.$background = null; |
---|
1348 | return this.backdrop.overlayElementShown = false; |
---|
1349 | }; |
---|
1350 | |
---|
1351 | Tour.prototype._applyBackdropPadding = function(padding, data) { |
---|
1352 | if (typeof padding === 'object') { |
---|
1353 | if (padding.top == null) { |
---|
1354 | padding.top = 0; |
---|
1355 | } |
---|
1356 | if (padding.right == null) { |
---|
1357 | padding.right = 0; |
---|
1358 | } |
---|
1359 | if (padding.bottom == null) { |
---|
1360 | padding.bottom = 0; |
---|
1361 | } |
---|
1362 | if (padding.left == null) { |
---|
1363 | padding.left = 0; |
---|
1364 | } |
---|
1365 | data.offset.top = data.offset.top - padding.top; |
---|
1366 | data.offset.left = data.offset.left - padding.left; |
---|
1367 | data.width = data.width + padding.left + padding.right; |
---|
1368 | data.height = data.height + padding.top + padding.bottom; |
---|
1369 | } else { |
---|
1370 | data.offset.top = data.offset.top - padding; |
---|
1371 | data.offset.left = data.offset.left - padding; |
---|
1372 | data.width = data.width + (padding * 2); |
---|
1373 | data.height = data.height + (padding * 2); |
---|
1374 | } |
---|
1375 | return data; |
---|
1376 | }; |
---|
1377 | |
---|
1378 | Tour.prototype._clearTimer = function() { |
---|
1379 | window.clearTimeout(this._timer); |
---|
1380 | this._timer = null; |
---|
1381 | return this._duration = null; |
---|
1382 | }; |
---|
1383 | |
---|
1384 | return Tour; |
---|
1385 | |
---|
1386 | })(); |
---|
1387 | return window.Tour = Tour; |
---|
1388 | })(jQuery, window); |
---|