Catalyst-View-Component-jQuery

 view release on metacpan or  search on metacpan

examples/README  view on Meta::CPAN

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

package TestApp::Controller::Root;

use strict;
use warnings;

use Catalyst;
use base 'Catalyst::Controller';

use CatalystX::Menu::Suckerfish;

__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

    $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

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<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

 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(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


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

=item * Search CPAN

L<http://search.cpan.org/dist/Catalyst-View-Component-jQuery/>

=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.477 second using v1.01-cache-2.11-cpan-87723dcf8b7 )