Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More ā†’
Socket
Sign inDemoInstall
Socket

tether-shepherd

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tether-shepherd - npm Package Compare versions

Comparing version 1.2.0 to 1.6.0

dist/js/tether.js

2

bower.json
{
"name": "tether-shepherd",
"version": "1.2.0",
"version": "1.5.2",
"homepage": "https://github.com/HubSpot/shepherd",

@@ -5,0 +5,0 @@ "authors": [

(function() {
var ShepherdInstallHelper, addEventListener, firstStepSelector, ready;
var ShepherdInstallHelper, addEventListener, buttonLocation, firstStepSelector, options, ready, render, tour;

@@ -30,95 +30,133 @@ addEventListener = function(el, eventName, handler) {

ShepherdInstallHelper = {
init: function(options) {
var i, j, k, len, len1, ref, ref1, step, stepOptions, steps, textLines, tour;
if (!((options != null ? (ref = options.steps) != null ? ref.length : void 0 : void 0) > 0)) {
return;
}
tour = new Shepherd.Tour({
defaults: {
classes: "shepherd-element shepherd-open shepherd-theme-" + options.theme
}
});
steps = [];
ref1 = options.steps;
for (j = 0, len = ref1.length; j < len; j++) {
step = ref1[j];
if (step.title && step.text && step.attachToSelector && step.attachToDirection) {
if (typeof step.text === 'string') {
textLines = step.text.split('\n');
if (textLines.length) {
step.text = textLines;
}
options = INSTALL_OPTIONS;
tour = null;
buttonLocation = null;
render = function() {
var existing, i, id, j, k, lastI, len, len1, open, ref, ref1, step, stepOptions, steps, textLines;
tour || (tour = new Shepherd.Tour);
steps = [];
ref = options.steps;
for (j = 0, len = ref.length; j < len; j++) {
step = ref[j];
if (step.text && step.attachToSelector && step.attachToDirection) {
if (typeof step.text === 'string') {
textLines = step.text.split('\n');
if (textLines.length) {
step.text = textLines;
}
steps.push(step);
}
steps.push(step);
}
for (i = k = 0, len1 = steps.length; k < len1; i = ++k) {
step = steps[i];
if (i === 0) {
firstStepSelector = step.attachToSelector;
}
open = (ref1 = tour.getCurrentStep()) != null ? ref1.id : void 0;
lastI = -1;
for (i = k = 0, len1 = steps.length; k < len1; i = ++k) {
step = steps[i];
if (i === 0) {
firstStepSelector = step.attachToSelector;
}
stepOptions = {
title: step.title,
text: step.text,
showCancelLink: step.showCancelLink,
attachTo: step.attachToSelector + ' ' + step.attachToDirection,
classes: "shepherd-element shepherd-theme-" + options.theme,
scrollTo: options.scrollTo
};
stepOptions.buttons = [];
if (i > 0) {
stepOptions.buttons.push({
text: 'Back',
action: tour.back,
classes: 'shepherd-button-secondary'
});
} else if (steps.length > 1) {
stepOptions.buttons.push({
text: 'Exit',
action: tour.cancel,
classes: 'shepherd-button-secondary'
});
}
if (i < steps.length - 1) {
stepOptions.buttons.push({
text: 'Next',
action: tour.next
});
} else {
stepOptions.buttons.push({
text: 'Done',
action: tour.next
});
}
id = "step-" + i;
existing = tour.getById(id);
if (existing) {
existing.setOptions(stepOptions);
existing.render();
if (open === id) {
tour.show(id);
}
stepOptions = {
title: step.title,
text: step.text,
showCancelLink: step.showCancelLink,
attachTo: step.attachToSelector + ' ' + step.attachToDirection
};
stepOptions.buttons = [];
if (i > 0) {
stepOptions.buttons.push({
text: 'Back',
action: tour.back,
classes: 'shepherd-button-secondary'
});
} else if (steps.length > 1) {
stepOptions.buttons.push({
text: 'Exit',
action: tour.cancel,
classes: 'shepherd-button-secondary'
});
}
if (i < steps.length - 1) {
stepOptions.buttons.push({
text: 'Next',
action: tour.next
});
} else {
stepOptions.buttons.push({
text: 'Done',
action: tour.next
});
}
} else {
tour.addStep('step-' + i, stepOptions);
}
return ready(function() {
var button, buttonLocation, ref2, ref3, ref4, ref5;
if (options.trigger === 'first-page-visit') {
if (((ref2 = window.Eager) != null ? (ref3 = ref2.installs) != null ? (ref4 = ref3.preview) != null ? ref4.appId : void 0 : void 0 : void 0) === 'AalP5veMma6s') {
lastI = i;
}
while (existing = tour.getById("step-" + (++lastI))) {
tour.removeStep(existing.id);
}
return ready(function() {
var button, ref2, start, tries;
if (options.trigger === 'first-page-visit' && !Shepherd.activeTour) {
tries = 0;
start = function() {
if (document.querySelector(firstStepSelector)) {
tour.start();
} else if (document.querySelector(firstStepSelector) && ((ref5 = window.localStorage) != null ? ref5.eagerShepherdHasRun : void 0) !== 'true') {
if (typeof localStorage !== "undefined" && localStorage !== null) {
localStorage.eagerShepherdHasRun = 'true';
if (INSTALL_ID !== 'preview') {
return typeof localStorage !== "undefined" && localStorage !== null ? localStorage.eagerShepherdHasRun = 'true' : void 0;
}
tour.start();
} else if (tries < 3) {
tries++;
return setTimeout(start, 250);
}
};
if (INSTALL_ID === 'preview' || ((ref2 = window.localStorage) != null ? ref2.eagerShepherdHasRun : void 0) !== 'true') {
start();
}
if (options.trigger === 'button-click') {
buttonLocation = Eager.createElement(options.buttonLocation);
button = document.createElement('button');
button.className = "shepherd-start-tour-button shepherd-theme-" + options.theme;
button.appendChild(document.createTextNode(options.buttonText));
if ((buttonLocation != null ? buttonLocation.appendChild : void 0) != null) {
buttonLocation.appendChild(button);
return addEventListener(button, 'click', function() {
return tour.start();
});
}
}
if (options.trigger === 'button-click') {
buttonLocation = Eager.createElement(options.buttonLocation, buttonLocation);
button = document.createElement('button');
button.className = "shepherd-start-tour-button shepherd-theme-" + options.theme;
button.appendChild(document.createTextNode(options.buttonText));
if (buttonLocation) {
buttonLocation.appendChild(button);
return addEventListener(button, 'click', function() {
return tour.start();
});
}
});
}
} else if (buttonLocation != null ? buttonLocation.parentNode : void 0) {
Eager.createElement({
method: 'append',
selector: 'x:not(x)'
}, buttonLocation);
return buttonLocation = null;
}
});
};
render();
ShepherdInstallHelper = {
setOptions: function(opts) {
options = opts;
return render();
},
tour: tour
};
window.ShepherdInstallHelper = ShepherdInstallHelper;
}).call(this);

@@ -1,2 +0,2 @@

/*! tether-shepherd 1.2.0 */
/*! tether-shepherd 1.5.2 */

@@ -19,3 +19,3 @@ (function(root, factory) {

var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { var object = _x5, property = _x6, receiver = _x7; desc = parent = getter = undefined; _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; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
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); } } };

@@ -68,2 +68,28 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

var positionRe = /^(.+) (top|left|right|bottom|center|\[[a-z ]+\])$/;
function parsePosition(str) {
if (typeof str === 'object') {
if (str.hasOwnProperty("element") && str.hasOwnProperty("on")) {
return str;
}
return null;
}
var matches = positionRe.exec(str);
if (!matches) {
return null;
}
var on = matches[2];
if (on[0] === '[') {
on = on.substring(1, on.length - 1);
}
return {
'element': matches[1],
'on': on
};
}
function parseShorthand(obj, props) {

@@ -77,13 +103,13 @@ if (obj === null || typeof obj === 'undefined') {

var vals = obj.split(' ');
var valsLen = vals.length;
var propsLen = props.length;
if (valsLen > propsLen) {
vals[0] = vals.slice(0, valsLen - propsLen + 1).join(' ');
vals.splice(1, (valsLen, propsLen));
}
var out = {};
var j = props.length - 1;
for (var i = vals.length - 1; i >= 0; i--) {
if (j === 0) {
out[props[j]] = vals.slice(0, i + 1).join(' ');
break;
} else {
out[props[j]] = vals[i];
}
var out = {};
for (var i = 0; i < propsLen; ++i) {
var prop = props[i];
out[prop] = vals[i];
j--;
}

@@ -112,3 +138,3 @@

var methods = ['_show', 'show', 'hide', 'isOpen', 'cancel', 'complete', 'scrollTo', 'destroy'];
var methods = ['_show', 'show', 'hide', 'isOpen', 'cancel', 'complete', 'scrollTo', 'destroy', 'render'];
methods.map(function (method) {

@@ -187,14 +213,15 @@ _this[method] = _this[method].bind(_this);

value: function getAttachTo() {
var opts = parseShorthand(this.options.attachTo, ['element', 'on']) || {};
var selector = opts.element;
var opts = parsePosition(this.options.attachTo) || {};
var returnOpts = extend({}, opts);
if (typeof selector === 'string') {
opts.element = document.querySelector(selector);
if (!opts.element) {
throw new Error('The element for this Shepherd step was not found ' + selector);
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);
}
}
return opts;
return returnOpts;
}

@@ -209,3 +236,3 @@ }, {

var opts = this.getAttachTo();
var attachment = ATTACHMENT[opts.on || 'right'];
var attachment = ATTACHMENT[opts.on || 'right'] || opts.on;
if (typeof opts.element === 'undefined') {

@@ -294,3 +321,3 @@ opts.element = 'viewport';

value: function isOpen() {
return hasClass(this.el, 'shepherd-open');
return this.el && hasClass(this.el, 'shepherd-open');
}

@@ -325,4 +352,4 @@ }, {

value: function destroy() {
if (typeof this.el !== 'undefined') {
document.body.removeChild(this.el);
if (typeof this.el !== 'undefined' && this.el.parentNode) {
this.el.parentNode.removeChild(this.el);
delete this.el;

@@ -356,3 +383,3 @@ }

if (typeof this.options.title !== 'undefined') {
if (this.options.title) {
header.innerHTML += '<h3 class=\'shepherd-title\'>' + this.options.title + '</h3>';

@@ -533,2 +560,23 @@ this.el.className += ' shepherd-has-title';

}, {
key: 'removeStep',
value: function removeStep(name) {
var current = this.getCurrentStep();
for (var i = 0; i < this.steps.length; ++i) {
var step = this.steps[i];
if (step.id === name) {
step.hide();
step.destroy();
this.steps.splice(i, 1);
break;
}
}
if (current && current.id === name) {
this.currentStep = undefined;
if (this.steps.length) this.show(0);else this.hide();
}
}
}, {
key: 'getById',

@@ -570,3 +618,3 @@ value: function getById(id) {

value: function cancel() {
if (typeof this.currentStep !== 'undefined') {
if (this.currentStep) {
this.currentStep.hide();

@@ -580,3 +628,3 @@ }

value: function complete() {
if (typeof this.currentStep !== 'undefined') {
if (this.currentStep) {
this.currentStep.hide();

@@ -590,3 +638,3 @@ }

value: function hide() {
if (typeof this.currentStep !== 'undefined') {
if (this.currentStep) {
this.currentStep.hide();

@@ -638,2 +686,6 @@ }

if (this.currentStep) {
this.currentStep.hide();
}
this.currentStep = next;

@@ -640,0 +692,0 @@ next.show();

@@ -1,1 +0,1 @@

!function(e,t){"function"==typeof define&&define.amd?define(["tether"],t):"object"==typeof exports?module.exports=t(require("tether")):e.Shepherd=t(e.Tether)}(this,function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e){var t=document.createElement("div");return t.innerHTML=e,t.children[0]}function o(e,t){var n=void 0;return"undefined"!=typeof e.matches?n=e.matches:"undefined"!=typeof e.matchesSelector?n=e.matchesSelector:"undefined"!=typeof e.msMatchesSelector?n=e.msMatchesSelector:"undefined"!=typeof e.webkitMatchesSelector?n=e.webkitMatchesSelector:"undefined"!=typeof e.mozMatchesSelector?n=e.mozMatchesSelector:"undefined"!=typeof e.oMatchesSelector&&(n=e.oMatchesSelector),n.call(e,t)}function s(e,t){if(null===e||"undefined"==typeof e)return e;if("object"==typeof e)return e;var n=e.split(" "),i=n.length,o=t.length;i>o&&(n[0]=n.slice(0,i-o+1).join(" "),n.splice(1,o));for(var s={},r=0;o>r;++r){var h=t[r];s[h]=n[r]}return s}var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),h=function(e,t,n){for(var i=!0;i;){var o=e,s=t,r=n;h=a=u=void 0,i=!1,null===o&&(o=Function.prototype);var h=Object.getOwnPropertyDescriptor(o,s);if(void 0!==h){if("value"in h)return h.value;var u=h.get;return void 0===u?void 0:u.call(r)}var a=Object.getPrototypeOf(o);if(null===a)return void 0;e=a,t=s,n=r,i=!0}},u=e.Utils,a=u.Evented,c=u.addClass,d=u.extend,l=u.hasClass,p=u.removeClass,f=u.uniqueId,v=new a,y={top:"bottom center",left:"middle right",right:"middle left",bottom:"top center",center:"middle center"},m=function(u){function a(e,n){return t(this,a),h(Object.getPrototypeOf(a.prototype),"constructor",this).call(this,e,n),this.tour=e,this.bindMethods(),this.setOptions(n),this}return n(a,u),r(a,[{key:"bindMethods",value:function(){var e=this,t=["_show","show","hide","isOpen","cancel","complete","scrollTo","destroy"];t.map(function(t){e[t]=e[t].bind(e)})}},{key:"setOptions",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.options=e,this.destroy(),this.id=this.options.id||this.id||"step-"+f();var t=this.options.when;if(t)for(var n in t)if({}.hasOwnProperty.call(t,n)){var i=t[n];this.on(n,i,this)}this.options.buttons||(this.options.buttons=[{text:"Next",action:this.tour.next}])}},{key:"getTour",value:function(){return this.tour}},{key:"bindAdvance",value:function(){var e=this,t=s(this.options.advanceOn,["selector","event"]),n=t.event,i=t.selector,r=function(t){e.isOpen()&&("undefined"!=typeof i?o(t.target,i)&&e.tour.next():e.el&&t.target===e.el&&e.tour.next())};document.body.addEventListener(n,r),this.on("destroy",function(){return document.body.removeEventListener(n,r)})}},{key:"getAttachTo",value:function(){var e=s(this.options.attachTo,["element","on"])||{},t=e.element;if("string"==typeof t&&(e.element=document.querySelector(t),!e.element))throw new Error("The element for this Shepherd step was not found "+t);return e}},{key:"setupTether",value:function(){if("undefined"==typeof e)throw new Error("Using the attachment feature of Shepherd requires the Tether library");var t=this.getAttachTo(),n=y[t.on||"right"];"undefined"==typeof t.element&&(t.element="viewport",n="middle center");var i={classPrefix:"shepherd",element:this.el,constraints:[{to:"window",pin:!0,attachment:"together"}],target:t.element,offset:t.offset||"0 0",attachment:n};this.tether&&this.tether.destroy(),this.tether=new e(d(i,this.options.tetherOptions))}},{key:"show",value:function(){var e=this;if("undefined"!=typeof this.options.beforeShowPromise){var t=this.options.beforeShowPromise();if("undefined"!=typeof t)return t.then(function(){return e._show()})}this._show()}},{key:"_show",value:function(){var e=this;this.trigger("before-show"),this.el||this.render(),c(this.el,"shepherd-open"),document.body.setAttribute("data-shepherd-step",this.id),this.setupTether(),this.options.scrollTo&&setTimeout(function(){e.scrollTo()}),this.trigger("show")}},{key:"hide",value:function(){this.trigger("before-hide"),p(this.el,"shepherd-open"),document.body.removeAttribute("data-shepherd-step"),this.tether&&this.tether.destroy(),this.tether=null,this.trigger("hide")}},{key:"isOpen",value:function(){return l(this.el,"shepherd-open")}},{key:"cancel",value:function(){this.tour.cancel(),this.trigger("cancel")}},{key:"complete",value:function(){this.tour.complete(),this.trigger("complete")}},{key:"scrollTo",value:function(){var e=this.getAttachTo(),t=e.element;"undefined"!=typeof this.options.scrollToHandler?this.options.scrollToHandler(t):"undefined"!=typeof t&&t.scrollIntoView()}},{key:"destroy",value:function(){"undefined"!=typeof this.el&&(document.body.removeChild(this.el),delete this.el),this.tether&&this.tether.destroy(),this.tether=null,this.trigger("destroy")}},{key:"render",value:function(){var e=this;"undefined"!=typeof this.el&&this.destroy(),this.el=i("<div class='shepherd-step "+(this.options.classes||"")+"' data-id='"+this.id+"' "+(this.options.idAttribute?'id="'+this.options.idAttribute+'"':"")+"></div>");var t=document.createElement("div");t.className="shepherd-content",this.el.appendChild(t);var n=document.createElement("header");if(t.appendChild(n),"undefined"!=typeof this.options.title&&(n.innerHTML+="<h3 class='shepherd-title'>"+this.options.title+"</h3>",this.el.className+=" shepherd-has-title"),this.options.showCancelLink){var o=i("<a href class='shepherd-cancel-link'>āœ•</a>");n.appendChild(o),this.el.className+=" shepherd-has-cancel-link",this.bindCancelLink(o)}"undefined"!=typeof this.options.text&&!function(){var n=i("<div class='shepherd-text'></div>"),o=e.options.text;"function"==typeof o&&(o=o.call(e,n)),o instanceof HTMLElement?n.appendChild(o):("string"==typeof o&&(o=[o]),o.map(function(e){n.innerHTML+="<p>"+e+"</p>"})),t.appendChild(n)}();var s=document.createElement("footer");this.options.buttons&&!function(){var t=i("<ul class='shepherd-buttons'></ul>");e.options.buttons.map(function(n){var o=i("<li><a class='shepherd-button "+(n.classes||"")+"'>"+n.text+"</a>");t.appendChild(o),e.bindButtonEvents(n,o.querySelector("a"))}),s.appendChild(t)}(),t.appendChild(s),document.body.appendChild(this.el),this.setupTether(),this.options.advanceOn&&this.bindAdvance()}},{key:"bindCancelLink",value:function(e){var t=this;e.addEventListener("click",function(e){e.preventDefault(),t.cancel()})}},{key:"bindButtonEvents",value:function(e,t){var n=this;e.events=e.events||{},"undefined"!=typeof e.action&&(e.events.click=e.action);for(var i in e.events)if({}.hasOwnProperty.call(e.events,i)){var o=e.events[i];"string"==typeof o&&!function(){var e=o;o=function(){return n.tour.show(e)}}(),t.addEventListener(i,o)}this.on("destroy",function(){for(var n in e.events)if({}.hasOwnProperty.call(e.events,n)){var i=e.events[n];t.removeEventListener(n,i)}})}}]),a}(a),g=function(e){function i(){var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];t(this,i),h(Object.getPrototypeOf(i.prototype),"constructor",this).call(this,n),this.bindMethods(),this.options=n,this.steps=this.options.steps||[];var o=["complete","cancel","hide","start","show","active","inactive"];return o.map(function(t){!function(t){e.on(t,function(n){n=n||{},n.tour=e,v.trigger(t,n)})}(t)}),this}return n(i,e),r(i,[{key:"bindMethods",value:function(){var e=this,t=["next","back","cancel","complete","hide"];t.map(function(t){e[t]=e[t].bind(e)})}},{key:"addStep",value:function(e,t){return"undefined"==typeof t&&(t=e),t instanceof m?t.tour=this:(("string"==typeof e||"number"==typeof e)&&(t.id=e.toString()),t=d({},this.options.defaults,t),t=new m(this,t)),this.steps.push(t),this}},{key:"getById",value:function(e){for(var t=0;t<this.steps.length;++t){var n=this.steps[t];if(n.id===e)return n}}},{key:"getCurrentStep",value:function(){return this.currentStep}},{key:"next",value:function(){var e=this.steps.indexOf(this.currentStep);e===this.steps.length-1?(this.hide(e),this.trigger("complete"),this.done()):this.show(e+1,!0)}},{key:"back",value:function(){var e=this.steps.indexOf(this.currentStep);this.show(e-1,!1)}},{key:"cancel",value:function(){"undefined"!=typeof this.currentStep&&this.currentStep.hide(),this.trigger("cancel"),this.done()}},{key:"complete",value:function(){"undefined"!=typeof this.currentStep&&this.currentStep.hide(),this.trigger("complete"),this.done()}},{key:"hide",value:function(){"undefined"!=typeof this.currentStep&&this.currentStep.hide(),this.trigger("hide"),this.done()}},{key:"done",value:function(){v.activeTour=null,p(document.body,"shepherd-active"),this.trigger("inactive",{tour:this})}},{key:"show",value:function(){var e=arguments.length<=0||void 0===arguments[0]?0:arguments[0],t=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];this.currentStep?this.currentStep.hide():(c(document.body,"shepherd-active"),this.trigger("active",{tour:this})),v.activeTour=this;var n=void 0;if(n="string"==typeof e?this.getById(e):this.steps[e])if("undefined"==typeof n.options.showOn||n.options.showOn())this.trigger("show",{step:n,previous:this.currentStep}),this.currentStep=n,n.show();else{var i=this.steps.indexOf(n),o=t?i+1:i-1;this.show(o,t)}}},{key:"start",value:function(){this.trigger("start"),this.currentStep=null,this.next()}}]),i}(a);return d(v,{Tour:g,Step:m,Evented:a}),v});
!function(e,t){"function"==typeof define&&define.amd?define(["tether"],t):"object"==typeof exports?module.exports=t(require("tether")):e.Shepherd=t(e.Tether)}(this,function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e){var t=document.createElement("div");return t.innerHTML=e,t.children[0]}function r(e,t){var n=void 0;return"undefined"!=typeof e.matches?n=e.matches:"undefined"!=typeof e.matchesSelector?n=e.matchesSelector:"undefined"!=typeof e.msMatchesSelector?n=e.msMatchesSelector:"undefined"!=typeof e.webkitMatchesSelector?n=e.webkitMatchesSelector:"undefined"!=typeof e.mozMatchesSelector?n=e.mozMatchesSelector:"undefined"!=typeof e.oMatchesSelector&&(n=e.oMatchesSelector),n.call(e,t)}function s(e){if("object"==typeof e)return e.hasOwnProperty("element")&&e.hasOwnProperty("on")?e:null;var t=g.exec(e);if(!t)return null;var n=t[2];return"["===n[0]&&(n=n.substring(1,n.length-1)),{element:t[1],on:n}}function o(e,t){if(null===e||"undefined"==typeof e)return e;if("object"==typeof e)return e;for(var n=e.split(" "),i={},r=t.length-1,s=n.length-1;s>=0;s--){if(0===r){i[t[r]]=n.slice(0,s+1).join(" ");break}i[t[r]]=n[s],r--}return i}var h=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),u=function(e,t,n){for(var i=!0;i;){var r=e,s=t,o=n;i=!1,null===r&&(r=Function.prototype);var h=Object.getOwnPropertyDescriptor(r,s);if(void 0!==h){if("value"in h)return h.value;var u=h.get;if(void 0===u)return;return u.call(o)}var a=Object.getPrototypeOf(r);if(null===a)return;e=a,t=s,n=o,i=!0,h=a=void 0}},a=e.Utils,c=a.Evented,l=a.addClass,d=a.extend,p=a.hasClass,f=a.removeClass,v=a.uniqueId,y=new c,m={top:"bottom center",left:"middle right",right:"middle left",bottom:"top center",center:"middle center"},g=/^(.+) (top|left|right|bottom|center|\[[a-z ]+\])$/,b=function(a){function c(e,n){return t(this,c),u(Object.getPrototypeOf(c.prototype),"constructor",this).call(this,e,n),this.tour=e,this.bindMethods(),this.setOptions(n),this}return n(c,a),h(c,[{key:"bindMethods",value:function(){var e=this,t=["_show","show","hide","isOpen","cancel","complete","scrollTo","destroy","render"];t.map(function(t){e[t]=e[t].bind(e)})}},{key:"setOptions",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.options=e,this.destroy(),this.id=this.options.id||this.id||"step-"+v();var t=this.options.when;if(t)for(var n in t)if({}.hasOwnProperty.call(t,n)){var i=t[n];this.on(n,i,this)}this.options.buttons||(this.options.buttons=[{text:"Next",action:this.tour.next}])}},{key:"getTour",value:function(){return this.tour}},{key:"bindAdvance",value:function(){var e=this,t=o(this.options.advanceOn,["selector","event"]),n=t.event,i=t.selector,s=function(t){e.isOpen()&&("undefined"!=typeof i?r(t.target,i)&&e.tour.next():e.el&&t.target===e.el&&e.tour.next())};document.body.addEventListener(n,s),this.on("destroy",function(){return document.body.removeEventListener(n,s)})}},{key:"getAttachTo",value:function(){var e=s(this.options.attachTo)||{},t=d({},e);return"string"==typeof e.element&&(t.element=document.querySelector(e.element),t.element||console.error("The element for this Shepherd step was not found "+e.element)),t}},{key:"setupTether",value:function(){if("undefined"==typeof e)throw new Error("Using the attachment feature of Shepherd requires the Tether library");var t=this.getAttachTo(),n=m[t.on||"right"]||t.on;"undefined"==typeof t.element&&(t.element="viewport",n="middle center");var i={classPrefix:"shepherd",element:this.el,constraints:[{to:"window",pin:!0,attachment:"together"}],target:t.element,offset:t.offset||"0 0",attachment:n};this.tether&&this.tether.destroy(),this.tether=new e(d(i,this.options.tetherOptions))}},{key:"show",value:function(){var e=this;if("undefined"!=typeof this.options.beforeShowPromise){var t=this.options.beforeShowPromise();if("undefined"!=typeof t)return t.then(function(){return e._show()})}this._show()}},{key:"_show",value:function(){var e=this;this.trigger("before-show"),this.el||this.render(),l(this.el,"shepherd-open"),document.body.setAttribute("data-shepherd-step",this.id),this.setupTether(),this.options.scrollTo&&setTimeout(function(){e.scrollTo()}),this.trigger("show")}},{key:"hide",value:function(){this.trigger("before-hide"),f(this.el,"shepherd-open"),document.body.removeAttribute("data-shepherd-step"),this.tether&&this.tether.destroy(),this.tether=null,this.trigger("hide")}},{key:"isOpen",value:function(){return this.el&&p(this.el,"shepherd-open")}},{key:"cancel",value:function(){this.tour.cancel(),this.trigger("cancel")}},{key:"complete",value:function(){this.tour.complete(),this.trigger("complete")}},{key:"scrollTo",value:function(){var e=this.getAttachTo(),t=e.element;"undefined"!=typeof this.options.scrollToHandler?this.options.scrollToHandler(t):"undefined"!=typeof t&&t.scrollIntoView()}},{key:"destroy",value:function(){"undefined"!=typeof this.el&&this.el.parentNode&&(this.el.parentNode.removeChild(this.el),delete this.el),this.tether&&this.tether.destroy(),this.tether=null,this.trigger("destroy")}},{key:"render",value:function(){var e=this;"undefined"!=typeof this.el&&this.destroy(),this.el=i("<div class='shepherd-step "+(this.options.classes||"")+"' data-id='"+this.id+"' "+(this.options.idAttribute?'id="'+this.options.idAttribute+'"':"")+"></div>");var t=document.createElement("div");t.className="shepherd-content",this.el.appendChild(t);var n=document.createElement("header");if(t.appendChild(n),this.options.title&&(n.innerHTML+="<h3 class='shepherd-title'>"+this.options.title+"</h3>",this.el.className+=" shepherd-has-title"),this.options.showCancelLink){var r=i("<a href class='shepherd-cancel-link'>āœ•</a>");n.appendChild(r),this.el.className+=" shepherd-has-cancel-link",this.bindCancelLink(r)}"undefined"!=typeof this.options.text&&!function(){var n=i("<div class='shepherd-text'></div>"),r=e.options.text;"function"==typeof r&&(r=r.call(e,n)),r instanceof HTMLElement?n.appendChild(r):("string"==typeof r&&(r=[r]),r.map(function(e){n.innerHTML+="<p>"+e+"</p>"})),t.appendChild(n)}();var s=document.createElement("footer");this.options.buttons&&!function(){var t=i("<ul class='shepherd-buttons'></ul>");e.options.buttons.map(function(n){var r=i("<li><a class='shepherd-button "+(n.classes||"")+"'>"+n.text+"</a>");t.appendChild(r),e.bindButtonEvents(n,r.querySelector("a"))}),s.appendChild(t)}(),t.appendChild(s),document.body.appendChild(this.el),this.setupTether(),this.options.advanceOn&&this.bindAdvance()}},{key:"bindCancelLink",value:function(e){var t=this;e.addEventListener("click",function(e){e.preventDefault(),t.cancel()})}},{key:"bindButtonEvents",value:function(e,t){var n=this;e.events=e.events||{},"undefined"!=typeof e.action&&(e.events.click=e.action);for(var i in e.events)if({}.hasOwnProperty.call(e.events,i)){var r=e.events[i];"string"==typeof r&&!function(){var e=r;r=function(){return n.tour.show(e)}}(),t.addEventListener(i,r)}this.on("destroy",function(){for(var n in e.events)if({}.hasOwnProperty.call(e.events,n)){var i=e.events[n];t.removeEventListener(n,i)}})}}]),c}(c),w=function(e){function i(){var e=this,n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];t(this,i),u(Object.getPrototypeOf(i.prototype),"constructor",this).call(this,n),this.bindMethods(),this.options=n,this.steps=this.options.steps||[];var r=["complete","cancel","hide","start","show","active","inactive"];return r.map(function(t){!function(t){e.on(t,function(n){n=n||{},n.tour=e,y.trigger(t,n)})}(t)}),this}return n(i,e),h(i,[{key:"bindMethods",value:function(){var e=this,t=["next","back","cancel","complete","hide"];t.map(function(t){e[t]=e[t].bind(e)})}},{key:"addStep",value:function(e,t){return"undefined"==typeof t&&(t=e),t instanceof b?t.tour=this:(("string"==typeof e||"number"==typeof e)&&(t.id=e.toString()),t=d({},this.options.defaults,t),t=new b(this,t)),this.steps.push(t),this}},{key:"removeStep",value:function(e){for(var t=this.getCurrentStep(),n=0;n<this.steps.length;++n){var i=this.steps[n];if(i.id===e){i.hide(),i.destroy(),this.steps.splice(n,1);break}}t&&t.id===e&&(this.currentStep=void 0,this.steps.length?this.show(0):this.hide())}},{key:"getById",value:function(e){for(var t=0;t<this.steps.length;++t){var n=this.steps[t];if(n.id===e)return n}}},{key:"getCurrentStep",value:function(){return this.currentStep}},{key:"next",value:function(){var e=this.steps.indexOf(this.currentStep);e===this.steps.length-1?(this.hide(e),this.trigger("complete"),this.done()):this.show(e+1,!0)}},{key:"back",value:function(){var e=this.steps.indexOf(this.currentStep);this.show(e-1,!1)}},{key:"cancel",value:function(){this.currentStep&&this.currentStep.hide(),this.trigger("cancel"),this.done()}},{key:"complete",value:function(){this.currentStep&&this.currentStep.hide(),this.trigger("complete"),this.done()}},{key:"hide",value:function(){this.currentStep&&this.currentStep.hide(),this.trigger("hide"),this.done()}},{key:"done",value:function(){y.activeTour=null,f(document.body,"shepherd-active"),this.trigger("inactive",{tour:this})}},{key:"show",value:function(){var e=arguments.length<=0||void 0===arguments[0]?0:arguments[0],t=arguments.length<=1||void 0===arguments[1]?!0:arguments[1];this.currentStep?this.currentStep.hide():(l(document.body,"shepherd-active"),this.trigger("active",{tour:this})),y.activeTour=this;var n=void 0;if(n="string"==typeof e?this.getById(e):this.steps[e])if("undefined"==typeof n.options.showOn||n.options.showOn())this.trigger("show",{step:n,previous:this.currentStep}),this.currentStep&&this.currentStep.hide(),this.currentStep=n,n.show();else{var i=this.steps.indexOf(n),r=t?i+1:i-1;this.show(r,t)}}},{key:"start",value:function(){this.trigger("start"),this.currentStep=null,this.next()}}]),i}(c);return d(y,{Tour:w,Step:b,Evented:c}),y});

@@ -52,3 +52,2 @@ var del = require('del');

// CSS

@@ -71,2 +70,7 @@ gulp.task('css', function() {

// Make a copy of tether available to those not using bundling
gulp.task('copy-tether', function() {
gulp.src('./bower_components/tether/tether.js')
.pipe(gulp.dest(distDir + '/js'));
});

@@ -95,5 +99,6 @@ // Eager

// Watch
gulp.task('watch', ['js', 'css'], function() {
gulp.task('watch', ['js', 'css', 'eager'], function() {
gulp.watch('./src/js/**/*', ['js']);
gulp.watch('./src/css/**/*', ['css']);
gulp.watch('./src/eager/**/*', ['eager']);
});

@@ -103,4 +108,4 @@

// Defaults
gulp.task('build', ['js', 'css', 'eager']);
gulp.task('build', ['js', 'css', 'eager', 'copy-tether']);
gulp.task('default', ['build']);

@@ -10,14 +10,22 @@ {

"type": "script",
"src": "./dist/js/shepherd.js"
"src": "./dist/js/tether.js"
},
{
"type": "script",
"src": "./dist/eager/installHelper.js"
"src": "./dist/js/shepherd.js"
},
{
"type": "script",
"contents": "ShepherdInstallHelper.init(INSTALL_OPTIONS)"
"src": "./dist/eager/installHelper.js"
}
]
},
"preview": {
"handlers": [
{
"options": ["*"],
"execute": "ShepherdInstallHelper.setOptions(INSTALL_OPTIONS)"
}
]
},
"options": {

@@ -77,4 +85,10 @@ "properties": {

},
"scrollTo": {
"order": 5,
"title": "Scroll To",
"description": "Should the page be scrolled to show steps when they open?",
"type": "boolean"
},
"steps": {
"order": 5,
"order": 6,
"title": "Steps",

@@ -81,0 +95,0 @@ "description": "Create a guided tour by creating steps anchored to the parts of your site you want to call attention. Each tour step points to a specific part of your page.",

{
"name": "tether-shepherd",
"version": "1.2.0",
"version": "1.6.0",
"description": "Guide your users through a tour of your app.",

@@ -5,0 +5,0 @@ "authors": [

## Shepherd
[![npm
version](https://badge.fury.io/js/tether-shepherd.svg)](http://badge.fury.io/js/tether-shepherd)
[![Bower
version](https://badge.fury.io/bo/tether-shepherd.svg)](http://badge.fury.io/bo/tether-shepherd)
[![GitHub
version](https://badge.fury.io/gh/HubSpot%2Fshepherd.svg)](http://badge.fury.io/gh/HubSpot%2Fshepherd)

@@ -8,0 +6,0 @@

@@ -46,2 +46,28 @@ /* global Tether */

const positionRe = /^(.+) (top|left|right|bottom|center|\[[a-z ]+\])$/
function parsePosition (str) {
if (typeof(str) === 'object') {
if (str.hasOwnProperty("element") && str.hasOwnProperty("on")) {
return str;
}
return null;
}
let matches = positionRe.exec(str);
if (!matches) {
return null;
}
let on = matches[2];
if (on[0] === '['){
on = on.substring(1, on.length - 1);
}
return {
'element': matches[1],
'on': on
};
}
function parseShorthand (obj, props) {

@@ -55,13 +81,13 @@ if (obj === null || typeof obj === 'undefined') {

let vals = obj.split(' ');
const valsLen = vals.length;
const propsLen = props.length;
if (valsLen > propsLen) {
vals[0] = vals.slice(0, (valsLen - propsLen) + 1).join(' ');
vals.splice(1, (valsLen, propsLen));
}
let out = {};
let j = props.length - 1;
for (let i = vals.length - 1; i >= 0; i--){
if (j === 0){
out[props[j]] = vals.slice(0, i + 1).join(' ');
break;
} else {
out[props[j]] = vals[i];
}
let out = {};
for (let i = 0; i < propsLen; ++i) {
const prop = props[i];
out[prop] = vals[i];
j--;
}

@@ -91,3 +117,4 @@

'scrollTo',
'destroy'
'destroy',
'render'
];

@@ -155,14 +182,15 @@ methods.map((method) => {

getAttachTo() {
let opts = parseShorthand(this.options.attachTo, ['element', 'on']) || {};
const selector = opts.element;
let opts = parsePosition(this.options.attachTo) || {};
let returnOpts = extend({}, opts);
if (typeof selector === 'string') {
opts.element = document.querySelector(selector);
if (!opts.element) {
throw new Error(`The element for this Shepherd step was not found ${selector}`);
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}`);
}
}
return opts;
return returnOpts;
}

@@ -176,3 +204,3 @@

let opts = this.getAttachTo();
let attachment = ATTACHMENT[opts.on || 'right'];
let attachment = ATTACHMENT[opts.on || 'right'] || opts.on;
if (typeof opts.element === 'undefined') {

@@ -251,3 +279,3 @@ opts.element = 'viewport';

isOpen() {
return hasClass(this.el, 'shepherd-open');
return this.el && hasClass(this.el, 'shepherd-open');
}

@@ -276,4 +304,4 @@

destroy() {
if (typeof this.el !== 'undefined') {
document.body.removeChild(this.el);
if (typeof this.el !== 'undefined' && this.el.parentNode) {
this.el.parentNode.removeChild(this.el);
delete this.el;

@@ -304,3 +332,3 @@ }

if (typeof this.options.title !== 'undefined') {
if (this.options.title) {
header.innerHTML += `<h3 class='shepherd-title'>${ this.options.title }</h3>`;

@@ -460,2 +488,25 @@ this.el.className += ' shepherd-has-title';

removeStep(name) {
const current = this.getCurrentStep();
for (let i = 0; i < this.steps.length; ++i) {
const step = this.steps[i];
if (step.id === name) {
step.hide();
step.destroy();
this.steps.splice(i, 1);
break;
}
}
if (current && current.id === name){
this.currentStep = undefined;
if (this.steps.length)
this.show(0);
else
this.hide();
}
}
getById(id) {

@@ -492,3 +543,3 @@ for (let i = 0; i < this.steps.length; ++i) {

cancel() {
if (typeof this.currentStep !== 'undefined') {
if (this.currentStep) {
this.currentStep.hide();

@@ -501,3 +552,3 @@ }

complete() {
if (typeof this.currentStep !== 'undefined') {
if (this.currentStep) {
this.currentStep.hide();

@@ -510,3 +561,3 @@ }

hide() {
if (typeof this.currentStep !== 'undefined') {
if (this.currentStep) {
this.currentStep.hide();

@@ -553,2 +604,6 @@ }

if (this.currentStep) {
this.currentStep.hide();
}
this.currentStep = next;

@@ -555,0 +610,0 @@ next.show();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc