source: trunk/plugins/TakeATour/js/custom-bootstrap-tour-standalone.js @ 28775

Last change on this file since 28775 was 28775, checked in by flop25, 10 years ago

adjustments for 2.7
js updated to 9.0.3

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