forked from OpenNeo/impress
1 line
3.3 KiB
JavaScript
1 line
3.3 KiB
JavaScript
|
var disqus_shortname="dresstoimpress";(function(){function s(){var e=document.createElement("script");e.async=!0,e.type="text/javascript",e.src="http://"+disqus_shortname+".disqus.com/count.js",(document.getElementsByTagName("HEAD")[0]||document.getElementsByTagName("BODY")[0]).appendChild(e)}var e=$("#pet-preview"),t=e.find("img"),n=e.find("span"),r=$("#main-pet-name");e.click(function(){r.val(i.Job.current.name).closest("form").submit()});var i={clear:function(){typeof i.Job.fallback!="undefined"&&i.Job.fallback.setAsCurrent()},displayLoading:function(){e.addClass("loading"),n.text("Loading...")},failed:function(){e.addClass("hidden")},notFound:function(e,t){i.failed(),n.empty(),$("#preview-"+e+"-template").tmpl(t).appendTo(n)},updateWithName:function(){var e=r.val(),t;if(e){currentName=e;if(!i.Job.current||e!=i.Job.current.name)t=new i.Job.Name(e),t.setAsCurrent(),i.displayLoading()}else i.clear()}};$.get("/spotlight_pets.txt",function(e){var t=e.split("\n"),n=Math.floor(Math.random()*(t.length-1));i.Job.fallback=new i.Job.Name(t[n]),i.Job.current||i.Job.fallback.setAsCurrent()}),i.Job=function(e,n){function o(){return petImage(n+"/"+e,s)}function u(){r.loading=!0,t.attr("src",o())}var r=this,s=2;r.loading=!1,this.increaseQualityIfPossible=function(){s==2&&(s=4,u())},this.setAsCurrent=function(){i.Job.current=r,u()}},i.Job.Name=function(e){this.name=e,i.Job.apply(this,[e,"cpn"])},i.Job.Hash=function(e){i.Job.apply(this,[e,"cp"])},$(function(){var o;r.val(PetQuery.name),i.updateWithName(),r.keyup(function(){o&&(clearTimeout(o),i.Job.current.loading=!1),o=setTimeout(i.updateWithName,250)}),t.load(function(){i.Job.current.loading&&(i.Job.loading=!1,i.Job.current.increaseQualityIfPossible(),e.removeClass("loading").removeClass("hidden").addClass("loaded"),n.text(i.Job.current.name))}).error(function(){i.Job.current.loading&&(i.Job.loading=!1,i.notFound("pet-not-found"))});var u=$("#species, #color");u.change(function(){var e={},t={};u.each(function(){var n=$(this),r=n.children(":selected"),i=n.attr("id");e[i]=r.val(),t[i]=r.text()}),name=t.color+" "+t.species,i.displayLoading(),$.ajax({url:"/species/"+e.species+"/color/"+e.color+"/pet_type.json",data:{"for":"image"},dataType:"json",success:function(e){var n;e?(n=new i.Job.Hash(e.image_hash),n.name=name,n.setAsCurrent()):i.notFound("pet-type-not-found",{color_name:t.color,species_name:t.species})}})}),$.getJSON("http://blog.openneo.net/api/read/json?callback=?",function(e){var t=e.posts[0],n=$("#blog-preview"),r=t["url-with-slug"],i="Here's the latest!",o="",u=500,a;t.type=="regular"?(i=t["regular-title"],o=t["regular-body"]):t.type=="link"?(i=t["link-text"],o=t["link-description"]):t.type=="photo"&&(o=t["photo-caption"],a=t["photo-url-75"]),n.find("h2").text(i).wrapInner($("<a/>",{href:r}));var f=n.find("div");f.html(o),$("<a/>",{id:"blog-preview-comments",href:r+"#disqus_thread"}).appendTo(n),a&&n.find("img").attr("src",a).parent().attr("href",r);var l={};f.find(".locale").each(function(){var e=$(this),t=e.attr("class").match(/locale-(\S+)/)[1];l[t]=e});var c=$("#locale option:selected").attr("data-fallbacks").split(","),h=null;for(var p=0;p<c.length;p++)if(l.hasOwnProperty(c[p])){h=c[p];break}if(h){for(var d in l)l[d].hide();l[h].show(),f.find(".no-locale").hide()}n.fadeIn("medium"),s()})})})(),$("#latest-contribution-created-at").timeago();
|