Advertisement
deliciousthemes

Portfolio script

Feb 20th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function() {
  2.     // Isotope for Portfolio
  3.  
  4. jQuery('.patti-grid[id^="gridwrapper_"]').each( function() {
  5.  
  6.     var $div = jQuery(this);
  7.     var token = $div.data('token');
  8.     var settingObj = window['dt_grid_' + token];   
  9.    
  10.     var $container = '';
  11.     var $optionSets = '';
  12.  
  13.     $initial_filter = '';
  14.  
  15.     if (typeof settingObj === 'undefined') {
  16.         $container = jQuery(" .grid_portfolio");
  17.         $optionSets = jQuery('#gridwrapper_portfolio #options .option-set');
  18.     }
  19.     else {
  20.         if(settingObj.initial_word != '') {
  21.             $initial_filter = '.'+settingObj.initial_word+'';
  22.         }          
  23.         $container = jQuery(".grid_"+settingObj.id+"");
  24.         $optionSets = jQuery('#gridwrapper_'+settingObj.id+'  #options .option-set');
  25.     }
  26.  
  27.     colWidth = function () {
  28.         var w = $container.width(),
  29.             columnNum = 1,
  30.             columnWidth = 0;
  31.  
  32.         // apply default settings
  33.         if(vals.grid_manager != 1) {
  34.             if (w > 1440) {
  35.                 columnNum  = 7;
  36.             } else if (w > 1365) {
  37.                 columnNum  = 5;
  38.             } else if (w > 1279) {
  39.                 columnNum  = 5;
  40.             } else if (w > 1023) {
  41.                 columnNum  = 5;
  42.             } else if (w > 767) {
  43.                 columnNum  = 3;
  44.             } else if (w > 479) {
  45.                 columnNum  = 2;
  46.             }  
  47.         }  
  48.  
  49.         // apply custom settings
  50.         else {
  51.             if (w > 1440) {
  52.                 columnNum  = vals.grid_very_wide;
  53.             } else if (w > 1365) {
  54.                 columnNum  = vals.grid_wide;
  55.             } else if (w > 1279) {
  56.                 columnNum  = vals.grid_normal;
  57.             } else if (w > 1023) {
  58.                 columnNum  = vals.grid_small;
  59.             } else if (w > 767) {
  60.                 columnNum  = vals.grid_tablet;
  61.             } else if (w > 479) {
  62.                 columnNum  = vals.grid_phone;
  63.             }  
  64.         }
  65.  
  66.  
  67.         columnWidth = Math.floor(w/columnNum);
  68.  
  69.         $container.find('.grid-item').each(function() {
  70.             var $item = jQuery(this);
  71.  
  72.             var gwidth = 4;
  73.             if(vals.grid_manager == 1) {
  74.                 gwidth = vals.grid_gutter_width
  75.             }
  76.  
  77.             $item.css({'margin': gwidth/2});
  78.  
  79.             if ($item.hasClass('item-wide')) {
  80.                 if (w < 480) {
  81.                     jQuery('.item-wide').css({
  82.                         'width'      : ((columnWidth)-gwidth) + 'px',
  83.                         'height' : Math.round(((columnWidth)-gwidth) * 0.7777777) + 'px'
  84.                     });
  85.                     jQuery('.item-wide img').css({
  86.                         'width'      : ((columnWidth)-gwidth) + 'px',
  87.                         'height' : 'auto'
  88.                     });
  89.                 }
  90.                 else {
  91.                     jQuery('.item-wide').css({
  92.                         'width'      : ((columnWidth*2)-gwidth) + 'px',
  93.                         'height' : Math.round((2*(((columnWidth)-gwidth) * 0.7777777))+gwidth) + 'px'
  94.                     });
  95.                     jQuery('.item-wide img').css({
  96.                         'width'      : ((columnWidth*2)-gwidth) + 'px',
  97.                         'height' : 'auto'
  98.                     });            
  99.                 }
  100.             }  
  101.            
  102.             if ($item.hasClass('item-small')) {
  103.                 jQuery('.item-small').css({
  104.                     'width'      : ((columnWidth)-gwidth) + 'px',
  105.                     'height' : Math.round(((columnWidth)-gwidth) * 0.7777777) + 'px'
  106.                 });
  107.                 jQuery('.item-small img').css({
  108.                     'width'      : ((columnWidth)-gwidth) + 'px',
  109.                     'height' : 'auto'
  110.                 });                    
  111.             }
  112.                
  113.             if ($item.hasClass('item-long')) {
  114.                 if (w < 480) {
  115.                     jQuery('.item-long').css({
  116.                         'width'      : ((columnWidth)-gwidth) + 'px',
  117.                         'height' : Math.round(((columnWidth)-gwidth) * 0.7777777/2) + 'px'
  118.                     });
  119.                     jQuery('.item-long img').css({
  120.                         'width'      : ((columnWidth)-gwidth) + 'px',
  121.                         'height' : 'auto'
  122.                     });    
  123.                 }
  124.                 else {
  125.                     jQuery('.item-long').css({
  126.                         'width'      : ((columnWidth*2)-gwidth) + 'px',
  127.                         'height' : Math.round(((columnWidth)-gwidth) * 0.7777777) + 'px'
  128.                     });
  129.                     jQuery('.item-long img').css({
  130.                         'width'      : ((columnWidth*2)-gwidth) + 'px',
  131.                         'height' : 'auto'
  132.                     });                
  133.                 }
  134.             }
  135.            
  136.             if ($item.hasClass('item-high')) {
  137.                 jQuery('.item-high').css({
  138.                     'width'      : ((columnWidth)-gwidth) + 'px',
  139.                     'height' : Math.round((2*(((columnWidth)-gwidth) * 0.7777777))+gwidth) + 'px'
  140.                 });
  141.                 jQuery('.item-high img').css({
  142.                     'width'      : ((columnWidth)-gwidth) + 'px',
  143.                     'height' : 'auto'
  144.                 });            
  145.             }              
  146.  
  147.         });
  148.         return columnWidth;
  149.     }
  150.  
  151.     // Isotope Call
  152.     gridIsotope = function () {
  153.         $container.isotope({
  154.             layoutMode : 'masonry',
  155.             itemSelector: '.grid-item',
  156.             animationEngine: 'jquery',
  157.             filter: $initial_filter,   
  158.             masonry: { columnWidth: colWidth(), gutterWidth: 0 }
  159.         });
  160.     };
  161.  
  162.     resizedIsotope = function () {
  163.         $container.isotope({
  164.             layoutMode : 'masonry',
  165.             itemSelector: '.grid-item',
  166.             animationEngine: 'jquery',
  167.             masonry: { columnWidth: colWidth(), gutterWidth: 0 }
  168.         });
  169.     }; 
  170.  
  171.     gridIsotope();
  172.     jQuery(window).smartresize(resizedIsotope);
  173.     jQuery(window).load(gridIsotope);
  174.  
  175.  
  176.     // Portfolio Filtering
  177.  
  178.     $optionLinks = $optionSets.find('a');
  179.  
  180.     if($initial_filter != '') {
  181.         $optionLinks.each(function(){
  182.             var $this = jQuery(this);
  183.             if ( $this.hasClass('selected') ) {
  184.                 $this.removeClass('selected');
  185.             }
  186.             if($this.attr('data-option-value') == $initial_filter) {
  187.                 $this.addClass('selected');
  188.             }
  189.         });
  190.     }
  191.  
  192.     $optionLinks.click(function(){
  193.         var $this = jQuery(this);
  194.         // don't proceed if already selected
  195.         if ( $this.hasClass('selected') ) {
  196.             return false;
  197.         }
  198.         var $optionSet = $this.parents('.option-set');
  199.         $optionSet.find('.selected').removeClass('selected');
  200.         $this.addClass('selected');
  201.  
  202.         // make option object dynamically, i.e. { filter: '.my-filter-class' }
  203.         var options = {},
  204.             key = $optionSet.attr('data-option-key'),
  205.             value = $this.attr('data-option-value');
  206.         // parse 'false' as false boolean
  207.         value = value === 'false' ? false : value;
  208.         options[ key ] = value;
  209.         if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
  210.           // changes in layout modes need extra logic
  211.           changeLayoutMode( $this, options )
  212.         } else {
  213.           // otherwise, apply new options
  214.           $container.isotope( options );
  215.         }
  216.        
  217.         return false;
  218.     });            
  219.    
  220.  
  221.     });
  222. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement