forum.coppermine-gallery.net

Support => cpg1.5 plugins => cpg1.5.x Support => cpg1.5 plugin contributions => Topic started by: Αndré on January 07, 2009, 09:00:40 am

Title: Keyboard Navigation for cpg1.5.x
Post by: Αndré on January 07, 2009, 09:00:40 am
Navigate to the previous/next picture, go back to the thumbnail page and switch the file info details via the keyboard arrows.

Since version 2.0 it's possible to navigate to the previous/next thumbnail page.
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: SaWey on January 07, 2009, 11:05:38 am
It might be easier to just use jQuery to do all that, wouldn't this code work:

Code: (javascript) [Select]
var sthhasfocus;

$('.navmenu_pic[rel!=nofollow]').each(function(id, el){
    if(id==0){
        $(this).attr('id', 'thumb');
    }else if(id==1){
        $(this).attr({id: 'prev', accesskey: 'p'});
    }else if(id==2){
        $(this).attr({id: 'next', accesskey: 'n'});
    }
});

$('.textinput').blur(function () {sthhasfocus = false;});
$('.textinput').focus(function () {sthhasfocus = true;});

$(window).keydown(function(e){
if (!e)
        e = window.event;
    if (e.which)
        Tastencode = e.which;
    else if (e.keyCode)
        Tastencode = e.keyCode;

console.log(sthhasfocus + ' ' + Tastencode);
    if (sthhasfocus != true)
    {
        if(Tastencode == 37 && $('#prev').attr('title') != '')
            window.location = $('#prev').attr('href');
        if(Tastencode == 39 && $('#next').attr('title') != '')
            window.location = $('#next').attr('href');
        if(Tastencode == 38)
            window.location = $('#thumb').attr('href');
        if(Tastencode == 40)
        {
            blocking('picinfo','yes', 'block');
            return false;
        }
    }
});
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Αndré on January 07, 2009, 11:34:52 am
I haven't worked with jQuery yet, but your code doesn't work as is.

Is this function correct?
Code: [Select]
function(id, el){
    if(id==0){
        $(this).attr('id', 'thumb');
    }else if(id==1){
        $(this).attr({id: 'prev', accesskey: 'p'});
    }else if(id==2){
        $(this).attr({id: 'next', accesskey: 'n'});
    }
}
I think it could come to problems, when someone change the order of (or add/remove) buttons in the navbar.
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: SaWey on January 07, 2009, 11:44:13 am
I wrote this quickly and it worked for me, but there could be some mistakes :)

I just checked it and saw I left a firebug command in there, which prevents it from working when you don't have firebug

this code works for IE7, FF3 & Chrome:
Code: (javascript) [Select]
var sthhasfocus;
$(document).ready(function() {
$('.navmenu_pic[rel!=nofollow]').each(function(id, el){
if(id==0){
$(this).attr('id', 'thumb');
}else if(id==1){
$(this).attr({id: 'prev', accesskey: 'p'});
}else if(id==2){
$(this).attr({id: 'next', accesskey: 'n'});
}
});

$('.textinput').blur(function () {sthhasfocus = false;});
$('.textinput').focus(function () {sthhasfocus = true;});
});

$(document).keydown(function(e){
if (!e)
        e = window.event;
    if (e.which)
        Tastencode = e.which;
    else if (e.keyCode)
        Tastencode = e.keyCode;
    if (sthhasfocus != true)
    {
        if(Tastencode == 37 && $('#prev').attr('title') != '')
            window.location = $('#prev').attr('href');
        if(Tastencode == 39 && $('#next').attr('title') != '')
            window.location = $('#next').attr('href');
        if(Tastencode == 38)
            window.location = $('#thumb').attr('href');
        if(Tastencode == 40)
        {
            blocking('picinfo','yes', 'block');
            return false;
        }
    }
});


