Created
February 15, 2011 21:19
-
-
Save popthestack/828263 to your computer and use it in GitHub Desktop.
tumblr solaris theme without hiding youtube videos
This file contains 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
// Solaris functions v1.1 by Matthew Buchanan http://matthewbuchanan.name except where noted | |
// Bind events to zoom controls to switch between link and high-res URLs | |
// and to open lightbox if there is no enclosing anchor around the image. | |
$("span.zoomcontrol").live("mouseenter", function() { | |
$(this).fadeTo("fast",0.75); | |
}).live("mouseleave", function() { | |
$(this).fadeTo("fast",0.375); | |
}).live("click", function(e) { | |
e.preventDefault(); | |
$.fancybox($(this).prev().data("highres"), { | |
"titleShow": false, | |
"type": "iframe", | |
"width": "90%", | |
"height": "90%", | |
"scrolling": "no", | |
"autoScale": false, | |
"margin": 10, | |
"overlayColor": overlayColor, | |
"overlayOpacity": 0.75, | |
"hideOnContentClick": true, | |
"centerOnScroll": true | |
}); | |
$.fancybox.resize(); | |
}); | |
// Notes handling adapted from an idea by Jarred Bishop http://jarredbishop.info | |
no_likes = false; | |
no_reblogs = true; | |
no_replies = true; | |
likes_scrollpane = false; | |
reblogs_scrollpane = false; | |
notes_count = 0; | |
likes_auto_scroll = false; | |
reblogs_auto_scroll = false; | |
function handleNotes() { | |
// Replace missing 0 when there are no notes | |
$(".post-counts p.notes a").each(function() { | |
if ($(this).html() == "") $(this).html("0"); | |
}); | |
attachNoteMouseHandlers(); | |
processNotes(); | |
if (useCufon) { | |
Cufon.set("fontFamily", "League Gothic"); | |
Cufon.replace("#notes h3"); | |
} | |
} | |
function tumblrNotesLoaded(html) { | |
likes_auto_scroll = $("#notes-likes ol.notes").data("jScrollPanePosition") == $("#notes-likes ol.notes").data("jScrollPaneMaxScroll"); | |
reblogs_auto_scroll = $("#notes-reblogs ol.notes").data("jScrollPanePosition") == $("#notes-reblogs ol.notes").data("jScrollPaneMaxScroll"); | |
} | |
function tumblrNotesInserted(html) { | |
processNotes(); | |
} | |
function addNoteCounts(id, singular, plural) { | |
var count = $(id + " ol.notes li").length; | |
if (count > 0) { | |
if (count == 1) $(id + " h3").html(count + " " + singular); | |
else $(id + " h3").html(count + " " + plural); | |
} | |
} | |
function attachNoteMouseHandlers() { | |
// Display captions on hover | |
$("#notes a.overlay").live("mouseenter", function() { | |
// Workaround for Tumblr "submission" markup missing <span class="action"> | |
if ($(this).siblings("span.action").length) { | |
var caption = $(this).siblings("span.action").html(); | |
} else { | |
var caption = "<a href='" + $(this).siblings("a.source_tumblelog").first()[0] + "'>" | |
+ $(this).siblings("a.source_tumblelog").first().html() + "</a> submitted this to <a href='" | |
+ $(this).siblings("a.source_tumblelog").last()[0] + "'>" | |
+ $(this).siblings("a.source_tumblelog").last().html() + "</a>"; | |
} | |
if ($(this).parent().hasClass("with_commentary")) { | |
caption += $(this).siblings("blockquote").html(); | |
} | |
if (($(this).parents("#notes-likes").length && likes_scrollpane) || ($(this).parents("#notes-reblogs").length && reblogs_scrollpane)) { | |
$(this).parents("div.jScrollPaneContainer").next().show().html(caption); | |
} else { | |
$(this).parents("ol.notes").next().show().html(caption); | |
} | |
}).live("mouseleave", function() { | |
if (($(this).parents("#notes-likes").length && likes_scrollpane) || ($(this).parents("#notes-reblogs").length && reblogs_scrollpane)) { | |
$(this).parents("div.jScrollPaneContainer").next().show().html(" "); | |
} else { | |
$(this).parents("ol.notes").next().show().html(" "); | |
} | |
}); | |
} | |
function processNotes() { | |
notes_count = $("#notes-likes ol.notes li:not(.note_processed)").length; | |
// Move unprocessed notes to relevant lists | |
if (notes_count > 0) { | |
$("#notes-likes ol.notes li:not(.note_processed)").each(function() { | |
if (!$(this).find("a.more_notes_link").length) { | |
$(this).addClass("note_processed"); | |
var url = $(this).find("a:first-child").attr("href"); | |
$("<a>", {"class":"overlay","href":url}).prependTo($(this)); | |
var avatar = $(this).find("img.avatar:first"); | |
// Rewrite avatar URLs to load 40x40 versions | |
if (avatar) avatar.attr("src", avatar.attr("src").replace("_16.","_40.")); | |
if ($(this).hasClass("reblog")) { | |
if (no_reblogs) { | |
$("<ol>", {"class":"notes"}).html(" ").appendTo($("#notes-reblogs")); | |
$("<p>", {"class":"notes-text"}).appendTo($("#notes-reblogs")); | |
no_reblogs = false; | |
} | |
$(this).detach().appendTo($("#notes-reblogs ol.notes")); | |
} else if ($(this).hasClass("reply") || $(this).hasClass("answer") || $(this).hasClass("photo")) { | |
if (no_replies) { | |
$("<ol>", {"class":"notes"}).html(" ").appendTo($("#notes-replies")); | |
no_replies = false; | |
} | |
$(this).detach().appendTo($("#notes-replies ol.notes")); | |
} | |
} | |
}); | |
addNoteCounts("#notes-likes", "Like", "Likes"); | |
addNoteCounts("#notes-reblogs", "Reblog", "Reblogs"); | |
addNoteCounts("#notes-replies", "Reply", "Replies"); | |
if (useCufon) { | |
Cufon.refresh("#notes h3"); | |
} | |
// Widen single list | |
if ($("#notes-likes ol.notes li").length == 0) { | |
$("#notes-likes").hide(); | |
$("#notes-reblogs").addClass("wide"); | |
no_likes = true; | |
} else { | |
$("#notes-likes").show(); | |
$("#notes-reblogs").removeClass("wide"); | |
no_likes = false; | |
} | |
if (no_reblogs) { | |
$("#notes-reblogs").hide(); | |
$("#notes-likes").addClass("wide"); | |
} else { | |
$("#notes-reblogs").show(); | |
$("#notes-likes").removeClass("wide"); | |
} | |
if (no_replies) { | |
$("#notes-replies").hide(); | |
} else { | |
$("#notes-replies").show(); | |
} | |
// Add scrollpanes if lists are longer than eight rows | |
if (no_likes || no_reblogs) { | |
var scrollPaneThreshold = 136; | |
} else { | |
var scrollPaneThreshold = 64; | |
} | |
if ($("#notes-likes ol.notes li").length > scrollPaneThreshold) { | |
$likesNotes = $("#notes-likes ol.notes"); | |
$likesNotes.jScrollPaneRemove(); | |
$likesNotes.css({"height":360}).jScrollPane({"scrollbarWidth":6,"dragMinHeight":40}); | |
if (likes_auto_scroll) $likesNotes[0].scrollTo($likesNotes.data("jScrollPaneMaxScroll")); | |
likes_scrollpane = true; | |
} | |
if ($("#notes-reblogs ol.notes li").length > scrollPaneThreshold) { | |
$reblogsNotes = $("#notes-reblogs ol.notes"); | |
$reblogsNotes.jScrollPaneRemove(); | |
$reblogsNotes.css({"height":360}).jScrollPane({"scrollbarWidth":6,"dragMinHeight":40}); | |
if (reblogs_auto_scroll) $reblogsNotes[0].scrollTo($reblogsNotes.data("jScrollPaneMaxScroll")); | |
reblogs_scrollpane = true; | |
} | |
} | |
} | |
function fixVimeo() { | |
/* | |
Better Vimeo Embeds 2.1 by Matthew Buchanan | |
Modelled on the Vimeo Embedinator Script | |
http://mattbu.ch/tumblr/vimeo-embeds/ | |
Released under a Creative Commons attribution license: | |
http://creativecommons.org/licenses/by/3.0/nz/ | |
*/ | |
var color = vimeoColor; | |
var opts = "title=0&byline=0&portrait=0"; | |
$("iframe[src^='http://player.vimeo.com']").each(function() { | |
var src = $(this).attr("src"); | |
var w = $(this).attr("width"); | |
var h = $(this).attr("height"); | |
if (src.indexOf("?") == -1) { | |
$(this).replaceWith( | |
"<iframe src='"+src+"?"+opts+"&color="+ | |
color+"' width='"+w+"' height='"+h+ | |
"' frameborder='0'></iframe>" | |
); | |
} | |
}); | |
$("object[data^='http://vimeo.com']").each(function() { | |
var $obj = $(this); | |
var data = $obj.attr("data"); | |
var temp = data.split("clip_id=")[1]; | |
var id = temp.split("&")[0]; | |
var server = temp.split("&")[1]; | |
var w = $obj.attr("width"); | |
var h = $obj.attr("height"); | |
$obj.replaceWith( | |
"<iframe src='http://player.vimeo.com/video/" | |
+id+"?"+server+"&"+opts+"&color="+color+ | |
"' width='"+w+"' height='"+h+ | |
"' frameborder='0'></iframe>" | |
); | |
}); | |
} | |
function fixYouTube() { | |
/* | |
Widescreen YouTube Embeds by Matthew Buchanan, Hayden Hunter & Thijs Jacobs | |
http://matthewbuchanan.name/451892574 | |
http://blog.haydenhunter.me | |
http://thijsjacobs.com | |
Released under a Creative Commons attribution license: | |
http://creativecommons.org/licenses/by/3.0/nz/ | |
*/ | |
$(function() { | |
$("object").each(function () { | |
if ($(this).find("embed[src^='http://www.youtube.com']").length > 0) { | |
// Identify and hide embed(s) | |
var parent = $(this).parent(); | |
// Commenting out this line because it friggin hides youtube videos. | |
// parent.css("visibility","hidden"); | |
var youtubeCode = parent.html(); | |
var params = ""; | |
if (youtubeCode.toLowerCase().indexOf("<param") == -1) { | |
// IE doesn't return params with html(), so… | |
$("param", this).each(function () { | |
params += $(this).get(0).outerHTML; | |
}); | |
} | |
// Set colours in control bar to match page background | |
var oldOpts = /rel=0/g; | |
var newOpts = "rel=0&color1=0xFFFFFF&color2=0xFFFFFF"; | |
youtubeCode = youtubeCode.replace(oldOpts, newOpts); | |
if (params != "") { | |
params = params.replace(oldOpts, newOpts); | |
youtubeCode = youtubeCode.replace(/<embed/i, params + "<embed"); | |
} | |
// Replace YouTube embed with new code > Color | |
parent.html(youtubeCode); | |
// Extract YouTube ID and calculate ideal height | |
var youtubeIDParam = $(this).find("embed").attr("src"); | |
var youtubeIDPattern = /\/v\/([0-9A-Za-z-_]*)/; | |
var youtubeID = youtubeIDParam.match(youtubeIDPattern); | |
var youtubeHeight = Math.floor(parent.find("object").width() * 0.75 + 25); | |
var youtubeHeightWide = Math.floor(parent.find("object").width() * 0.5625 + 25); | |
// Test for widescreen aspect ratio | |
$.ajax({ | |
url: "http://gdata.youtube.com/feeds/api/videos/" + youtubeID[1] + "?v=2&alt=json-in-script", | |
dataType: "jsonp", | |
timeout: 5000, | |
success: function(data){ | |
oldOpts = /height="?([0-9]*)"?/g; | |
if (data.entry.media$group.yt$aspectRatio != null) { | |
newOpts = 'height="' + youtubeHeightWide + '"'; | |
} else { | |
newOpts = 'height="' + youtubeHeight + '"'; | |
} | |
youtubeCode = youtubeCode.replace(oldOpts, newOpts); | |
if (params != "") { | |
params = params.replace(oldOpts, newOpts); | |
youtubeCode = youtubeCode.replace(/<embed/i, params + "<embed"); | |
} | |
// Replace YouTube embed with new code | |
parent.html(youtubeCode); | |
} | |
}); | |
// Toggle visibility | |
parent.css("visibility","visible"); | |
} | |
}); | |
}); | |
} | |
function startSlideshows() { | |
$(".html_photoset p.photoset_caption").each(function() { | |
$(this).prev().find("img.photoset_photo").attr("title", $(this).html()); | |
$(this).remove(); | |
}); | |
$(".html_photoset").has("img").nivoSlider({effect: "sliceDown"}); | |
$(".nivo-controlNav").each(function() { | |
var width = $(this).width(); | |
var newWidth = 0 - width/2; | |
$(this).css("margin-left",""+newWidth+"px"); | |
}); | |
} | |
function handleExternalAudio() { | |
// Check tags for replacement metadata | |
$("div.post-audio div.post-tags a").each(function() { | |
var tag = $(this).text(); | |
// Process art:, track: and artist: tags then hide them | |
if (tag.substring(0,4) == "art:") { | |
var imgUrl = tag.replace("art:",""); | |
$(this).closest("div.post-container").find("div.art").html("<div class='overlay'></div><img src='" + imgUrl + "' width='124' height='124' alt='Artwork' border='0' />"); | |
$(this).hide(); | |
} else if (tag.substring(0,6) == "track:") { | |
var trackName = tag.replace("track:",""); | |
var $meta = $(this).closest("div.post-container").find("div.audio-meta"); | |
if ($meta.find("div.track").length) | |
$meta.find("div.track p").html(trackName); | |
else | |
$meta.find("div.play-count").after("<div class='track icon-text'><p>" + trackName + "</p></div>"); | |
if (useCufon) Cufon.refresh("div.audio-panel div.icon-text p"); | |
$meta.find("div.track p").show(); | |
$(this).hide(); | |
} else if (tag.substring(0,7) == "artist:") { | |
var artistName = tag.replace("artist:",""); | |
var $meta = $(this).closest("div.post-container").find("div.audio-meta"); | |
if ($meta.find("div.artist").length) | |
$meta.find("div.artist p").html(artistName); | |
else | |
$meta.append("<div class='artist icon-text'><p>" + artistName + "</p></div>"); | |
if (useCufon) Cufon.refresh("div.audio-panel div.icon-text p"); | |
$meta.find("div.artist p").show(); | |
$(this).hide(); | |
} | |
// Hide tag list if empty | |
if ($(this).parent().find("a:visible").length == 0) $(this).parent().hide(); | |
}); | |
} | |
function timeOfDay() { | |
// Switch theme to Dark mode between 8pm and 6am local time | |
if (switchAtNight) { | |
var d = new Date(); | |
var h = d.getHours(); | |
if (h < 6 || h > 19) { | |
$("body").addClass("dark"); | |
$("#search input.submit").attr("src", "http://static.tumblr.com/gpln05e/GNKkyw255/search-go-dark.png"); | |
overlayColor = "#20282F"; | |
} else { | |
$("body").removeClass("dark"); | |
$("#search input.submit").attr("src", "http://static.tumblr.com/gpln05e/DsWkyw25k/search-go.png"); | |
overlayColor = "#FFF"; | |
} | |
} | |
} | |
$(function() { | |
$("div.post-counts p.notes a").each(function() { | |
if ($(this).html() == "") $(this).html("0"); | |
}); | |
// Load grey images for content source | |
$("div.share img").each(function() { | |
$(this).attr("src", $(this).attr("src").replace(/_000/g, "_7f8b98")); | |
}); | |
// Attach typographic elements for quotes | |
$("div.post-quote-or-answer blockquote.quote").each(function() { | |
var $lastBlockLevelElement = $(this).find("p,dl,div,noscript,blockquote,form,hr,table,fieldset,address,ol,ul,h1,h2,h3,h4,h5,h6").last(); | |
if ($lastBlockLevelElement.length) $lastBlockLevelElement.append("”"); | |
else $(this).append("”"); | |
}); | |
$("div.post-quote-or-answer div.content").each(function() { | |
var $firstBlockLevelElement = $(this).find("p,dl,div,noscript,blockquote,form,hr,table,fieldset,address,ol,ul,h1,h2,h3,h4,h5,h6").first(); | |
if ($firstBlockLevelElement.length) $firstBlockLevelElement.prepend("— ").addClass("outdent"); | |
else $(this).prepend("— ").addClass("outdent"); | |
}); | |
timeOfDay(); | |
if (useCufon) { | |
Cufon.set("fontFamily", "League Gothic"); | |
Cufon.replace(".dark #disqus_thread h3", { fontSize: "24px", color: "#50585F", textTransform: "uppercase" }); | |
Cufon.replace("#disqus_thread h3", { fontSize: "24px", color: "#B0B8BF", textTransform: "uppercase" }); | |
if (!customHeader) Cufon.replace("h1", { lineHeight: 1 }); | |
Cufon.replace("h2, h3, h4, blockquote.quote, div.audio-panel div.play-count p"); | |
Cufon.replace("div.audio-panel div.icon-text p"); | |
Cufon.replace("div.post-counts p a", {hover: true}); | |
} | |
$("h1, h2, h3, h4, blockquote.quote, div.audio-panel div.play-count p, div.audio-panel div.icon-text p").show(); | |
handleExternalAudio(); | |
$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase()); | |
if ($.browser.webkit) $("body").addClass("webkit"); | |
if ($.browser.chrome) $("body").addClass("chrome"); | |
// Hide Twitter panel if page mode is displayed (eg. on search results or day pages) | |
$("div.page-mode").each(function() { | |
$("#twitter").removeClass("show"); | |
}); | |
// Hide Disqus on Ask and Submit pages | |
var path = window.location.pathname; | |
if (path == "/ask/" || path == "/ask" || path == "/submit/" || path == "/submit") $("div.disqus_block").hide(); | |
$("div.content:not(:has(p,dl,div,noscript,blockquote,form,hr,table,fieldset,address,ol,ul,h1,h2,h3,h4,h5,h6))").addClass("no-block-elements"); | |
$("#nav ul a, a.shorturl, a.permalink, div.pagination a[href!='']").blend({"speed": 300}); | |
$("div.pagination a[href='']").addClass("empty").click(function(e) { e.preventDefault(); }); | |
$("<div>", {"class":"icon"}).prependTo("div.audio-panel div.icon-text, #notes-likes, #notes-reblogs, #notes-replies"); | |
$("div.post").hover(function() { | |
$(this).find("div.meta-icons a").css({'opacity':0,'visibility':'visible'}).animate({opacity:1}); | |
}, function() { | |
$(this).find("div.meta-icons a").animate({opacity:0}, function(){ | |
$(this).css({'visibility':'hidden'}); | |
}); | |
}); | |
// Create a zoom control for each image with a high-res URL | |
$("div.post-photo img.post-image").each(function(){ | |
if ($(this).data("highres")) { | |
$("<span>", {"class":"zoomcontrol"}).insertAfter($(this)).css("opacity",0.375); | |
if ($(this).data("highres") == $(this).parent("a").attr("href")) { | |
$(this).parent("a").click(function(e) { | |
e.preventDefault(); | |
$.fancybox($(this).find("img.post-image").data("highres"), { | |
"titleShow": false, | |
"type": "iframe", | |
"width": "90%", | |
"height": "90%", | |
"scrolling": "no", | |
"autoScale": false, | |
"margin": 10, | |
"overlayColor": overlayColor, | |
"overlayOpacity": 0.75, | |
"hideOnContentClick": true, | |
"centerOnScroll": true | |
}); | |
$.fancybox.resize(); | |
}); | |
} | |
} | |
}); | |
if (themeAuthor) { | |
var $footerText = $("#footer > :last-child"); | |
if ($footerText.html() != "") $footerText.append(" "); | |
$footerText.append('<a href="http://solaristheme.tumblr.com">Solaris theme</a> by <a href="http://matthewbuchanan.name">Matthew Buchanan</a>.'); | |
} | |
handleNotes(); | |
$("#likes .post_info_bottom").css("opacity",0.5); | |
$("#likes .like_post").hover(function() { | |
$(this).find(".post_info_bottom").fadeTo("fast",1); | |
}, function() { | |
$(this).find(".post_info_bottom").fadeTo("fast",0.5); | |
}); | |
if (useCufon) { | |
var iv = setInterval(function() { | |
if ($("#disqus_thread h3").length) { | |
Cufon.refresh(".dark #disqus_thread h3"); | |
Cufon.refresh("#disqus_thread h3"); | |
$(".dark #disqus_thread h3, #disqus_thread h3").show(); | |
clearInterval(iv); | |
} | |
}, 100); | |
} | |
fixVimeo(); | |
fixYouTube(); | |
startSlideshows(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment