Guest User

Untitled

a guest
May 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. A quick jQuery plugin for asynchronously embedding a gist in an HTML document.
  2.  
  3. There are a couple of ways to use it. First is the direct method that will insert it into the current position in the document:
  4.  
  5. <script>$.gist(409808)</script>
  6.  
  7. Secondly, there is a more jQuery oriented method:
  8.  
  9. <div id="placeholder"></div>
  10. <script>$('#placeholder').gist(409808);
  11.  
  12. A couple of notes:
  13.  
  14. 1. This works asynchronously, which has the advantage of not blocking the loading of a page. This has the slight disadvantage of "popping" in after it has loaded, but this could be alleviated with animations etc. by creating an event handler for the `gistloaded` event.
  15.  
  16. 2. The default gist stylesheet will not be included via this method. The URL of the stylesheet does get passed in via the 'stylesheet' key of the returned JSON, so again if desired you could catch the `gistloaded` event and pull the stylesheet out of the JSON object.
  17.  
  18. 3. As mentioned, after the gist has been loaded and inserted into the DOM, a `gistloaded` event is triggered on the newly created DOM object. This is to facilitate adding any custom behaviours after the gist has loaded. Potentially this could be things like animations, attaching events etc.
  19.  
  20. 4. Currently if you specify an element to 'receive' the gist, that element is replaced, so be cautious of using it again.
  21.  
  22. 5. A single file from the gist can be included by specifying the second parameter, the file name as a string: `$.gist(409808, 'gist.js')`.
Add Comment
Please, Sign In to add comment