Concerning the change of order, I don't think the user will change the prev/next buttons :) But then again, who knows...
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Αndré on January 07, 2009, 11:53:04 am
I have firebug, too. But it doesn't work for me (I have to say, that I don't have the actual svn version). Maybe I do something wrong ???

My codebase.php:
Code: [Select]
<?php
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
js_include('plugins/keyboard_navigation_jquery/js/keyboard_navigation.js');
The .js file will be included in the html source code.

In keyboard_navigation.js is your code. Something more to do?
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: SaWey on January 07, 2009, 12:01:12 pm
You shouldn't include the script directly like that, you should do it within a function that's been called by the API, because now, the script is loaded before jQuery and it has to be loaded after it to use its functionality.
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Αndré on January 07, 2009, 01:39:41 pm
the script is loaded before jQuery and it has to be loaded after it to use its functionality.
You're right :D It works now in my gallery as plugin.

Can you explain me what the "el" is for?
   $('.navmenu_pic[rel!=nofollow]').each(function(id, el){
It still works, if I delete the "el" :P


Concerning the change of order, I don't think the user will change the prev/next buttons :) But then again, who knows...
See here (http://erwischt.org/dessau/photos/displayimage.php?pos=-121163) - 1. prev file, 2. thumbnail page, 3. next file. Isn't there a better way to detect the buttons and give them an id? If not, I think my first plugin version is more flexible for the different themes.
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: SaWey on January 07, 2009, 04:17:30 pm
Can you explain me what the "el" is for? It still works, if I delete the "el" :P
'el' was used in my first version until I remembered I could use the 'this' keyword

See here (http://erwischt.org/dessau/photos/displayimage.php?pos=-121163) - 1. prev file, 2. thumbnail page, 3. next file. Isn't there a better way to detect the buttons and give them an id? If not, I think my first plugin version is more flexible for the different themes.

Here I have a better one, this should work on all templates:
Code: [Select]
var sthhasfocus;
$(document).ready(function() {

$('.navmenu_pic img[src*=thumb]').parent().attr('id', 'thumb');
$('.navmenu_pic img[src*=prev]').parent().attr({id: 'prev', accesskey: 'p'});
$('.navmenu_pic img[src*=next]').parent().attr({id: 'next', accesskey: 'n'});
$('.textinput').blur(function () {sthhasfocus = false;});
$('.textinput').focus(function () {sthhasfocus = true;});
});

$(document).keydown(function(e){
if (!e)
        e = window.event;
    if (e.which)
        Tastencode = e.which;
    else if (e.keyCode)
        Tastencode = e.keyCode;
    if (sthhasfocus != true)
    {
        if(Tastencode == 37 && $('#prev').attr('title') != '')
            window.location = $('#prev').attr('href');
        if(Tastencode == 39 && $('#next').attr('title') != '')
            window.location = $('#next').attr('href');
        if(Tastencode == 38)
            window.location = $('#thumb').attr('href');
        if(Tastencode == 40)
        {
            blocking('picinfo','yes', 'block');
            return false;
        }
    }
});
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Αndré on January 08, 2009, 09:32:07 am
I attached the jQuery version (v1.1.0) in my first post.

I still use my plugin hook:
Code: [Select]
$template_img_navbar = CPGPluginAPI::filter('theme_img_navbar', $template_img_navbar);
Can someone commit this hook to the svn? I think it's useful for this plugin (because my plugin refers to the navbar) and maybe it can be used for other plugins (e.g. in my 1.4.x gallery I have added a button in the navbar to add/remove favorite pictures - I could use this hook to create a plugin for this). Thank you :)
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Paver on January 08, 2009, 10:31:16 am
Hook 'theme_img_navbar' committed to SVN.
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Αndré on January 08, 2009, 10:39:48 am
Thank you Paver. Shall we split the coding discussion from the announcement thread?
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Paver on January 08, 2009, 10:47:21 am
I think everything before the release of 1.5 (beta or final release) is coding discussion so why not keep it all here for development.

Later, a separate announcement thread can be created for the plugin once 1.5 is released and then you can use that for support from users.  This thread can be linked from it for historical purposes.

That's my suggestion.
Title: Re: Keyboard Navigation for CPG 1.5.x
Post by: Joachim Müller on March 21, 2009, 12:36:38 pm
Added plugin to downloads section and to subversion repository (http://coppermine.svn.sourceforge.net/viewvc/coppermine/branches/cpg1.5.x/plugins/keyboard_navigation/).
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: bockor on June 04, 2010, 12:48:08 am
Hi guys!

I`m using this plugin v1.3 and LightBox Slideshow jquery (NotesFor.net) v2.9 plugin at the same time. When in LightBox view, the keyboard plugin overrides the LightBox keydown event and LightBox dissapears.
So I added one more condition before taking action on keydown event of this plugin. I`m checking if lightbox is currently on or not.
Added to codebase.php before line 40:
Code: [Select]

var lb = $("#jquery-lightbox").length;
if (sthhasfocus != true && lb!=1) { ....

Oh.. and description says "Coppermine 1.5.x Plugin - keyword_navigation" ... should be keyboard_navigation :)

Hope this helps for somebody else.



Title: Re: Keyboard Navigation for cpg1.5.x
Post by: Αndré on June 04, 2010, 08:06:58 am
Thanks for reporting. Attached updated plugin to initial post.
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: papukaija on June 10, 2010, 09:52:05 am
Why not include javascript file with the $js_includes[]? The benefit is that the js file will be included at the same place than the other js files. The second benefit is that the Jsmin plugin (http://forum.coppermine-gallery.net/index.php/topic,63223.0.html) would be able to use the javascript file from this plugin.
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: Αndré on June 10, 2010, 10:04:04 am
I don't know / I can't remember ;) Maybe it's a historical issue. I'll think about that :)
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: Αndré on June 11, 2010, 11:42:36 am
Attached version 1.5 to initial post.
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: papukaija on June 11, 2010, 11:31:50 pm
Thanks for your fast updated release.
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: pols1337 on January 15, 2012, 04:35:13 am
Quick question: does the "Down" button do anything? 

I thought maybe it would show / hide the file information, but I can't see any changes on my gallery. 
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: papukaija on January 15, 2012, 01:11:42 pm
@pols1337: Yes, that's what it's supposed to do. Please post a link to your gallery (http://forum.coppermine-gallery.net/index.php/topic,55415.msg270616.html#msg270616) if you require further help.

switch the file info details via the keyboard arrows.
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: pols1337 on January 15, 2012, 07:40:54 pm
Ah okay, yes it does show / hide the file information.  I just wasn't sure about the functionality. 

Another question: it only works on displayimage.php correct?  For example, it does not navigate between album pages (that show the thumbnails)? 
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: Αndré on January 15, 2012, 08:17:42 pm
it does not navigate between album pages (that show the thumbnails)? 
Correct. But that might be a good addition ;)
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: pols1337 on January 15, 2012, 11:09:05 pm
You should do it! 

/support  :)
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: Αndré on January 17, 2012, 04:11:55 pm
Version 2.0 attached to initial post.
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: Αndré on September 05, 2012, 05:02:07 pm
Version 2.1 (attached to initial post) uses a different way to detect if some form element currently has focus (better compatibility with e.g. the annotation plugin).
Title: undefinded page in keyboard naviagation
Post by: jaus on December 15, 2013, 02:21:46 pm
I installed the Keyboard Navigation for cpg1.5.x plugin and have noticed that, while the plugin is installed, using an arrow key while in the slideshow causes cpg to go to  <mysite>\undefined,  resulting in a 404 error page.  I assume this is a bug?
Title: Re: Keyboard Navigation for cpg1.5.x
Post by: Αndré on December 16, 2013, 12:05:58 pm
Fixed in SVN revision 8628. Version 2.2 attached to initial post.