/* ===========================================================
# bootstrap-tour - v0.8.0
# http://bootstraptour.com
# ==============================================================
# Copyright 2012-2013 Ulrich Sossou
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/
(function($, window) {
var Tour, document;
document = window.document;
Tour = (function() {
function Tour(options) {
this._options = $.extend({
name: "tour",
container: "body",
keyboard: true,
storage: window.localStorage,
debug: false,
backdrop: false,
redirect: true,
orphan: false,
duration: false,
basePath: "",
template: "
").parent().html();
$element.popover({
placement: step.placement,
trigger: "manual",
title: step.title,
content: step.content,
html: true,
animation: step.animation,
container: step.container,
template: step.template,
selector: step.element
}).popover("show");
$tip = $element.data("bs.popover") ? $element.data("bs.popover").tip() : $element.data("popover").tip();
$tip.attr("id", step.id);
this._reposition($tip, step);
if (isOrphan) {
return this._center($tip);
}
};
Tour.prototype._reposition = function($tip, step) {
var offsetBottom, offsetHeight, offsetRight, offsetWidth, originalLeft, originalTop, tipOffset;
offsetWidth = $tip[0].offsetWidth;
offsetHeight = $tip[0].offsetHeight;
tipOffset = $tip.offset();
originalLeft = tipOffset.left;
originalTop = tipOffset.top;
offsetBottom = $(document).outerHeight() - tipOffset.top - $tip.outerHeight();
if (offsetBottom < 0) {
tipOffset.top = tipOffset.top + offsetBottom;
}
offsetRight = $("html").outerWidth() - tipOffset.left - $tip.outerWidth();
if (offsetRight < 0) {
tipOffset.left = tipOffset.left + offsetRight;
}
if (tipOffset.top < 0) {
tipOffset.top = 0;
}
if (tipOffset.left < 0) {
tipOffset.left = 0;
}
$tip.offset(tipOffset);
if (step.placement === "bottom" || step.placement === "top") {
if (originalLeft !== tipOffset.left) {
return this._replaceArrow($tip, (tipOffset.left - originalLeft) * 2, offsetWidth, "left");
}
} else {
if (originalTop !== tipOffset.top) {
return this._replaceArrow($tip, (tipOffset.top - originalTop) * 2, offsetHeight, "top");
}
}
};
Tour.prototype._center = function($tip) {
return $tip.css("top", $(window).outerHeight() / 2 - $tip.outerHeight() / 2);
};
Tour.prototype._replaceArrow = function($tip, delta, dimension, position) {
return $tip.find(".arrow").css(position, delta ? 50 * (1 - delta / dimension) + "%" : "");
};
Tour.prototype._scrollIntoView = function(element, callback) {
var $element, $window, offsetTop, scrollTop, windowHeight,
_this = this;
if (!element) {
return callback();
}
$element = $(element);
$window = $(window);
offsetTop = $element.offset().top;
windowHeight = $window.height();
scrollTop = Math.max(0, offsetTop - (windowHeight / 2));
this._debug("Scroll into view. ScrollTop: " + scrollTop + ". Element offset: " + offsetTop + ". Window height: " + windowHeight + ".");
return $("body").stop().animate({
scrollTop: Math.ceil(scrollTop)
}, function() {
callback();
return _this._debug("Scroll into view. Animation end element offset: " + ($element.offset().top) + ". Window height: " + ($window.height()) + ".");
});
};
Tour.prototype._onResize = function(callback, timeout) {
return $(window).on("resize.tour-" + this._options.name, function() {
clearTimeout(timeout);
return timeout = setTimeout(callback, 100);
});
};
Tour.prototype._setupMouseNavigation = function() {
var _this = this;
_this = this;
$(document).off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=next]:not(.disabled)").on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=next]:not(.disabled)", function(e) {
e.preventDefault();
return _this.next();
});
$(document).off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=prev]:not(.disabled)").on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=prev]:not(.disabled)", function(e) {
e.preventDefault();
return _this.prev();
});
$(document).off("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=end]").on("click.tour-" + this._options.name, ".popover.tour-" + this._options.name + " *[data-role=end]", function(e) {
e.preventDefault();
return _this.end();
});
return $(document).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=pause-resume]", function(e) {
var $this;
e.preventDefault();
$this = $(this);
$this.text(_this._paused ? $this.data("pause-text") : $this.data("resume-text"));
if (_this._paused) {
return _this.resume();
} else {
return _this.pause();
}
});
};
Tour.prototype._setupKeyboardNavigation = function() {
var _this = this;
if (!this._options.keyboard) {
return;
}
return $(document).on("keyup.tour-" + this._options.name, function(e) {
if (!e.which) {
return;
}
switch (e.which) {
case 39:
e.preventDefault();
if (_this._isLast()) {
return _this.next();
} else {
return _this.end();
}
break;
case 37:
e.preventDefault();
if (_this._current > 0) {
return _this.prev();
}
break;
case 27:
e.preventDefault();
return _this.end();
}
});
};
Tour.prototype._makePromise = function(result) {
if (result && $.isFunction(result.then)) {
return result;
} else {
return null;
}
};
Tour.prototype._callOnPromiseDone = function(promise, cb, arg) {
var _this = this;
if (promise) {
return promise.then(function(e) {
return cb.call(_this, arg);
});
} else {
return cb.call(this, arg);
}
};
Tour.prototype._showBackdrop = function(element) {
if (this.backdrop.backgroundShown) {
return;
}
this.backdrop = $("
", {
"class": "tour-backdrop"
});
this.backdrop.backgroundShown = true;
return $("body").append(this.backdrop);
};
Tour.prototype._hideBackdrop = function() {
this._hideOverlayElement();
return this._hideBackground();
};
Tour.prototype._hideBackground = function() {
this.backdrop.remove();
this.backdrop.overlay = null;
return this.backdrop.backgroundShown = false;
};
Tour.prototype._showOverlayElement = function(element) {
var $background, $element, offset;
if (this.backdrop.overlayElementShown) {
return;
}
this.backdrop.overlayElementShown = true;
$element = $(element);
$background = $("
");
offset = $element.offset();
offset.top = offset.top;
offset.left = offset.left;
$background.width($element.innerWidth()).height($element.innerHeight()).addClass("tour-step-background").offset(offset);
$element.addClass("tour-step-backdrop");
$("body").append($background);
this.backdrop.$element = $element;
return this.backdrop.$background = $background;
};
Tour.prototype._hideOverlayElement = function() {
if (!this.backdrop.overlayElementShown) {
return;
}
this.backdrop.$element.removeClass("tour-step-backdrop");
this.backdrop.$background.remove();
this.backdrop.$element = null;
this.backdrop.$background = null;
return this.backdrop.overlayElementShown = false;
};
Tour.prototype._clearTimer = function() {
window.clearTimeout(this._timer);
this._timer = null;
return this._duration = null;
};
return Tour;
})();
return window.Tour = Tour;
})(jQuery, window);