Created
March 19, 2012 08:29
-
-
Save 0x46616c6b/2102942 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getAjaxUrl(){return"/wp-admin/admin-ajax.php"}function isMobile(){return navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)}function isExternalLink(c){var b,d,a;a=$(c).attr("href");if(a==="#"){return false}d=$("base").attr("url").split("//")[1].split("/")[0];b=a.split("//")[1].split("/")[0];return d!==b}function isPage(a){return $(a).parent().hasClass("menu-item-object-page")}function isPost(b){var a=$(b).attr("href");return a.indexOf("?p=")!==-1||a.indexOf("?page_id=")!==-1}function isHome(a){return $(a).parent().hasClass("menu-item-home")}function isArrow(a){return $(a).hasClass("arrow")}function getNumberOfArticles(){return POSTCOUNT}function getArticlesWidth(){return 280*getNumberOfArticles()+280}function getPostId(a){return $(a).length!==0?parseInt($(a).attr("id").split("-")[1]):false}function getPostIdFromLink(a){var b;if(!isExternalLink(a)&&isPost(a)){b=$(a).closest("article");return getPostId(b)}else{return false}}function hasPreviousPosting(c){var a,b;a=getPostId(c);if(a===false){return false}b=getAjaxUrl();return $.ajax({url:b,type:"GET",data:{action:"hasprevious",id:a},success:function(d){return parseInt(d)===1?true:false}})}function scrollLeft(a){$(".articles").animate({left:"+=280"},500);return a()}function scrollRight(a){$(".articles").animate({left:"-=280"},500);return a()}function getVisibleArticlesWidth(){return Math.floor($(window).width()/280)*280-280}function getPosition(a){return parseInt($(a).closest("article").data("position"))}function getPostitionFromDom(a){return $(a).data("position")}function getLinkFromDom(c){var b,a;b=$("body").hasClass("page")?$("#page-"+c):$("#post-"+c);if($(b).length!==0){a=$(b).find("a.more-link");return $(a).attr("href")}else{return false}}function scrollToPosition(c,b){var a;if(POS===c){b()}else{if(POS<c){a=(c-POS)*280;$(".articles").animate({left:"-="+a},500,function(){b()});POS=c}else{if(POS>c){a=(POS)*280;$(".articles").animate({left:"+="+a},500,function(){b()});POS=POS-c}}}}function openPost(b){var c,d;function a(){$.get($(b).attr("href"),function(e){c=$(b).closest("article");if($(c).length!==0){$(c).animate({width:"+=280"},500,function(){$(this).addClass("open");$(this).html(e)})}})}if($("article.open").length!==0){d=getPostId($("article.open"));if(d!==getPostIdFromLink(b)){closePost(a())}}else{a()}}function closePost(d){var b,c,a;if(d===undefined){d=function(){return true}}b=$("article.open");if($("article.open").length!==0){console.log("close post");c=getPostId(b);a=getLinkFromDom(c);console.log(c);console.log(a);$(b).animate({width:"-=280"},250,function(){console.log(a+"&more");$(this).removeClass("open jspScrollable").removeAttr("style");$.get(a+"&more",function(e){$(b).html(e);$("a").unbind();bindEventstoAnchors();d()})})}}function ajaxNextPosts(){var b,a;b=Math.ceil($("article").length/10)+1;a="/?paged="+b;$.get(a,function(c){$("body.home .articles").append(c);$("body.home .articles").width(getArticlesWidth())})}function bindEventstoAnchors(){$("a").unbind();$("a").click(function(c){var b,a,d;c.preventDefault();b=$(this);if(!isExternalLink(b)){if(isPost(b)){a=getPosition(b);scrollToPosition(a,function(){openPost(b)})}if(isPage(b)||isHome(b)){window.location=$(b).attr("href")}if(isArrow(b)){d=Math.floor($(".visible").width()/280)-1;if(b.hasClass("next")){if(POS<POSTCOUNT-d){if(POS===(POSTCOUNT-d-1)&&$("article").length%10===0){ajaxNextPosts()}$(".arrow.previous").animate({opacity:1},400);scrollRight(function(){POS+=1})}else{$(".arrow.next").animate({opacity:0},400)}}if(b.hasClass("previous")){if(POS>1){$(".arrow.next").animate({opacity:1},400);scrollLeft(function(){POS-=1})}else{$(".arrow.previous").animate({opacity:0},400)}}}}else{window.location=$(b).attr("href")}});$("a.btn-close").click(function(a){a.preventDefault();closePost()})}function bindEventsToArrows(){if(!isMobile()){$(document).bind("mousemove",function(a){bodyHeight=$("body").height();$(".arrow").css("top",(a.pageY-35)+"px");if(a.pageY<80||a.pageY>bodyHeight-50){$(".arrow.next").css("display","none")}else{$(".arrow.next").css("display","block")}if(a.pageY<250||a.pageY>bodyHeight-100){$(".arrow.previous").css("display","none")}else{$(".arrow.previous").css("display","block")}})}}function openNextPost(){var c,a,b,d;c=$("article.open");a=$(c).next();if($(a).length!==0){console.log("open next post...");b=getLinkFromDom(getPostId(a));d=getPostitionFromDom(a);console.log(b);console.log(d);closePost(function(){scrollToPosition(d,function(){openPost(b)})})}}function openPrevPost(){var c,b,a,d;c=$("article.open");b=$(c).prev();if($(b).length!==0){console.log("open prev post...");a=getLinkFromDom(getPostId(b));d=getPostitionFromDom(b);console.log(a);console.log(d);closePost(function(){scrollToPosition(d,function(){openPost(a)})})}}$(document).ready(function(){var a;POS=1;if($("body").hasClass("page")){POSTCOUNT=$("article").length;$("body.page .visible").width(getVisibleArticlesWidth());$("body.page .articles").width(getArticlesWidth()+280)}else{POSTCOUNT=$("#postcount").val();$("body.home .visible").width(getVisibleArticlesWidth());$("body.home .articles").width(getArticlesWidth())}$("body.home .visible").width(getVisibleArticlesWidth());$("body.home .articles").width(getArticlesWidth());$.Placeholder.init({color:"#d71d7e"});bindEventstoAnchors();bindEventsToArrows();$(window).keydown(function(b){switch(b.keyCode){case 37:$(".previous").trigger("click");break;case 39:$(".next").trigger("click");break}});$(window).resize(function(){$(".visible").width(getVisibleArticlesWidth())})}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment