Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retethering issue when anchor refs are removed #95

Merged
merged 4 commits into from
Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions dist/js/shepherd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! tether-shepherd 1.5.1 */
/*! tether-shepherd 1.5.2 */

(function(root, factory) {
if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -67,7 +67,6 @@ function matchesSelector(el, sel) {
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;
Expand Down Expand Up @@ -207,18 +206,23 @@ var Step = (function (_Evented) {
}, {
key: 'getAttachTo',
value: function getAttachTo() {
var returnOpts = {};
var opts = parsePosition(this.options.attachTo) || {};
var selector = opts.element;

if (typeof selector === 'string') {
opts.element = document.querySelector(selector);
returnOpts.on = opts.on;
if (opts.offset !== 'undefined') {
returnOpts.offset = opts.offset;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just do returnOpts = extend({}, opts)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right - I got this confused with something else, it's only a single level of props so i wouldn't need deep copy anyway.


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) {
throw new Error('The element for this Shepherd step was not found ' + opts.element);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned that throwing an error may be more aggressive than is necessary. It might be better to use console.error here, to not prevent other js on the page from executing properly.

}
}

return opts;
return returnOpts;
}
}, {
key: 'setupTether',
Expand Down
Loading