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

Untitled

By: a guest on Jun 25th, 2012  |  syntax: None  |  size: 1.46 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.         <title>Loading GitHub Gists After Page Content Has Loaded -- UPDATED</title>
  5.  
  6.         <style type="text/css">
  7.  
  8.                 .gist,
  9.                 pre {
  10.                         font-size: 12px ;
  11.                 }
  12.  
  13.         </style>
  14.  
  15.         <!-- Load the jQuery library a and the Gist plugin. -->
  16.         <script type="text/javascript" src="../jquery-1.7.1.js"></script>
  17.         <script type="text/javascript" src="./jquery.gist.js"></script>
  18.  
  19.         <!-- Load the Gist after DOM ready. -->
  20.         <script type="text/javascript">
  21.  
  22.                 $(function(){
  23.  
  24.                         // Get the placeholder.
  25.                         var placeholder = $( "#placeholder" );
  26.  
  27.                         // Get the gist with the given ID. This will come back
  28.                         // as both a hash of file names and an ordered array.
  29.                         var gistResult = $.getGist( "1600811" );
  30.  
  31.                         // When the gist has loaded, append the contents to the
  32.                         // rendered DOM.
  33.                         gistResult.done(
  34.                                 function( gist ){
  35.  
  36.                                         // Empty the placeholder.
  37.                                         placeholder.empty();
  38.  
  39.                                         // Get the ordered files.
  40.                                         var ordered = gist.ordered;
  41.  
  42.                                         // Add each gist to the content.
  43.                                         for (var i = 0 ; i < ordered.length; i++){
  44.  
  45.                                                 // Add a title for the gist.
  46.                                                 placeholder.append(
  47.                                                         "<h3>" + ordered[ i ].fileName + "</h3>"
  48.                                                 );
  49.  
  50.                                                 // Add the gist content.
  51.                                                 placeholder.append( ordered[ i ].content );
  52.  
  53.                                         }
  54.  
  55.                                 }
  56.                         );
  57.  
  58.                 });
  59.  
  60.         </script>
  61. </head>
  62. <body>
  63.  
  64.         <h1>
  65.                 Loading GitHub Gists After Page Content Has Loaded
  66.         </h1>
  67.  
  68.         <h2>
  69.                 Gists From GitHub:
  70.         </h2>
  71.  
  72.         <div id="placeholder">
  73.                 Loading...
  74.         </div>
  75.  
  76.         <p>
  77.                 This page has finised loading.
  78.         </p>
  79.  
  80. </body>
  81. </html>