jegtheme

main.js

Apr 17th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ------------------------------------------------------------------------- *
  2.  *  Main Script
  3.  * ------------------------------------------------------------------------- */
  4.  
  5. var $ = jQuery.noConflict();
  6.  
  7. /** map **/
  8. $.fn.jrmap = function () {
  9.     "use strict";
  10.     return $(this).each(function () {
  11.         var element = this;
  12.         var content = $(element).find('.contenthidden').html();
  13.         var options = {
  14.             lat: $(element).data('lat'),
  15.             lng: $(element).data('lng'),
  16.             zoom: $(element).data('zoom'),
  17.             ratio: $(element).data('ratio'),
  18.             showpopup: $(element).data('showpopup'),
  19.             title: $(element).data('title')
  20.         };
  21.  
  22.         var mapresize = function () {
  23.             var elewidth = $(element).width();
  24.             $(element).height(elewidth * options.ratio);
  25.         };
  26.  
  27.         var createmap = function () {
  28.  
  29.             var eleid = $(element).attr('id');
  30.             var mapOptions = {
  31.                 zoom: parseInt(options.zoom, 10),
  32.                 center: new google.maps.LatLng(parseFloat(options.lat), parseFloat(options.lng)),
  33.                 mapTypeId: google.maps.MapTypeId.ROADMAP,
  34.                 zoomControl: true,
  35.                 scaleControl: false,
  36.                 panControl: false,
  37.                 scrollwheel: false
  38.             };
  39.             var map = new google.maps.Map(document.getElementById(eleid), mapOptions);
  40.             var marker = new google.maps.Marker({
  41.                 position: new google.maps.LatLng(parseFloat(options.lat), parseFloat(options.lng)),
  42.                 map: map,
  43.                 zIndex: 10,
  44.                 title: options.title
  45.             });
  46.  
  47.  
  48.             if (options.showpopup === true) {
  49.  
  50.                 var contentString = '<div id="mapcontent">' +
  51.                     '<h3>' + options.title + '</h3>' +
  52.                     '<div id="bodyContent">' +
  53.                     content +
  54.                     '</div>' +
  55.                     '</div>';
  56.  
  57.                 var infowindow = new google.maps.InfoWindow({
  58.                     content: contentString,
  59.                     maxWidth: 300
  60.                 });
  61.  
  62.                 google.maps.event.addListener(marker, 'click', function () {
  63.                     infowindow.open(map, marker);
  64.                 });
  65.  
  66.                 window.setTimeout(function () {
  67.                     infowindow.open(map, marker);
  68.                 }, 5000);
  69.             }
  70.  
  71.         };
  72.  
  73.         $(window).bind('resize', mapresize);
  74.         mapresize();
  75.         google.maps.event.addDomListener(window, 'load', createmap);
  76.         createmap();
  77.     });
  78. };
  79.  
  80. /** jskill plugin **/
  81. $.fn.jskill = function () {
  82.     "use strict";
  83.     return $(this).each(function () {
  84.         var element = $(this);
  85.  
  86.         window.setTimeout(function () {
  87.             element.waypoint(function (direction) {
  88.                 var progressbar = $(this).find('.bar-bg');
  89.  
  90.                 element.addClass('show');
  91.  
  92.                 $(progressbar).each(function (i) {
  93.                     var ele = $(this);
  94.  
  95.                     window.setTimeout(function () {
  96.                         var width = $(ele).attr('data-width') + '%';
  97.                         $(ele).css('width', width);
  98.                     }, 250 * i);
  99.                 });
  100.             }, {
  101.                 offset: '80%',
  102.                 triggerOnce: true,
  103.                 context: window
  104.             });
  105.         }, 1000);
  106.     });
  107. };
  108.  
  109. /** Jeg OwlGallery plugin **/
  110. $.fn.jowlgallery = function (options) {
  111.     "use strict";
  112.     var setting = {
  113.         items : 7,
  114.         itemsDesktop      : [1000,6],
  115.         itemsDesktopSmall : [900,6],
  116.         itemsTablet       : [1024,6],
  117.         itemsMobile       : [320,4],
  118.         slideSpeed : 500,
  119.         autoPlay : true,
  120.         navigation : false,
  121.         thumbnail : '.gallery-slider-thumbnail',
  122.         theme     : 'owl-jowlgallery',
  123.         thumbnail_theme : 'owl-jowlgallerythumbnail',
  124.         zoom: true
  125.     };
  126.  
  127.     if (options) {
  128.         options = $.extend(setting, options);
  129.     } else {
  130.         options = $.extend(setting);
  131.     }
  132.  
  133.     var slider = this;
  134.     var thumbnail = $(options.thumbnail);
  135.  
  136.     function featuredSliderCenter(number){
  137.         var thumbVisible = thumbnail.data("owlCarousel").owl.visibleItems;
  138.         var num = number;
  139.         var found = false;
  140.         for(var i in thumbVisible){
  141.             if(num === thumbVisible[i]){
  142.                 found = true;
  143.             }
  144.         }
  145.  
  146.         if(found===false){
  147.             if(num>thumbVisible[thumbVisible.length-1]){
  148.                 thumbnail.trigger("owl.goTo", num - thumbVisible.length+2);
  149.             }else{
  150.                 if(num - 1 === -1){
  151.                     num = 0;
  152.                 }
  153.                 thumbnail.trigger("owl.goTo", num);
  154.             }
  155.         } else if(num === thumbVisible[thumbVisible.length-1]){
  156.             thumbnail.trigger("owl.goTo", thumbVisible[1]);
  157.         } else if(num === thumbVisible[0]){
  158.             thumbnail.trigger("owl.goTo", num-1);
  159.         }
  160.     }
  161.  
  162.     function featuredSliderCenterSync(el){
  163.         var current = this.currentItem;
  164.         thumbnail
  165.           .find(".owl-item")
  166.           .removeClass("active")
  167.           .eq(current)
  168.           .addClass("active");
  169.         if(thumbnail.data("owlCarousel") !== undefined){
  170.           featuredSliderCenter(current);
  171.         }
  172.     }
  173.  
  174.     if (slider.length >= 1) {
  175.         slider.owlCarousel({
  176.             slideSpeed : options.slideSpeed,
  177.             paginationSpeed : 400,
  178.             addClassActive : true,
  179.             navigation : options.navigation,
  180.             navigationText : false,
  181.             pagination : false,
  182.             singleItem:true,
  183.             autoPlay: options.autoPlay,
  184.             afterAction : featuredSliderCenterSync,
  185.             responsiveRefreshRate : 200,
  186.             theme : options.theme,
  187.             lazyLoad: true,
  188.             mouseScroll : false
  189.         });
  190.  
  191.         thumbnail.owlCarousel({
  192.             items : options.items,
  193.             itemsDesktop      : options.itemsDesktop,
  194.             itemsDesktopSmall : options.itemsDesktopSmall,
  195.             itemsTablet       : options.itemsTablet,
  196.             itemsMobile       : options.itemsMobile,
  197.             pagination        : false,
  198.             responsiveRefreshRate : 100,
  199.             theme : options.thumbnail_theme,
  200.             lazyLoad: true,
  201.             afterInit : function(el){
  202.               el.find(".owl-item").eq(0).addClass("active");
  203.             }
  204.         });
  205.  
  206.         if (options.mouseScroll) {
  207.             thumbnail.on('mousewheel', '.owl-wrapper', function (e) {
  208.                 if (e.deltaY > 0) {
  209.                     thumbnail.trigger('owl.next');
  210.                 } else {
  211.                     thumbnail.trigger('owl.prev');
  212.                 }
  213.                 e.preventDefault();
  214.             });
  215.         }
  216.  
  217.         $('.owl-wrapper', slider).each(function() {
  218.             if(options.zoom) {
  219.                 $.magnificPopup.instance.next = function() {
  220.                     $(this.st.galleryslider).trigger('owl.next');
  221.                     $.magnificPopup.proto.next.call(this);
  222.                 };
  223.  
  224.                 $.magnificPopup.instance.prev = function() {
  225.                     $(this.st.galleryslider).trigger('owl.prev');
  226.                     $.magnificPopup.proto.prev.call(this);
  227.                 };
  228.  
  229.                 $(this).magnificPopup({
  230.                     delegate: 'a',
  231.                     type: 'image',
  232.                     zoom: {
  233.                         enabled:true
  234.                     },
  235.                     gallery: {
  236.                         enabled:true
  237.                     },
  238.                     image: {
  239.                         titleSrc: function(item) {
  240.                             var slideCaption = $(item.el).next().text();
  241.                             return slideCaption;
  242.                         },
  243.                         verticalFit: true
  244.                     },
  245.                     galleryslider: slider
  246.                 });
  247.             }
  248.         });
  249.  
  250.         thumbnail.on("click", ".owl-item", function(e){
  251.             e.preventDefault();
  252.             var number = $(this).data("owlItem");
  253.             slider.trigger("owl.goTo",number);
  254.         });
  255.     }
  256. };
  257.  
  258. function image_zoom() {
  259.     if(jmagzoption.usezoom) {
  260.  
  261.         $(".article-content a > img[class*=' wp-image-']").each(function(){
  262.             var element = $(this).parent();
  263.             $(element).magnificPopup({
  264.                 type:'image',
  265.                 zoom: {
  266.                     enabled:true
  267.                 },
  268.                 image: {
  269.                     titleSrc: function(item) {
  270.                         return $(item.el).find('img').attr('alt');
  271.                     },
  272.                     verticalFit: true
  273.                 }
  274.             });
  275.         });
  276.  
  277.         $(".gallery").magnificPopup({
  278.             delegate: 'a',
  279.             type: 'image',
  280.             zoom: {
  281.                 enabled:true
  282.             },
  283.             gallery: {
  284.                 enabled:true
  285.             },
  286.             image: {
  287.                 titleSrc: function(item) {
  288.                     return $(item.el).find('img').attr('alt');
  289.                 },
  290.                 verticalFit: true
  291.             }
  292.         });
  293.     }
  294. }
  295.  
  296. /***************************
  297.  * Carousel Post & Gallery
  298.  **************************/
  299.  
  300. function breaking_news_carousel () {
  301.     "use strict";
  302.     // Breaking News: Carousel
  303.     $(".breakingnews-carousel").owlCarousel({
  304.         itemsCustom : [
  305.             [0, 1],
  306.             [768, 2],
  307.             [1024, 3],
  308.             [1400, 4],
  309.             [1600, 5]
  310.         ],
  311.         slideSpeed: 200,
  312.         navigation : true,
  313.         pagination : false,
  314.         navigationText : false,
  315.         autoPlay: true,
  316.         lazyLoad: true,
  317.         theme : 'owl-breakingnews'
  318.     });
  319.  
  320.     // Breaking News: Marquee
  321.     $('.breakingnews-marquee ul').marquee({
  322.         duration: 10000,
  323.         pauseOnHover: true
  324.     });
  325. }
  326.  
  327. function carousel_element() {
  328.     "use strict";
  329.     // Carousel Post
  330.  
  331.     $(".carousel-post").each(function(){
  332.         var number = $(this).data('width');
  333.         $(this).owlCarousel({
  334.             itemsCustom : [
  335.                 [0, 1],
  336.                 [768, 2],
  337.                 [1024, 3],
  338.                 [1400, number],
  339.                 [1600, number]
  340.             ],
  341.             navigation : true,
  342.             pagination : false,
  343.             navigationText : false,
  344.             autoPlay: true,
  345.             lazyLoad: true,
  346.             autoHeight : true,
  347.             theme : 'owl-carouselpost'
  348.         });
  349.     });
  350.  
  351.     // Carousel Postbox
  352.     $(".postbox").owlCarousel({
  353.         itemsCustom : [
  354.             [0, 1],
  355.             [768, 2],
  356.             [1024, 3],
  357.             [1400, 3],
  358.             [1600, 3]
  359.         ],
  360.         navigation : true,
  361.         pagination : false,
  362.         navigationText : false,
  363.         autoPlay: true,
  364.         lazyLoad: true,
  365.         autoHeight : true,
  366.         theme : 'owl-carouselpost'
  367.     });
  368.  
  369.     // Single Post Featured Gallery
  370.     $(".featured-gallery").jowlgallery({
  371.         navigation : true,
  372.         navigationText : false,
  373.         slideSpeed : 300,
  374.         paginationSpeed : 400,
  375.         singleItem:true,
  376.         autoPlay: false,
  377.         theme : 'owl-carouselpost',
  378.         zoom: true
  379.     });
  380.  
  381.     // gallery slider
  382.     $('.gallery-slider').jowlgallery({
  383.         thumbnail: '.gallery-slider-thumbnail',
  384.         navigation: true,
  385.         autoPlay: false,
  386.         mouseScroll: false,
  387.         zoom: true
  388.     });
  389. }
  390.  
  391. /***************************
  392.  * Reviews Search Toggle
  393.  **************************/
  394. function review_search() {
  395.     "use strict";
  396.     $(".search-bar-wrapper .searchkeyword").bind('click', function(){
  397.         $(".filter-toggle i").removeClass('fa-th-large').addClass('fa-close');
  398.         $('.search-filter-wrapper').slideDown();
  399.     });
  400.     $(".filter-toggle i").bind('click', function(){
  401.         var element = this;
  402.         if($(this).hasClass('fa-th-large')) {
  403.             $(".filter-toggle i").removeClass('fa-th-large').addClass('fa-close');
  404.             $('.search-filter-wrapper').slideDown();
  405.         } else {
  406.             $(".filter-toggle i").removeClass('fa-close').addClass('fa-th-large');
  407.             $('.search-filter-wrapper').slideUp();
  408.         }
  409.     });
  410. }
  411.  
  412. /***************************
  413.  * menu category hover
  414.  **************************/
  415. var category_xhr = null;
  416. function menu_category_hover_exe(element, loadanimation) {
  417.     "use strict";
  418.     var container = $(element).parents('.newsfeed');
  419.     var postcontainer = $(container).find('.newsfeed-posts');
  420.     var overlay = $(container).find(".newsfeed-overlay");
  421.     var categoryid = $(element).data('menu-category-id');
  422.  
  423.     var currentcontainer = $(postcontainer).find(".newsfeed-container[data-content-category-id='" + categoryid + "']");
  424.  
  425.     $(container).find('.newsfeed-categories li').removeClass('active');
  426.     $(element).addClass('active');
  427.  
  428.     if($(currentcontainer).length < 1) {
  429.         // ajax request
  430.         var action = 'get_mega_category_item';
  431.         if($(element).hasClass('review-menu')) {
  432.             action = 'get_mega_review_item';
  433.         }
  434.  
  435.         $(overlay).stop().fadeIn("fast");
  436.  
  437.         if(category_xhr !== null) {
  438.             category_xhr.abort();
  439.         }
  440.         category_xhr = $.ajax({
  441.             url: jmagzoption.ajaxurl,
  442.             type: "post",
  443.             dataType: "html",
  444.             data: {
  445.                 'categoryid' : categoryid,
  446.                 'action' : action
  447.             },
  448.             success: function (data) {
  449.                 $(postcontainer).css('height',$(postcontainer).height())
  450.                     .find('.newsfeed-container')
  451.                     .hide();
  452.                 $(postcontainer).append(data);
  453.  
  454.                 currentcontainer = $(postcontainer).find(".newsfeed-container[data-content-category-id='" + categoryid + "']");
  455.                 menu_category_carousel(currentcontainer);
  456.                 $(overlay).stop().fadeOut(function(){
  457.                     $(postcontainer).css('height','');
  458.                 });
  459.  
  460.             }
  461.         });
  462.     } else {
  463.         if(loadanimation) {
  464.             // load available content
  465.             $(postcontainer).css('height',$(postcontainer).height())
  466.                 .find('.newsfeed-container')
  467.                 .hide();
  468.  
  469.             $(overlay).stop().fadeOut(function(){
  470.                 $(currentcontainer).fadeIn();
  471.                 $(postcontainer).css('height','');
  472.             });
  473.         }
  474.     }
  475.  
  476. }
  477.  
  478. function menu_category() {
  479.     "use strict";
  480.     // first menu
  481.     menu_category_carousel($(".newsfeed-container"));
  482.  
  483.     // menu category
  484.     $(".newsfeed-categories li").bind('mouseenter', function(){
  485.         menu_category_hover_exe(this, true);
  486.     });
  487. }
  488.  
  489. function menu_category_carousel(element){
  490.     "use strict";
  491.     $(element).owlCarousel({
  492.         navigation : false,
  493.         pagination : true,
  494.         navigationText : false,
  495.         lazyLoad : true
  496.     });
  497. }
  498.  
  499. /** handle navigation scroll bar **/
  500. function navigation_scrollbar ()
  501. {
  502.     "use strict";
  503.     var $sidebarwrapper = $(".sidebar-posts");
  504.     if ($sidebarwrapper.length) {
  505.         $sidebarwrapper.jScrollPane({
  506.             mouseWheelSpeed: 50,
  507.             contentWidth: '0px'
  508.         });
  509.         var navscrolpane = $sidebarwrapper.data('jsp');
  510.  
  511.         var calculate_sidebar_size = function () {
  512.             $sidebarwrapper.css('height', $(window).height() - $('.sidebar-footer').height());
  513.             navscrolpane.reinitialise();
  514.         };
  515.  
  516.         $(window).bind('resize load', calculate_sidebar_size);
  517.         $(".sidebar-post-wrapper").mutate('height', calculate_sidebar_size);
  518.     }
  519. }
  520.  
  521.  
  522. /** related post popup **/
  523. function popup_post() {
  524.     "use strict";
  525.     var popupflag = $('#end-content');
  526.     var popup = $('.popup-post');
  527.  
  528.     popupflag.waypoint(function (direction) {
  529.         if(direction == 'up'){
  530.             popup.removeClass('active');
  531.         } else {
  532.             popup.addClass('active');
  533.         }
  534.     }, {
  535.         offset: '100%',
  536.         context: window
  537.     });
  538.  
  539.     $('.popup-close').click(function(e) {
  540.         e.preventDefault();
  541.         popup.removeClass('active');
  542.     });
  543. }
  544.  
  545. /** sticky sidebar **/
  546. function sticky_sidebar() {
  547.     "use strict";
  548.     if ($('#sidebar').length > 0) {
  549.         var sidebar_top = $('#sidebar').offset().top;
  550.         var do_sticky_sidebar = function(){
  551.             if($(window).width() > 1200) {
  552.                 var toppos = $(window).scrollTop();
  553.                 $('#sidebar')[toppos > sidebar_top ? 'addClass' : 'removeClass']('fixed');
  554.             }
  555.         };
  556.  
  557.         if($(window).width() > 1200) {
  558.             do_sticky_sidebar();
  559.             $(window).bind('scroll', do_sticky_sidebar);
  560.         } else {
  561.             $('#sidebar').removeClass('fixed');
  562.             $(window).unbind('scroll', do_sticky_sidebar);
  563.         }
  564.     }
  565. }
  566.  
  567. /** sticky share bar **/
  568. function sticky_share()
  569. {
  570.     "use strict";
  571.     var sharerbar = $('.article-sharer');
  572.     var dummyblock = $('.dummy-share-block');
  573.     var sharetop = 0;
  574.  
  575.     var sticky_share_bar = function()
  576.     {
  577.         var toppos = $(window).scrollTop();
  578.  
  579.         if (toppos > sharetop) {
  580.             if ($('.article-sharer-placeholder').length > 0) $('<div class="article-sharer-placeholder"></div>').insertBefore(sharerbar);
  581.             sharerbar.addClass('fixed');
  582.             dummyblock.addClass('fixed');
  583.         } else {
  584.             $('.article-sharer-placeholder').remove();
  585.             sharerbar.removeClass('fixed');
  586.             dummyblock.removeClass('fixed');
  587.         }
  588.     };
  589.  
  590.     var setup_sticky_variable = function()
  591.     {
  592.         if($(window).width() > 1024 && $(sharerbar).length) {
  593.  
  594.             /* normalize sticky variable **/
  595.             $('.article-sharer-placeholder').remove();
  596.             sharerbar.removeClass('fixed');
  597.             sharetop = Math.floor(sharerbar.offset().top);
  598.             sticky_share_bar();
  599.  
  600.             $(window)
  601.                 .unbind('scroll', sticky_share_bar)
  602.                 .bind('scroll', sticky_share_bar);
  603.         } else {
  604.             $(window).unbind('scroll', sticky_share_bar);
  605.         }
  606.     };
  607.  
  608.     setup_sticky_variable();
  609.     $(window).bind('resize', setup_sticky_variable);
  610.     $('#content').mutate('height', setup_sticky_variable);
  611. }
  612.  
  613. /** top search **/
  614.  
  615. function search_toggle(){
  616.     "use strict";
  617.  
  618.     var search_xhr = null;
  619.     var searchtimeout = null;
  620.  
  621.     var searchresult = $(".top-search .search-result");
  622.     var searchwrapper = $(".top-search .search-result-wrapper");
  623.     var searchnoresult = $(".top-search .search-noresult");
  624.     var searchbutton = $(".top-search .search-all-button");
  625.  
  626.     var loadingclass = $(".top-search button i").data('loading');
  627.     var normalclass = $(".top-search button i").data('normal');
  628.     var topsearchbutton = $(".top-search button i");
  629.  
  630.     function no_data() {
  631.         searchnoresult.show();
  632.         searchwrapper.hide();
  633.         searchbutton.hide();
  634.     }
  635.  
  636.     function data_exist() {
  637.         searchnoresult.hide();
  638.         searchwrapper.show();
  639.         searchbutton.show();
  640.     }
  641.  
  642.     function do_live_search(word) {
  643.         clearTimeout(searchtimeout);
  644.         searchtimeout = setTimeout(function(){
  645.             if(search_xhr !== null) {
  646.                 search_xhr.abort();
  647.             }
  648.  
  649.             topsearchbutton.attr('class', loadingclass);
  650.             search_xhr = $.ajax({
  651.                 url: jmagzoption.ajaxurl,
  652.                 type: "post",
  653.                 dataType: "html",
  654.                 data: {
  655.                     's' : word,
  656.                     'action' : 'get_ajax_live_search'
  657.                 },
  658.                 success: function (data) {
  659.  
  660.                     topsearchbutton.attr('class', normalclass);
  661.                     if(data === ''){
  662.                         no_data();
  663.                     } else {
  664.                         searchwrapper.html('').append(data);
  665.                         data_exist();
  666.                     }
  667.                     $(searchresult).show();
  668.                 }
  669.             });
  670.         }, 200);
  671.     }
  672.  
  673.     var cacheword = '';
  674.     $(".top-search [name='s']").bind('keyup', function(){
  675.         var searchword = $(this).val();
  676.         if(searchword.trim().length >= 3 && searchword !== cacheword) {
  677.             do_live_search(searchword);
  678.             cacheword = searchword;
  679.         } else if(searchword.trim().length < 3) {
  680.             searchresult.hide();
  681.         }
  682.     });
  683.  
  684.     $(searchbutton).bind('click',function(){
  685.         $(".top-search form").submit();
  686.     });
  687.  
  688.     $('.top-search-toggle').click(function(){
  689.         $('.top-search-toggle, .top-socials, .right-menu').hide();
  690.         $('.top-search .search-form').fadeIn();
  691.         $('.top-search').removeClass('no-active').addClass('active');
  692.  
  693.         return false;
  694.     });
  695.  
  696.     $(document).mouseup(function(e) {
  697.         if (!$(e.target).parents('.top-search .search-form').length > 0) {
  698.             $('.top-search .search-form').hide();
  699.             $('.top-search-toggle, .top-socials, .right-menu').fadeIn();
  700.             $('.top-search').removeClass('active').addClass('no-active');
  701.         }
  702.     });
  703. }
  704.  
  705. /** mobile menu **/
  706. function mobile_menu() {
  707.     "use strict";
  708.     /** menu open **/
  709.     $('.sidebar-toggle').click(function () {
  710.         $('body').toggleClass('menu-active push-content-right');
  711.     });
  712.     $('.menu-toggle').click(function () {
  713.         console.log('menu show');
  714.         $('#mobile-menu').toggleClass('active');
  715.         $('body').toggleClass('menu-active push-content-left');
  716.     });
  717.  
  718.     /** menu close **/
  719.  
  720.     function mobile_sidebar_close(e) {
  721.         // Mobile Sidebar Close
  722.         if ($('body').hasClass('push-content-right') && !$(e.target).parents('#sidebar').length > 0) {
  723.             $('body').removeClass('menu-active push-content-right');
  724.         }
  725.         // Mobile Menu Close
  726.         if ($('#mobile-menu').hasClass('active') && !$(e.target).parents('#mobile-menu').length > 0) {
  727.             $('#mobile-menu').removeClass('active');
  728.             $('body').removeClass('menu-active push-content-left');
  729.         }
  730.     }
  731.  
  732.     $(document).mouseup(function (e) {
  733.         mobile_sidebar_close(e);
  734.     });
  735.     $('body').bind("touchend", function (e) {
  736.         mobile_sidebar_close(e);
  737.     });
  738. }
  739.  
  740. /** navigation menu **/
  741. function navigation_menu () {
  742.     "use strict";
  743.     var loadnewsfeed = function() {
  744.         var parent = $(this).parent();
  745.         if($(parent).hasClass('mega-menu')) {
  746.             var currentactive = $(".newsfeed-categories > li.active", this);
  747.             menu_category_hover_exe(currentactive, false);
  748.         }
  749.     };
  750.  
  751.     $('header ul.menu').superfish({
  752.         popUpSelector: 'ul,.sub-menu',
  753.         animation: {height:'show', opacity:'show'},
  754.         onShow: loadnewsfeed
  755.     });
  756. }
  757.  
  758. /** Multimedia Embed **/
  759. $.youtube_parser = function (url) {
  760.     var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  761.     var match = url.match(regExp);
  762.  
  763.     if (match && match[7].length === 11) {
  764.         return match[7];
  765.     }
  766.     /*jshint latedef: true */
  767.     window.alert("Url Incorrect");
  768. };
  769.  
  770. $.vimeo_parser = function (url) {
  771.     "use strict";
  772.     var regExp = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
  773.     var match = url.match(regExp);
  774.  
  775.     if (match) {
  776.         return match[2];
  777.     }
  778.  
  779.     // check if using https
  780.     regExp = /https:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
  781.     match = url.match(regExp);
  782.  
  783.     if (match) {
  784.         return match[2];
  785.     }
  786.  
  787.     /*jshint latedef: true */
  788.     window.alert("not a vimeo url");
  789. };
  790.  
  791. $.type_video_youtube = function (ele, autoplay, repeat) {
  792.     "use strict";
  793.     var youtube_id = $.youtube_parser($(ele).attr('data-src'));
  794.     var additionalstring = '';
  795.     var iframe = '';
  796.     if(repeat) {
  797.         additionalstring += ( autoplay === true ) ? "autoplay=1&" : "";
  798.         additionalstring += (repeat === true ) ? "loop=1&playlist=" + youtube_id : "";
  799.         iframe = '<iframe width="700" height="500" src="https://www.youtube.com/v/' + youtube_id + '?version=3&' + additionalstring + 'showinfo=1&autohide=1&rel=0&wmode=opaque" frameborder="0" allowfullscreen></iframe>';
  800.     } else {
  801.         additionalstring += ( autoplay === true ) ? "autoplay=1&" : "";
  802.         iframe = '<iframe width="700" height="500" src="https://www.youtube.com/embed/' + youtube_id + '?' + additionalstring + 'showinfo=1&autohide=1&rel=0&wmode=opaque" frameborder="0" allowfullscreen></iframe>';
  803.     }
  804.     $('.video-container', ele).append(iframe);
  805. };
  806.  
  807. $.type_video_vimeo = function (ele, autoplay, repeat) {
  808.     "use strict";
  809.     var vimeo_id = $.vimeo_parser($(ele).attr('data-src'));
  810.     var additionalstring = '';
  811.     additionalstring += ( autoplay === true ) ? "autoplay=1&" : "";
  812.     additionalstring += (repeat === true ) ? "loop=1&" : "";
  813.     var iframe = '<iframe src="https://player.vimeo.com/video/' + vimeo_id + '?' + additionalstring + 'title=0&byline=0&portrait=0" width="700" height="500" webkitallowfullscreen mozallowfullscreen frameborder="0"></iframe>';
  814.     $('.video-container', ele).append(iframe);
  815. };
  816.  
  817. $.type_soundcloud = function (ele) {
  818.     "use strict";
  819.     var soundcloudurl = $(ele).attr('data-src');
  820.     var iframe = '<iframe src="https://w.soundcloud.com/player/?url=' + encodeURIComponent(soundcloudurl) + '" width="700" height="500" frameborder="0"></iframe>';
  821.     $('.video-container', ele).append(iframe);
  822. };
  823.  
  824. $.type_audio = function(ele){
  825.     "use strict";
  826.     var musicmp3 = '';
  827.     var musicogg = '';
  828.  
  829.     if ($(ele).data('mp3') !== '') {
  830.         musicmp3 = "<source type='audio/mpeg' src='" + $(ele).data('mp3') + "' />";
  831.     }
  832.  
  833.     if ($(ele).data('ogg') !== '') {
  834.         musicogg = "<source type='audio/ogg' src='" + $(ele).data('ogg') + "' />";
  835.     }
  836.  
  837.     var audio =
  838.         "<audio preload='none' style='width: 100%; visibility: hidden;' controls='controls'>" +
  839.         musicmp3 + musicogg +
  840.         "</audio>";
  841.  
  842.     $(ele).append(audio);
  843.  
  844.  
  845.     var settings = {};
  846.  
  847.     if ( typeof _wpmejsSettings !== 'undefined' ) {
  848.         settings = _wpmejsSettings;
  849.     }
  850.  
  851.     settings.success = function (mejs) {
  852.         var autoplay, loop;
  853.  
  854.         if ( 'flash' === mejs.pluginType ) {
  855.             autoplay = mejs.attributes.autoplay && 'false' !== mejs.attributes.autoplay;
  856.             loop = mejs.attributes.loop && 'false' !== mejs.attributes.loop;
  857.  
  858.             autoplay && mejs.addEventListener( 'canplay', function () {
  859.                 mejs.play();
  860.             }, false );
  861.  
  862.             loop && mejs.addEventListener( 'ended', function () {
  863.                 mejs.play();
  864.             }, false );
  865.         }
  866.     };
  867.  
  868.     $(ele).find('audio').mediaelementplayer( settings );
  869. };
  870.  
  871. $.type_video_html5 = function (ele, autoplay, options, container) {
  872.     "use strict";
  873.     var cover = $(ele).data('cover');
  874.  
  875.     options.pauseOtherPlayers = false;
  876.  
  877.     var videomp4 = '';
  878.     var videowebm = '';
  879.     var videoogg = '';
  880.  
  881.     var themesurl = '';
  882.  
  883.     if ($(ele).data('mp4') !== '') {
  884.         videomp4 = "<source type='video/mp4' src='" + $(ele).data('mp4') + "' />";
  885.     }
  886.  
  887.     if ($(ele).data('webm') !== '') {
  888.         videowebm = "<source type='video/webm' src='" + $(ele).data('webm') + "' />";
  889.     }
  890.  
  891.     if ($(ele).data('ogg') !== '') {
  892.         videoogg = "<source type='video/ogg' src='" + $(ele).data('ogg') + "' />";
  893.     }
  894.  
  895.     var preload = autoplay ? "preload='auto'" : "preload='none'";
  896.     var object = "<object width='100%' height='100%' type='application/x-shockwave-flash' data='" + themesurl + "/public/mediaelementjs/flashmediaelement.swf'>" +
  897.         "<param name='movie' value='" + themesurl + "/public/mediaelementjs/flashmediaelement.swf' />" +
  898.         "<param name='flashvars' value='controls=true&file=" + $(ele).data('mp4') + "' />" +
  899.         "<img src='" + cover + "' alt='No video playback capabilities' title='No video playback capabilities' />" +
  900.         "</object>";
  901.     var iframe = "<video id='player' style='width:100%;height:100%;' width='100%' height='100%' poster='" + cover + "' controls='controls' " + preload + ">" +
  902.         videomp4 + videowebm + videoogg + object +
  903.         "</video>";
  904.  
  905.     $(container, ele).append(iframe);
  906.     if (autoplay) {
  907.         options.success = function (mediaElement) {
  908.             if (mediaElement.pluginType === 'flash') {
  909.                 mediaElement.addEventListener('canplay', function () {
  910.                     mediaElement.play();
  911.                 }, false);
  912.             } else {
  913.                 mediaElement.play();
  914.             }
  915.         };
  916.     }
  917.  
  918.     $(ele).find('video').mediaelementplayer(options);
  919. };
  920.  
  921. function do_media_render(){
  922.     "use strict";
  923.     // youtube
  924.     if ($("[data-type='youtube']").length) {
  925.         $("[data-type='youtube']").each(function () {
  926.             var autoplay = $(this).data('autoplay');
  927.             var repeat = $(this).data('repeat');
  928.             $.type_video_youtube($(this), autoplay, repeat);
  929.         });
  930.     }
  931.  
  932.     // vimeo
  933.     if ($("[data-type='vimeo']").length) {
  934.         $("[data-type='vimeo']").each(function () {
  935.             var autoplay = $(this).data('autoplay');
  936.             var repeat = $(this).data('repeat');
  937.             $.type_video_vimeo($(this), autoplay, repeat);
  938.         });
  939.     }
  940.  
  941.     // sound cloud
  942.     if ($("[data-type='soundcloud']").length) {
  943.         $("[data-type='soundcloud']").each(function () {
  944.             $.type_soundcloud($(this));
  945.         });
  946.     }
  947.  
  948.     // audio
  949.     if ($("[data-type='audio']").length) {
  950.         $("[data-type='audio']").each(function () {
  951.             $.type_audio($(this));
  952.         });
  953.     }
  954.  
  955.     // html 5 video
  956.     if($("video").length) {
  957.         $('video').mediaelementplayer();
  958.     }
  959. }
  960.  
  961. function pin_it_image() {
  962.     "use strict";
  963.     $("img").attr("data-pin-no-hover", true);
  964.     $(".article-content img, .featured img").removeAttr("data-pin-no-hover");
  965. }
  966.  
  967. function sidebar_loading() {
  968.     "use strict";
  969.     var buttonloadmore = $(".sidebar-loadmore");
  970.     var currentcontainer = $(".sidebar-post-wrapper");
  971.  
  972.     var btnstrong = $(buttonloadmore).find('strong');
  973.     var btni = $(buttonloadmore).find('i');
  974.     var loadmoredata = null;
  975.  
  976.     var loadmoretext = $(buttonloadmore).data('loadmore');
  977.     var loadingtext = $(buttonloadmore).data('loading');
  978.     var btnendtext = $(buttonloadmore).data('end');
  979.  
  980.     $(buttonloadmore).bind('click', function(e){
  981.         e.preventDefault();
  982.  
  983.         if(!$(buttonloadmore).hasClass('active')) {
  984.  
  985.             // lock
  986.             $(buttonloadmore).addClass('active');
  987.             $(btnstrong).text(loadingtext);
  988.             $(btni).addClass('fa-spin');
  989.  
  990.             if($(buttonloadmore).hasClass('sidebar-loadmore-review')) {
  991.                 loadmoredata = {
  992.                     'page' : $(buttonloadmore).data('page') + 1,
  993.                     'action' : 'get_sidebar_review',
  994.                     'isblog' : jmagzoption.isblog,
  995.                     'postid' : jmagzoption.postid
  996.                 };
  997.             } else {
  998.                 loadmoredata = {
  999.                     'page' : $(buttonloadmore).data('page') + 1,
  1000.                     'action' : 'get_sidebar_feed',
  1001.                     'isblog' : jmagzoption.isblog,
  1002.                     'postid' : jmagzoption.postid
  1003.                 };
  1004.             }
  1005.  
  1006.             $.ajax({
  1007.                 url: jmagzoption.ajaxurl,
  1008.                 type: "post",
  1009.                 dataType: "html",
  1010.                 data: loadmoredata,
  1011.                 success: function (data) {
  1012.                     if(data !== '') {
  1013.                         $(currentcontainer).append(data);
  1014.  
  1015.                         // unlock
  1016.                         $(btnstrong).text(loadmoretext);
  1017.                         $(btni).removeClass('fa-spin');
  1018.                         $(buttonloadmore).removeClass('active');
  1019.  
  1020.                         $(buttonloadmore).data('page', $(buttonloadmore).data('page') + 1);
  1021.                     } else {
  1022.                         $(btni).remove();
  1023.                         $(btnstrong).text(btnendtext);
  1024.                     }
  1025.  
  1026.                     $("#sidebar img.unveil").unveil(0, function() {
  1027.                         $(this).load(function() {
  1028.                             this.style.opacity = 1;
  1029.                         });
  1030.                     });
  1031.                 }
  1032.             });
  1033.         }
  1034.     });
  1035. }
  1036.  
  1037. function copy_clipboard() {
  1038.     "use strict";
  1039.     var client = new ZeroClipboard( document.getElementById("shorturl") );
  1040.  
  1041.     client.on( "ready", function( readyEvent ) {
  1042.         client.on( "aftercopy", function( event ) {
  1043.             alert(jmagzoption.copyclipboard);
  1044.         } );
  1045.     } );
  1046. }
  1047.  
  1048. function open_share() {
  1049.     "use strict";
  1050.     $(".socials-share > a").each(function(){
  1051.         $(this).bind('click', function(e){
  1052.             e.preventDefault();
  1053.             var url = $(this).attr('href');
  1054.             var social = $(this).data('shareto');
  1055.             window.open(url, jmagzoption.shareto , "height=300,width=600");
  1056.         });
  1057.     });
  1058. }
  1059.  
  1060. function home_slider() {
  1061.     "use strict";
  1062.     /** Home Slider **/
  1063.     $('.featured-slider').jowlgallery({
  1064.         items: 5,
  1065.         thumbnail: '.featured-slider-thumbnail',
  1066.         theme: 'owl-featuredslider',
  1067.         thumbnail_theme: 'owl-featuredthumbnail',
  1068.         zoom: false
  1069.     });
  1070.  
  1071.     $('.featured-slider-2').jowlgallery({
  1072.         items: 4,
  1073.         itemsDesktop      : [1000,4],
  1074.         itemsDesktopSmall : [900,3],
  1075.         itemsTablet       : [1024,3],
  1076.         itemsMobile       : [320,2],
  1077.         thumbnail: '.featured-slider-2-thumbnail',
  1078.         theme: 'owl-featuredslider',
  1079.         thumbnail_theme: 'owl-featuredthumbnail',
  1080.         lazyLoad: true,
  1081.         zoom: false
  1082.     });
  1083. }
  1084.  
  1085. function post_tooltip() {
  1086.     "use strict";
  1087.     if ($("[data-toggle='tooltip']").length) {
  1088.         $("[data-toggle='tooltip']").tooltip();
  1089.     }
  1090. }
  1091.  
  1092. function map_shortcode() {
  1093.     "use strict";
  1094.     /** map shortcode **/
  1095.     if ($(".jrmap").length) {
  1096.         do_load_googlemap('mapshortcode');
  1097.     }
  1098. }
  1099.  
  1100. function close_alert() {
  1101.     "use strict";
  1102.     $(".alert .close").bind('click', function(){
  1103.         var parent = $(this).parents('.alert');
  1104.         $(parent).fadeOut(500,function(){
  1105.             $(this).remove();
  1106.         });
  1107.     });
  1108. }
  1109.  
  1110. var blog_facebook_widget = function(){
  1111.     "use strict";
  1112.     try {
  1113.         FB.XFBML.parse();
  1114.     } catch (ex) { }
  1115. };
  1116.  
  1117. var tweetticker = function () {
  1118.     "use strict";
  1119.     $('.jeg-tweets').each(function () {
  1120.         var element = $(this),
  1121.             $tweet = null,
  1122.             $next = null;
  1123.         $(element).height($(element).find('li:first').outerHeight());
  1124.  
  1125.         window.setInterval(function () {
  1126.             $tweet = $(element).find('li:first');
  1127.             $next = $tweet.next();
  1128.  
  1129.             $(element).animate({height: ($next.outerHeight()) + 'px'}, 800);
  1130.             $tweet.animate({marginTop: '-' + $tweet.outerHeight() + 'px'}, 400, function () {
  1131.                 $(this).detach().appendTo($(element).find('ul')).removeAttr('style');
  1132.             });
  1133.         }, 4000);
  1134.     });
  1135. };
  1136.  
  1137.  
  1138. function load_comment_script() {
  1139.     "use strict";
  1140.     if(jmagzoption.commentscript == 'facebook') {
  1141.         var appid = jmagzoption.fbapps ? "&appId=" + jmagzoption.fbapps : "";
  1142.         (function(d, s, id) {
  1143.             var js, fjs = d.getElementsByTagName(s)[0];
  1144.             if (d.getElementById(id)) return;
  1145.             js = d.createElement(s); js.id = id;
  1146.             js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0" + appid;
  1147.             fjs.parentNode.insertBefore(js, fjs);
  1148.         }(document, 'script', 'facebook-jssdk'));
  1149.     } else if(jmagzoption.commentscript == 'disqus') {
  1150.         (function() {
  1151.             var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
  1152.             dsq.src = '//' + jmagzoption.disqus_shortname + '.disqus.com/embed.js';
  1153.             (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  1154.         })();
  1155.     }
  1156. }
  1157.  
  1158. function do_comment_script() {
  1159.     "use strict";
  1160.     if(jmagzoption.commentscript === 'facebook') {
  1161.         FB.XFBML.parse();
  1162.     } else if(jmagzoption.commentscript === 'disqus') {
  1163.         DISQUS.reset({
  1164.             reload: true
  1165.         });
  1166.     }
  1167. }
  1168.  
  1169. var do_add_to_cart = function() {
  1170.     $.ajax({
  1171.         url: jmagzoption.ajaxurl,
  1172.         type: "post",
  1173.         dataType: "html",
  1174.         data: {
  1175.             'action' : 'get_ajax_add_cart'
  1176.         },
  1177.         success: function (data) {
  1178.             $(".topcart").html('').append(data);
  1179.         }
  1180.     });
  1181. };
  1182.  
  1183. function bind_add_to_cart() {
  1184.     "use strict";
  1185.  
  1186.     $('body').bind('added_to_cart', do_add_to_cart);
  1187. }
  1188.  
  1189. function videolistloader(){
  1190.     $(".video-wrapper-list > a").bind('click', function(){
  1191.         var id = $(this).data('id');
  1192.         var action = 'get_video_single';
  1193.         var parent = $(this).parent();
  1194.         var grandparent = $(parent).parent();
  1195.         var element = this;
  1196.  
  1197.         $(parent).find('a').removeClass('active');
  1198.         $(element).addClass('active');
  1199.  
  1200.         $.ajax({
  1201.             url: jmagzoption.ajaxurl,
  1202.             type: "post",
  1203.             dataType: "html",
  1204.             data: {
  1205.                 'postid' : id,
  1206.                 'action' : action
  1207.             },
  1208.             success: function (data) {
  1209.                 $(grandparent).find('.video-wrapper-content').html('').append(data);
  1210.                 if($(data).data('type') === 'youtube') {
  1211.                     $.type_video_youtube($(grandparent).find('.video-wrapper-content > div'), true, false);
  1212.                 } else if($(data).data('type') === 'vimeo') {
  1213.                     $.type_video_vimeo($(grandparent).find('.video-wrapper-content > div'), true, false);
  1214.                 } else if($(data).prop('tagName') === 'VIDEO'){
  1215.                     $(grandparent).find('video').mediaelementplayer();
  1216.                 }
  1217.  
  1218.             }
  1219.         });
  1220.  
  1221.         return false;
  1222.     });
  1223. }
  1224.  
  1225. function image_unveil() {
  1226.     "use strict";
  1227.     $("img.unveil").unveil(0, function() {
  1228.         $(this).load(function() {
  1229.             this.style.opacity = 1;
  1230.         });
  1231.     });
  1232. }
  1233.  
  1234. var execute_once = true;
  1235.  
  1236. function jmagz_dispatch(){
  1237.     "use strict";
  1238.  
  1239.     if(execute_once) {
  1240.         /** sticky sidebar **/
  1241.         sticky_sidebar();
  1242.         $(window).bind('resize', sticky_sidebar);
  1243.  
  1244.         /** handle navigation scroll bar **/
  1245.         navigation_scrollbar();
  1246.  
  1247.         /** handle menu **/
  1248.         navigation_menu();
  1249.  
  1250.         /** Menu Category Hover **/
  1251.         menu_category();
  1252.  
  1253.         /** Home Slider **/
  1254.         home_slider();
  1255.  
  1256.         /** search toogle **/
  1257.         search_toggle();
  1258.  
  1259.         /** mobile menu **/
  1260.         mobile_menu();
  1261.  
  1262.         /** sidebar loading **/
  1263.         sidebar_loading();
  1264.  
  1265.         /** breaking news carousel **/
  1266.         breaking_news_carousel();
  1267.  
  1268.         /** load comment script **/
  1269.         load_comment_script();
  1270.  
  1271.         execute_once = false;
  1272.  
  1273.         /** bind add to cart **/
  1274.         bind_add_to_cart();
  1275.  
  1276.     } else {
  1277.  
  1278.         /** execute map shortcode **/
  1279.         mapshortcode();
  1280.  
  1281.         /** do comment script **/
  1282.         do_comment_script();
  1283.     }
  1284.  
  1285.     /** Carousel Post & Gallery **/
  1286.     carousel_element();
  1287.  
  1288.     /** review bar animation **/
  1289.     $('.review-bars').jskill();
  1290.  
  1291.     // Reviews Search
  1292.     review_search();
  1293.  
  1294.     // jQuery Select
  1295.     $("select:visible, .search-filter-wrapper select").chosen({
  1296.         disable_search_threshold: 10,
  1297.         allow_single_deselect: true
  1298.     });
  1299.  
  1300.     /** image **/
  1301.     image_zoom();
  1302.  
  1303.     /** sticky share **/
  1304.     sticky_share();
  1305.  
  1306.     /** related post popup **/
  1307.     popup_post();
  1308.  
  1309.     /** media render **/
  1310.     do_media_render();
  1311.  
  1312.     /** add pin it on image hover **/
  1313.     pin_it_image();
  1314.  
  1315.     /** copy clipboard **/
  1316.     if(jmagzoption.isie != true) {
  1317.         copy_clipboard();
  1318.     }
  1319.  
  1320.     /** open share **/
  1321.     open_share();
  1322.  
  1323.     /** post tooltips **/
  1324.     post_tooltip();
  1325.  
  1326.     /** execute map shortcode **/
  1327.     map_shortcode();
  1328.  
  1329.     /** close allert **/
  1330.     close_alert();
  1331.  
  1332.     /** facebook widget **/
  1333.     blog_facebook_widget();
  1334.  
  1335.     /** twitter ticker **/
  1336.     tweetticker();
  1337.  
  1338.     /** video list loader **/
  1339.     videolistloader();
  1340.  
  1341.     /** jmagz unveil **/
  1342.     image_unveil();
  1343.  
  1344.     /** reload cart **/
  1345.     do_add_to_cart();
  1346. }
  1347.  
  1348. $(document).ready(jmagz_dispatch);
  1349. $(document).bind('jmagz-ajax-load ready', function(){});
  1350.  
  1351. /**
  1352.  * google map load
  1353.  **/
  1354. Array.prototype.unique = function() {
  1355.     var a = this;
  1356.     for(var i=0; i<a.length; ++i) {
  1357.         for(var j=i+1; j<a.length; ++j) {
  1358.             if(a[i] === a[j])
  1359.                 a.splice(j--, 1);
  1360.         }
  1361.     }
  1362.     return a;
  1363. };
  1364.  
  1365. var mapenqueued = false;
  1366. var functionarray = [];
  1367.  
  1368. function do_load_googlemap(cb) {
  1369.     if(!mapenqueued) {
  1370.         var script = document.createElement('script');
  1371.         script.type = 'text/javascript';
  1372.         script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' +
  1373.         'callback=executemapcallback';
  1374.         document.body.appendChild(script);
  1375.         mapenqueued = true;
  1376.     }
  1377.     functionarray.push(cb);
  1378. }
  1379.  
  1380. function executemapcallback() {
  1381.     functionarray  = functionarray.unique();
  1382.     for(var i = 0; i < functionarray.length; i++) {
  1383.         window[functionarray[i]]();
  1384.     }
  1385. }
  1386.  
  1387. /** need to use asynch map and loaded only when it needed **/
  1388. function mapshortcode() {
  1389.     $(".jrmap").jrmap();
  1390. }
Add Comment
Please, Sign In to add comment