Posts tagged Fancybox 2 Gallery by Ajax response
Fancybox 2 Gallery by Ajax response
1 month ago
Llamamos una galeria desde la etiqueta HTML <a href='javascript:void(0);' id='' />galeria</a> usando Ajax generado por PHP
Codigo Javascript:
jQuery(function($) { //al hacer click en determinada etiqueta ejecutamos la llamada ajax y con la respuesta //recogida generamos un slide show $('.gellery_from_link a').live('click', function() { var item = $(this); //get a href $.fancybox.showActivity(); $.ajax({ url: '?action=gallery&rand='+Math.random(), //rand for hotlink scripting data: 'gallery_id='+item.attr('id'), // get a href id for generate ajax result type: 'POST', dataType: 'json', cache: false, success: function(data) { $.fancybox(data, { type: 'image', //important autoScale: true, transitionIn: 'elastic', transitionOut: 'elastic', padding: 20, }); } }); }); });
Php > generando la respuesta ajax:
< ?php //Hot Link script function IsHotlink() { $domain = explode("/",$_SERVER['PHP_SELF']); $isFromDomain = strstr($_SERVER['HTTP_REFERER'],$domain[2]); $isFromAjax = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; $isHotlink = !$isFromDomain && !$isFromAjax; return $isHotlink; } if( $_REQUEST['action'] == 'gallery' && !IsHotlink() ) { $dm->gallery_id = $_REQUEST['gallery_id']; //recogemos $_POST id de la galleria $dm->fdir = "gallery/".$dm->gallery_id."/"; //ruta hasta lacarpeta con id de la galeria $dm->fItems = read_dir($dm->fdir); $dm->items = array(); foreach( $dm->fItems as $v => $k ) { array_push($dm->items, array('href' => $dm->fdir.$dm->fItems[$v]) ); } exit( json_encode( $dm->items ) ); //generamos la respuesta ajax y cerramos el documento. /* ejemplo de la respuesta: [href: "/gallery/2011-11-25_1.JPG", href: "/gallery/2011-11-25_2.JPG"] */ } ?>
![[Dm211] [Dm211]](http://blog.dm211.com/wp-content/themes/mystique-extend/uploads/dm211_2k11_logoShaded_102.png)