Ticket #539: function.jAjaxLink.php

File function.jAjaxLink.php, 2.3 kB (added by sylvain261, 8 months ago)

Plugin pour jtpl

Line 
1 <?php
2 /**
3 * @package    jelix
4 * @subpackage jtpl_plugin
5 * @version    $Id$
6 * @author     Sylvain de Vathaire
7 * @copyright  2008 Sylvain de Vathaire
8 * @link        http://www.jelix.org
9 * @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
10 */
11
12 /**
13  * function plugin :  Cr�un lien HTML g�nt le chargement d'une zone en ajax OU si js d�ctiv�echargeant la page avec la zone affich� * Rely on jquery and ajaxZone
14  *
15  * @param jTpl $tpl template engine
16  * @param string $txt txt of the link tag
17  * @param string $blockId Id of the HTML containet element (usualy a div element)
18  * @param string $tplName Template to load using the ajaxZone
19  * @param array  $tagAttr Attributes of the tag
20  * @param string $classActive className to use if the link is the active one
21  * @param boolean $defaultActiveLink Is this link the default active one ?
22  */
23 function jtpl_function_html_jAjaxLink($tpl,$txt, $blockId, $tplName, $tagAttr = array(), $classActive = "", $defaultActiveLink = false){
24
25
26     //is this link should be the active one ?
27     $activeTpl = $GLOBALS['gJCoord']->request->getParam($blockId.'activeTpl');
28     if(($activeTpl == $tplName) || ($activeTpl == '' && $defaultActiveLink)){
29         $isActiveLink = true;
30     }else{
31         $isActiveLink = false;
32     }
33
34     //Construct the dynamic attributes of the tag
35     if($isActiveLink){
36         if(array_key_exists('class', $tagAttr)){
37             $tagAttr['class'] = $tagAttr['class'].' '.$classActive;
38         }else{
39             $tagAttr['class'] = $classActive;
40         }
41     }
42
43     $pageURL = 'http://'.$_SERVER['HTTP_HOST'].$GLOBALS['gJCoord']->request->urlScript.$GLOBALS['gJCoord']->request->urlPathInfo.'?';
44     $q = http_build_query(array_merge($_GET, array($blockId.'activeTpl'=> $tplName)), '', '&');
45     if(strpos($q, '%3A')!==false)
46         $q = str_replace( '%3A', ':', $q);
47     $pageURL .=$q;
48     $tagAttr['href'] = $pageURL;
49
50     $tagAttr['srcurl'] = jUrl::get('commun~ajax:getZone', array('zone'=>'commun~ajax', 'blockId'=>$blockId, $blockId.'activeTpl'=> $tplName), true);
51     $tagAttr['targetid'] = $blockId;
52     $tagAttr['activeclassname'] = $classActive;
53
54     //display the tag
55     echo('<a ');
56     foreach ($tagAttr as $attrName => $attrVal) {
57         echo($attrName."='".$attrVal."' ");
58     }
59     echo('>'.$txt.'</a>');
60 }
61 ?>
62
Download in other formats: Original Format