diff --git a/spec/regexper_spec.js b/spec/regexper_spec.js
index c3fabc4..a4a05fc 100644
--- a/spec/regexper_spec.js
+++ b/spec/regexper_spec.js
@@ -9,11 +9,15 @@ describe('regexper.js', function() {
beforeEach(function() {
this.root = document.createElement('div');
this.root.innerHTML = [
- '
',
+ '',
'',
'',
- '',
- '',
'',
].join('');
@@ -308,7 +312,8 @@ describe('regexper.js', function() {
it('hides the download link', function() {
this.regexper.updateLinks();
- expect(this.regexper.download.parentNode.style.display).toEqual('none');
+ expect(this.regexper.links.className).toMatch(/\bexample\b/);
+ expect(this.regexper.links.className).toMatch(/\bhide-download\b/);
});
});
@@ -334,7 +339,8 @@ describe('regexper.js', function() {
it('hides the permalink', function() {
this.regexper.updateLinks();
- expect(this.regexper.permalink.parentNode.style.display).toEqual('none');
+ expect(this.regexper.links.className).toMatch(/\bexample\b/);
+ expect(this.regexper.links.className).toMatch(/\bhide-permalink\b/);
});
});
diff --git a/src/index.html b/src/index.html
index 9af9bbb..026d5a5 100644
--- a/src/index.html
+++ b/src/index.html
@@ -4,8 +4,12 @@
diff --git a/src/js/regexper.js b/src/js/regexper.js
index fade574..9843312 100644
--- a/src/js/regexper.js
+++ b/src/js/regexper.js
@@ -10,8 +10,11 @@ export default class Regexper {
this.field = root.querySelector('#regexp-input');
this.error = root.querySelector('#error');
this.warnings = root.querySelector('#warnings');
- this.permalink = root.querySelector('a[data-glyph="link-intact"]');
- this.download = root.querySelector('a[data-glyph="data-transfer-download"]');
+
+ this.links = this.form.querySelector('ul');
+ this.permalink = this.links.querySelector('a[data-glyph="link-intact"]');
+ this.download = this.links.querySelector('a[data-glyph="data-transfer-download"]');
+
this.svgContainer = root.querySelector('#regexp-render');
}
@@ -97,6 +100,8 @@ export default class Regexper {
}
updateLinks() {
+ var classes = _.without(this.links.className.split(' '), ['hide-download', 'hide-permalink']);
+
try {
this.download.parentNode.style.display = null;
this.download.href = this.buildBlobURL(this.svgContainer.querySelector('.svg').innerHTML);
@@ -104,15 +109,17 @@ export default class Regexper {
catch(e) {
// Blobs or URLs created from them don't work here.
// Giving up on the download link
- this.download.parentNode.style.display = 'none';
+ classes.push('hide-download');
}
if (this.permalinkEnabled) {
this.permalink.parentNode.style.display = null;
this.permalink.href = location.toString();
} else {
- this.permalink.parentNode.style.display = 'none';
+ classes.push('hide-permalink');
}
+
+ this.links.className = classes.join(' ');
}
displayWarnings(warnings) {
diff --git a/src/sass/main.scss b/src/sass/main.scss
index 9471b09..75ecb79 100644
--- a/src/sass/main.scss
+++ b/src/sass/main.scss
@@ -273,6 +273,12 @@ header {
body.has-results & {
display: inline-block;
}
+
+ &.hide-permalink .permalink,
+ &.hide-permalink .download::after,
+ &.hide-download .download {
+ display: none;
+ }
}
}