Skip to content

Commit

Permalink
Returns click focus to parent window when iframe is clicked so that t…
Browse files Browse the repository at this point in the history
…he Escape-to-close will work; fixes #47
  • Loading branch information
scott2b committed Sep 16, 2016
1 parent d33e2e0 commit 8f9dbc1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/js/bookmarklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function iFrame(apiRoot) {
url = composeURL(text, image, cite)

loadTemplate(url);
bindEscape();

return false;
}
Expand Down Expand Up @@ -71,6 +72,15 @@ function iFrame(apiRoot) {
document.body.removeChild(bookMarklet)
}

function bindEscape() {
document.onkeydown = function(evt) {
if ( evt.key === 'Escape'
|| evt.keyCode === 27) {
}
bookmarklet.iFrame().closeiFrame();
}
}

return {
init: init,
closeiFrame: closeiFrame
Expand Down
13 changes: 12 additions & 1 deletion src/js/compositions.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ KL.Pullquote = (function() {
}
};

bindClicks = function() {
/* Return click focus to parent of iframe so parent keybindings
* continue to work.
*/
document.onclick = function(evt) {
window.parent.focus();
};
}

/**
* _init: creates the composition for pullquote
*
Expand All @@ -122,7 +131,9 @@ KL.Pullquote = (function() {
//{ position: "kl-anchor-left", use_image: true },
//{ position: "kl-anchor-right", use_image: true },
//{ position: "kl-anchor-false", use_image: false }
])
]);

bindClicks();
}();

})();
6 changes: 0 additions & 6 deletions src/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
});
req.open('GET', '{{ pullquoteURL }}templates/template.html');
req.send();
document.onkeydown = function(evt) {
if ( evt.key === 'Escape'
|| evt.keyCode === 27) {
}
bookmarklet.iFrame().closeiFrame();
}
}
})();"

Expand Down

0 comments on commit 8f9dbc1

Please sign in to comment.