Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created March 12, 2014 15:20
Show Gist options
  • Save yitsushi/9509071 to your computer and use it in GitHub Desktop.
Save yitsushi/9509071 to your computer and use it in GitHub Desktop.
var Application = (function() {
var modules = {};
return {
delegate: function(name, callback) {
modules[name] = callback;
},
init: function() {
for (var name in modules) {
if (modules.hasOwnProperty(name)) {
modules[name]();
}
}
}
}
}());
// A kifele mutató linkeket nyissa új lapon.
Application.delegate('external_link', function() {
jQuery('a[href^="http://"], a[href^="https://"], a[href^="/downloads"]')
.attr('target', '_blank');
});
// Google+ commentekhez.
window.___gcfg = {lang: '{{ site.lang }}'};
Application.delegate('google-plus-comment', function() {
function _getComputedStyle(el, cssprop){
if (el.currentStyle) {
// for IE
return el.currentStyle[cssprop]
} else if (document.defaultView && document.defaultView.getComputedStyle) {
// Any other normal brwoser (like Chrome, Firefox)
return document.defaultView.getComputedStyle(el, "")[cssprop]
} else {
// Try get inline style
return el.style[cssprop]
}
}
var script = document.createElement('script'); script.type = 'text/javascript';
script.async = true;
script.onload = function() {
if (gapi && gapi['comments'] && gapi.comments['render']) {
var gPlusCommentContainer = document.getElementById('gpluscomments');
if (gPlusCommentContainer == null) {
return false;
}
gapi.comments.render(
'gpluscomments',
{
href: gPlusCommentContainer.getAttribute('data-href'),
view_type: gPlusCommentContainer.getAttribute('data-viewtype'),
first_party_property: "BLOGGER",
width: parseInt(_getComputedStyle(gPlusCommentContainer, "width"), 10)
}
);
}
};
script.src = 'https://apis.google.com/js/plusone.js?publisherid={{ site.googleplus_page }}';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
});
// Facebook all.js betöltése.
Application.delegate('facebook', function() {
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#appId=212934732101925&xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
});
(function() {
var javaScriptFiles = [
'{{ root_url }}/javascripts/libs/jquery-1.9.1.min.js',
'{{ root_url }}/javascripts/modernizr-2.0.js',
'{{ root_url }}/javascripts/ender.js',
'{{ root_url }}/javascripts/octopress.js',
'http://www.google.hu/coop/cse/brand?form=cse-search-box&lang=hu'
];
function loadJavaScript(script, callback) {
var element = document.createElement("script");
element.src = script;
element.onload = script.onreadystatechange = callback;
document.body.appendChild(element);
}
function loadNext(callback) {
if (javaScriptFiles.length < 1) {
return callback(null, true);
}
var current = javaScriptFiles.shift();
loadJavaScript(current, function() {
loadNext(callback);
});
}
function downloadJSAtOnload() {
loadNext(Application.init);
}
if (window.addEventListener) {
window.addEventListener("load", downloadJSAtOnload, false);
} else if (window.attachEvent) {
window.attachEvent("onload", downloadJSAtOnload);
} else {
window.onload = downloadJSAtOnload;
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment