Created
September 23, 2011 07:56
-
-
Save jcayzac/1236928 to your computer and use it in GitHub Desktop.
Crotte.js (my JS injector for blogger's mobile template)
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
(function() { | |
if (window.crotte_is_loaded) { | |
return; | |
} | |
window.crotte_is_loaded=true | |
var crotte_load_script = function(cnd, src, cb) { | |
if (cnd) { | |
var s = document.createElement('script'); | |
s.type = 'text/javascript'; | |
s.async = true; | |
s.src=src; | |
s.onreadystatechange= function () { | |
if (this.readyState == 'complete') cb(); | |
} | |
s.onload=cb; | |
var head = document.getElementsByTagName('head')[0]; | |
head.appendChild(s); | |
} | |
else { | |
cb(); | |
} | |
}; | |
var crotte_load_stylesheet = function(src) { | |
if (document.createStyleSheet) { | |
document.createStyleSheet(src); | |
} | |
else { | |
var css = $('<link>'); | |
css.attr({ | |
rel: "stylesheet", | |
type: "text/css", | |
href: src | |
}); | |
$("head").append(css); | |
} | |
}; | |
crotte_load_script(!window.jQuery, '//code.jquery.com/jquery.min.js', function() { | |
(function($){ | |
$(function() { | |
// replace <youtube video="xxx" /> | |
// with <iframe> embed code | |
$('youtube').replaceWith(function() { | |
var elem = $(this); | |
var video = elem.attr('video'); | |
var html = '<iframe class="youtube" src="//www.youtube.com/embed/' + video + '?hd=1&autohide=1&fs=1&iv_load_policy=3&loop=1&rel=0&showsearch=0& showinfo=0&modestbranding=1&enablejsapi=1" allowfullscreen="allowfullscreen" frameborder="0"></iframe>'; | |
return html; | |
}); | |
// replace <gist code="xxx" /> | |
// with embed code | |
var gists = $('gist'); | |
if (gists.length>0) { | |
crotte_load_stylesheet('//barxyzfoocssbaz.googlecode.com/svn/trunk/gist.css'); | |
} | |
gists.each(function() { | |
var elem = $(this); | |
var code = elem.attr('code'); | |
$.getJSON( | |
'https://gist.github.com/'+code+'.json?callback=?', | |
function(data) { | |
elem.after(data.div); | |
} | |
); | |
}); | |
$('.gist-file').css({ | |
'position':'relative', | |
'z-index':'1' | |
}); | |
$('.gist-data').each(function() { | |
}) | |
}); | |
})(jQuery); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment