Advertisement
Panag

theme_trust.js

Jul 25th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //////////////////////////////////////////////////////////////
  2. // Set Variables
  3. /////////////////////////////////////////////////////////////
  4.  
  5. var transitionSpeed = 500;
  6. var scrollSpeed = 700;
  7. var fadeDelay = 100;
  8. var currentProject = "";
  9. var nextProject = "";
  10. var previousHeight = "";
  11. var emptyProjectBoxHeight = 100;
  12. var hasSlideshow = false;
  13.    
  14. ///////////////////////////////    
  15. // iPad and iPod Detection
  16. ///////////////////////////////
  17.    
  18. function isiPad(){
  19.     return (navigator.platform.indexOf("iPad") != -1);
  20. }
  21.  
  22. function isiPhone(){
  23.     return (
  24.         //Detect iPhone
  25.         (navigator.platform.indexOf("iPhone") != -1) ||
  26.         //Detect iPod
  27.         (navigator.platform.indexOf("iPod") != -1)
  28.     );
  29. }
  30.  
  31.  
  32. ///////////////////////////////    
  33. // Isotope Browser Check
  34. ///////////////////////////////
  35.  
  36. function isotopeAnimationEngine(){
  37.     if(jQuery.browser.mozilla || jQuery.browser.msie){
  38.         return "jquery";
  39.     }else{
  40.         return "css";
  41.     }
  42. }
  43.  
  44.  
  45. ///////////////////////////////    
  46. // Lightbox
  47. ///////////////////////////////
  48.  
  49. function lightboxInit() {
  50.     if(screen.width > 500){
  51.         jQuery("a[rel^='prettyPhoto']").prettyPhoto({
  52.             social_tools: false,
  53.             deeplinking: false
  54.         });
  55.     }
  56. }
  57.  
  58.  
  59. ///////////////////////////////
  60. // Project Filtering
  61. ///////////////////////////////
  62.  
  63. function projectFilterInit() {
  64.     jQuery('#filterNav a').click(function(){
  65.         var selector = jQuery(this).attr('data-filter');   
  66.         jQuery('#projects .thumbs').isotope({
  67.             filter: selector,          
  68.             hiddenStyle : {
  69.                 opacity: 0,
  70.                 scale : 1
  71.             }          
  72.         });
  73.    
  74.         if ( !jQuery(this).hasClass('selected') ) {
  75.             jQuery(this).parents('#filterNav').find('.selected').removeClass('selected');
  76.             jQuery(this).addClass('selected');
  77.         }
  78.    
  79.         return false;
  80.     });
  81. }
  82.  
  83.  
  84. ///////////////////////////////
  85. // Project thumbs
  86. ///////////////////////////////
  87.  
  88. function projectThumbInit() {
  89.    
  90.     if(!isiPad() && !isiPhone()) {
  91.         jQuery(".project.small").hover(
  92.             function() {
  93.                 if(!jQuery(this).hasClass("selected")){
  94.                     jQuery(this).find('img:last').stop().fadeTo("fast", .9);
  95.                 }
  96.                    
  97.             },
  98.             function() {
  99.                 if(!jQuery(this).hasClass("selected")){
  100.                     jQuery(this).find('img:last').stop().fadeTo("fast", 1);
  101.                 }  
  102.         });
  103.        
  104.         jQuery(".project.small").hover(
  105.             function() {
  106.                
  107.                     jQuery(this).find('.title').stop().fadeTo("fast", 1);
  108.                     jQuery(this).find('img:last').attr('title','');
  109.                
  110.             },
  111.             function() {
  112.                 if(!jQuery(this).hasClass("selected")){
  113.                     jQuery(this).find('.title').stop().fadeTo("fast", 0);
  114.                 }              
  115.         });
  116.     }  
  117.    
  118.    
  119.     jQuery('.thumbs.masonry').isotope({
  120.         // options
  121.         itemSelector : '.project.small',
  122.         layoutMode : 'masonry',
  123.         animationEngine: isotopeAnimationEngine()
  124.     });
  125.    
  126.  
  127.     jQuery(".project.small").css("opacity", "1");  
  128.    
  129.     jQuery(".project.small.ajx").click(function(){
  130.         jQuery(".thumbs .selected .title").hide();
  131.         jQuery(".thumbs .selected").find('img:last').stop().fadeTo("fast", 1); 
  132.         jQuery(".thumbs .selected").removeClass("selected");                       
  133.         jQuery(this).addClass("selected");     
  134.         jQuery(".thumbs .selected .title").show();
  135.            
  136.         var projectSlug = jQuery(this).attr('id').replace(/^project-/, '');
  137.         jQuery.scrollTo(0, scrollSpeed);       
  138.         processProject(projectSlug);
  139.     });
  140.    
  141. }
  142.    
  143.    
  144. ///////////////////////////////    
  145. //  Project Loading
  146. ///////////////////////////////
  147.  
  148. function processProject(projectSlug) { 
  149.  
  150.     // Prevent projecBox from collapsing   
  151.     jQuery("#projectBox").css("height", jQuery("#projectHolder").outerHeight());   
  152.    
  153.     // Fade out the old project
  154.     if(currentProject != "") {         
  155.         jQuery("#projectHolder").fadeOut(transitionSpeed,
  156.             function() {
  157.                 jQuery(".project.ajax").remove();
  158.                 currentProject = "";                       
  159.                 if(projectSlug){
  160.                     loadProject(projectSlug);
  161.                     jQuery("#ajaxLoading").fadeIn('fast');         
  162.                 };
  163.             });
  164.     }else{
  165.         //No project currently loaded - open the projectBox to show the loader.
  166.         if(projectSlug){
  167.             jQuery("#homeMessage").removeClass('withBorder');
  168.             jQuery("#pageHead").removeClass('withBorder');
  169.             jQuery("#projectBox").animate({
  170.                 height: emptyProjectBoxHeight
  171.             }, scrollSpeed,
  172.             function() {               
  173.                 jQuery("#ajaxLoading").fadeIn('fast',
  174.                     function() {
  175.                         loadProject(projectSlug);      
  176.                 });
  177.             });                
  178.         };
  179.     }  
  180.    
  181.     if(!projectSlug){
  182.         jQuery("#projectBox").animate({
  183.             height: 0
  184.             }, scrollSpeed,
  185.             function() {               
  186.                 jQuery("#homeMessage").addClass('withBorder');
  187.                 jQuery("#pageHead").addClass('withBorder');            
  188.             });
  189.                            
  190.     }      
  191. }
  192.  
  193.    
  194. function loadProject(projectSlug) {
  195.     // Scroll to the top of the projects   
  196.     jQuery("#projectHolder").load(     
  197.         MyAjax.ajaxurl,
  198.         {          
  199.             action : 'myajax-submit',          
  200.             slug : projectSlug
  201.         },
  202.         function( response ) {
  203.            
  204.         }
  205.     );
  206. }
  207.  
  208.  
  209. function waitForMedia(projectSlug, slideshowDelay) {
  210.    
  211.     var totalMediaElements = 0;
  212.     var loadedMediaElements = 0;
  213.     var mediaTypes = ['img'];
  214.    
  215.     for(var i=0; i<=mediaTypes.length; i++) {
  216.         totalMediaElements += jQuery("#projectHolder " + mediaTypes[i]).length;
  217.     }
  218.     //alert(totalMediaElements);
  219.    
  220.     if(totalMediaElements > 0){
  221.         for(var i=0; i<=mediaTypes.length; i++) {
  222.             jQuery("#projectHolder " + mediaTypes[i]).each(function() {                
  223.                 jQuery(this).load(function() {             
  224.                     loadedMediaElements++;
  225.                     if(loadedMediaElements == totalMediaElements) {
  226.                         jQuery("#ajaxLoading").fadeOut('fast',
  227.                         function(){                    
  228.                             //Set up the slideshow
  229.                             jQuery('.flexslider').flexslider({
  230.                                 slideshowSpeed: slideshowDelay+"000",  
  231.                                 directionNav: true,                
  232.                                 animation: "fade"
  233.                             });
  234.                             showProject(projectSlug);
  235.                         });
  236.                     }
  237.                 });
  238.             });
  239.         }
  240.     }else{
  241.         jQuery("#ajaxLoading").fadeOut('fast',
  242.         function(){        
  243.             //Fix Vimeo embed for iPad         
  244.             if(isiPad()) {             
  245.                 jQuery.each(jQuery("iframe"), function() {
  246.                     jQuery(this).attr({
  247.                         src: jQuery(this).attr("src")
  248.                     });
  249.                 });
  250.             }          
  251.             showProject(projectSlug);          
  252.         });    
  253.     }  
  254. }
  255.  
  256. function showProject(projectSlug) {    
  257.    
  258.     // Fade in the new project 
  259.     jQuery("#projectHolder").fadeIn(transitionSpeed);  
  260.     currentProject = "project-" + projectSlug;
  261.     jQuery("#" + currentProject).addClass("selected"); 
  262.    
  263.     // Adjust the height of project container
  264.    
  265.     targetHeight = jQuery("#projectHolder").outerHeight(); 
  266.     jQuery("#projectHolder").css("height", targetHeight);  
  267.     jQuery("#projectBox").animate({
  268.         height: jQuery("#projectHolder").outerHeight()
  269.     }, scrollSpeed,
  270.     function() {
  271.         jQuery("#projectHolder").css("height", "auto");            
  272.         jQuery("#projectBox").css("height", "auto");       
  273.     });
  274.     previousHeight = targetHeight; 
  275.    
  276.     jQuery("#projectHolder .closeBtn").click(function(){
  277.         jQuery(".thumbs .selected .title").hide();
  278.         jQuery(".thumbs .selected").find('img:last').stop().fadeTo("fast", 1); 
  279.         jQuery(".thumbs .selected").removeClass("selected");       
  280.         jQuery.scrollTo(0, scrollSpeed);   
  281.         processProject();
  282.     });
  283.     addthis.toolbox('.addthis_toolbox');
  284. }
  285.  
  286. ///////////////////////////////
  287. // Project Nav
  288. ///////////////////////////////
  289.  
  290. function nextPrevProject(slug) {
  291.     var projectSlug = slug;
  292.     jQuery(".thumbs .selected .title").hide();
  293.     jQuery(".thumbs .selected").find('img:last').stop().fadeTo("fast", 1); 
  294.     jQuery(".thumbs .selected").removeClass("selected");                       
  295.     jQuery("#project-"+projectSlug).addClass("selected");  
  296.     jQuery(".thumbs .selected").find('.title').stop().fadeTo("fast", 1);       
  297.    
  298.     jQuery.scrollTo(0, scrollSpeed);       
  299.     processProject(projectSlug);
  300. }
  301.    
  302.    
  303. jQuery.noConflict();
  304. jQuery(document).ready(function(){
  305.    
  306.     lightboxInit();
  307.     projectThumbInit();
  308.     projectFilterInit();
  309.    
  310.     // Show project is there is a hash in the URL
  311.     var projectSlug = location.hash.replace("\#","");  
  312.     if(projectSlug != "index"){
  313.         processProject(projectSlug);
  314.     }  
  315.    
  316. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement