Advertisement
jegtheme

jquery.jcommon.js

Aug 16th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** jquery.jcommon.js **/
  2. (function ($, window) {
  3.     "use strict";
  4.  
  5.     $.fn.checkimageloaded = function () {
  6.         $(this).find("img").each(function(i){
  7.             var element = this;
  8.             setTimeout(function(){
  9.                 var src = $(element).attr('src');
  10.                 var img = new Image();
  11.                 $(img).load(function () {}).attr('src', src);
  12.             }, i * 200);
  13.         });
  14.     };
  15.  
  16.     /** reduced element **/
  17.     $.jreducedtop = function () {
  18.         var reducedelement = ['.headermenu', '.responsiveheader', '.topnavigation'];
  19.         var ofset = 0;
  20.  
  21.         $(reducedelement).each(function () {
  22.             var ele = $(this);
  23.             if ($(ele).is(":visible")) {
  24.                 ofset -= $(ele).height();
  25.             }
  26.         });
  27.  
  28.         if($(".toptransparent").length && $(window).width() > 1024) {
  29.             return 0;
  30.         }
  31.  
  32.         return ofset;
  33.     };
  34.  
  35.     $.jreducedtoplanding = function () {
  36.         var ishorizontal = $(".horizontalnav").length;
  37.         var istwoline = $(".topnavtwoline").length;
  38.         var issmallnav = $(".topnavsmaller").length;
  39.         var issidenav = $(".sidenav").length;
  40.         var issidenoheadermenu = $(".noheadermenu").length;
  41.         var offset = 0;
  42.  
  43.         if ($(window).width() > 1024) {
  44.             if (issidenav) {
  45.                 if (issidenoheadermenu) {
  46.                     offset = 0;
  47.                 } else {
  48.                     offset = $(".headermenu").height();
  49.                 }
  50.             } else if (ishorizontal) {
  51.                 if (!issmallnav && !istwoline) {
  52.                     offset = $(".topnavigation").height();
  53.                 } else if (istwoline && !issmallnav) {
  54.                     offset = $(".topwrapperbottom").height();
  55.                 } else if (issmallnav && !istwoline) {
  56.                     offset = window.joption.smallmenuheight;
  57.                 } else if (istwoline && issmallnav) {
  58.                     offset = window.joption.smallmenuheight;
  59.                 }
  60.             }
  61.         } else {
  62.             offset = $('.responsiveheader').height();
  63.         }
  64.  
  65.         return -1 * offset;
  66.     };
  67.  
  68.     $.fn.joffset = function () {
  69.         $(this).show();
  70.         var offset = $(this).offset();
  71.         $(this).hide();
  72.         return offset;
  73.     };
  74.  
  75.     $.fn.jwidth = function () {
  76.         $(this).show();
  77.         var width = $(this).outerWidth();
  78.         $(this).hide();
  79.         return width;
  80.     };
  81.  
  82.     /** accordion page **/
  83.     $.fn.jaccordionpage = function () {
  84.         var element = $(this);
  85.         var firstelement = $(".halfpagepanel", element).get(0);
  86.  
  87.         var initialize = function () {
  88.             $(firstelement).addClass('active');
  89.             $(".halfpagepanel-body").stop().slideUp("fast", function () {
  90.                 $(window).trigger('resize');
  91.             });
  92.             $(".halfpagepanel-body", firstelement).stop().slideDown("fast");
  93.         };
  94.  
  95.         var collapseme = function (e) {
  96.             var target = e.target;
  97.             var targetelement = $(target).parent(".halfpagepanel");
  98.  
  99.             var slidetargetelement = function (target) {
  100.                 $(".halfpagepanel", element).removeClass('active');
  101.                 $(".halfpagepanel-body", element).stop().slideUp("fast");
  102.                 $(".halfpagepanel-body", target).stop().slideDown("fast");
  103.                 $(target).addClass('active');
  104.             };
  105.  
  106.             if ($(targetelement).hasClass('active')) {
  107.                 target = $(targetelement).next().length > 0 ? $(targetelement).next() : $(targetelement).prev();
  108.                 slidetargetelement(target);
  109.             } else {
  110.                 slidetargetelement(targetelement);
  111.             }
  112.         };
  113.  
  114.         initialize();
  115.         $(".halfpagepanel-header", element).bind('click', collapseme);
  116.     };
  117.  
  118.     /**** fullscreen ****/
  119.     $.fn.fsfullheight = function (topelements) {
  120.         var element = this;
  121.         var calculateheight = function () {
  122.             var wh = $(window).height();
  123.  
  124.             if(!$(".toptransparent").length) {
  125.                 $(topelements).each(function () {
  126.                     var ele = $(this);
  127.                     if ($(ele).is(":visible")) {
  128.                         wh -= $(ele).outerHeight();
  129.                     }
  130.                 });
  131.             }
  132.  
  133.             if (wh < 320) {
  134.                 wh = 320;
  135.             }
  136.             $(element).css({ 'height': wh });
  137.         };
  138.  
  139.         $(window).bind('resize load', calculateheight);
  140.         $(document).bind('ready', calculateheight);
  141.     };
  142.  
  143.     /**** share function ****/
  144.  
  145.  
  146.     $.youtube_parser = function (url) {
  147.         var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  148.         var match = url.match(regExp);
  149.  
  150.         if (match && match[7].length === 11) {
  151.             return match[7];
  152.         }
  153.         /*jshint latedef: true */
  154.         window.alert("Url Incorrect");
  155.     };
  156.  
  157.     $.vimeo_parser = function (url) {
  158.         var regExp = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
  159.         var match = url.match(regExp);
  160.  
  161.         if (match) {
  162.             return match[2];
  163.         }
  164.  
  165.         // check if using https
  166.         regExp = /https:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
  167.         match = url.match(regExp);
  168.  
  169.         if (match) {
  170.             return match[2];
  171.         }
  172.  
  173.         /*jshint latedef: true */
  174.         window.alert("not a vimeo url");
  175.     };
  176.  
  177.     $.type_video_youtube = function (ele, autoplay, repeat) {
  178.         var youtube_id = $.youtube_parser($(ele).attr('data-src'));
  179.         var additionalstring = '';
  180.         var iframe = '';
  181.         if(repeat) {
  182.             additionalstring += ( autoplay === true ) ? "autoplay=1&" : "";
  183.             additionalstring += (repeat === true ) ? "loop=1&playlist=" + youtube_id : "";
  184.             iframe = '<iframe width="700" height="500" src="http://www.youtube.com/v/' + youtube_id + '?version=3&' + additionalstring + 'showinfo=1&theme=light&autohide=1&rel=0&wmode=opaque" frameborder="0" allowfullscreen></iframe>';
  185.         } else {
  186.             additionalstring += ( autoplay === true ) ? "autoplay=1&" : "";
  187.             iframe = '<iframe width="700" height="500" src="http://www.youtube.com/embed/' + youtube_id + '?' + additionalstring + 'showinfo=1&theme=light&autohide=1&rel=0&wmode=opaque" frameborder="0" allowfullscreen></iframe>';
  188.         }
  189.         $('.video-container', ele).append(iframe);
  190.     };
  191.  
  192.     $.type_video_vimeo = function (ele, autoplay, repeat) {
  193.         var vimeo_id = $.vimeo_parser($(ele).attr('data-src'));
  194.         var additionalstring = '';
  195.         additionalstring += ( autoplay === true ) ? "autoplay=1&" : "";
  196.         additionalstring += (repeat === true ) ? "loop=1&" : "";
  197.         var iframe = '<iframe src="http://player.vimeo.com/video/' + vimeo_id + '?' + additionalstring + 'title=0&byline=0&portrait=0" width="700" height="500" webkitallowfullscreen mozallowfullscreen frameborder="0"></iframe>';
  198.         $('.video-container', ele).append(iframe);
  199.     };
  200.  
  201.     $.type_soundcloud = function (ele) {
  202.         var soundcloudurl = $(ele).attr('data-src');
  203.         var iframe = '<iframe src="https://w.soundcloud.com/player/?url=' + encodeURIComponent(soundcloudurl) + '" width="700" height="500" frameborder="0"></iframe>';
  204.         $('.video-container', ele).append(iframe);
  205.     };
  206.  
  207.     $.type_video_html5 = function (ele, autoplay, options, container) {
  208.         var cover = $(ele).data('cover');
  209.  
  210.         options.pauseOtherPlayers = false;
  211.  
  212.         var videomp4 = '';
  213.         var videowebm = '';
  214.         var videoogg = '';
  215.  
  216.         /*
  217.         var dummyvideotest = "<video></video>";
  218.         var canplaymp4 = $(dummyvideotest).get(0).canPlayType("video/mp4");
  219.         var canplaywebm = $(dummyvideotest).get(0).canPlayType("video/webm");
  220.         var canplayogg = $(dummyvideotest).get(0).canPlayType("video/ogg");
  221.  
  222.         if (!window.joption.ismobile && ((canplaymp4 === 'maybe' || canplaymp4 === '') && (canplaywebm === 'maybe' || canplaywebm === '') && (canplayogg === 'maybe' || canplayogg === ''))) {
  223.             options.mode = 'shim';
  224.             options.pluginPath = window.joption.themesurl + "/public/mediaelementjs/";
  225.             options.flashName = 'flashmediaelement.swf';
  226.         }
  227.         */
  228.  
  229.         if ($(ele).data('mp4') !== '') {
  230.             videomp4 = "<source type='video/mp4' src='" + $(ele).data('mp4') + "' />";
  231.         }
  232.  
  233.         if ($(ele).data('webm') !== '') {
  234.             videowebm = "<source type='video/webm' src='" + $(ele).data('webm') + "' />";
  235.         }
  236.  
  237.         if ($(ele).data('ogg') !== '') {
  238.             videoogg = "<source type='video/ogg' src='" + $(ele).data('ogg') + "' />";
  239.         }
  240.  
  241.         var preload = autoplay ? "preload='auto'" : "preload='none'";
  242.         var object = "<object width='100%' height='100%' type='application/x-shockwave-flash' data='" + window.joption.themesurl + "/public/mediaelementjs/flashmediaelement.swf'>" +
  243.             "<param name='movie' value='" + window.joption.themesurl + "/public/mediaelementjs/flashmediaelement.swf' />" +
  244.             "<param name='flashvars' value='controls=true&file=" + $(ele).data('mp4') + "' />" +
  245.             "<img src='" + cover + "' alt='No video playback capabilities' title='No video playback capabilities' />" +
  246.             "</object>";
  247.         var iframe = "<video id='player' poster='" + cover + "' controls='controls' " + preload + ">" +
  248.             videomp4 + videowebm + videoogg +
  249.             // object +
  250.             "</video>";
  251.  
  252.         $(container, ele).append(iframe);
  253.         if (autoplay) {
  254.             options.success = function (mediaElement) {
  255.                 if (mediaElement.pluginType === 'flash') {
  256.                     mediaElement.addEventListener('canplay', function () {
  257.                         mediaElement.play();
  258.                     }, false);
  259.                 } else {
  260.                     mediaElement.play();
  261.                 }
  262.             };
  263.         }
  264.  
  265.         $(ele).find('video').mediaelementplayer(options);
  266.     };
  267.  
  268.     $.get_image_container_size = function (img, container, nocrop) {
  269.         var nh, nw, nt, nl;
  270.  
  271.         var h = $(img).get(0).naturalHeight;
  272.         var w = $(img).get(0).naturalWidth;
  273.  
  274.         if (h === 0) {
  275.             h = $(img).data('height');
  276.             w = $(img).data('width');
  277.         }
  278.  
  279.         var r = ( h / w );
  280.         var wh = $(container).height();
  281.         var ww = $(container).width();
  282.         var wr = wh / ww;
  283.  
  284.         var resizeWidth = function () {
  285.             nw = ww;
  286.             nh = ww * r;
  287.             nl = ( ww - nw ) / 2;
  288.             nt = ( wh - nh ) / 2;
  289.  
  290.             return [nh, nw, nl, nt];
  291.         };
  292.  
  293.         var resizeHeight = function () {
  294.             nw = wh / r;
  295.             nh = wh;
  296.             nl = ( ww - nw ) / 2;
  297.             nt = ( wh - nh ) / 2;
  298.             return [nh, nw, nl, nt];
  299.         };
  300.  
  301.         if (nocrop) {
  302.             if (wr > r) {
  303.                 return resizeWidth();
  304.             }
  305.             return resizeHeight();
  306.         }
  307.         if (wr > r) {
  308.             return resizeHeight();
  309.         }
  310.         return resizeWidth();
  311.  
  312.     };
  313.  
  314.     $.new_get_image_container_size = function (img, container, mode) {
  315.         var nh, nw, nt, nl;
  316.  
  317.         var h = $(img).get(0).naturalHeight;
  318.         var w = $(img).get(0).naturalWidth;
  319.  
  320.         if (h === 0) {
  321.             h = $(img).data('height');
  322.             w = $(img).data('width');
  323.         }
  324.  
  325.         var r = ( h / w );
  326.         var wh = $(container).height();
  327.         var ww = $(container).width();
  328.         var wr = wh / ww;
  329.  
  330.         var resizeWidth = function () {
  331.             nw = ww;
  332.             nh = ww * r;
  333.             nl = ( ww - nw ) / 2;
  334.             nt = ( wh - nh ) / 2;
  335.  
  336.             return [nh, nw, nl, nt];
  337.         };
  338.  
  339.         var resizeHeight = function () {
  340.             nw = wh / r;
  341.             nh = wh;
  342.             nl = ( ww - nw ) / 2;
  343.             nt = ( wh - nh ) / 2;
  344.             return [nh, nw, nl, nt];
  345.         };
  346.  
  347.         var resizenoupscale = function () {
  348.             nw = w;
  349.             nh = h;
  350.             nl = ( ww - nw ) / 2;
  351.             nt = ( wh - nh ) / 2;
  352.             return [nh, nw, nl, nt];
  353.         };
  354.  
  355.         if (mode === 'fit') {
  356.             if (wr > r) {
  357.                 return resizeWidth();
  358.             }
  359.             return resizeHeight();
  360.         }
  361.  
  362.         if (mode === 'zoom') {
  363.             if (wr > r) {
  364.                 return resizeHeight();
  365.             }
  366.             return resizeWidth();
  367.         }
  368.  
  369.         if (mode === 'fitNoUpscale') {
  370.             if (h > wh || w > ww) {
  371.                 return $.new_get_image_container_size(img, container, "fit");
  372.             }
  373.  
  374.             return resizenoupscale();
  375.         }
  376.     };
  377.  
  378.     $.portfolio_popup = function () {
  379.         $(".ppopup a").hoverIntent({
  380.             over: function () {
  381.                 var parent = $(this).parent();
  382.                 var element = $(parent).find('.portfoliopopup');
  383.                 var offset = $(parent).position();
  384.                 var h = $(parent).height();
  385.                 var w = $(parent).width();
  386.  
  387.                 $(element).css({
  388.                     'display': 'block',
  389.                     'position': 'fixed',
  390.                     'top': 0,
  391.                     'left': 0
  392.                 });
  393.                 var ew = $(element).width();
  394.                 $(element).css({'width': ew + 2});
  395.  
  396.                 if (element.hasClass('ppopup-left')) {
  397.                     $(element).css({
  398.                         'position': 'absolute',
  399.                         'display': 'block',
  400.                         'left': offset.left - 8,
  401.                         'top': h + 30
  402.                     }).animate({
  403.                         'opacity': 1,
  404.                         'top': h
  405.                     }, 300);
  406.  
  407.                 } else {
  408.  
  409.                     $(element).css({
  410.                         'position': 'absolute',
  411.                         'display': 'block',
  412.                         'left': offset.left - ew + ( w / 2 ) - 2,
  413.                         'top': h + 30
  414.                     }).animate({
  415.                         'opacity': 1,
  416.                         'top': h
  417.                     }, 300);
  418.                 }
  419.             },
  420.             out: function () {
  421.                 var parent = $(this).parent();
  422.                 var element = $(parent).find('.portfoliopopup');
  423.                 var h = $(parent).height();
  424.                 $(element).animate({
  425.                     'top': h + 30,
  426.                     'opacity': 0
  427.                 }, 300, function () {
  428.                     $(element).css({
  429.                         'display': 'none',
  430.                         'top': 0,
  431.                         'left': 0,
  432.                         'opacity': 0
  433.                     });
  434.                 });
  435.             },
  436.             timeout: 250
  437.         });
  438.  
  439.         if ($(".portfoliobottomnav").length) {
  440.             $(".portfoliobottomnav  > div").hoverIntent({
  441.                 over: function () {
  442.                     var element = $(this).find('.portfoliopopup');
  443.                     var offset = $(this).position();
  444.                     var h = $(this).height();
  445.                     var w = $(this).width();
  446.  
  447.                     if ($(element).hasClass('leftpopup')) {
  448.                         $(element).css({
  449.                             'display': 'block',
  450.                             'left': offset.left + 2,
  451.                             'top': ( h * -1 ) - 30
  452.                         }).animate({
  453.                             'opacity': 1,
  454.                             'top': ( h * -1 )
  455.                         }, 300);
  456.                     } else {
  457.                         $(element).css({
  458.                             'display': 'block',
  459.                             'left': offset.left - $(element).width() + ( w / 2 ) - 2,
  460.                             'top': ( h * -1 ) - 30
  461.                         }).animate({
  462.                             'opacity': 1,
  463.                             'top': ( h * -1 )
  464.                         }, 300);
  465.                     }
  466.                 },
  467.                 out: function () {
  468.                     var element = $(this).find('.portfoliopopup');
  469.                     var h = $(this).height();
  470.  
  471.                     $(element).animate({
  472.                         'top': ( h * -1 ) - 30,
  473.                         'opacity': 0
  474.                     }, 300, function () {
  475.                         $(element).css({
  476.                             'display': 'none',
  477.                             'top': 0,
  478.                             'left': 0,
  479.                             'opacity': 0
  480.                         });
  481.                     });
  482.                 },
  483.                 timeout: 250
  484.             });
  485.         }
  486.     };
  487.  
  488.     $.open_in_new_tab = function (url) {
  489.         // var win = window.open(url, '_blank');
  490.         var win = window.open(url, '_blank', 'location=yes,height=400,width=800,scrollbars=yes,status=yes');
  491.         win.focus();
  492.     };
  493.  
  494.     $.setuptop = function (animarr) {
  495.         // setup item
  496.         $(animarr).each(function () {
  497.             var $item = $(this),
  498.                 t = parseInt($item.css('top'), 10) + ( $item.height() / 2);
  499.             $item.css({
  500.                 top: t + 'px',
  501.                 opacity: 0
  502.             });
  503.         });
  504.     };
  505.  
  506.  
  507.     $.shuffleitem = function (animarr) {
  508.         var array = [];
  509.         $(animarr).each(function (i) {
  510.             array[i] = $(this);
  511.         });
  512.  
  513.         // shuffle
  514.         var copy = [], n = array.length, i;
  515.         while (n) {
  516.             i = Math.floor(Math.random() * array.length);
  517.             if (i in array) {
  518.                 copy.push(array[i]);
  519.                 delete array[i];
  520.                 n--;
  521.             }
  522.         }
  523.  
  524.         return copy;
  525.     };
  526.  
  527.     $.animate_hide = function (animation, container, animarr, callback) {
  528.         var animationtimeout = 0;
  529.  
  530.         if (animation === "fade" || animation === "normal") {
  531.             $(animarr).each(function () {
  532.                 var element = $(this);
  533.                 $(this).animate({
  534.                     "opacity": 0
  535.                 }, 800, function(){
  536.                     $(element).addClass('isotope-hide-element');
  537.                     $(element).remove();
  538.                     // $(container).isotope('remove', $(element));
  539.                 });
  540.             });
  541.             animationtimeout = 1000;
  542.         } else if (animation === "seqfade" || animation === "upfade" || animation === "sequpfade") {
  543.             $($(animarr).get().reverse()).each(function (i) {
  544.                 var element = $(this);
  545.                 window.setTimeout(function () {
  546.                     $(element).show().animate({
  547.                         "opacity": 0
  548.                     }, 800, function(){
  549.                         $(element).addClass('isotope-hide-element');
  550.                         $(element).remove();
  551.                         // $(container).isotope('remove', $(element));
  552.                     });
  553.                 }, 100 + i * 50);
  554.             });
  555.             animationtimeout = 1000 + $(animarr).length * 50;
  556.         } else if (animation === "randomfade" || animation === "randomupfade") {
  557.             var shufflearray = $.shuffleitem(animarr);
  558.             $(shufflearray).each(function (i) {
  559.                 var element = $(this);
  560.                 window.setTimeout(function () {
  561.                     $(element).show().animate({
  562.                         "opacity": 0
  563.                     }, 800, function(){
  564.                         $(element).addClass('isotope-hide-element');
  565.                         $(element).remove();
  566.                         // $(container).isotope('remove', $(element));
  567.                     });
  568.                 }, 100 + i * 50);
  569.             });
  570.             animationtimeout = 1000 + $(animarr).length * 50;
  571.         }
  572.  
  573.         window.setTimeout(function () {
  574.             $(container).isotope('remove', $(animarr));
  575.             callback.call();
  576.         }, animationtimeout);
  577.     };
  578.  
  579.     $.animate_load = function (animation, container, animarr, callback) {
  580.         var animationtimeout = 0;
  581.         var shufflearray;
  582.         var i;
  583.  
  584.         // hide all element that not yet loaded
  585.         $(animarr).each(function () {
  586.             $(this).css({"opacity": 0});
  587.         });
  588.  
  589.         if (animation === "normal") {
  590.             $(animarr).each(function () {
  591.                 $(this).css({"opacity": 1});
  592.             });
  593.             animationtimeout = 1000;
  594.         } else if (animation === "fade") {
  595.             $(animarr).each(function () {
  596.                 $(this).animate({
  597.                     "opacity": 1
  598.                 }, 1000);
  599.             });
  600.             animationtimeout = 1000;
  601.         } else if (animation === "seqfade") {
  602.             $(animarr).each(function (i) {
  603.                 var element = $(this);
  604.                 window.setTimeout(function () {
  605.                     $(element).show().animate({
  606.                         "opacity": 1
  607.                     }, 1000);
  608.                 }, 100 + i * 50);
  609.             });
  610.             animationtimeout = 500 + ($(animarr).length * 50);
  611.         } else if (animation === "upfade") {
  612.             $.setuptop(animarr);
  613.             $(animarr).each(function () {
  614.                 var element = $(this);
  615.                 $(element).animate({
  616.                     top: parseInt($(element).css('top'), 10) - ( $(element).height() / 2),
  617.                     opacity: 1
  618.                 }, 1500);
  619.             });
  620.             animationtimeout = 2000;
  621.         } else if (animation === "sequpfade") {
  622.             $.setuptop(animarr);
  623.             $(animarr).each(function (i) {
  624.                 var element = $(this);
  625.                 window.setTimeout(function () {
  626.                     $(element).animate({
  627.                         top: parseInt($(element).css('top'), 10) - ( $(element).height() / 2),
  628.                         opacity: 1
  629.                     }, 1000);
  630.                 }, 100 + i * 50);
  631.             });
  632.             animationtimeout = 500 + ($(animarr).length * 50);
  633.         } else if (animation === "randomfade") {
  634.             shufflearray = $.shuffleitem(animarr);
  635.             var animaterandomfade = function () {
  636.                 var element = shufflearray.pop();
  637.                 $(element).animate({
  638.                     "opacity": 1
  639.                 }, 1000);
  640.             };
  641.             for (i = 0; i < shufflearray.length; i++) {
  642.                 window.setTimeout(animaterandomfade, 75 + i * 50);
  643.             }
  644.             animationtimeout = 500 + ($(animarr).length * 50);
  645.         } else if (animation === "randomupfade") {
  646.             shufflearray = $.shuffleitem(animarr);
  647.             $.setuptop();
  648.             var animaterandomupfade = function () {
  649.                 var element = shufflearray.pop();
  650.                 $(element).animate({
  651.                     top: parseInt($(element).css('top'), 10) - ( $(element).height() / 2),
  652.                     opacity: 1
  653.                 }, 1000);
  654.             };
  655.             for (i = 0; i < shufflearray.length; i++) {
  656.                 window.setTimeout(animaterandomupfade, 75 + i * 50);
  657.             }
  658.             animationtimeout = 500 + ($(animarr).length * 50);
  659.         }
  660.  
  661.         window.setTimeout(function () {
  662.             callback.call();
  663.         }, (animationtimeout + 1000));
  664.     };
  665.  
  666.     $.bindComment = function () {
  667.         $(".replycomment").click(function () {
  668.             var i = $(this).parents(".coment-box").parent();
  669.             var f = $("#respond");
  670.             var x = $("<div id='comment-box-reply'></div>");
  671.             var t = $("<div id='temp-comment-holder' style='display:none;'></div>");
  672.             var p = $("#comment_parent");
  673.             var c = "data-comment-id";
  674.  
  675.             $(".closecommentform").removeClass('liststyle');
  676.             $(".replycomment").show();
  677.             $("#comment-box-reply").remove();
  678.  
  679.             if (!$("#temp-comment-holder").length) {
  680.                 t.insertBefore(f);
  681.             }
  682.  
  683.             x.insertAfter($(i).find('.coment-box-inner')).append(f);
  684.             p.val($(this).attr(c));
  685.  
  686.             $(this).hide();
  687.  
  688.             $(i).find(".closecommentform").addClass('liststyle').click(function () {
  689.                 f.insertAfter("#temp-comment-holder");
  690.                 $("#temp-comment-holder").remove();
  691.                 $("#comment-box-reply").remove();
  692.                 $(this).removeClass('liststyle');
  693.                 $(i).find('.replycomment').show();
  694.                 $("#comment_parent").val(0);
  695.             });
  696.         });
  697.     };
  698.  
  699.     $.fn.jsharefollow = function () {
  700.         return $(this).each(function () {
  701.             var element = this;
  702.             var parent = $(element).parents(".article-inner-wrapper");
  703.             var posmeta = {};
  704.             var addmargin = 15;
  705.  
  706.             var ishorizontal = $(".horizontalnav").length;
  707.             var istwoline = $(".topnavtwoline").length;
  708.             var issmallnav = $(".topnavsmaller").length;
  709.             var issidenav = $(".sidenav").length;
  710.             var issidenoheadermenu = $(".noheadermenu").length;
  711.  
  712.             var updateposmeta = function () {
  713.                 var topmargin = 0;
  714.  
  715.                 if(issidenav) {
  716.                     if(issidenoheadermenu) {
  717.                         topmargin = 0;
  718.                     } else {
  719.                         topmargin = $(".headermenu").height();
  720.                     }
  721.                 } else if(ishorizontal) {
  722.                     topmargin = $(".topnavigation").height();
  723.  
  724.                     if(window.jpobj.globaltop > window.joption.menucollapsed) {
  725.                         if (istwoline && !issmallnav) {
  726.                             topmargin = $(".topwrapperbottom").height();
  727.                         } else if( ( issmallnav && !istwoline ) || ( istwoline && issmallnav ) ) {
  728.                             topmargin = window.joption.smallmenuheight;
  729.                         }
  730.                     }
  731.                 }
  732.  
  733.                 topmargin = parseInt(topmargin, 10);
  734.  
  735.                 posmeta = {
  736.                     scrollbegin: parent.offset().top - topmargin,
  737.                     scrollstop: parent.offset().top - topmargin + parent.height() - $(element).outerHeight(true)
  738.                 };
  739.             };
  740.  
  741.             var updateposition = function () {
  742.                 updateposmeta();
  743.                 var scrollpos = window.jpobj.globaltop;
  744.  
  745.                 if (scrollpos > posmeta.scrollbegin - addmargin && scrollpos < posmeta.scrollstop) {
  746.                     var topposition = scrollpos - posmeta.scrollbegin + addmargin;
  747.                     $(element).css({ 'top': topposition });
  748.                 } else if (scrollpos < posmeta.scrollbegin - addmargin) {
  749.                     $(element).css({ 'top': 0 });
  750.                 } else if (scrollpos > posmeta.scrollstop) {
  751.                     $(element).css({ 'top': parent.height() - $(element).outerHeight(true) });
  752.                 }
  753.  
  754.             };
  755.  
  756.             updateposmeta();
  757.             $(window).bind('jscroll', updateposition);
  758.             $(window).bind('resize', function () {
  759.                 updateposmeta();
  760.                 updateposition();
  761.             });
  762.         });
  763.     };
  764.  
  765.     $.fn.jrmap = function () {
  766.         return $(this).each(function () {
  767.             var element = this;
  768.             var content = $(element).find('.contenthidden').html();
  769.             var options = {
  770.                 lat: $(element).data('lat'),
  771.                 lng: $(element).data('lng'),
  772.                 zoom: $(element).data('zoom'),
  773.                 ratio: $(element).data('ratio'),
  774.                 showpopup: $(element).data('showpopup'),
  775.                 title: $(element).data('title')
  776.             };
  777.  
  778.             var mapresize = function () {
  779.                 var elewidth = $(element).width();
  780.                 $(element).height(elewidth * options.ratio);
  781.             };
  782.  
  783.             var createmap = function () {
  784.  
  785.                 var eleid = $(element).attr('id');
  786.                 var mapOptions = {
  787.                     zoom: parseInt(options.zoom, 10),
  788.                     center: new google.maps.LatLng(parseFloat(options.lat), parseFloat(options.lng)),
  789.                     mapTypeId: google.maps.MapTypeId.ROADMAP,
  790.                     zoomControl: true,
  791.                     scaleControl: false,
  792.                     panControl: false,
  793.                     scrollwheel: false
  794.                 };
  795.                 var map = new google.maps.Map(document.getElementById(eleid), mapOptions);
  796.                 var marker = new google.maps.Marker({
  797.                     position: new google.maps.LatLng(parseFloat(options.lat), parseFloat(options.lng)),
  798.                     map: map,
  799.                     zIndex: 10,
  800.                     title: options.title
  801.                 });
  802.  
  803.  
  804.                 if (options.showpopup === true) {
  805.  
  806.                     var contentString = '<div id="mapcontent">' +
  807.                         '<h3>' + options.title + '</h3>' +
  808.                         '<div id="bodyContent">' +
  809.                         content +
  810.                         '</div>' +
  811.                         '</div>';
  812.  
  813.                     var infowindow = new google.maps.InfoWindow({
  814.                         content: contentString,
  815.                         maxWidth: 300
  816.                     });
  817.  
  818.                     google.maps.event.addListener(marker, 'click', function () {
  819.                         infowindow.open(map, marker);
  820.                     });
  821.  
  822.                     window.setTimeout(function () {
  823.                         infowindow.open(map, marker);
  824.                     }, 5000);
  825.                 }
  826.  
  827.             };
  828.  
  829.             $(window).bind('resize', mapresize);
  830.             mapresize();
  831.             google.maps.event.addDomListener(window, 'load', createmap);
  832.         });
  833.     };
  834.  
  835.     $.fn.jskill = function () {
  836.         return $(this).each(function () {
  837.             var element = $(this);
  838.  
  839.             window.setTimeout(function () {
  840.                 element.waypoint(function (direction) {
  841.                     var grapwrap = $(this).find('.graphwrap');
  842.  
  843.                     $(grapwrap).each(function (i) {
  844.                         var ele = $(this);
  845.  
  846.                         window.setTimeout(function () {
  847.                             var width = $(ele).find('.grapholder').attr('data-width') + '%';
  848.                             $(ele).find('.grapholder').css('width', width);
  849.                             $(ele).find('strong').css('opacity', 1);
  850.                         }, 200 * i);
  851.                     });
  852.                 }, {
  853.                     offset: '80%',
  854.                     triggerOnce: true,
  855.                     context: window
  856.                 });
  857.             }, 1000);
  858.         });
  859.     };
  860.  
  861.  
  862.     $.fn.jfsvideo = function (autoplay) {
  863.         return $(this).each(function () {
  864.             var element = this;
  865.  
  866.             if ($(element).data('type') === 'youtube') {
  867.                 $.type_video_youtube($("[data-type='youtube']"), autoplay);
  868.             }
  869.  
  870.             if ($("[data-type='vimeo']").length) {
  871.                 $.type_video_vimeo($("[data-type='vimeo']"), autoplay);
  872.             }
  873.  
  874.             if ($("[data-type='soundcloud']").length) {
  875.                 $.type_soundcloud($("[data-type='soundcloud']"));
  876.             }
  877.         });
  878.     };
  879.  
  880.     $.jgetbrowser = function () {
  881.         var e = navigator.appName, t = navigator.userAgent, n;
  882.         var r = t.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
  883.         if (r && ( n = t.match(/version\/([\.\d]+)/i)) !== null) {
  884.             r[2] = n[1];
  885.         }
  886.         r = r ? [r[1], r[2]] : [e, navigator.appVersion, "-?"];
  887.         return r[0];
  888.     };
  889.  
  890.  
  891.     $.fn.jfullvideo = function () {
  892.         return $(this).each(function () {
  893.             var element = $(this);
  894.             var video = $(this).find('video');
  895.             var vparent = $(video).parent();
  896.             var dimvid = $(video).data('height') / $(video).data('width');
  897.             var parallax_enabled = $(this).hasClass('parallaxvideo');
  898.  
  899.             var calculatevideo = function () {
  900.                 $(element).find(".mejs-video").css({
  901.                     'width' :  $(vparent).width(),
  902.                     'height' : $(vparent).height()
  903.                 });
  904.  
  905.                 var videotopposition, videoleftposition, elementdim;
  906.                 if(parallax_enabled) {
  907.                     elementdim = $(window).height() / $(window).width();
  908.                 } else {
  909.                     elementdim = $(element).height() / $(element).width();
  910.                 }
  911.  
  912.                 $(video).attr('style', '');
  913.                 if (elementdim > dimvid) {
  914.                     $(video).removeClass("heightauto").addClass("widthauto");
  915.                     videoleftposition = ( $(video).width() - $(vparent).width() ) / 2;
  916.                     $(video).css('left', "-" + videoleftposition + "px");
  917.                 } else {
  918.                     $(video).removeClass("widthauto").addClass("heightauto");
  919.                     videotopposition = ( $(video).height() - $(vparent).height() ) / 2;
  920.                     $(video).css('top', "-" + videotopposition + "px");
  921.                 }
  922.             };
  923.  
  924.             if (!window.joption.ismobile) {
  925.  
  926.                 var videomedia = $(video).mediaelementplayer({
  927.                     enableAutosize: true,
  928.                     videoWidth: '100%',
  929.                     videoHeight: '100%',
  930.                     followContainerHeight: true,
  931.                     pauseOtherPlayers: false,
  932.                     features: []
  933.                 });
  934.  
  935.                 $(videomedia).bind('play', function(){
  936.                     var resizetimeout = 0;
  937.                     $(window).bind('resize', function(){
  938.                         window.clearTimeout(resizetimeout);
  939.                         resizetimeout = window.setTimeout(function(){
  940.                             calculatevideo();
  941.                         }, 200);
  942.                     });
  943.                 });
  944.  
  945.             } else {
  946.                 $(element).find('.video-fallback').show();
  947.             }
  948.  
  949.         });
  950.     };
  951.  
  952. })(jQuery, window);
  953.  
  954.  
  955. /** jpobj **/
  956. jpobj = {
  957.     supportTranslate3d: null,
  958.     supportTransition: null,
  959.     isMobile: null,
  960.     doTranslate: null,
  961.     browser: null,
  962.     isIphone: false,
  963.     isAndroid: false
  964. };
  965.  
  966. (function ($, window, document) {
  967.     "use strict";
  968.  
  969.     var isSupport3d = function () {
  970.         var el = document.createElement('div'),
  971.             supportsTranslate3D, transforms = {
  972.                 'WebkitTransform': '-webkit-transform',
  973.                 'OTransform': '-o-transform',
  974.                 'MSTransform': '-ms-transform',
  975.                 'MozTransform': '-moz-transform',
  976.                 'Transform': 'transform'
  977.             };
  978.  
  979.         // Add it to the body to get the computed style.
  980.         document.body.insertBefore(el, null);
  981.  
  982.         var t;
  983.         for (t in transforms) {
  984.             if (el.style[t] !== undefined) {
  985.                 el.style[t] = "translate3d(1px,1px,1px)";
  986.                 supportsTranslate3D = window.getComputedStyle(el).getPropertyValue(transforms[t]);
  987.             }
  988.         }
  989.  
  990.         document.body.removeChild(el);
  991.  
  992.         return (supportsTranslate3D !== undefined && supportsTranslate3D !== null && supportsTranslate3D.length > 0 && supportsTranslate3D !== "none");
  993.     };
  994.  
  995.     var supportsTransition = function () {
  996.         var div = document.createElement("div");
  997.         var p, ext, pre = ["ms", "O", "Webkit", "Moz"];
  998.         for (p in pre) {
  999.             if (div.style[pre[p] + "Transition"] !== undefined) {
  1000.                 ext = pre[p];
  1001.                 break;
  1002.             }
  1003.         }
  1004.         return ext;
  1005.     };
  1006.  
  1007.  
  1008.     var getBrowserDetail = function () {
  1009.         var N = navigator.appName,
  1010.             ua = navigator.userAgent,
  1011.             tem;
  1012.         var M = ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
  1013.         if (M && (tem = ua.match(/version\/([\.\d]+)/i)) !== null) {
  1014.             M[2] = tem[1];
  1015.         }
  1016.         M = M ? [M[1], M[2]] : [N, navigator.appVersion, '-?'];
  1017.  
  1018.         return M;
  1019.     };
  1020.  
  1021.     var do3dTranslate = function (ele, x, y) {
  1022.         $(ele).css('-' + window.jpobj.supportTransition + '-transform', 'translate3d(' + x + ', ' + y + ', 0)');
  1023.     };
  1024.  
  1025.     var doNormalTranslate = function (ele, x, y) {
  1026.         $(ele).css({
  1027.             "left": x,
  1028.             "top": y
  1029.         });
  1030.     };
  1031.  
  1032.     var checkIphone = function () {
  1033.         var ua = navigator.userAgent,
  1034.             iphone = ua.indexOf('iPhone') !== -1 || ua.indexOf('iPod') !== -1;
  1035.         return iphone;
  1036.     };
  1037.  
  1038.     var checkAndroid = function () {
  1039.         var ua = navigator.userAgent,
  1040.             android = ua.indexOf('Android') !== -1;
  1041.  
  1042.         return android;
  1043.     };
  1044.  
  1045.     var setupJpobj = function () {
  1046.         window.jpobj.supportTranslate3d = isSupport3d();
  1047.         window.jpobj.supportTransition = supportsTransition();
  1048.         window.jpobj.browser = getBrowserDetail();
  1049.         window.jpobj.isIphone = checkIphone();
  1050.         window.jpobj.isAndroid = checkAndroid();
  1051.         window.jpobj.globaltop = -1;
  1052.  
  1053.         if (window.jpobj.supportTranslate3d) {
  1054.             window.jpobj.doTranslate = do3dTranslate;
  1055.         } else {
  1056.             window.jpobj.doTranslate = doNormalTranslate;
  1057.         }
  1058.     };
  1059.  
  1060.     // setup jpobj
  1061.     setupJpobj();
  1062.  
  1063.  
  1064.     /***  scroll trigger ***/
  1065.     var scrolltrigger = function () {
  1066.         var scroll = window.requestAnimationFrame ||
  1067.             window.webkitRequestAnimationFrame ||
  1068.             window.mozRequestAnimationFrame ||
  1069.             window.msRequestAnimationFrame ||
  1070.             window.oRequestAnimationFrame ||
  1071.             function (callback) {
  1072.                 window.setTimeout(callback, 1000 / 60);
  1073.             };
  1074.  
  1075.         var loop = function () {
  1076.             if (window.jpobj.globaltop === window.pageYOffset) {
  1077.                 scroll(loop);
  1078.                 return false;
  1079.             } else {
  1080.                 window.jpobj.globaltop = window.pageYOffset;
  1081.                 $(window).trigger('jscroll');
  1082.             }
  1083.             scroll(loop);
  1084.         };
  1085.  
  1086.         loop();
  1087.     };
  1088.  
  1089.     $(window).bind('load', function () {
  1090.         scrolltrigger();
  1091.     });
  1092.     /***  scroll trigger ***/
  1093.  
  1094. })(jQuery, window, document);
  1095.  
  1096.  
  1097. (function (window) {
  1098.     "use strict";
  1099.  
  1100.     var lastTime = 0;
  1101.     var vendors = ['ms', 'moz', 'webkit', 'o'];
  1102.     for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  1103.         window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
  1104.         window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
  1105.     }
  1106.  
  1107.     if (!window.requestAnimationFrame) {
  1108.         window.requestAnimationFrame = function (callback) {
  1109.             var currTime = new Date().getTime();
  1110.             var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  1111.             var id = window.setTimeout(function () {
  1112.                     callback(currTime + timeToCall);
  1113.                 },
  1114.                 timeToCall);
  1115.             lastTime = currTime + timeToCall;
  1116.             return id;
  1117.         };
  1118.     }
  1119.  
  1120.     if (!window.cancelAnimationFrame) {
  1121.         window.cancelAnimationFrame = function (id) {
  1122.             clearTimeout(id);
  1123.         };
  1124.     }
  1125. }(window));
  1126.  
  1127.  
  1128.  
  1129. /**
  1130. * google map load
  1131. **/
  1132. Array.prototype.unique_array = function() {
  1133.     var a = this;
  1134.     for(var i=0; i<a.length; ++i) {
  1135.         for(var j=i+1; j<a.length; ++j) {
  1136.             if(a[i] === a[j])
  1137.                 a.splice(j--, 1);
  1138.         }
  1139.     }
  1140.     return a;
  1141. };
  1142.  
  1143. var mapenqueued = false;
  1144. var functionarray = [];
  1145.  
  1146. function do_load_googlemap(cb) {
  1147.     if(!mapenqueued) {
  1148.         var script = document.createElement('script');
  1149.         script.type = 'text/javascript';
  1150.         script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' +
  1151.             'callback=executemapcallback';
  1152.         document.body.appendChild(script);
  1153.         mapenqueued = true;
  1154.     }
  1155.     functionarray.push(cb);
  1156. }
  1157.  
  1158. function executemapcallback() {
  1159.     functionarray  = functionarray.unique_array();
  1160.     for(var i = 0; i < functionarray.length; i++) {
  1161.         window[functionarray[i]]();
  1162.     }
  1163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement