Keydownmanagement

General questions about CMSimple
Post Reply
sareide
Posts: 21
Joined: Sat Apr 07, 2012 1:26 pm

Keydownmanagement

Post by sareide » Sun Jul 06, 2014 9:09 pm

Hi all
is there an addon to manage keydown presses, that is to say, when I press keyboard arrow to right I go to the next sbling page, when I press keyboard arrow to left I go to the previous sbling page?

thanks in advance
sareide
Last edited by cmb on Sun Jul 06, 2014 9:15 pm, edited 1 time in total.
Reason: moved from "General Discussions" to "General Support" forum

cmb
Posts: 13244
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Keydownmanagement

Post by cmb » Sun Jul 06, 2014 9:31 pm

Hi sareide,

no, there is no such add-on. And it seems to me for this kind of functionality a CMSimple plugin is not the right solution[1]. Consider that you actually want to change the behavior of the browser; something that might be done via a bookmarklet, and might better left for the individual user to install.

It might be that some browsers already allow such navigation between pages, but they would probably need respective rel="next" and rel="prev" attributes, but these are not yet available in CMSimple(_XH). That is, however, planned for CMSimple_XH 1.6.3.

[1] It would be possible to do this with JavaScript, but that would be very annoying for some users (the arrow keys might be used for scrolling), and it might break other functionality of the website.

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

sareide
Posts: 21
Joined: Sat Apr 07, 2012 1:26 pm

Re: Keydownmanagement

Post by sareide » Mon Jul 07, 2014 6:03 pm

Hi
I'd like only two handlers to manage page left and page right. Consider that this feature is present in lightbox galleries, and It would be useful (with the add of a button toggle on the interface to set keyboard navigation on and off). or up and down for a child page.
I'm going to think a solution.....
bye
sareide

cmb
Posts: 13244
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Keydownmanagement

Post by cmb » Fri Aug 08, 2014 8:06 pm

Okay, a simple solution for modern browsers only (IE >= 9, as well as current version of Chrome, Firefox etc.) All changes go to template.htm. At first you have to wrap containers with certain ID around the previous and next page links that are generated by CMSimple_XH:

Code: Select all

<div id="previous_page"><?php echo previouspage();?></div>
<div id="next_page"><?php echo nextpage();?></div>
Then add just before the closing </body> tag:

Code: Select all

<script type="text/javascript">/* <![CDATA[ */
if (typeof document.addEventListener !== "undefined" &&
        typeof document.querySelector !== "undefined") {
    document.addEventListener("keydown", function (event) {
        var a;

        switch (event.keyCode) {
        case 37: // left
            a = document.querySelector("#previous_page a");
            if (a) {
                location.href = a.href;
            }
            break;
        case 39: // right
            a = document.querySelector("#next_page a");
            if (a) {
                location.href = a.href;
            }
            break;
        }
    });
}
/* ]]> */</script>
</body><!-- this line should be already there -->
If a user holds down the left or right arrow for a while, the navigation repeats--that may be desireable or not. If not change "keydown" in the 4th line to "keyup".
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply