Skip to content

Commit

Permalink
fixes insertion of title element to not use innerHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckcarpenter committed Aug 28, 2018
1 parent d2478a2 commit 580fe8a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 11 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"dependencies": {
"element-matches": "^0.1.2",
"lodash": "^4.17.10",
"popper.js": "^1.14.3"
"popper.js": "^1.14.3",
"sinon": "^6.1.5"
},
"devDependencies": {
"autoprefixer": "^9.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src/js/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ export function bindMethods(methods) {
methods.map((method) => {
this[method] = this[method].bind(this);
});
}
}
16 changes: 9 additions & 7 deletions src/js/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class Step extends Evented {
header.appendChild(link);

element.classList.add('shepherd-has-cancel-link');

this.bindCancelLink(link);
}
}
Expand Down Expand Up @@ -138,6 +137,14 @@ export class Step extends Evented {
const element = createFromHTML(`<div class='${classes}' data-id='${this.id}' id="${this.options.idAttribute}"}>`);
const header = document.createElement('header');

if (this.options.title) {
const title = document.createElement('h3');
title.classList.add('shepherd-title');
title.innerHTML = `${this.options.title}`;
header.prepend(title);
element.classList.add('shepherd-has-title');
}

content.classList.add('shepherd-content');
element.appendChild(content);
content.appendChild(header);
Expand All @@ -153,11 +160,6 @@ export class Step extends Evented {
this._addButtons(content);
this._addCancelLink(element, header);

if (this.options.title) {
header.innerHTML += `<h3 class="shepherd-title">${this.options.title}</h3>`;
element.classList.add('shepherd-has-title');
}

return element;
}

Expand Down Expand Up @@ -222,7 +224,7 @@ export class Step extends Evented {
const { when } = this.options;

this.destroy();
this.id = this.options.id || this.id || `step-${uniqueId()}`;
this.id = this.options.id || `step-${uniqueId()}`;

This comment has been minimized.

Copy link
@RobbieTheWagner

RobbieTheWagner Aug 28, 2018

Member

@chuckcarpenter why remove this.id?


_.forOwn(when, (handler, event) => {
this.on(event, handler, this);
Expand Down
20 changes: 20 additions & 0 deletions test/unit/test.step.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { spy } from 'sinon';

chai.use(chaiAsPromised);
const { assert } = chai;
Expand Down Expand Up @@ -144,6 +145,25 @@ describe('Step', () => {

assert.isOk(advanced, 'next triggered for advanceOn');
});

it('it should call removeEventListener when destoryed', function(done){
const el = document.createElement('div');
const body = spy(document.body, 'removeEventListener');
const step = new Step({
next: () => true
}, {
advanceOn: { event: 'test' }
});
step.el = el;
step.el.hidden = false;

step.bindAdvance();
step.trigger('destroy');
assert.ok(body.called);
body.restore();
done();
});

});

describe('bindButtonEvents()', () => {
Expand Down
70 changes: 68 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@
debug "^3.1.0"
lodash.once "^4.1.1"

"@sinonjs/commons@^1.0.1":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.0.2.tgz#3e0ac737781627b8844257fadc3d803997d0526e"
dependencies:
type-detect "4.0.8"

"@sinonjs/formatio@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-2.0.0.tgz#84db7e9eb5531df18a8c5e0bfb6e449e55e654b2"
dependencies:
samsam "1.3.0"

"@sinonjs/samsam@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/samsam/-/samsam-2.0.0.tgz#9163742ac35c12d3602dece74317643b35db6a80"

"@types/blob-util@1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@types/blob-util/-/blob-util-1.3.3.tgz#adba644ae34f88e1dd9a5864c66ad651caaf628a"
Expand Down Expand Up @@ -2539,7 +2555,7 @@ dev-ip@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/dev-ip/-/dev-ip-1.0.1.tgz#a76a3ed1855be7a012bb8ac16cb80f3c00dc28f0"

diff@3.5.0:
diff@3.5.0, diff@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"

Expand Down Expand Up @@ -4635,6 +4651,10 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

just-extend@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-3.0.0.tgz#cee004031eaabf6406da03a7b84e4fe9d78ef288"

killable@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.0.tgz#da8b84bd47de5395878f95d64d02f2449fe05e6b"
Expand Down Expand Up @@ -4837,6 +4857,10 @@ lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"

lodash.isfinite@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/lodash.isfinite/-/lodash.isfinite-3.3.2.tgz#fb89b65a9a80281833f0b7478b3a5104f898ebb3"
Expand Down Expand Up @@ -4880,6 +4904,10 @@ loglevel@^1.4.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.1.tgz#e0fc95133b6ef276cdc8887cdaf24aa6f156f8fa"

lolex@^2.3.2, lolex@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.1.tgz#e40a8c4d1f14b536aa03e42a537c7adbaf0c20be"

long@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
Expand Down Expand Up @@ -5330,6 +5358,16 @@ nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"

nise@^1.4.2:
version "1.4.4"
resolved "https://registry.yarnpkg.com/nise/-/nise-1.4.4.tgz#b8d9dd35334c99e514b75e46fcc38e358caecdd0"
dependencies:
"@sinonjs/formatio" "^2.0.0"
just-extend "^3.0.0"
lolex "^2.3.2"
path-to-regexp "^1.7.0"
text-encoding "^0.6.4"

no-case@^2.2.0:
version "2.3.2"
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.2.tgz#60b813396be39b3f1288a4c1ed5d1e7d28b464ac"
Expand Down Expand Up @@ -5863,6 +5901,12 @@ path-to-regexp@0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"

path-to-regexp@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
dependencies:
isarray "0.0.1"

path-type@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441"
Expand Down Expand Up @@ -6814,6 +6858,10 @@ safe-regex@^1.1.0:
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"

samsam@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.3.0.tgz#8d1d9350e25622da30de3e44ba692b5221ab7c50"

sass-graph@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/sass-graph/-/sass-graph-2.2.4.tgz#13fbd63cd1caf0908b9fd93476ad43a51d1e0b49"
Expand Down Expand Up @@ -6998,6 +7046,20 @@ signal-exit@^3.0.0, signal-exit@^3.0.1, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

sinon@^6.1.5:
version "6.1.5"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-6.1.5.tgz#41451502d43cd5ffb9d051fbf507952400e81d09"
dependencies:
"@sinonjs/commons" "^1.0.1"
"@sinonjs/formatio" "^2.0.0"
"@sinonjs/samsam" "^2.0.0"
diff "^3.5.0"
lodash.get "^4.4.2"
lolex "^2.7.1"
nise "^1.4.2"
supports-color "^5.4.0"
type-detect "^4.0.8"

slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
Expand Down Expand Up @@ -7732,6 +7794,10 @@ test-exclude@^4.2.0, test-exclude@^4.2.1:
read-pkg-up "^1.0.1"
require-main-filename "^1.0.1"

text-encoding@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"

text-table@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
Expand Down Expand Up @@ -7902,7 +7968,7 @@ type-check@~0.3.2:
dependencies:
prelude-ls "~1.1.2"

type-detect@^4.0.0:
type-detect@4.0.8, type-detect@^4.0.0, type-detect@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c"

Expand Down

0 comments on commit 580fe8a

Please sign in to comment.