Advertisement
jegtheme

jquery.jcommon.js

Jun 20th, 2014
305
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=0&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=0&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.                 $(this).animate({
  532.                     "opacity": 0
  533.                 }, 800);
  534.             });
  535.             animationtimeout = 1000;
  536.         } else if (animation === "seqfade" || animation === "upfade" || animation === "sequpfade") {
  537.             $($(animarr).get().reverse()).each(function (i) {
  538.                 var element = $(this);
  539.                 window.setTimeout(function () {
  540.                     $(element).show().animate({
  541.                         "opacity": 0
  542.                     }, 800);
  543.                 }, 100 + i * 50);
  544.             });
  545.             animationtimeout = 1000 + $(animarr).length * 50;
  546.         } else if (animation === "randomfade" || animation === "randomupfade") {
  547.             var shufflearray = $.shuffleitem(animarr);
  548.             $(shufflearray).each(function (i) {
  549.                 var element = $(this);
  550.                 window.setTimeout(function () {
  551.                     $(element).show().animate({
  552.                         "opacity": 0
  553.                     }, 800);
  554.                 }, 100 + i * 50);
  555.             });
  556.             animationtimeout = 1000 + $(animarr).length * 50;
  557.         }
  558.  
  559.         window.setTimeout(function () {
  560.             $(container).isotope('remove', $(animarr));
  561.             callback.call();
  562.         }, animationtimeout);
  563.     };
  564.  
  565.     $.animate_load = function (animation, container, animarr, callback) {
  566.         var animationtimeout = 0;
  567.         var shufflearray;
  568.         var i;
  569.  
  570.         // hide all element that not yet loaded
  571.         $(animarr).each(function () {
  572.             $(this).css({"opacity": 0});
  573.         });
  574.  
  575.         if (animation === "normal") {
  576.             $(animarr).each(function () {
  577.                 $(this).css({"opacity": 1});
  578.             });
  579.             animationtimeout = 1000;
  580.         } else if (animation === "fade") {
  581.             $(animarr).each(function () {
  582.                 $(this).animate({
  583.                     "opacity": 1
  584.                 }, 1000);
  585.             });
  586.             animationtimeout = 1000;
  587.         } else if (animation === "seqfade") {
  588.             $(animarr).each(function (i) {
  589.                 var element = $(this);
  590.                 window.setTimeout(function () {
  591.                     $(element).show().animate({
  592.                         "opacity": 1
  593.                     }, 1000);
  594.                 }, 100 + i * 50);
  595.             });
  596.             animationtimeout = 500 + ($(animarr).length * 50);
  597.         } else if (animation === "upfade") {
  598.             $.setuptop(animarr);
  599.             $(animarr).each(function () {
  600.                 var element = $(this);
  601.                 $(element).animate({
  602.                     top: parseInt($(element).css('top'), 10) - ( $(element).height() / 2),
  603.                     opacity: 1
  604.                 }, 1500);
  605.             });
  606.             animationtimeout = 2000;
  607.         } else if (animation === "sequpfade") {
  608.             $.setuptop(animarr);
  609.             $(animarr).each(function (i) {
  610.                 var element = $(this);
  611.                 window.setTimeout(function () {
  612.                     $(element).animate({
  613.                         top: parseInt($(element).css('top'), 10) - ( $(element).height() / 2),
  614.                         opacity: 1
  615.                     }, 1000);
  616.                 }, 100 + i * 50);
  617.             });
  618.             animationtimeout = 500 + ($(animarr).length * 50);
  619.         } else if (animation === "randomfade") {
  620.             shufflearray = $.shuffleitem(animarr);
  621.             var animaterandomfade = function () {
  622.                 var element = shufflearray.pop();
  623.                 $(element).animate({
  624.                     "opacity": 1
  625.                 }, 1000);
  626.             };
  627.             for (i = 0; i < shufflearray.length; i++) {
  628.                 window.setTimeout(animaterandomfade, 75 + i * 50);
  629.             }
  630.             animationtimeout = 500 + ($(animarr).length * 50);
  631.         } else if (animation === "randomupfade") {
  632.             shufflearray = $.shuffleitem(animarr);
  633.             $.setuptop();
  634.             var animaterandomupfade = function () {
  635.                 var element = shufflearray.pop();
  636.                 $(element).animate({
  637.                     top: parseInt($(element).css('top'), 10) - ( $(element).height() / 2),
  638.                     opacity: 1
  639.                 }, 1000);
  640.             };
  641.             for (i = 0; i < shufflearray.length; i++) {
  642.                 window.setTimeout(animaterandomupfade, 75 + i * 50);
  643.             }
  644.             animationtimeout = 500 + ($(animarr).length * 50);
  645.         }
  646.  
  647.         window.setTimeout(function () {
  648.             callback.call();
  649.         }, (animationtimeout + 1000));
  650.     };
  651.  
  652.     $.bindComment = function () {
  653.         $(".replycomment").click(function () {
  654.             var i = $(this).parents(".coment-box").parent();
  655.             var f = $("#respond");
  656.             var x = $("<div id='comment-box-reply'></div>");
  657.             var t = $("<div id='temp-comment-holder' style='display:none;'></div>");
  658.             var p = $("#comment_parent");
  659.             var c = "data-comment-id";
  660.  
  661.             $(".closecommentform").removeClass('liststyle');
  662.             $(".replycomment").show();
  663.             $("#comment-box-reply").remove();
  664.  
  665.             if (!$("#temp-comment-holder").length) {
  666.                 t.insertBefore(f);
  667.             }
  668.  
  669.             x.insertAfter($(i).find('.coment-box-inner')).append(f);
  670.             p.val($(this).attr(c));
  671.  
  672.             $(this).hide();
  673.  
  674.             $(i).find(".closecommentform").addClass('liststyle').click(function () {
  675.                 f.insertAfter("#temp-comment-holder");
  676.                 $("#temp-comment-holder").remove();
  677.                 $("#comment-box-reply").remove();
  678.                 $(this).removeClass('liststyle');
  679.                 $(i).find('.replycomment').show();
  680.                 $("#comment_parent").val(0);
  681.             });
  682.         });
  683.     };
  684.  
  685.     $.fn.jsharefollow = function () {
  686.         return $(this).each(function () {
  687.             var element = this;
  688.             var parent = $(element).parents(".article-inner-wrapper");
  689.             var posmeta = {};
  690.             var addmargin = 15;
  691.  
  692.             var ishorizontal = $(".horizontalnav").length;
  693.             var istwoline = $(".topnavtwoline").length;
  694.             var issmallnav = $(".topnavsmaller").length;
  695.             var issidenav = $(".sidenav").length;
  696.             var issidenoheadermenu = $(".noheadermenu").length;
  697.  
  698.             var updateposmeta = function () {
  699.                 var topmargin = 0;
  700.  
  701.                 if(issidenav) {
  702.                     if(issidenoheadermenu) {
  703.                         topmargin = 0;
  704.                     } else {
  705.                         topmargin = $(".headermenu").height();
  706.                     }
  707.                 } else if(ishorizontal) {
  708.                     topmargin = $(".topnavigation").height();
  709.  
  710.                     if(window.jpobj.globaltop > window.joption.menucollapsed) {
  711.                         if (istwoline && !issmallnav) {
  712.                             topmargin = $(".topwrapperbottom").height();
  713.                         } else if( ( issmallnav && !istwoline ) || ( istwoline && issmallnav ) ) {
  714.                             topmargin = window.joption.smallmenuheight;
  715.                         }
  716.                     }
  717.                 }
  718.  
  719.                 topmargin = parseInt(topmargin, 10);
  720.  
  721.                 posmeta = {
  722.                     scrollbegin: parent.offset().top - topmargin,
  723.                     scrollstop: parent.offset().top - topmargin + parent.height() - $(element).outerHeight(true)
  724.                 };
  725.             };
  726.  
  727.             var updateposition = function () {
  728.                 updateposmeta();
  729.                 var scrollpos = window.jpobj.globaltop;
  730.  
  731.                 if (scrollpos > posmeta.scrollbegin - addmargin && scrollpos < posmeta.scrollstop) {
  732.                     var topposition = scrollpos - posmeta.scrollbegin + addmargin;
  733.                     $(element).css({ 'top': topposition });
  734.                 } else if (scrollpos < posmeta.scrollbegin - addmargin) {
  735.                     $(element).css({ 'top': 0 });
  736.                 } else if (scrollpos > posmeta.scrollstop) {
  737.                     $(element).css({ 'top': parent.height() - $(element).outerHeight(true) });
  738.                 }
  739.  
  740.             };
  741.  
  742.             updateposmeta();
  743.             $(window).bind('jscroll', updateposition);
  744.             $(window).bind('resize', function () {
  745.                 updateposmeta();
  746.                 updateposition();
  747.             });
  748.         });
  749.     };
  750.  
  751.     $.fn.jrmap = function () {
  752.         return $(this).each(function () {
  753.             var element = this;
  754.             var content = $(element).find('.contenthidden').html();
  755.             var options = {
  756.                 lat: $(element).data('lat'),
  757.                 lng: $(element).data('lng'),
  758.                 zoom: $(element).data('zoom'),
  759.                 ratio: $(element).data('ratio'),
  760.                 showpopup: $(element).data('showpopup'),
  761.                 title: $(element).data('title')
  762.             };
  763.  
  764.             var mapresize = function () {
  765.                 var elewidth = $(element).width();
  766.                 $(element).height(elewidth * options.ratio);
  767.             };
  768.  
  769.             var createmap = function () {
  770.  
  771.                 var eleid = $(element).attr('id');
  772.                 var mapOptions = {
  773.                     zoom: parseInt(options.zoom, 10),
  774.                     center: new google.maps.LatLng(parseFloat(options.lat), parseFloat(options.lng)),
  775.                     mapTypeId: google.maps.MapTypeId.ROADMAP,
  776.                     zoomControl: true,
  777.                     scaleControl: false,
  778.                     panControl: false,
  779.                     scrollwheel: false
  780.                 };
  781.                 var map = new google.maps.Map(document.getElementById(eleid), mapOptions);
  782.                 var marker = new google.maps.Marker({
  783.                     position: new google.maps.LatLng(parseFloat(options.lat), parseFloat(options.lng)),
  784.                     map: map,
  785.                     zIndex: 10,
  786.                     title: options.title
  787.                 });
  788.  
  789.  
  790.                 if (options.showpopup === true) {
  791.  
  792.                     var contentString = '<div id="mapcontent">' +
  793.                         '<h3>' + options.title + '</h3>' +
  794.                         '<div id="bodyContent">' +
  795.                         content +
  796.                         '</div>' +
  797.                         '</div>';
  798.  
  799.                     var infowindow = new google.maps.InfoWindow({
  800.                         content: contentString,
  801.                         maxWidth: 300
  802.                     });
  803.  
  804.                     google.maps.event.addListener(marker, 'click', function () {
  805.                         infowindow.open(map, marker);
  806.                     });
  807.  
  808.                     window.setTimeout(function () {
  809.                         infowindow.open(map, marker);
  810.                     }, 5000);
  811.                 }
  812.  
  813.             };
  814.  
  815.             $(window).bind('resize', mapresize);
  816.             mapresize();
  817.             google.maps.event.addDomListener(window, 'load', createmap);
  818.         });
  819.     };
  820.  
  821.     $.fn.jskill = function () {
  822.         return $(this).each(function () {
  823.             var element = $(this);
  824.  
  825.             window.setTimeout(function () {
  826.                 element.waypoint(function (direction) {
  827.                     var grapwrap = $(this).find('.graphwrap');
  828.  
  829.                     $(grapwrap).each(function (i) {
  830.                         var ele = $(this);
  831.  
  832.                         window.setTimeout(function () {
  833.                             var width = $(ele).find('.grapholder').attr('data-width') + '%';
  834.                             $(ele).find('.grapholder').css('width', width);
  835.                             $(ele).find('strong').css('opacity', 1);
  836.                         }, 200 * i);
  837.                     });
  838.                 }, {
  839.                     offset: '80%',
  840.                     triggerOnce: true,
  841.                     context: window
  842.                 });
  843.             }, 1000);
  844.         });
  845.     };
  846.  
  847.  
  848.     $.fn.jfsvideo = function (autoplay) {
  849.         return $(this).each(function () {
  850.             var element = this;
  851.  
  852.             if ($(element).data('type') === 'youtube') {
  853.                 $.type_video_youtube($("[data-type='youtube']"), autoplay);
  854.             }
  855.  
  856.             if ($("[data-type='vimeo']").length) {
  857.                 $.type_video_vimeo($("[data-type='vimeo']"), autoplay);
  858.             }
  859.  
  860.             if ($("[data-type='soundcloud']").length) {
  861.                 $.type_soundcloud($("[data-type='soundcloud']"));
  862.             }
  863.         });
  864.     };
  865.  
  866.     $.jgetbrowser = function () {
  867.         var e = navigator.appName, t = navigator.userAgent, n;
  868.         var r = t.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
  869.         if (r && ( n = t.match(/version\/([\.\d]+)/i)) !== null) {
  870.             r[2] = n[1];
  871.         }
  872.         r = r ? [r[1], r[2]] : [e, navigator.appVersion, "-?"];
  873.         return r[0];
  874.     };
  875.  
  876.  
  877.     $.fn.jfullvideo = function () {
  878.         return $(this).each(function () {
  879.             var element = $(this);
  880.             var video = $(this).find('video');
  881.             var vparent = $(video).parent();
  882.             var dimvid = $(video).height() / $(video).width();
  883.             var parallax_enabled = $(this).hasClass('parallaxvideo');
  884.  
  885.             console.log("video dimension : " + dimvid + " video height : " + $(video).height() + "  video width : " + $(video).width());
  886.  
  887.             var calculatevideo = function () {
  888.                 $(element).find(".mejs-video").css({
  889.                     'width' :  $(vparent).width(),
  890.                     'height' : $(vparent).height()
  891.                 });
  892.  
  893.                 var videotopposition, videoleftposition;
  894.                 var elementdim = $(element).height() / $(element).width();
  895.  
  896.                 console.log("wrapper dimension : " + elementdim + " wrapper height : " + $(element).height() + "  wrapper width : " + $(element).width());
  897.  
  898.                 $(video).attr('style', '');
  899.                 if (elementdim > dimvid) {
  900.                     // set left & width to auto
  901.                     $(video).removeClass("heightauto").addClass("widthauto");
  902.                     videoleftposition = ( $(video).width() - $(vparent).width() ) / 2;
  903.                     if (!parallax_enabled) {
  904.                         $(video).css('left', "-" + videoleftposition + "px");
  905.                     }
  906.                 } else {
  907.                     // set top & height to auto
  908.                     $(video).removeClass("widthauto").addClass("heightauto");
  909.                     videotopposition = ( $(video).height() - $(vparent).height() ) / 2;
  910.                     if (!parallax_enabled) {
  911.                         $(video).css('top', "-" + videotopposition + "px");
  912.                     }
  913.                 }
  914.  
  915.                 if (parallax_enabled) {
  916.                     reset_paralax();
  917.                 }
  918.             };
  919.  
  920.             /** additional parallax effect for video **/
  921.             if (parallax_enabled) {
  922.  
  923.                 var parent, movespeed, elepos, dpos, scrolldiff, ratio, scrollpos;
  924.                 parent = $(this).parent();
  925.                 movespeed = $(this).data('parallaxspeed');
  926.  
  927.                 var init_position = function () {
  928.                     var calcpos = function () {
  929.                         var minpos = elepos.top - $(window).height();
  930.                         var maxpos = $(parent).next().position().top;
  931.  
  932.                         return {
  933.                             'min': minpos,
  934.                             'max': maxpos,
  935.                             'diff': (maxpos - minpos)
  936.                         };
  937.                     };
  938.  
  939.                     elepos = $(parent).position();
  940.                     dpos = calcpos();
  941.                 };
  942.  
  943.                 var reset_paralax = function () {
  944.                     window.setTimeout(function () {
  945.                         init_position();
  946.                         do_parallax();
  947.                     }, 500);
  948.                 };
  949.  
  950.                 var parallaxvideo = function (ratio, scrolldiff) {
  951.                     window.jpobj.doTranslate(element, "0px", scrolldiff - $(window).height() - (ratio * movespeed) + "px");
  952.                 };
  953.  
  954.                 var do_parallax = function () {                
  955.                     if (dpos !== undefined) {
  956.                         ratio = null;
  957.                         scrollpos = $(window).scrollTop();
  958.                        
  959.                         if (scrollpos >= dpos.min && scrollpos <= dpos.max) {
  960.                             scrolldiff = scrollpos - dpos.min;
  961.                             ratio = scrolldiff / dpos.diff;
  962.                             parallaxvideo(ratio, scrolldiff);
  963.                         }
  964.                     }
  965.                 };
  966.  
  967.                 if (!window.joption.ismobile) {
  968.                     if (parallax_enabled) {
  969.                         $(window).bind('scroll', do_parallax);
  970.                     }
  971.                 }
  972.             }
  973.  
  974.             if (!window.joption.ismobile) {
  975.  
  976.                 var videomedia = $(video).mediaelementplayer({
  977.                     enableAutosize: true,
  978.                     videoWidth: '100%',
  979.                     videoHeight: '100%',
  980.                     followContainerHeight: true,
  981.                     pauseOtherPlayers: false,
  982.                     features: []
  983.                 });
  984.  
  985.                 $(videomedia).bind('play', function(){
  986.                     var resizetimeout = 0;
  987.                     $(window).bind('resize', function(){
  988.                         window.clearTimeout(resizetimeout);
  989.                         resizetimeout = window.setTimeout(function(){
  990.                             calculatevideo();
  991.                         }, 500);
  992.                     });
  993.                 });
  994.  
  995.                 if (parallax_enabled) {
  996.                     $(window).bind('scroll', do_parallax);
  997.                 }
  998.             } else {
  999.                 $(element).find('.video-fallback').show();
  1000.             }
  1001.  
  1002.         });
  1003.     };
  1004.  
  1005. })(jQuery, window);
  1006.  
  1007.  
  1008. /** jpobj **/
  1009. jpobj = {
  1010.     supportTranslate3d: null,
  1011.     supportTransition: null,
  1012.     isMobile: null,
  1013.     doTranslate: null,
  1014.     browser: null,
  1015.     isIphone: false,
  1016.     isAndroid: false
  1017. };
  1018.  
  1019. (function ($, window, document) {
  1020.     "use strict";
  1021.  
  1022.     var isSupport3d = function () {
  1023.         var el = document.createElement('div'),
  1024.             supportsTranslate3D, transforms = {
  1025.                 'WebkitTransform': '-webkit-transform',
  1026.                 'OTransform': '-o-transform',
  1027.                 'MSTransform': '-ms-transform',
  1028.                 'MozTransform': '-moz-transform',
  1029.                 'Transform': 'transform'
  1030.             };
  1031.  
  1032.         // Add it to the body to get the computed style.
  1033.         document.body.insertBefore(el, null);
  1034.  
  1035.         var t;
  1036.         for (t in transforms) {
  1037.             if (el.style[t] !== undefined) {
  1038.                 el.style[t] = "translate3d(1px,1px,1px)";
  1039.                 supportsTranslate3D = window.getComputedStyle(el).getPropertyValue(transforms[t]);
  1040.             }
  1041.         }
  1042.  
  1043.         document.body.removeChild(el);
  1044.  
  1045.         return (supportsTranslate3D !== undefined && supportsTranslate3D !== null && supportsTranslate3D.length > 0 && supportsTranslate3D !== "none");
  1046.     };
  1047.  
  1048.     var supportsTransition = function () {
  1049.         var div = document.createElement("div");
  1050.         var p, ext, pre = ["ms", "O", "Webkit", "Moz"];
  1051.         for (p in pre) {
  1052.             if (div.style[pre[p] + "Transition"] !== undefined) {
  1053.                 ext = pre[p];
  1054.                 break;
  1055.             }
  1056.         }
  1057.         return ext;
  1058.     };
  1059.  
  1060.  
  1061.     var getBrowserDetail = function () {
  1062.         var N = navigator.appName,
  1063.             ua = navigator.userAgent,
  1064.             tem;
  1065.         var M = ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
  1066.         if (M && (tem = ua.match(/version\/([\.\d]+)/i)) !== null) {
  1067.             M[2] = tem[1];
  1068.         }
  1069.         M = M ? [M[1], M[2]] : [N, navigator.appVersion, '-?'];
  1070.  
  1071.         return M;
  1072.     };
  1073.  
  1074.     var do3dTranslate = function (ele, x, y) {
  1075.         $(ele).css('-' + window.jpobj.supportTransition + '-transform', 'translate3d(' + x + ', ' + y + ', 0)');
  1076.     };
  1077.  
  1078.     var doNormalTranslate = function (ele, x, y) {
  1079.         $(ele).css({
  1080.             "left": x,
  1081.             "top": y
  1082.         });
  1083.     };
  1084.  
  1085.     var checkIphone = function () {
  1086.         var ua = navigator.userAgent,
  1087.             iphone = ua.indexOf('iPhone') !== -1 || ua.indexOf('iPod') !== -1;
  1088.         return iphone;
  1089.     };
  1090.  
  1091.     var checkAndroid = function () {
  1092.         var ua = navigator.userAgent,
  1093.             android = ua.indexOf('Android') !== -1;
  1094.  
  1095.         return android;
  1096.     };
  1097.  
  1098.     var setupJpobj = function () {
  1099.         window.jpobj.supportTranslate3d = isSupport3d();
  1100.         window.jpobj.supportTransition = supportsTransition();
  1101.         window.jpobj.browser = getBrowserDetail();
  1102.         window.jpobj.isIphone = checkIphone();
  1103.         window.jpobj.isAndroid = checkAndroid();
  1104.         window.jpobj.globaltop = -1;
  1105.  
  1106.         if (window.jpobj.supportTranslate3d) {
  1107.             window.jpobj.doTranslate = do3dTranslate;
  1108.         } else {
  1109.             window.jpobj.doTranslate = doNormalTranslate;
  1110.         }
  1111.     };
  1112.  
  1113.     // setup jpobj
  1114.     setupJpobj();
  1115.  
  1116.  
  1117.     /***  scroll trigger ***/
  1118.     var scrolltrigger = function () {
  1119.         var scroll = window.requestAnimationFrame ||
  1120.             window.webkitRequestAnimationFrame ||
  1121.             window.mozRequestAnimationFrame ||
  1122.             window.msRequestAnimationFrame ||
  1123.             window.oRequestAnimationFrame ||
  1124.             function (callback) {
  1125.                 window.setTimeout(callback, 1000 / 60);
  1126.             };
  1127.  
  1128.         var loop = function () {
  1129.             if (window.jpobj.globaltop === window.pageYOffset) {
  1130.                 scroll(loop);
  1131.                 return false;
  1132.             } else {
  1133.                 window.jpobj.globaltop = window.pageYOffset;
  1134.                 $(window).trigger('jscroll');
  1135.             }
  1136.             scroll(loop);
  1137.         };
  1138.  
  1139.         loop();
  1140.     };
  1141.  
  1142.     $(window).bind('load', function () {
  1143.         scrolltrigger();
  1144.     });
  1145.     /***  scroll trigger ***/
  1146.  
  1147. })(jQuery, window, document);
  1148.  
  1149.  
  1150. (function (window) {
  1151.     "use strict";
  1152.  
  1153.     var lastTime = 0;
  1154.     var vendors = ['ms', 'moz', 'webkit', 'o'];
  1155.     for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
  1156.         window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
  1157.         window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
  1158.     }
  1159.  
  1160.     if (!window.requestAnimationFrame) {
  1161.         window.requestAnimationFrame = function (callback) {
  1162.             var currTime = new Date().getTime();
  1163.             var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  1164.             var id = window.setTimeout(function () {
  1165.                     callback(currTime + timeToCall);
  1166.                 },
  1167.                 timeToCall);
  1168.             lastTime = currTime + timeToCall;
  1169.             return id;
  1170.         };
  1171.     }
  1172.  
  1173.     if (!window.cancelAnimationFrame) {
  1174.         window.cancelAnimationFrame = function (id) {
  1175.             clearTimeout(id);
  1176.         };
  1177.     }
  1178. }(window));
  1179.  
  1180.  
  1181.  
  1182. /**
  1183. * google map load
  1184. **/
  1185. Array.prototype.unique = function() {
  1186.     var a = this;
  1187.     for(var i=0; i<a.length; ++i) {
  1188.         for(var j=i+1; j<a.length; ++j) {
  1189.             if(a[i] === a[j])
  1190.                 a.splice(j--, 1);
  1191.         }
  1192.     }
  1193.     return a;
  1194. };
  1195.  
  1196. var mapenqueued = false;
  1197. var functionarray = [];
  1198.  
  1199. function do_load_googlemap(cb) {
  1200.     if(!mapenqueued) {
  1201.         var script = document.createElement('script');
  1202.         script.type = 'text/javascript';
  1203.         script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' +
  1204.             'callback=executemapcallback';
  1205.         document.body.appendChild(script);
  1206.         mapenqueued = true;
  1207.     }
  1208.     functionarray.push(cb);
  1209. }
  1210.  
  1211. function executemapcallback() {
  1212.     functionarray  = functionarray.unique();
  1213.     for(var i = 0; i < functionarray.length; i++) {
  1214.         window[functionarray[i]]();
  1215.     }
  1216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement