Catalyst-View-Component-jQuery

 view release on metacpan or  search on metacpan

examples/README  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
This example requires:
 
CatalystX::Menu::Suckerfish - used to generate a Superfish navbar from test application's action attributes.
 
Read the begin action in TestApp/Controller/Root.pm to see how the jQuery wrapper instance
(JavaScript::Framework::jQuery::Plugin::Superfish) is instantiated so that its assets
will be inserted into the template (TestApp/root/src/index.tt2).
 
Run the example with:
 
perl script/testapp_server.pl

examples/TestApp/Controller/Root.pm  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
use strict;
 
 
 
__PACKAGE__->config(namespace => q{});
 
sub begin :Private {
    my ( $self, $c ) = @_;
 
    my $suckerfish = CatalystX::Menu::Suckerfish->new(
        context => $c,
        ul_id => 'navmenu',
        ul_class => 'sf-menu',
        menupath_attr => 'MenuPath',
        menutitle_attr => 'MenuTitle',
        text_container => {
            element => 'span',
            attrs => { class => 'sf-label' },
        },
        add_nodes => [
            {
                menupath => '/Other sites/Google',
                menutitle => 'Google',
                uri => 'http://google.com',
            },

examples/TestApp/Controller/Root.pm  view on Meta::CPAN

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    $c->stash(menu => $suckerfish->output);
}
 
sub end :Private {
    my ( $self, $c ) = @_;
    $c->forward('TestApp::View::TT') unless $c->res->body;
}
 
sub index
    :Path
    :MenuPath('/Home')
    :MenuTitle('Home Page')
    {
    my ( $self, $c ) = @_;
}
 
sub dostuff
    :Local
    :MenuPath('/Stuff')
    :MenuTitle('Do Stuff')
    {
    my ( $self, $c ) = @_;
    $c->stash->{template} = 'index.tt2';
    $c->forward('index');
}
 
sub prettypix
    :Local
    :MenuPath('/Pretty/Pictures')
    :MenuTitle('See pretty pictures')
    {
    my ( $self, $c ) = @_;
    $c->stash->{template} = 'index.tt2';
    $c->forward('index');
}
 
sub printtemplate
    :Local
    :MenuPath('/How it works/The template')
    :MenuTitle('The template')
    {
    my ( $self, $c ) = @_;
    my $text;
    { local (@ARGV, $/) = 'TestApp/root/src/index.tt2'; $text = <> }
    $c->res->content_type('text/plain');
    $c->res->body($text);
}
 
1;

examples/TestApp/root/src/index.tt2  view on Meta::CPAN

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Catalyst::View::Component::jQuery Demo</title>
[% jquery.link_elements %]
[% jquery.script_src_elements %]
</head>
<body>
    <h2>Catalyst::View::Component::jQuery Demo</h2>
<p>
    Navigation menu generated automatically from Catalyst application action attributes (MenuPath and MenuTitle).
</p>
<div style="float: left">
[% menu %]
</div>
<p style="clear: both">
    This page demonstrates the use of <a href="http://search.cpan.org/perldoc?Catalyst::View::Component::jQuery">Catalyst::View::Component::jQuery</a>
    to make a "jquery" method available in your TT templates.
</p>
<p><a href="http://search.cpan.org/perldoc?CatalystX::Menu::Suckerfish">CatalystX::Menu::Suckerfish</a>
    is used to generate a Suckerfish-style menu from action attributes defined in the TestApp application.
    Modify the MenuPath and MenuTitle attributes and restart the application to see how the menu is
    automatically generated on-the-fly.
</p>
<p>
    Running the testapp_server.pl script with the -r switch will automatically restart the script if you
    want a quick way to test changes.
</p>
<p>
The following three lines in the template print the html elements required to fetch the stylesheets and
JavaScript files required by your jQuery plugins, and then the jQuery ready event.
[% stag = "[\%"

examples/TestApp/root/static/js/superfish.js  view on Meta::CPAN

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 */
 
;(function($){
        $.fn.superfish = function(op){
 
                var sf = $.fn.superfish,
                        c = sf.c,
                        $arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
                        over = function(){
                                var $$ = $(this), menu = getMenu($$);
                                clearTimeout(menu.sfTimer);
                                $$.showSuperfishUl().siblings().hideSuperfishUl();
                        },
                        out = function(){
                                var $$ = $(this), menu = getMenu($$), o = sf.op;
                                clearTimeout(menu.sfTimer);
                                menu.sfTimer=setTimeout(function(){
                                        o.retainPath=($.inArray($$[0],o.$path)>-1);
                                        $$.hideSuperfishUl();
                                        if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
                                },o.delay);    
                        },
                        getMenu = function($menu){
                                var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
                                sf.op = sf.o[menu.serial];
                                return menu;
                        },
                        addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
                         
                return this.each(function() {
                        var s = this.serial = sf.o.length;
                        var o = $.extend({},sf.defaults,op);
                        o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){

lib/Catalyst/View/Component/jQuery.pm  view on Meta::CPAN

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
In your Controller:
 
 $c->view('TT')->jquery->construct_plugin(
    name => 'Superfish',
    target_selector => '#navbar',
 );
 
I<#navbar> is the document id of a UL element containing navigation links.
 
See L<CatalystX::Menu::Suckerfish> for one method for generating such a
UL element automatically by decorating C<action> methods with
attributes.
 
In your template:
 
 [% jquery.script_src_elements %]
 [% jquery.link_elements %]
 
 [% jquery.document_ready %]

lib/Catalyst/View/Component/jQuery.pm  view on Meta::CPAN

259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
=item * Search CPAN
 
 
=back
 
=cut
 
=head1 SEE ALSO
 
L<JavaScript::Framework::jQuery>, L<CatalystX::Menu::Suckerfish>, L<Moose>, L<Moose::Role>, L<Catalyst>, L<perl>
 
=head1 COPYRIGHT AND LICENSE
 
Copyright 2009 David P.C. Wollmann, all rights reserved.
 
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
 
=cut



( run in 0.443 second using v1.01-cache-2.11-cpan-87723dcf8b7 )