Advertisement
jegtheme

jquery.jcommon.js

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