Skip to content

Commit 7e0cf5b

Browse files
committed
fixes #599
1 parent 8ff6e9b commit 7e0cf5b

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

client/head/modal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Modal.prototype.remove = function() {
6969
document.body.classList.remove('paranja-open');
7070
document.body.removeChild(this.elem);
7171
document.removeEventListener("keydown", this.onDocumentKeyDown);
72+
this.elem.dispatchEvent(new CustomEvent("modal-remove"));
7273
};
7374

7475
module.exports = Modal;

handlers/tutorial/client/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ function init() {
1313
initSidebarHighlight();
1414

1515
delegate(document, '[data-action="tutorial-map"]', 'click', function(event) {
16-
new TutorialMapModal();
16+
if (event.which != 1) return; // only left-click, FF needs this
1717
event.preventDefault();
18+
showTutorialMapModal();
1819
});
1920

2021
prism.init();
@@ -28,10 +29,23 @@ function init() {
2829
var tutorialMapElem = document.querySelector('.tutorial-map');
2930
if (tutorialMapElem) {
3031
new TutorialMap(tutorialMapElem);
32+
} else if (/[&?]map\b/.test(location.href)) {
33+
showTutorialMapModal();
3134
}
3235

3336
}
3437

38+
function showTutorialMapModal() {
39+
40+
if (!/[&?]map\b/.test(location.href)) {
41+
window.history.replaceState(null, null, ~location.href.indexOf('?') ? (location.href + '&map') : (location.href + '?map'));
42+
}
43+
var modal = new TutorialMapModal();
44+
modal.elem.addEventListener('tutorial-map-remove', function() {
45+
window.history.replaceState(null, null, location.href.replace(/[&?]map\b/, ''));
46+
});
47+
48+
}
3549

3650
function initSidebarHighlight() {
3751

handlers/tutorial/client/tutorialMapModal.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ var trackSticky = require('client/trackSticky');
1515
* - after registration for "confirm email" link
1616
*/
1717
function TutorialMapModal() {
18+
this.elem = document.createElement('div');
19+
document.body.appendChild(this.elem);
20+
1821
var modal = new Modal({hasClose: false});
1922
var spinner = new Spinner();
2023
modal.setContent(spinner.elem);
@@ -28,11 +31,13 @@ function TutorialMapModal() {
2831

2932
request.addEventListener('success', (event) => {
3033
modal.remove();
31-
document.body.insertAdjacentHTML('beforeEnd', '<div class="tutorial-map-overlay"></div>');
32-
this.elem = document.body.lastChild;
33-
this.elem.innerHTML = event.result + '<button class="close-button tutorial-map-overlay__close"></button>';
3434

35-
this.elem.addEventListener('click', (e) => {
35+
this.elem.innerHTML = '<div class="tutorial-map-overlay"></div>';
36+
this.mapElem = this.elem.firstChild;
37+
38+
this.mapElem.innerHTML = event.result + '<button class="close-button tutorial-map-overlay__close"></button>';
39+
40+
this.mapElem.addEventListener('click', (e) => {
3641
if (e.target.classList.contains('tutorial-map-overlay__close')) {
3742
this.remove();
3843
}
@@ -42,9 +47,9 @@ function TutorialMapModal() {
4247

4348
document.body.classList.add('tutorial-map_on');
4449

45-
this.elem.addEventListener('scroll', trackSticky);
50+
this.mapElem.addEventListener('scroll', trackSticky);
4651

47-
new TutorialMap(this.elem.firstElementChild);
52+
new TutorialMap(this.mapElem.firstElementChild);
4853
});
4954

5055
request.addEventListener('fail', () => modal.remove());
@@ -54,6 +59,7 @@ function TutorialMapModal() {
5459
delegate.delegateMixin(TutorialMapModal.prototype);
5560

5661
TutorialMapModal.prototype.remove = function() {
62+
this.elem.dispatchEvent(new CustomEvent('tutorial-map-remove'));
5763
this.elem.remove();
5864
document.body.classList.remove('tutorial-map_on');
5965
document.removeEventListener("keydown", this.onDocumentKeyDown);

0 commit comments

Comments
 (0)