Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 15th, 2012  |  syntax: JavaScript  |  size: 0.78 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <a class="ajax" rel="showGallery" href="photo/gallery/1">Gallery 1</a>
  2. <a class="ajax" rel="showGallery" href="photo/gallery/2">Gallery 2</a>
  3.  
  4. <script>
  5.         $( function() {
  6.                 $( 'a.ajax' ).live( 'click', function() {
  7.                         var href = $( this ).attr( 'href' );
  8.                         var drawFunc = $( this ).attr( 'rel' );
  9.                        
  10.                         var data = getFromCache( 'some_key' );
  11.                        
  12.                         if ( data ) {
  13.                                 draw( drawFunc, data );
  14.                                 // Save in stack
  15.                         } else {
  16.                                 $.get(
  17.                                         href,
  18.                                         {},
  19.                                         function( data ) {
  20.                                                 draw( drawFunc, data );
  21.                                                 // Save in stack
  22.                                         },
  23.                                         'json'
  24.                                 );
  25.                         }
  26.                        
  27.                         return false;
  28.                 });
  29.         });
  30.        
  31.         function draw( drawFunc, data )
  32.         {
  33.                 // Spec effects
  34.                 drawFunc( data );
  35.                 // Spec effects
  36.         }
  37.        
  38.         function showGallery( data )
  39.         {
  40.                 // Draw gallery
  41.         }
  42. </script>