Gist embeds like this one:
<script src="https://gist.github.com/matthewspencer/005044062dd93fbe59ce.js"></script>Use document.write() which is totally uncool if you are doing stuff like history.pushState().
This plugin provides an alternative way to embed gists.
In your JavaScript you’ll want:
$('[data-gist]').gist()Which maps to the corresponding markup:
<div data-gist="005044062dd93fbe59ce"></div>Or if you want to embed a specific file from a gist:
<div data-gist="005044062dd93fbe59ce" data-file="access_to_tools-sh"></div>This library can be install with npm, bower, or just by downloading the zip. It is written in the UMD pattern to support AMD, CommonJS, and global usage.
npm
npm install async-gist --save
bower
bower install async-gist --save
A few options can be passed, for example, here we make the timeout 2 seconds:
$('[data-gist]').gist({
timeout: 2000
})Default: 1000
Description: How long to wait for the jsonp.
Default: onAjaxSuccess
Description: It is best to leave this alone and let the internal function do the need. It’ll load the needed stylesheet and gist content.
Default: onAjaxError
Description: It is also best to leave this alone. It’ll display a link to the gist on failure to load.