|
NAMEJQuery - Interface to Jquery, a language based on JavascriptVERSIONVersion 1.00SYNOPSISJQuery provides some of the functionality provided by the JQuery language.use JQuery; my $jquery = new JQuery(jqueryDir => '/jquery_js') ; my $accordion = JQuery::Accordion->new(id => 'myAccordion', headers => \@headers, texts => \@texts, panelHeight => 200, panelWidth => '400px' ) ; $jquery->add_css_last(new JQuery::CSS( hash => {'#myAccordion' => {width => '600px'}})) ; my $data = [['Id','Total','Ip','Time','US Short Date','US Long Date'], ['66672', '$22.79','172.78.200.124','08:02','12-24-2000','Jul 6, 2006 8:14 AM'], ['66672','$2482.79','172.78.200.124','15:10','12-12-2001','Jan 6, 2006 8:14 AM'] ] ; my $tableHTML = $jquery->Add(JQuery::TableSorter->new(id => 'table1', data => $data, headerClass => 'largeHeaders', dateFormat=>'dd/mm/yyyy' ))->HTML ; $jquery->add($accordion) ; my $html = $accordion->HTML . $tableHTML ; my $jquery_code = $jquery->get_jquery_code ; my $css = $jquery->get_css ; DESCRIPTIONJQuery is a frontend for the jQuery language. I use JQuery to refer to the Perl part or the package, and jQuery to reference the javascript part or the package.A quote from <http://jquery.com>: jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. JQuery.pm is the main module. There are other modules such as Form, TableSorter, Splitter, Taconite ..., all of which provide different functionality. The main module needs to be instantiated, and each instance of the other modules needs to be registered with the main module. It is then the responsibility of JQuery.pm to produce the relevant HTML, css and javascript code. One of the objectives is to produce javascript functioniality with as little user code as possible and to provide reasonable defaults. "Reasonable" is of course in the sight of the beholder. Most defaults are provided by css, and can be changed easily. Another objective is to allow module writers to be able to add new functionality within this framework. Using JQueryJQuery comes packaged with jQuery javascript files. Since the javascript directory is going to be needed by the web server, you will probably need to copy the whole of the jquery_js directory to somewhere the web server can access. Remember to change the web server config file if necessary.JQuery::CSSJQuery::CSS is a helper module that helps create CSS objects uses CSS module from CPAN.CSS can be created in the following ways: my $css = new JQuery::CSS(text => 'body {font-family: Arial, Sans-Serif;font-size: 10px;}') ; my $css = new JQuery::CSS( hash => { '.odd' => {'background-color' => "#FFF"} , '.even' => {'background-color' => "#D7FF00"} , }) ; my $css = new JQuery::CSS(file => 'dates/default.css') ;
InitializationJQuery needs to be initialized.my $jquery = new JQuery(jqueryDir => '/jquery_js', usePacked => 1) ; The parameter jqueryDir specifies where the javascript files can be found. When using a web server, this refers to the directory defined by the web server. If usePacked is set, the compressed jQuery files are used if available. Adding CSSCSS objects can be added to JQuery using $jquery->add_css($css) or $jquery->add_css_last($css) add_css outputs css before the css of the modules. add_css_last outputs css after the css of the modules. This is useful if you want to change the default css supplied by the package. Functions
JQuery::ExamplesThere are a number of working examples in the cgi-bin directory, which can be found in the Perl distribution under the JQuery directory. The examples are mostly written using CGI::Application , so you will need to install CGI-Application to run the examples. This is not a restriction, as the modules will work using CGI and mod-apache as well, and hopefully the framework of yor choice.Demo.pmThe examples mostly use Demo.pm. This is a very simple module which initializes JQuery, calls get_jquery_code, get_cssThe module Demo.pm simply does some of the repetitive work. The setupfunction initiates $jquery. cgiapp_postrun gets runs $jquery->get_jquery_code, $jquery->get_css and puts both of these, and the HTML, into a very basic template. AjaxLet's start with the Ajax.Suppose you have a button, not neccessarily in a form, and you want some action to happen when the user presses the button. Firstly, the JQuery module needs to be initialized. use JQuery ; use JQuery::Taconite ; my $jquery = new JQuery(jqueryDir => '/jquery_js') ; The button to be pressed needs an id, as it is going to accessed by javascript. So the HTML fragment could read: <input id="ex1" type="button" value="Run Example 1" /> JQuery::Taconite->new(id => 'ex1', remoteProgram => '/cgi-bin/jquery_taconite_results.pl', rm => 'myRunMode', addToJQuery => $jquery) ; You may or may not need to set the run mode. CGI-Applications normally need them, to define which function is to be executed in the CGI program. When the button is pressed, some output will be shown, and a placeholder is needed to display the text. The HTML fragment might be: <div id="example4" style="display:none; background-color: #ffa; padding:10px; border:1px solid #ccc"> Initially this div is hidden. </div> This is a div where, initially, the text is not shown. Example Programs
WRITING NEW MODULESA module needs to provide the following methodsnew - to create the object id - the id of the object. There are some modules that don't need this. This only happens in the case of where an instance does not have any css related to the id. get_css - returns the css for the instance. The return value may be an array reference. css may be plain text or a JQuery:CSS object. HTML - returns the HTML text for the instance packages_needed - returns a list of jquery packages needed for the javascript to run get_jquery_code - returns the jQuery code AUTHORPeter Gordon, "<peter at pg-consultants.com>"ACKNOWLEDGMENTSThanks to Brent Pedersen for pointing me in the direction of JQuery and to all contibutors to jQuery from whom css/images/whatever have been plagiarized.BUGSPlease report any bugs or feature requests to "bug-jquery at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=JQuery>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.SUPPORTYou can find documentation for this module with the perldoc command.perldoc JQuery You can also look for information at:
COPYRIGHT & LICENSECopyright 2007 Peter Gordon, all rights reserved.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |