next - previous page for the Logitech R400 presenter tool 

15 views
Skip to first unread message

mimosinnet

unread,
Feb 14, 2017, 2:15:40 PM2/14/17
to Mojolicious
This is a prototype implementing the 'next' and 'previous' slide for the Logitech R400 presenter tool using Mojolicious and jQuery. Really nice being able to insert perl code in the jQuery script! 
#!/usr/bin/env perl
use Mojolicious::Lite; 
get '/' => sub { shift->redirect_to('slide/1') };
get '/slide/:number' => sub {
my $c = shift;
my $number = $c->param('number');
$c->render ( number => $number );
} => 'slide'; 
app->start; 
__DATA__ 
@@ slide.html.ep
% title "slide $number";
% layout 'next_slide';
%= t p => "Slide $number"
<script>
$(document).ready(function(){
   $(document).keydown(function(e) {
if ( e.which === 33 ) {
window.location.href = '/slide/<%= $number - 1 %>';        
} else if ( e.which === 34 ) {
window.location.href = '/slide/<%= $number + 1 %>'; 
}
    });
});
</script> 
@@ layouts/next_slide.html.ep
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<h2>Press 'page-up' for previous slide, 'page-down' for next slide</h2>
%= content
</body>

Reply all
Reply to author
Forward
0 new messages