Skip to content

Instantly share code, notes, and snippets.

View rakeshpai's full-sized avatar

Rakesh Pai rakeshpai

View GitHub Profile
@rakeshpai
rakeshpai / _gaqAsAnApi.html
Created January 16, 2012 20:55
Google Analytics Using an Array as an API
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
// <snip> Load the JS required to process the _gaq "queue".
})();
</script>
@rakeshpai
rakeshpai / fbWithoutFbAsyncInit.html
Created January 16, 2012 20:53
FB without fbAsyncInit
<script>
window.FB = window.FB || {
onReady: function() {
// This is called when the code has loaded.
}
};
// Load the SDK Asynchronously
(function(d){
// <snip>
@rakeshpai
rakeshpai / fbJSSdkCheck.js
Created January 16, 2012 20:52
Inside FB's JS SDK
if(window.fbAsyncInit && !window.fbAsyncInit.hasRun){
window.fbAsyncInit.hasRun = true;
fbAsyncInit();
}
@rakeshpai
rakeshpai / fbAsyncInit.html
Created January 16, 2012 20:51
Facebook's fbAsyncInit function declaration
<script>
window.fbAsyncInit = function() {
// <snip>
// The FB object is now ready to use
};
// Load the SDK Asynchronously
(function(d){
// <snip>
// Asynchronouly load Facebook's JS SDK
@rakeshpai
rakeshpai / twitter_anywhere_api.html
Created January 16, 2012 20:49
How Twitter's @anywhere API is made available
<script src="http://platform.twitter.com/anywhere.js?id=YOUR_API_KEY&v=1" type="text/javascript"></script>
<script>
// The twttr object is available to use immediately
twttr.anywhere(function() {
// Other code here
});
</script>
@rakeshpai
rakeshpai / errorception-loader.html
Created January 11, 2012 14:33
Errorception's async loader
<script>
// <snip>
(function (window, document) {
var loader = function () {
var script = document.createElement("script"), tag = document.getElementsByTagName("script")[0];
script.src = "http://errorception.com/projects/" + _errs[0] + "/beacon.js";
tag.parentNode.insertBefore(script, tag);
};
// Wait until window.onload before downloading any more code.
@rakeshpai
rakeshpai / ga-loader.html
Created January 11, 2012 14:32
Google Analytics' async loader
<script type="text/javascript">
// <snip>
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
@rakeshpai
rakeshpai / fb-loader.html
Created January 11, 2012 14:31
Facebook's JS SDK's loader script
<script>
// <snip>
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
@rakeshpai
rakeshpai / ncz-loader.html
Created January 11, 2012 14:30
A dynamic script loader by Nicholas Zakas
<script>
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "file.js";
document.body.appendChild(script);
</script>
@rakeshpai
rakeshpai / better-self-exec-anon-function-compressed.js
Created January 9, 2012 09:07
Better anonymous function compressed with Closure Compiler
// Note: Line breaks added for clarity
(function(a, b, c) {
/*
Your code here
Calls to window.whatever will become a.whatever
Similarly, document.whatever will be b.whatever, and c will be undefined
*/
}(window, document))