Skip to content

Instantly share code, notes, and snippets.

@botic
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save botic/1bf07e4ff2bedb1141eb to your computer and use it in GitHub Desktop.

Select an option

Save botic/1bf07e4ff2bedb1141eb to your computer and use it in GitHub Desktop.
Credits for Alpbuzz
// ==UserScript==
// @name Alpbuzz Credits
// @namespace naderer.alpbuzz
// @include http://www.alpbach.org/alpbuzz*
// @version 1
// @grant none
// ==/UserScript==
(function(jQuery) {
// do not apply on frontpage
if (window.location.href.indexOf("alpbach.org/alpbuzz/2015") < 0) {
return;
}
var detectCredit = function(str) {
if (str.indexOf(" Naderer") > 0) {
return "Philipp Naderer";
} else if (str.indexOf(" Puiu") > 0) {
return "Luiza Puiu";
}
return null;
};
if (typeof jQuery === "function") {
var $ = jQuery;
$(document).ready(function() {
var updateOffsets = function() {
var mobile = false;
if (window.matchMedia && window.matchMedia("(max-width: 768px)").matches) {
mobile = true;
}
$(".efaImageCredit").each(function(index, creditEl) {
var $creditEl = $(creditEl);
var $el = $creditEl.prev();
var expanded = false;
if ($el.hasClass("img-responsive")) {
if (window.matchMedia && window.matchMedia("(min-width: 1200px)").matches) {
expanded = true;
}
}
if ($el.prop("tagName") === "IMG") {
$creditEl.css({
"bottom": ((mobile ? 8 : 5) + $creditEl.width()) + "px",
"left": ((mobile ? 0 : 15) + (expanded ? 8 : 0) + $el.width()) + "px"
});
} else {
$creditEl.remove();
}
});
};
$(window).on("resize", function(ev) {
updateOffsets();
});
$("img.wp-post-image, img.img-responsive").on('load',function(){
updateOffsets();
});
var mobile = false;
if (window.matchMedia && window.matchMedia("(max-width: 768px)").matches) {
mobile = true;
}
$("img.wp-post-image, img.img-responsive").each(function(index, el) {
var $el = $(el);
var credit = detectCredit($el.attr("alt"));
if (credit !== null) {
var $creditEl = $("<div>").addClass("efaImageCredit");
var leftOffset = 15;
if ($el.hasClass("img-responsive")) {
leftOffset += 6;
if (window.matchMedia && window.matchMedia("(min-width: 1200px)").matches) {
leftOffset += 8;
}
}
$creditEl.text("Photo: " + credit);
$creditEl.css({
"font-size": "11px",
"font-family": "Mundo Sans, sans-serif",
"font-weight": "300",
"position": "relative",
"bottom": 0,
"left": ((mobile ? 0 : 15) + $el.width()) + "px",
"display": "inline-block",
"transform": "rotate(90deg)",
"-webkit-transform": "rotate(90deg)",
"-moz-transform": "rotate(90deg)",
"-o-transform": "rotate(90deg)",
"-ms-transform": "rotate(90deg)",
"transform-origin": "top left"
});
$el.after($creditEl);
$creditEl.css("bottom", ((mobile ? 8 : 5) + $creditEl.width()) + "px");
}
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment