Created
June 19, 2012 02:14
-
-
Save luisdalmolin/2951945 to your computer and use it in GitHub Desktop.
Carregando os gists por ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Carregando GIST's por ajax</title> | |
<style type="text/css"> | |
body { | |
font-family: Helvetica, sans-serif; | |
font-size: 13px; | |
margin: 10px; } | |
</style> | |
<link rel="stylesheet" href="https://gist.github.com/stylesheets/gist/embed.css" type="text/css" /> | |
<script type="text/javascript" src="js/jquery.js"></script> | |
<script type="text/javascript" src="js/jquery.gist.js"></script> | |
</head> | |
<body> | |
<h1>Carregando Gist's por ajax</h1> | |
<div data-gist="2951945"></div> | |
<script type="text/javascript"> | |
(function() { | |
$().loadGists(); | |
})(); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Carregando os gists por ajax | |
Author: Luís Dalmolin <[email protected]> | |
*/ | |
;(function ( $, window, undefined ) { | |
// carregando os gists | |
$.fn.loadGists = function( options ) | |
{ | |
// sobreescrevendo os defaults | |
var opt = $.extend( $.fn.loadGists.options, options ); | |
$( opt.element ).each(function(){ | |
var $this = $(this), | |
id = $this.attr('data-gist'), | |
url = 'https://gist.github.com/' + id + '.json'; | |
// mensagem de load | |
$this.html('Carregando gist ' + url + ' ...'); | |
// buscando o GIST | |
$.ajax({ | |
url : url, | |
dataType : 'jsonp', | |
timeout : 10000, | |
success: function(response) { | |
if( response && response.div ) { | |
// adicionando o conteudo | |
$this.html( response.div ); | |
} | |
}, | |
error: function(){ | |
$this.html('Erro ao carregar o GIST ' + url); | |
} | |
}); | |
}); | |
} | |
// defaults | |
$.fn.loadGists.options = { | |
element : '[data-gist]' | |
} | |
}(jQuery, window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment