/*! tether-shepherd 1.8.1 */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(["tether"], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('tether'));
root.Shepherd = factory(root.Tether);
}(this, function(Tether) {
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { var object = _x5, property = _x6, receiver = _x7; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x5 = parent; _x6 = property; _x7 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _Tether$Utils = Tether.Utils;
var Evented = _Tether$Utils.Evented;
var addClass = _Tether$Utils.addClass;
var extend = _Tether$Utils.extend;
var hasClass = _Tether$Utils.hasClass;
var removeClass = _Tether$Utils.removeClass;
var uniqueId = _Tether$Utils.uniqueId;
var Shepherd = new Evented();
function isUndefined(obj) {
return typeof obj === 'undefined';
return obj && obj.constructor === Array;
return obj && obj.constructor === Object;
function isObjectLoose(obj) {
return typeof obj === 'object';
'top right': 'bottom left',
'top left': 'bottom right',
'top center': 'bottom center',
'middle right': 'middle left',
'middle left': 'middle right',
'middle center': 'middle center',
'bottom left': 'top right',
'bottom right': 'top left',
'bottom center': 'top center',
'center': 'middle center',
'middle': 'middle center'
function createFromHTML(html) {
var el = document.createElement('div');
function matchesSelector(el, sel) {
if (!isUndefined(el.matches)) {
} else if (!isUndefined(el.matchesSelector)) {
matches = el.matchesSelector;
} else if (!isUndefined(el.msMatchesSelector)) {
matches = el.msMatchesSelector;
} else if (!isUndefined(el.webkitMatchesSelector)) {
matches = el.webkitMatchesSelector;
} else if (!isUndefined(el.mozMatchesSelector)) {
matches = el.mozMatchesSelector;
} else if (!isUndefined(el.oMatchesSelector)) {
matches = el.oMatchesSelector;
return matches.call(el, sel);
var positionRe = /^(.+) (top|left|right|bottom|center|\[[a-z ]+\])$/;
function parsePosition(str) {
if (isObjectLoose(str)) {
if (str.hasOwnProperty("element") && str.hasOwnProperty("on")) {
var matches = positionRe.exec(str);
on = on.substring(1, on.length - 1);
function parseShorthand(obj, props) {
if (obj === null || isUndefined(obj)) {
} else if (isObjectLoose(obj)) {
var vals = obj.split(' ');
var j = props.length - 1;
for (var i = vals.length - 1; i >= 0; i--) {
out[props[j]] = vals.slice(0, i + 1).join(' ');
var Step = (function (_Evented) {
_inherits(Step, _Evented);
function Step(tour, options) {
_classCallCheck(this, Step);
_get(Object.getPrototypeOf(Step.prototype), 'constructor', this).call(this, tour, options);
this.setOptions(options);
value: function bindMethods() {
var methods = ['_show', 'show', 'hide', 'isOpen', 'cancel', 'complete', 'scrollTo', 'destroy', 'render'];
methods.map(function (method) {
_this[method] = _this[method].bind(_this);
value: function setOptions() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.id = this.options.id || this.id || 'step-' + uniqueId();
var when = this.options.when;
for (var _event in when) {
if (({}).hasOwnProperty.call(when, _event)) {
var handler = when[_event];
this.on(_event, handler, this);
var buttonsJson = JSON.stringify(this.options.buttons);
var buttonsAreDefault = isUndefined(buttonsJson) || buttonsJson === "true";
var buttonsAreEmpty = buttonsJson === "{}" || buttonsJson === "[]" || buttonsJson === "null" || buttonsJson === "false";
var buttonsAreArray = !buttonsAreDefault && isArray(this.options.buttons);
var buttonsAreObject = !buttonsAreDefault && isObject(this.options.buttons);
// Show default button if undefined or 'true'
this.options.buttons = [{
// Can pass in an object which will assume asingle button
} else if (!buttonsAreEmpty && buttonsAreObject) {
this.options.buttons = [this.options.buttons];
// Falsey/empty values or non-object values prevent buttons from rendering
} else if (buttonsAreEmpty || !buttonsAreArray) {
this.options.buttons = false;
value: function getTour() {
value: function bindAdvance() {
// An empty selector matches the step element
var _parseShorthand = parseShorthand(this.options.advanceOn, ['selector', 'event']);
var event = _parseShorthand.event;
var selector = _parseShorthand.selector;
var handler = function handler(e) {
if (!isUndefined(selector)) {
if (matchesSelector(e.target, selector)) {
if (_this2.el && e.target === _this2.el) {
// TODO: this should also bind/unbind on show/hide
document.body.addEventListener(event, handler);
this.on('destroy', function () {
return document.body.removeEventListener(event, handler);
value: function getAttachTo() {
var opts = parsePosition(this.options.attachTo) || {};
var returnOpts = extend({}, opts);
if (typeof opts.element === 'string') {
// Can't override the element in user opts reference because we can't
// guarantee that the element will exist in the future.
returnOpts.element = document.querySelector(opts.element);
if (!returnOpts.element) {
console.error('The element for this Shepherd step was not found ' + opts.element);
value: function setupTether() {
if (isUndefined(Tether)) {
throw new Error("Using the attachment feature of Shepherd requires the Tether library");
var opts = this.getAttachTo();
var attachment = ATTACHMENT[opts.on] || ATTACHMENT.right;
if (isUndefined(opts.element)) {
opts.element = 'viewport';
attachment = 'middle center';
offset: opts.offset || '0 0',
this.tether = new Tether(extend(tetherOpts, this.options.tetherOptions));
if (!isUndefined(this.options.beforeShowPromise)) {
var beforeShowPromise = this.options.beforeShowPromise();
if (!isUndefined(beforeShowPromise)) {
return beforeShowPromise.then(function () {
value: function _show() {
this.trigger('before-show');
addClass(this.el, 'shepherd-open');
document.body.setAttribute('data-shepherd-step', this.id);
if (this.options.scrollTo) {
this.trigger('before-hide');
removeClass(this.el, 'shepherd-open');
document.body.removeAttribute('data-shepherd-step');
value: function isOpen() {
return this.el && hasClass(this.el, 'shepherd-open');
value: function cancel() {
value: function complete() {
this.trigger('complete');
value: function scrollTo() {
var _getAttachTo = this.getAttachTo();
var element = _getAttachTo.element;
if (!isUndefined(this.options.scrollToHandler)) {
this.options.scrollToHandler(element);
} else if (!isUndefined(element)) {
element.scrollIntoView();
value: function destroy() {
if (!isUndefined(this.el) && this.el.parentNode) {
this.el.parentNode.removeChild(this.el);
value: function render() {
if (!isUndefined(this.el)) {
this.el = createFromHTML('<div class=\'shepherd-step ' + (this.options.classes || '') + '\' data-id=\'' + this.id + '\' ' + (this.options.idAttribute ? 'id="' + this.options.idAttribute + '"' : '') + '></div>');
var content = document.createElement('div');
content.className = 'shepherd-content';
this.el.appendChild(content);
var header = document.createElement('header');
content.appendChild(header);
if (this.options.title) {
header.innerHTML += '<h3 class=\'shepherd-title\'>' + this.options.title + '</h3>';
this.el.className += ' shepherd-has-title';
if (this.options.showCancelLink) {
var link = createFromHTML("<a href class='shepherd-cancel-link'>✕</a>");
header.appendChild(link);
this.el.className += ' shepherd-has-cancel-link';
this.bindCancelLink(link);
if (!isUndefined(this.options.text)) {
var text = createFromHTML("<div class='shepherd-text'></div>");
var paragraphs = _this5.options.text;
if (typeof paragraphs === 'function') {
paragraphs = paragraphs.call(_this5, text);
if (paragraphs instanceof HTMLElement) {
text.appendChild(paragraphs);
if (typeof paragraphs === 'string') {
paragraphs = [paragraphs];
paragraphs.map(function (paragraph) {
text.innerHTML += '<p>' + paragraph + '</p>';
content.appendChild(text);
if (this.options.buttons) {
var footer = document.createElement('footer');
var buttons = createFromHTML("<ul class='shepherd-buttons'></ul>");
_this5.options.buttons.map(function (cfg) {
var button = createFromHTML('<li><a class=\'shepherd-button ' + (cfg.classes || '') + '\'>' + cfg.text + '</a>');
buttons.appendChild(button);
_this5.bindButtonEvents(cfg, button.querySelector('a'));
footer.appendChild(buttons);
content.appendChild(footer);
document.body.appendChild(this.el);
if (this.options.advanceOn) {
value: function bindCancelLink(link) {
link.addEventListener('click', function (e) {
value: function bindButtonEvents(cfg, el) {
cfg.events = cfg.events || {};