Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($){
  2.     "use strict";
  3.    
  4.     if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) ||
  5.         navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) ||
  6.         navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) ||
  7.         navigator.userAgent.match(/Windows Phone/i) ){
  8.         var gdlr_touch_device = true;
  9.     }else{
  10.         var gdlr_touch_device = false;
  11.     }
  12.    
  13.     // clear selection
  14.     function gdlrClearSelection() {
  15.         if(document.selection && document.selection.empty) {
  16.             document.selection.empty();
  17.         } else if(window.getSelection) {
  18.             var sel = window.getSelection();
  19.             sel.removeAllRanges();
  20.         }
  21.     }
  22.    
  23.     // retrieve GET variable from url
  24.     $.extend({
  25.       getUrlVars: function(){
  26.         var vars = [], hash;
  27.         var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  28.         for(var i = 0; i < hashes.length; i++)
  29.         {
  30.           hash = hashes[i].split('=');
  31.           vars.push(hash[0]);
  32.           vars[hash[0]] = hash[1];
  33.         }
  34.         return vars;
  35.       },
  36.       getUrlVar: function(name){
  37.         return $.getUrlVars()[name];
  38.       }
  39.     });
  40.    
  41.     // blog - port nav
  42.     function gdlr_set_item_outer_nav(){
  43.         $('.blog-item-wrapper > .gdlr-nav-container').each(function(){
  44.             var container = $(this).siblings('.blog-item-holder');
  45.             var child = $(this).children();
  46.             child.css({ 'top':container.position().top, 'bottom':'auto', height: container.height() - 50 });
  47.         });
  48.     }  
  49.    
  50.     function gdlr_set_post_slider_list_height(slider){
  51.         var img_height = 0;
  52.         slider.find('ul li img').each(function(){
  53.             if($(this).height() > img_height){
  54.                 img_height = $(this).height();
  55.             }
  56.         });
  57.        
  58.         var img_padding = (img_height - 20) / 2;
  59.         slider.find('.flex-direction-nav a').css({'padding-top':img_padding, 'padding-bottom':img_padding})
  60.     }  
  61.    
  62.     // runs flex slider function
  63.     $.fn.gdlr_flexslider = function(){
  64.         if(typeof($.fn.flexslider) == 'function'){
  65.             $(this).each(function(){
  66.                 var flex_attr = {
  67.                     animation: 'fade',
  68.                     animationLoop: true,
  69.                     prevText: '<i class="icon-angle-left" ></i>',
  70.                     nextText: '<i class="icon-angle-right" ></i>',
  71.                     useCSS: false
  72.                 };
  73.                
  74.                 // slide duration
  75.                 if( $(this).attr('data-pausetime') ){
  76.                     flex_attr.slideshowSpeed = parseInt($(this).attr('data-pausetime'));
  77.                 }
  78.                 if( $(this).attr('data-slidespeed') ){
  79.                     flex_attr.animationSpeed = parseInt($(this).attr('data-slidespeed'));
  80.                 }
  81.  
  82.                 // set the attribute for carousel type
  83.                 if( $(this).attr('data-type') == 'carousel' ){
  84.                     flex_attr.move = 1;
  85.                     flex_attr.animation = 'slide';
  86.                    
  87.                     if( $(this).closest('.gdlr-item-no-space, .style-without-space').length > 0 ){
  88.                         flex_attr.itemWidth = $(this).width() / parseInt($(this).attr('data-columns'));
  89.                         flex_attr.itemMargin = 0;                          
  90.                     }else{
  91.                         flex_attr.itemWidth = (($(this).width() + 30) / parseInt($(this).attr('data-columns'))) - 30;
  92.                         flex_attr.itemMargin = 30; 
  93.                     }      
  94.                    
  95.                     // if( $(this).attr('data-columns') == "1" ){ flex_attr.smoothHeight = true; }
  96.                 }else{
  97.                     if( $(this).attr('data-effect') ){
  98.                         flex_attr.animation = $(this).attr('data-effect');
  99.                     }
  100.                 }
  101.                 if( $(this).attr('data-columns') ){
  102.                     flex_attr.minItems = parseInt($(this).attr('data-columns'));
  103.                     flex_attr.maxItems = parseInt($(this).attr('data-columns'));   
  104.                 }              
  105.                
  106.                 // set the navigation to different area
  107.                 if( $(this).attr('data-nav-container') ){
  108.                     var flex_parent = $(this).parents('.' + $(this).attr('data-nav-container')).siblings('.gdlr-nav-container');
  109.                    
  110.                     if( flex_parent.find('.gdlr-flex-prev').length > 0 || flex_parent.find('.gdlr-flex-next').length > 0 ){
  111.                         flex_attr.controlNav = false;
  112.                         flex_attr.directionNav = false;
  113.                         flex_attr.start = function(slider){
  114.                             flex_parent.find('.gdlr-flex-next').click(function(){
  115.                                 slider.flexAnimate(slider.getTarget("next"), true);
  116.                             });
  117.                             flex_parent.find('.gdlr-flex-prev').click(function(){
  118.                                 slider.flexAnimate(slider.getTarget("prev"), true);
  119.                             });
  120.                            
  121.                             gdlr_set_item_outer_nav();
  122.                             $(window).resize(function(){ gdlr_set_item_outer_nav(); });
  123.                         }
  124.                     }else{
  125.                         flex_attr.controlNav = false;
  126.                         flex_attr.controlsContainer = flex_parent.find('.nav-container');  
  127.                     }
  128.                    
  129.                 }else if( $(this).closest('.gdlr-post-slider-list-item-wrapper.style-without-space').length ){
  130.                    
  131.                     flex_attr.start = function(slider){
  132.                         gdlr_set_post_slider_list_height(slider);
  133.                         $(window).resize(function(){
  134.                             gdlr_set_post_slider_list_height(slider);
  135.                         })
  136.                     }
  137.                 }
  138.  
  139.                 $(this).flexslider(flex_attr); 
  140.             });
  141.         }
  142.     }
  143.    
  144.     // runs nivo slider function
  145.     $.fn.gdlr_nivoslider = function(){
  146.         if(typeof($.fn.nivoSlider) == 'function'){
  147.             $(this).each(function(){
  148.                 var nivo_attr = {};
  149.                
  150.                 if( $(this).attr('data-pausetime') ){
  151.                     nivo_attr.pauseTime = parseInt($(this).attr('data-pausetime'));
  152.                 }
  153.                 if( $(this).attr('data-slidespeed') ){
  154.                     nivo_attr.animSpeed = parseInt($(this).attr('data-slidespeed'));
  155.                 }
  156.                 if( $(this).attr('data-effect') ){
  157.                     nivo_attr.effect = $(this).attr('data-effect');
  158.                 }
  159.  
  160.                 $(this).nivoSlider(nivo_attr); 
  161.             });
  162.         }
  163.     }  
  164.    
  165.     // runs isotope function
  166.     $.fn.gdlr_isotope = function(){
  167.         if(typeof($.fn.isotope) == 'function'){
  168.             $(this).each(function(){
  169.                 var layout = ($(this).attr('data-layout'))? $(this).attr('data-layout'): 'fitRows';
  170.                 if( layout == 'fitRows' ) return;
  171.                
  172.                 // execute isotope
  173.                 var isotope_element = $(this);
  174.                 isotope_element.children('.clear').remove();
  175.                 isotope_element.isotope({
  176.                     layoutMode: layout
  177.                 });
  178.                
  179.                 // resize event
  180.                 $(window).resize(function(){
  181.                     isotope_element.isotope();
  182.                 });            
  183.             });
  184.         }
  185.     }
  186.    
  187.     // runs fancybox function
  188.     $.fn.gdlr_fancybox = function(){
  189.         if(typeof($.fn.fancybox) == 'function'){
  190.             var fancybox_attr = {
  191.                 nextMethod : 'resizeIn',
  192.                 nextSpeed : 250,
  193.                 prevMethod : false,
  194.                 prevSpeed : 250,   
  195.                 helpers : { media : {} }
  196.             };
  197.            
  198.             if( typeof($.fancybox.helpers.thumbs) == 'object' ){
  199.                 fancybox_attr.helpers.thumbs = { width: 50, height: 50 };
  200.             }
  201.  
  202.             $(this).fancybox(fancybox_attr);
  203.         }  
  204.     }
  205.    
  206.     // responsive video
  207.     $.fn.gdlr_fluid_video = function(){
  208.         $(this).find('iframe[src^="http://www.youtube.com"], iframe[src^="//www.youtube.com"], iframe[src^="https://w.soundcloud.com"], ' +
  209.                      'iframe[src^="http://player.vimeo.com"], iframe[src^="//player.vimeo.com"]').each(function(){
  210.  
  211.             // ignore if inside layerslider
  212.             if( $(this).closest('.ls-container, .master-slider').length <= 0 ){
  213.                 if( ($(this).is('embed') && $(this).parent('object').length) || $(this).parent('.fluid-width-video-wrapper').length ){ return; }
  214.                 if( !$(this).attr('id') ){ $(this).attr('id', 'gdlr-video-' + Math.floor(Math.random()*999999)); }         
  215.            
  216.                 var ratio = $(this).height() / $(this).width();
  217.                 $(this).removeAttr('height').removeAttr('width');
  218.                 try{
  219.                     $(this).wrap('<div class="gdlr-fluid-video-wrapper"></div>').parent().css('padding-top', (ratio * 100)+"%");
  220.                 }catch(e){
  221.                 }
  222.             }
  223.        
  224.         });
  225.     }
  226.    
  227.     // pie chart
  228.     $.fn.gdlr_pie_chart = function(){
  229.         if(typeof($.fn.easyPieChart) == 'function'){
  230.             $(this).each(function(){
  231.                 var gdlr_chart = $(this);
  232.                
  233.                 $(this).easyPieChart({
  234.                     animate: 1200,
  235.                     lineWidth: gdlr_chart.attr('data-linewidth')? parseInt(gdlr_chart.attr('data-linewidth')): 8,
  236.                     size: gdlr_chart.attr('data-size')? parseInt(gdlr_chart.attr('data-size')): 155,
  237.                     barColor: gdlr_chart.attr('data-color')? gdlr_chart.attr('data-color'): '#a9e16e',
  238.                     trackColor: gdlr_chart.attr('data-bg-color')? gdlr_chart.attr('data-bg-color'): '#f2f2f2',
  239.                     backgroundColor: gdlr_chart.attr('data-background'),
  240.                     scaleColor: false,
  241.                     lineCap: 'square'
  242.                 });
  243.  
  244.                 // for responsive purpose
  245.                 if($.browser.msie && (parseInt($.browser.version) <= 8)) return;
  246.                 function limit_gdlr_chart_size(){
  247.                     if( gdlr_chart.parent().width() < parseInt(gdlr_chart.attr('data-size')) ){
  248.                         var max_width = gdlr_chart.parent().width() + 'px';
  249.                         gdlr_chart.css({'max-width': max_width, 'max-height': max_width});
  250.                     }              
  251.                 }
  252.                 limit_gdlr_chart_size();
  253.                 $(window).resize(function(){ limit_gdlr_chart_size(); });
  254.             });
  255.         }
  256.     }
  257.    
  258.     function gdlr_background_resize(){ 
  259.         var windowH = $(window).height();
  260.         $(".gdlr-header-wrapper.full-size-header").each(function(i){
  261.             var path = $(this);
  262.            
  263.             var path_height = $(window).height() - $(this).offset().top;
  264.             var nav_height = $(this).children('#gdlr-header-substitute').height();
  265.             if( nav_height == 0 ){
  266.                 nav_height = $(this).children('.gdlr-navigation-wrapper').height() + parseInt($(this).children('.gdlr-navigation-wrapper').css('border-top-width'));
  267.             }
  268.             $(this).children('.gdlr-header-container').height(path_height - nav_height);
  269.  
  270.             // variables
  271.             var contW = path.width();
  272.             var contH = path.height();
  273.             var imgW = path.attr("data-img-width");
  274.             var imgH = path.attr("data-img-height");
  275.             var ratio = imgW / imgH;
  276.            
  277.             // overflowing difference
  278.             var diff = parseFloat(path.attr("data-diff"));
  279.             diff = diff ? diff : 0;
  280.            
  281.             // remaining height to have fullscreen image only on parallax
  282.             var remainingH = 0;
  283.             if( path.hasClass("parallax") ){
  284.                 var maxH = contH > windowH ? contH : windowH;
  285.                 remainingH = windowH - contH;
  286.             }
  287.            
  288.             // set img values depending on cont
  289.             imgH = contH + remainingH + diff;
  290.             imgW = imgH * ratio;
  291.            
  292.             // fix when too large
  293.             if(contW > imgW){
  294.                 imgW = contW;
  295.                 imgH = imgW / ratio;
  296.             }
  297.            
  298.             path.data("resized-imgW", imgW);
  299.             path.data("resized-imgH", imgH);
  300.             path.css("background-size", imgW + "px " + imgH + "px");
  301.         });
  302.     }
  303.    
  304.     $(document).ready(function(){
  305.        
  306.         $(window).resize(gdlr_background_resize);
  307.         $(window).focus(gdlr_background_resize);
  308.         gdlr_background_resize();      
  309.    
  310.         // video responsive
  311.         $('body').gdlr_fluid_video();  
  312.        
  313.         // top woocommerce button
  314.         $('.gdlr-top-woocommerce-wrapper').hover(function(){
  315.             $(this).children('.gdlr-top-woocommerce').fadeIn(200);
  316.         }, function(){
  317.             $(this).children('.gdlr-top-woocommerce').fadeOut(200);
  318.         });
  319.        
  320.         // runs superfish menu
  321.         if(typeof($.fn.superfish) == 'function'){
  322.            
  323.             // create the mega menu script
  324.             $('#gdlr-main-navigation .sf-mega > ul').each(function(){  
  325.                 $(this).children('li').each(function(){
  326.                     var current_item = $(this);
  327.                     current_item.replaceWith(
  328.                         $('<div />').addClass('sf-mega-section')
  329.                                     .addClass(current_item.attr('data-column'))
  330.                                     .attr('data-size', current_item.attr('data-size'))
  331.                                     .html(  $('<div />').addClass('sf-mega-section-inner')
  332.                                                         .addClass(current_item.attr('class'))
  333.                                                         .attr('id', current_item.attr('id'))
  334.                                                         .html(current_item.html())
  335.                                     )      
  336.                     );
  337.                 });
  338.                 $(this).replaceWith(this.innerHTML);
  339.             });
  340.            
  341.             // make every menu same height
  342.             //$('#gdlr-main-navigation .sf-mega').each(function(){
  343.             //  var sf_mega = $(this); $(this).show();
  344.             // 
  345.             //  var row = 0; var column = 0; var max_height = 0;
  346.             //  sf_mega.children('.sf-mega-section').each(function(){
  347.             //      if( column % 60 == 0 ){
  348.             //          if( row != 0 ){
  349.             //              sf_mega.children('[data-row="' + row + '"]').children('.sf-mega-section-inner').height( max_height - 50 );
  350.             //              max_height = 0;
  351.             //          }
  352.             //          row++; $(this).addClass('first-column');
  353.             //      }      
  354.             //     
  355.             //      $(this).attr('data-row', row); 
  356.             //      column += eval('60*' + $(this).attr('data-size'));
  357.             // 
  358.             //      if( $(this).height() > max_height ){
  359.             //          max_height = $(this).height();
  360.             //      }
  361.             //  });
  362.             // 
  363.             //  sf_mega.children('[data-row="' + row + '"]').children('.sf-mega-section-inner').height( max_height - 50 );     
  364.             //});
  365.            
  366.             $('#gdlr-main-navigation').superfish({
  367.                 speed: 'fast'
  368.             });    
  369.         }      
  370.        
  371.         // blog hover
  372.         $('.blog-item-holder, .blog-list-item-wrapper, .gdlr-blog-nav-shortcode, .gdlr-recent-post-widget-item, .gdlr-post-slider-list-item-wrapper').on({
  373.             mouseenter: function(){
  374.                 if( $(this).hasClass('gdlr-zoom') ){
  375.                     $(this).find('img').transition({ scale: 1.1, duration: 150 });
  376.                 }
  377.                 if( $(this).hasClass('gdlr-opacity') ){
  378.                     $(this).animate({ opacity: 1, duration: 150 });
  379.                 }
  380.                 if( $(this).find('.gdlr-blog-overlay').length > 0 ){
  381.                     $(this).find('.gdlr-blog-overlay').animate({ opacity: 0.15, duration: 100 });
  382.                 }
  383.                 if( $(this).find('.gdlr-blog-overlay-icon').length > 0 ){
  384.                     $(this).find('.gdlr-blog-overlay-icon').animate({ opacity: 1, duration: 100 });
  385.                 }
  386.             },
  387.             mouseleave: function(){
  388.                 if( $(this).hasClass('gdlr-zoom') ){
  389.                     $(this).find('img').transition({ scale: 1, duration: 150 });
  390.                 }
  391.                 if( $(this).hasClass('gdlr-opacity') ){
  392.                     $(this).animate({ opacity: 0.6, duration: 150 });
  393.                 }
  394.                 if( $(this).find('.gdlr-blog-overlay').length > 0 ){
  395.                     $(this).find('.gdlr-blog-overlay').animate({ opacity: 0, duration: 100 });
  396.                 }
  397.                 if( $(this).find('.gdlr-blog-overlay-icon').length > 0 ){
  398.                     $(this).find('.gdlr-blog-overlay-icon').animate({ opacity: 0, duration: 100 });
  399.                 }
  400.             }
  401.         }, '.gdlr-blog-thumbnail');
  402.        
  403.         // blog list content height
  404.         $('.gdlr-blog-list-content-item .post-header').each(function(){
  405.             $(this).css('margin-top', (-$(this).height() / 2))
  406.         });
  407.         $(window).resize(function(){
  408.             $('.gdlr-blog-list-content-item .post-header').each(function(){
  409.                 $(this).css('margin-top', (-$(this).height() / 2))
  410.             });
  411.         });
  412.        
  413.         // blog ajax nav
  414.         $('.blog-item-wrapper').on('click', '.blog-item-ajax-nav > span, .blog-item-filter > a, .gdlr-pagination.gdlr-ajax > a', function(){
  415.             if( $(this).hasClass('active') ){ return false; }
  416.                        
  417.             var gdlr_status = '';
  418.             if( $(this).parent().is('.blog-item-filter') ){
  419.                 gdlr_status = 'category-filter';
  420.                
  421.                 var blog_holder = $(this).parent('.blog-item-filter').siblings('.blog-item-holder');
  422.                 blog_holder.addClass('gdlr-loading').children('.blog-item-holder-inner').slideUp();
  423.            
  424.                 $(this).addClass('active').siblings().removeClass('active');
  425.             }else if( $(this).parent().is('.gdlr-pagination') ){
  426.                 gdlr_status = 'pagination';
  427.                
  428.                 var blog_holder = $(this).closest('.blog-item-holder');
  429.                 blog_holder.addClass('gdlr-loading').children('.blog-item-holder-inner').slideUp();
  430.             }else{
  431.                 gdlr_status = 'ajax-nav';
  432.                
  433.                 var blog_holder = $(this).closest('.blog-item-holder');
  434.                 var blog_content = $(this).closest('.blog-item-ajax-content');
  435.                 var blog_height = blog_content.height();
  436.                 blog_content.addClass('gdlr-loading').children('.blog-item-ajax-content-inner').animate({opacity: 0});             
  437.             }
  438.            
  439.             // get ajax attribute
  440.             var attributes = {};
  441.             $.each(blog_holder.get(0).attributes, function(i, attrib){
  442.                 attributes[attrib.name.replace('data-', '')] = attrib.value;
  443.             });
  444.             attributes.paged = $(this).attr('data-page');
  445.            
  446.             if( gdlr_status == 'category-filter' ){
  447.                 attributes.category = $(this).attr('data-category');
  448.             }else if( gdlr_status == 'pagination' ){
  449.                 attributes.paged = $(this).attr('data-paged');
  450.             }
  451.            
  452.             $.ajax({
  453.                 type: 'POST',
  454.                 url: attributes.ajax,
  455.                 data: {'action': 'gdlr_blog_ajax_query', 'args': attributes},
  456.                 error: function(a, b, c){ console.log(a, b, c); },
  457.                 success: function(data){
  458.                     var gdlr_container_area = '';
  459.                    
  460.                     if( gdlr_status == 'ajax-nav' ){
  461.                         gdlr_container_area = blog_content.removeClass('gdlr-loading')
  462.                             .children('.blog-item-ajax-content-inner').replaceWith($(data).css('opacity', 0));
  463.                        
  464.                         var blog_new_height = blog_content.height();
  465.                         blog_content.height(blog_height);
  466.                         blog_content.animate({height: blog_new_height}, function(){ $(this).css('height', 'auto'); });
  467.                         blog_content.children('.blog-item-ajax-content-inner').animate({opacity: 1});
  468.                     }else{
  469.                         gdlr_container_area = blog_holder.removeClass('gdlr-loading').children('.blog-item-holder-inner').html(data).slideDown();
  470.                     }
  471.                    
  472.                     gdlr_container_area.gdlr_fluid_video();
  473.                     gdlr_container_area.find('.flexslider').gdlr_flexslider();
  474.                    
  475.                     gdlrClearSelection();
  476.                 }
  477.             });
  478.            
  479.             return false;
  480.         });
  481.    
  482.         // script for accordion item
  483.         $('.gdlr-accordion-item').each(function(){
  484.             var multiple_tab = $(this).hasClass('gdlr-multiple-tab');
  485.             $(this).children('.accordion-tab').children('.accordion-title').click(function(){
  486.                 var current_tab = $(this).parent();
  487.                 if( current_tab.hasClass('active') ){
  488.                     current_tab.removeClass('pre-active');
  489.                     $(this).children('i').removeClass('icon-minus').addClass('icon-plus');
  490.                     $(this).siblings('.accordion-content').slideUp(function(){ current_tab.removeClass('active'); });
  491.                 }else{
  492.                     current_tab.addClass('pre-active');
  493.                     $(this).children('i').removeClass('icon-plus').addClass('icon-minus'); 
  494.                     $(this).siblings('.accordion-content').slideDown(function(){ current_tab.addClass('active'); });
  495.                                
  496.                 }
  497.                
  498.                 // close another tab if multiple tab is not allowed ( accordion )
  499.                 if( !multiple_tab ){
  500.                     current_tab.siblings().removeClass('pre-active');
  501.                     current_tab.siblings().children('.accordion-title').children('i').removeClass('icon-minus').addClass('icon-plus');
  502.                     current_tab.siblings().children('.accordion-content').slideUp(function(){ $(this).parent().removeClass('active'); });
  503.                 }
  504.             });
  505.         });
  506.        
  507.         // script for tab item
  508.         $('.tab-title-wrapper').children().click(function(){
  509.             $(this).addClass('active');
  510.             $(this).siblings().removeClass('active');
  511.            
  512.             var selected_index = $(this).index() + 1;
  513.             $(this).parent().siblings('.tab-content-wrapper').children(':nth-child(' + selected_index + ')').each(function(){
  514.                 $(this).siblings().removeClass('active').hide();
  515.                 $(this).fadeIn(function(){ $(this).addClass('active'); });
  516.             })
  517.         });    
  518.    
  519.         // initiate the tab when the get tab variable is sent
  520.         var inital_tab = $.getUrlVar('tab');
  521.         if( inital_tab ){ $('#' + inital_tab.replace(',', ', #')).each(function(){ $(this).trigger('click'); }); }
  522.        
  523.         // script for code item
  524.         $('.gdlr-code-item .gdlr-code-title').click(function(){
  525.             var parent = $(this).parent();
  526.             if( parent.hasClass('active') ){
  527.                 $(this).children('i').removeClass('icon-minus').addClass('icon-plus');
  528.                 $(this).siblings('.gdlr-code-content').slideUp(function(){
  529.                     parent.removeClass('active');
  530.                 });
  531.             }else{
  532.                 $(this).children('i').removeClass('icon-plus').addClass('icon-minus');
  533.                 $(this).siblings('.gdlr-code-content').slideDown(function(){
  534.                     parent.addClass('active'); 
  535.                 });            
  536.             }
  537.         });    
  538.        
  539.         // script for parallax background
  540.         $('.gdlr-parallax-wrapper').each(function(){
  541.             if( $(this).hasClass('gdlr-background-image') ){
  542.                 var parallax_section = $(this);
  543.                 var parallax_speed = parseFloat(parallax_section.attr('data-bgspeed'));
  544.                 if( parallax_speed == 0 || gdlr_touch_device ) return;
  545.                 if( parallax_speed == -1 ){
  546.                     parallax_section.css('background-attachment', 'fixed');
  547.                     parallax_section.css('background-position', 'center center');
  548.                     return;
  549.                 }
  550.                    
  551.                 $(window).scroll(function(){
  552.                     // if in area of interest
  553.                     if( ( $(window).scrollTop() + $(window).height() > parallax_section.offset().top ) &&
  554.                         ( $(window).scrollTop() < parallax_section.offset().top + parallax_section.outerHeight() ) ){
  555.                        
  556.                         var scroll_pos = 0;
  557.                         if( $(window).height() > parallax_section.offset().top ){
  558.                             scroll_pos = $(window).scrollTop();
  559.                         }else{
  560.                             scroll_pos = $(window).scrollTop() + $(window).height() - parallax_section.offset().top;
  561.                         }
  562.                         parallax_section.css('background-position', 'center ' + (-scroll_pos * parallax_speed) + 'px');
  563.                     }
  564.                 });        
  565.             }else if( $(this).hasClass('gdlr-background-video') ){
  566.                 if(typeof($.fn.mb_YTPlayer) == 'function'){
  567.                     $(this).children('.gdlr-bg-player').mb_YTPlayer();
  568.                 }
  569.             }else{
  570.                 return;
  571.             }
  572.         });
  573.        
  574.         // responsive menu
  575.         if(typeof($.fn.dlmenu) == 'function'){
  576.             $('#gdlr-responsive-navigation').each(function(){
  577.                 $(this).find('.dl-submenu').each(function(){
  578.                     if( $(this).siblings('a').attr('href') && $(this).siblings('a').attr('href') != '#' ){
  579.                         var parent_nav = $('<li class="menu-item gdlr-parent-menu"></li>');
  580.                         parent_nav.append($(this).siblings('a').clone());
  581.                        
  582.                         $(this).prepend(parent_nav);
  583.                     }
  584.                 });
  585.                 $(this).dlmenu();
  586.             });
  587.         }  
  588.        
  589.         // gallery thumbnail type
  590.         $('.gdlr-gallery-thumbnail').each(function(){
  591.             var thumbnail_container = $(this).children('.gdlr-gallery-thumbnail-container');
  592.        
  593.             $(this).find('.gallery-item').click(function(){
  594.                 var selected_slide = thumbnail_container.children('[data-id="' + $(this).attr('data-id') + '"]');
  595.                 if(selected_slide.css('display') == 'block') return false;
  596.            
  597.                 // check the gallery height
  598.                 var image_width = selected_slide.children('img').attr('width');
  599.                 var image_ratio = selected_slide.children('img').attr('height') / image_width;
  600.                 var temp_height = image_ratio * Math.min(thumbnail_container.width(), image_width);
  601.                
  602.                 thumbnail_container.animate({'height': temp_height});
  603.                 selected_slide.fadeIn().siblings().hide();
  604.                 return false;
  605.             });    
  606.  
  607.             $(window).resize(function(){ thumbnail_container.css('height', 'auto') });
  608.         });
  609.  
  610.         // fancybox
  611.         $('a[href$=".jpg"], a[href$=".png"], a[href$=".gif"]').not('[data-rel="fancybox"], [href*="pinterest"]').attr('data-rel', 'fancybox');
  612.         $('[data-rel="fancybox"]').gdlr_fancybox();
  613.        
  614.         // image shortcode
  615.         $('.gdlr-image-link-shortcode').hover(function(){
  616.             $(this).find('.gdlr-image-link-overlay').animate({opacity: 0.8}, 150);
  617.             $(this).find('.gdlr-image-link-icon').animate({opacity: 1}, 150);
  618.         }, function(){
  619.             $(this).find('.gdlr-image-link-overlay').animate({opacity: 0}, 150);
  620.             $(this).find('.gdlr-image-link-icon').animate({opacity: 0}, 150);
  621.         });
  622.        
  623.         // Personnel
  624.         $('.gdlr-personnel-item.round-style .personnel-item').each(function(){
  625.             var current_item = $(this);
  626.             function gdlr_set_round_personnel_height(){
  627.                 current_item.find('.personnel-item-inner').each(function(){
  628.                     $(this).css('margin-top', -($(this).height()/2));
  629.                 });
  630.             }
  631.            
  632.             gdlr_set_round_personnel_height();
  633.             $(window).resize(function(){
  634.                 gdlr_set_round_personnel_height();
  635.             });
  636.         });
  637.         $('.gdlr-personnel-item.round-style .personnel-item').hover(function(){
  638.             $(this).find('.personnel-author-image').animate({'opacity':0.05}, 200);
  639.             $(this).find('.personnel-item-inner').animate({'opacity':1}, 200);
  640.         }, function(){
  641.             $(this).find('.personnel-author-image').animate({'opacity':1}, 200);
  642.             $(this).find('.personnel-item-inner').animate({'opacity':0}, 200);
  643.         });
  644.        
  645.         // Price Table
  646.         $('.gdlr-price-table-item').each(function(){
  647.             var price_table = $(this);
  648.            
  649.             function set_price_table_height(){
  650.                 var max_height = 0;
  651.                 var price_content = price_table.find('.price-content');
  652.                
  653.                 price_content.css('height', 'auto');
  654.                 price_content.each(function(){
  655.                     if( max_height < $(this).height() ){ max_height = $(this).height(); }
  656.                 });
  657.                 price_content.css('height', max_height);
  658.             }
  659.            
  660.             set_price_table_height()
  661.             $(window).resize(function(){ set_price_table_height(); });
  662.         });
  663.  
  664.         // Default text
  665.         $('form').submit(function(){
  666.             var has_default = false;
  667.             $(this).find('input[data-default]').each(function(){
  668.                 if( $(this).is('#url') ){
  669.                     if( $(this).val() == $(this).attr('data-default') ) $(this).val('');
  670.                 }else{
  671.                     if( $(this).val() == $(this).attr('data-default') ) has_default = true;
  672.                 }
  673.             });
  674.            
  675.             if(has_default) return false;
  676.         });
  677.        
  678.         // Search option
  679.         $('#gdlr-menu-search-button').click(function(){
  680.             var diff = ($(window).width() - $(this).closest('.gdlr-navigation-container').width()) / 2;
  681.             var right_val = $(window).width() - ($(this).offset().left + $(this).outerWidth() + diff) ;
  682.            
  683.             $(this).siblings('#gdlr-menu-search').css('right', right_val).slideToggle(200);
  684.            
  685.             gdlrClearSelection();
  686.         });
  687.         $('.search-text input[data-default], .gdlr-comments-area input[data-default]').each(function(){
  688.             var default_value = $(this).attr("data-default");
  689.             $(this).val(default_value);
  690.             $(this).live("blur", function(){
  691.                 if ($(this).val() == ""){
  692.                     $(this).val(default_value);
  693.                 }  
  694.             }).live("focus", function(){
  695.                 if ($(this).val() == default_value){
  696.                     $(this).val("");
  697.                 }
  698.             });    
  699.         });    
  700.  
  701.         // smooth anchor
  702.         if( window.location.hash ){
  703.             $('html, body').animate({
  704.                 scrollTop: $(window.location.hash).offset().top - 68
  705.             }, 500);
  706.         }
  707.         $('.gdlr-navigation a[href*="#"], .gdlr-responsive-navigation a[href*="#"]').click(function(){
  708.             if( $(this).attr('href').length > 1 ){
  709.                 var item_id = $(this.hash);
  710.                
  711.                 if( $('body').hasClass('home') ){
  712.                     if( item_id.length > 0 ){
  713.                         $('html, body').animate({
  714.                             scrollTop: item_id.offset().top - 68
  715.                         }, 500);
  716.                         return false;
  717.                     }
  718.                 }else{
  719.                     window.location.replace($('.body-wrapper').attr('data-home') + '/' + this.hash);
  720.                 }
  721.             }
  722.         });
  723.        
  724.         // logo responsive
  725.         var main_logo = $('.header-style-transparent .gdlr-logo img');
  726.         function gdlr_mobile_logo(){
  727.             if( main_logo && $(window).width() < 767 ){
  728.                 if( main_logo.attr('data-normal') && main_logo.attr('src') != main_logo.attr('data-normal') ){
  729.                      main_logo.attr('data-trans', main_logo.attr('src'));
  730.                      main_logo.attr('src', main_logo.attr('data-normal'));
  731.                 }                  
  732.             }else{
  733.                 if( main_logo.closest('.gdlr-fixed-header').length == 0 ){
  734.                     if( main_logo.attr('data-trans') && main_logo.attr('src') != main_logo.attr('data-trans') ){
  735.                         main_logo.attr('src', main_logo.attr('data-trans'));
  736.                     }      
  737.                 }
  738.             }
  739.         }
  740.         gdlr_mobile_logo();
  741.         $(window).resize(function(){ gdlr_mobile_logo(); });
  742.        
  743.         // animate ux
  744.         if( !gdlr_touch_device && ( !$.browser.msie || (parseInt($.browser.version) > 8)) ){
  745.        
  746.             // image ux
  747.             $('.content-wrapper img').each(function(){
  748.                 if( $(this).closest('.gdlr-ux, .ls-wp-container, .product, .flexslider, .nivoSlider').length ) return;
  749.                
  750.                 var ux_item = $(this);
  751.                 if( ux_item.offset().top > $(window).scrollTop() + $(window).height() ){
  752.                     ux_item.css({ 'opacity':0 });
  753.                 }else{ return; }
  754.                
  755.                 $(window).scroll(function(){
  756.                     if( $(window).scrollTop() + $(window).height() > ux_item.offset().top + 100 ){
  757.                         ux_item.animate({ 'opacity':1 }, 1200);
  758.                     }
  759.                 });                
  760.             });
  761.        
  762.             // item ux
  763.             $('.gdlr-ux').each(function(){
  764.                 var ux_item = $(this);
  765.                 if( ux_item.hasClass('gdlr-chart') || ux_item.hasClass('gdlr-skill-bar') ){
  766.                     if( ux_item.offset().top < $(window).scrollTop() + $(window).height() ){
  767.                         if( ux_item.hasClass('gdlr-chart') && (!$.browser.msie || (parseInt($.browser.version) > 8)) ){
  768.                             ux_item.gdlr_pie_chart();
  769.                         }else if( ux_item.hasClass('gdlr-skill-bar') ){
  770.                             ux_item.children('.gdlr-skill-bar-progress').each(function(){
  771.                                 if($(this).attr('data-percent')){
  772.                                     $(this).animate({width: $(this).attr('data-percent') + '%'}, 1200, 'easeOutQuart');
  773.                                 }
  774.                             });
  775.                         }
  776.                         return;
  777.                     }
  778.                 }else if( ux_item.offset().top > $(window).scrollTop() + $(window).height() ){
  779.                     ux_item.css({ 'opacity':0, 'padding-top':20, 'margin-bottom':-20 });
  780.                 }else{ return; }   
  781.  
  782.                 $(window).scroll(function(){
  783.                     if( $(window).scrollTop() + $(window).height() > ux_item.offset().top + 100 ){
  784.                         if( ux_item.hasClass('gdlr-chart') && (!$.browser.msie || (parseInt($.browser.version) > 8)) ){
  785.                             ux_item.gdlr_pie_chart();
  786.                         }else if( ux_item.hasClass('gdlr-skill-bar') ){
  787.                             ux_item.children('.gdlr-skill-bar-progress').each(function(){
  788.                                 if($(this).attr('data-percent')){
  789.                                     $(this).animate({width: $(this).attr('data-percent') + '%'}, 1200, 'easeOutQuart');
  790.                                 }
  791.                             });
  792.                         }else{
  793.                             ux_item.animate({ 'opacity':1, 'padding-top':0, 'margin-bottom':0 }, 1200);
  794.                         }
  795.                     }
  796.                 });                
  797.             });
  798.            
  799.         // do not animate on scroll in mobile
  800.         }else{
  801.        
  802.             // Pie chart
  803.             if(!$.browser.msie || (parseInt($.browser.version) > 8)){
  804.                 $('.gdlr-chart').gdlr_pie_chart();
  805.             }  
  806.  
  807.        
  808.             // skill bar
  809.             $('.gdlr-skill-bar-progress').each(function(){
  810.                 if($(this).attr('data-percent')){
  811.                     $(this).animate({width: $(this).attr('data-percent') + '%'}, 1200, 'easeOutQuart');
  812.                 }
  813.             });        
  814.         }      
  815.  
  816.         // runs nivoslider when available
  817.         $('.nivoSlider').gdlr_nivoslider();    
  818.        
  819.         // runs flexslider when available
  820.         $('.flexslider').gdlr_flexslider();
  821.        
  822.     });
  823.    
  824.     $(window).load(function(){
  825.        
  826.         // fix sidebar position
  827.         $(window).scroll(function(){
  828.             var sidebar = $('.gdlr-sidebar');
  829.             sidebar.each(function(){
  830.                 if( !gdlr_touch_device && $(window).width() > 960 ){
  831.                     var parent_ct = $(this).parents('.with-sidebar-container');
  832.                     if( $(this).height() < parent_ct.height() ){
  833.                         if( $(window).scrollTop() + $(window).height() >= parent_ct.offset().top + parent_ct.height() ){
  834.                             if( !$(this).hasClass('gdlr-absolute-sidebar') ){
  835.                                 $(this).css({'left': ''});
  836.                                 $(this).addClass('gdlr-absolute-sidebar').removeClass('gdlr-fixed-sidebar');
  837.                             }
  838.                         }else if( !$(this).hasClass('gdlr-fixed-sidebar') &&
  839.                             $(window).scrollTop() + $(window).height() >= parent_ct.offset().top + $(this).height()  ){
  840.                                
  841.                             $(this).attr('data-top-position', $(this).offset().top + $(this).height());
  842.                             $(this).css({'left': $(this).offset().left, 'width': $(this).width() });
  843.                             $(this).addClass('gdlr-fixed-sidebar').removeClass('gdlr-absolute-sidebar');
  844.                         }else if( $(this).hasClass('gdlr-fixed-sidebar') &&
  845.                             $(window).scrollTop() + $(window).height() < parent_ct.offset().top + $(this).height() ){
  846.                                
  847.                             $(this).css({'left': '', 'width': '' });
  848.                             $(this).removeClass('gdlr-fixed-sidebar');
  849.                         }
  850.                     }
  851.                 }else{
  852.                     $(this).removeClass('gdlr-fixed-sidebar gdlr-absolute-sidebar');
  853.                     $(this).css({'left': '', 'width': '' });
  854.                 }
  855.             });
  856.         });
  857.         $(window).resize(function(){
  858.             $('.gdlr-sidebar').removeClass('gdlr-fixed-sidebar');
  859.         });
  860.    
  861.         // run isotope when available
  862.         $('.gdlr-isotope').gdlr_isotope(); 
  863.        
  864.         // run pie chart for ie8 and below
  865.         if($.browser.msie && (parseInt($.browser.version) <= 8)){
  866.             $('.gdlr-chart').gdlr_pie_chart();
  867.         }  
  868.        
  869.         // sliding nav
  870.         var slide_nav = $('#gdlr-navigation-gimmick');
  871.         var current_pos = 0;
  872.         var current_menu_width = 0;
  873.  
  874.         // init menu width
  875.         $('#gdlr-main-navigation > ul > li.current-menu-item, #gdlr-main-navigation > ul > li.current-menu-ancestor, ' +
  876.           '#gdlr-main-navigation > ul > li.current_page_item, #gdlr-main-navigation > ul > li.current_page_ancestor' ).each(function(){
  877.             var padding = parseInt( $(this).css('padding-right') );
  878.             current_pos = $(this).position().left + padding;
  879.             current_menu_width = $(this).width();
  880.  
  881.             slide_nav.css({'width': current_menu_width, 'left': current_pos});
  882.         });
  883.         if( current_pos == 0 ){
  884.             current_pos = $('#gdlr-main-navigation').position().left;
  885.             slide_nav.css('left', current_pos);
  886.         }
  887.        
  888.         $('.gdlr-navigation a[href*="#"], .gdlr-responsive-navigation a[href*="#"]').click(function(){
  889.             var padding = parseInt( $(this).parent().css('padding-left') );
  890.             current_pos = $(this).parent().position().left + padding;
  891.             current_menu_width = $(this).parent().width();
  892.         });
  893.  
  894.         $(window).resize(function(){
  895.             // init menu width
  896.             $('#gdlr-main-navigation > ul > li.current-menu-item, #gdlr-main-navigation > ul > li.current-menu-ancestor, #gdlr-main-navigation > ul > li.current_page_item, #gdlr-main-navigation > ul > li.current_page_ancestor').each(function(){
  897.                 var padding = parseInt( $(this).css('padding-left') );
  898.                 current_pos = $(this).position().left + padding;
  899.                 current_menu_width = $(this).width();
  900.  
  901.                 slide_nav.css({'width': current_menu_width, 'left': current_pos});
  902.             });
  903.             if( current_pos == 0 ){
  904.                 current_pos = $('#gdlr-main-navigation').position().left;
  905.                 slide_nav.css('left', current_pos);
  906.             }
  907.         });
  908.            
  909.         $('#gdlr-main-navigation > ul > li').hover(function(){
  910.             var padding = parseInt( $(this).css('padding-left') );
  911.        
  912.             slide_nav.animate({ 'width': jQuery(this).width(), 'left': jQuery(this).position().left + padding},
  913.                 { queue: false, easing: 'easeOutQuad', duration: 250 });           
  914.         }, function(){
  915.             slide_nav.animate({ 'width': current_menu_width, 'left': current_pos },
  916.                 { queue: false, easing: 'easeOutQuad', duration: 250 });       
  917.         });    
  918.  
  919.         // float menu
  920.         $('.body-wrapper.float-menu').each(function(){
  921.             var sub_area = $('#gdlr-header-substitute');
  922.             var main_area = sub_area.siblings('.gdlr-navigation-wrapper');
  923.            
  924.             $(window).scroll(function(){
  925.                 if( main_area.hasClass('gdlr-fixed-header') && ($(this).scrollTop() <= sub_area.offset().top - parseInt($('html').css('margin-top')) || $(this).width() < 959)){
  926.                     sub_area.css('height','auto');
  927.                     main_area.insertAfter(sub_area);
  928.                     main_area.removeClass('gdlr-fixed-header');
  929.                    
  930.                 }else if( !main_area.hasClass('gdlr-fixed-header') && $(this).width() > 959 &&
  931.                     $(this).scrollTop() > sub_area.offset().top - parseInt($('html').css('margin-top')) ){
  932.                    
  933.                         sub_area.css('height',main_area.height() + parseInt(main_area.css('border-top-width')));
  934.                         main_area.addClass('gdlr-fixed-header');
  935.                         $('body').append(main_area);
  936.                 }              
  937.             });
  938.         });        
  939.        
  940.         $(window).trigger('resize');
  941.         $(window).trigger('scroll');
  942.     });
  943.    
  944. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement