Skip to content

Instantly share code, notes, and snippets.

@JDMcKinstry
Created January 13, 2017 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JDMcKinstry/cc6f3dce040626d355dbe149c2e823fe to your computer and use it in GitHub Desktop.
Save JDMcKinstry/cc6f3dce040626d355dbe149c2e823fe to your computer and use it in GitHub Desktop.
;(function() {
function createOpenLink(href, oType) {
var objStyle = {
'padding': '1em',
'text-align': 'center'
},
strStyle = $.map(objStyle, function(v, k) { return k + ': ' + v; }).join('; ') + ';',
attrs = { 'href': href, 'style': strStyle, 'target': '_blank', 'text': 'Open ' + oType },
lnkOpen = $('<a />', attrs);
return lnkOpen;
}
function formatImages() {
return $('article div > img:not(.customized):first-child').each(function(i) {
var href = this.src,
oType = this.tagName.charAt(0) + this.tagName.substr(1).toLowerCase(),
article = $(this).addClass('customized').closest('article'),
containerImg = article.children('header+div'),
containerComments = containerImg.next(),
lnkOpen = createOpenLink(href, oType);
containerImg.append(lnkOpen);
});
}
function formatVideos() {
return $('article div > video:not(.customized)').each(function(i) {
var href = this.src,
oType = this.tagName.charAt(0) + this.tagName.substr(1).toLowerCase(),
article = $(this).addClass('customized').closest('article'),
containerImg = article.children('header+div'),
containerComments = containerImg.next(),
lnkOpen = createOpenLink(href, oType);
containerImg.append(lnkOpen);
});
}
function init() {
if (document.readyState == 'complete' && window.hasOwnProperty('jQuery')) {
formatImages();
formatVideos();
}
setTimeout(init, 1e3);
}
init()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment