Advertisement
jegtheme

jeggallery.js

Jul 17th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * jeggallery.full.js
  3.  *  
  4.  * simple fragment of jeglio, uses only for load gallery
  5.  **/
  6. (function($) {
  7.     $.fn.jeggallery = function( options )
  8.     {
  9.         var settings = {};
  10.  
  11.         if (options) {
  12.             var options = $.extend(settings, options); 
  13.         } else {
  14.             var options = $.extend(settings);                  
  15.         }
  16.        
  17.         /** public **/
  18.         var touch                   = false;
  19.         if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
  20.             touch = true;
  21.         }
  22.        
  23.         var type_image = function(ele){
  24.             /** add tooltips for tips **/
  25.             if(!touch) {
  26.                 $('a.item-gallery-image', ele).jtooltip({});
  27.             }
  28.            
  29.             /** photo swipe **/        
  30.             (function(PhotoSwipe){
  31.                 photoswipe = $('a.item-gallery-image',ele).photoSwipe({
  32.                     backButtonHideEnabled           : false,
  33.                     captionAndToolbarAutoHideDelay  : 0,
  34.                     imageScaleMethod                : 'fitNoUpscale',
  35.                     allowUserZoom                   : true,
  36.                     getImageSource                  : function(obj){ return $(obj).attr('data'); }
  37.                 });
  38.                 photoswipe.addEventHandler(PhotoSwipe.EventTypes.onHide, function(e){
  39.                     $container.isotope("reLayout");
  40.                 });
  41.             }(window.Code.PhotoSwipe));        
  42.            
  43.             $('a', ele).click(function(){
  44.                 return false;
  45.             });
  46.         };
  47.        
  48.        
  49.         /** lazy load flex slider **/
  50.         var loadotherimage = function(sel) {
  51.             var datasrc = $('img',sel).attr('data-src');
  52.             if(datasrc != undefined) {                         
  53.                 var img = new Image();
  54.                 $(img).css("opacity" , 0);
  55.                 $('a', sel).html('').append(img);
  56.                 $(img).load(function(){
  57.                     $('img', sel).stop().animate({"opacity" : 1}, "fast");
  58.                 }).attr('src', datasrc);
  59.             }
  60.         };
  61.        
  62.         var loadnextprev = function(slider) {                  
  63.             // load next slide
  64.             var next = $('.flex-active-slide', slider).next();
  65.             loadotherimage(next);
  66.            
  67.             // load prev slide
  68.             var prev = $('.flex-active-slide', slider).prev();
  69.             loadotherimage(prev);
  70.         };
  71.        
  72.         var lazyloadflex = function(slider) {                  
  73.             var datasrc = $('.flex-active-slide img', slider).attr('data-src');
  74.             if(datasrc != undefined){
  75.                 var img = new Image();
  76.                 $(img).css("opacity" , 0);
  77.                 $('.flex-active-slide a', slider).html('').append(img);
  78.                
  79.                 $(img).load(function(){
  80.                     $('.flex-active-slide img', slider).stop().animate({"opacity" : 1}, "fast");
  81.                     loadnextprev(slider);
  82.                 }).attr('src', datasrc);
  83.             } else {
  84.                 if($('.flex-active-slide img', slider).css('opacity') == 0) {
  85.                     $('.flex-active-slide img', slider).animate({"opacity" : 1}, "fast");
  86.                 }
  87.                 loadnextprev(slider);
  88.             }
  89.         };
  90.         /** lazy load flex slider **/
  91.        
  92.         var type_gallery = function(ele){
  93.             $(ele).fotorama({
  94.                 allowfullscreen: true,
  95.                 arrows: 'true',
  96.                 nav: 'dots',
  97.                 fit : 'cover',
  98.                 maxwidth: '100%',
  99.                 ratio: 16/10,
  100.                 fit: 'contain'
  101.             });
  102.         };
  103.        
  104.         var type_audio = function(ele){
  105.             var audioresize = function () {
  106.                 var w = parseInt($(ele).css('width'),10);
  107.                 var h = 30;
  108.                 $('audio', ele).attr('width', '100%').attr('height', h);
  109.             };         
  110.            
  111.             $(window).resize(function(){audioresize();});          
  112.             $(window).resize();
  113.            
  114.             $('audio', ele).mediaelementplayer({
  115.                 pluginPath: template_css + "mediaelement/"
  116.             });
  117.         };
  118.        
  119.         var type_video = function(ele){
  120.             /** set size of video & image **/
  121.             $('video', ele).css({'width' : '100%','height': '100%'});
  122.             $('img', ele).css({'width': '100%','height': '100%'});         
  123.             $('video', ele).mediaelementplayer({});
  124.         };
  125.        
  126.         var youtube_parser = function (url)
  127.         {
  128.             var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  129.             var match = url.match(regExp);
  130.            
  131.             if ( match && match[7].length == 11 ) {
  132.                 return match[7];
  133.             } else {
  134.                 alert("Url Incorrect");
  135.             }
  136.         };
  137.        
  138.         var vimeo_parser = function (url)
  139.         {
  140.             var regExp = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
  141.             var match = url.match(regExp);
  142.  
  143.             if (match){
  144.                 return match[2];
  145.             }else{
  146.                 alert("not a vimeo url");
  147.             }
  148.  
  149.         };
  150.        
  151.         var type_video_youtube = function(ele){
  152.             var youtube_id = youtube_parser($('.video-container', ele).attr('data-src'));
  153.             var iframe = '<iframe width="700" height="500" src="http://www.youtube.com/embed/' + youtube_id +  '?showinfo=0&theme=light&autohide=1&rel=0&wmode=opaque" frameborder="0" allowfullscreen></iframe>';
  154.             $('.video-container', ele).append(iframe);
  155.         };
  156.        
  157.         var type_video_vimeo = function(ele){
  158.             var vimeo_id = vimeo_parser($('.video-container', ele).attr('data-src'));
  159.             var iframe = '<iframe src="http://player.vimeo.com/video/' + vimeo_id + '?title=0&byline=0&portrait=0" width="700" height="500" frameborder="0"></iframe>';
  160.             $('.video-container', ele).append(iframe);
  161.         };
  162.        
  163.         var type_ba = function (ele) {
  164.             $('.ba-gallery', ele).wpwBAgallery({
  165.                 height  :   'auto',
  166.                 width   :   'auto'
  167.             });
  168.         };
  169.        
  170.         $(this).each(function(){
  171.             var type = $(this).attr('data-type');  
  172.             switch(type) {
  173.                 case "gallery" :
  174.                     type_gallery(this);
  175.                     break;
  176.                 case "image" :
  177.                     type_image(this);
  178.                     break;
  179.                 case "video" :
  180.                     type_video(this);
  181.                     break;
  182.                 case "youtube" :
  183.                     type_video_youtube(this);
  184.                     break;
  185.                 case "vimeo" :
  186.                     type_video_vimeo(this);
  187.                     break; 
  188.                 case "audio" :
  189.                     type_audio(this);
  190.                     break;
  191.                 case "ba" :
  192.                     type_ba(this);
  193.                     break;
  194.                 default :
  195.                     break;
  196.             };
  197.         });
  198.        
  199.         $(window).bind("jmainremove", function(){          
  200.         });
  201.     };
  202. })(jQuery);
  203.  
  204. function setupCarousel(itemTotal, navstyle, tourl){
  205.     /** carousel **/
  206.     var minItem;
  207.     if(scw(iphonewidth)) {
  208.         minItem = itemTotal;
  209.     } else {
  210.         minItem = 4;
  211.     }
  212.    
  213.     jQuery('.carousel').elastislide({
  214.         imageW          : 180,
  215.         minItems        : minItem,
  216.         navigatorStyle  : navstyle,
  217.         onClick         : function(i){         
  218.             if($('a', i).attr('data-tourl') == "false") {
  219.                 return false;
  220.             } else {
  221.                 if(jcurtain == 1) {
  222.                     window.tourl($('a',i).attr('href'));
  223.                     return false;
  224.                 } else {
  225.                     window.location = $('a',i).attr('href');
  226.                     return true;
  227.                 }
  228.             }
  229.         }
  230.     });
  231. }
  232.  
  233. (function($) {
  234.     $.fn.jegfolio = function( options )
  235.     {
  236.         var settings = {
  237.             minItem         : 6
  238.         };
  239.  
  240.         if (options) {
  241.             var options = $.extend(settings, options); 
  242.         } else {
  243.             var options = $.extend(settings);                  
  244.         }
  245.        
  246.        
  247.         /** public **/
  248.         var touch                   = false;
  249.         if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
  250.             touch = true;
  251.         }
  252.        
  253.        
  254.         /** carousel **/
  255.         setupCarousel(options.minItem, 1, true);
  256.        
  257.         /** jeg gallery **/
  258.         $(".gallery-main").jeggallery({
  259.             direction_nav   :  options.direction_nav,
  260.             control_nav     :  options.control_nav         
  261.         });
  262.        
  263.        
  264.         /** portfolio gallery animation **/
  265.         $(".portfolio-gallery li").hover(function(){
  266.            
  267.             $(this).find('.shadow').stop().animate({
  268.                 'height'    : '100%'
  269.             },'fast');
  270.  
  271.             var h = ( ($(this).height() - $(this).find('.desc-holder').height()) / 2 ) - 5;
  272.            
  273.             $(this).find('.desc-holder').stop().animate({
  274.                 'bottom'    : h
  275.             },'fast');
  276.            
  277.         }, function(){
  278.            
  279.             $(this).find('.shadow').stop().animate({
  280.                 'height'    : '0'
  281.             },'fast');
  282.            
  283.             $(this).find('.desc-holder').stop().animate({
  284.                 'bottom'    : '-100'
  285.             },10); 
  286.         });
  287.        
  288.         var attach_social = function ()
  289.         {                  
  290.             var $this       = $('.single-portfolio-like');
  291.             var shareurl    = $('.single-portfolio-like').attr('data-url');
  292.             var imageurl    = $('.single-portfolio-like').attr('data-cover');
  293.            
  294.             /** facebook like **/
  295.             var fbl = $(document.createElement("fb:like"))
  296.                 .attr("href", shareurl)
  297.                 .attr("send", "false")
  298.                 .attr("layout", "button_count")
  299.                 .attr("show_faces", "false");
  300.            
  301.             var fbl = $("<div class='fblio'></div>").append(fbl);                      
  302.             $(".wrapper-social .facebook-sharer").empty().append(fbl);
  303.             FB.XFBML.parse($(".fblio", $this).get(0));         
  304.            
  305.             /** pinterest button **/
  306.             var pinurl = "http://pinterest.com/pin/create/button/?url="
  307.                 + encodeURIComponent(shareurl) + "&media=" + encodeURIComponent(imageurl);
  308.            
  309.             var pinvar = $(document.createElement("a"))
  310.                     .attr("href", pinurl)
  311.                     .attr("class", "pin-it-button")
  312.                     .attr("count-layout", "horizontal")
  313.                     .html('<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />');
  314.            
  315.             $(".wrapper-social .pinterest-sharer")
  316.                 .append(pinvar)
  317.                 .append('<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>');                      
  318.            
  319.            
  320.             /** google plus share **/
  321.             var gplusvar = $('<g:plusone size="medium" annotation="bubble" href="'
  322.                     + encodeURIComponent(shareurl) + '"></g:plusone>');
  323.             $(".wrapper-social .google-sharer").append(gplusvar);
  324.             gapi.plusone.go("google-sharer");
  325.            
  326.             /** twitter sharer **/
  327.             var twt = $(document.createElement("a"))
  328.                     .attr("class", "twitter-share-button")
  329.                     .attr("href", "http://twitter.com/share")
  330.                     .attr("data-url", document.URL)
  331.                     .html("Tweet");
  332.            
  333.             var twt = $("<div class='twtlio'></div>").append(twt);
  334.             $(".wrapper-social .twitter-sharer").append(twt);
  335.             twttr.widgets.load();
  336.            
  337.         };
  338.        
  339.        
  340.         attach_social();
  341.        
  342.     };
  343. })(jQuery);
  344.  
  345.  
  346. (function($) {
  347.     $.fn.jegblog = function( options )
  348.     {      
  349.         var settings = {
  350.             minItem         : 4
  351.         };
  352.  
  353.         if (options) {
  354.             var options = $.extend(settings, options); 
  355.         } else {
  356.             var options = $.extend(settings);
  357.         }
  358.        
  359.        
  360.         /** public **/
  361.         var touch                   = false;
  362.         if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
  363.             touch = true;
  364.         }
  365.        
  366.         var body = $(this);
  367.        
  368.         /** gallery **/
  369.         $(".blog-gallery-type", body).jeggallery({
  370.             direction_nav   :  options.direction_nav,
  371.             control_nav     :  options.control_nav
  372.         });
  373.        
  374.        
  375.         /** attach photoswipe **/
  376.         if($('.blog-gallery li a').length > 0 || $('.photoswipe').length > 0) {
  377.            
  378.             $('.blog-gallery li a').click(function() { return false; });
  379.             $('.photoswipe').click(function() { return false; });
  380.            
  381.             if(!options.uselightbox) {
  382.                 (function(PhotoSwipe){
  383.                     $(".blog-gallery").each(function(){
  384.                         $(this).find('a').photoSwipe({
  385.                             backButtonHideEnabled           : false,
  386.                             captionAndToolbarAutoHideDelay  : 0,
  387.                             allowUserZoom                   : true,
  388.                             imageScaleMethod                : 'fitNoUpscale',
  389.                             getImageSource                  : function(obj){ return $(obj).attr('href'); },
  390.                             getImageCaption                 : function(obj){ return $(obj).attr('data-title'); }
  391.                         });
  392.                     });
  393.                    
  394.                     $(".photoswipe").each(function(){
  395.                         $(this).photoSwipe({
  396.                             backButtonHideEnabled           : false,
  397.                             captionAndToolbarAutoHideDelay  : 0,
  398.                             allowUserZoom                   : true,
  399.                             imageScaleMethod                : 'fitNoUpscale',
  400.                             getImageSource                  : function(obj){ return $(obj).attr('href'); },
  401.                             getImageCaption                 : function(obj){ return $(obj).attr('data-title'); }
  402.                         });
  403.                     });
  404.                    
  405.                 }(window.Code.PhotoSwipe));
  406.             } else {
  407.                 $(".blog-gallery").each(function(){
  408.                     $(this).find('a').lightbox();                  
  409.                 });
  410.                 $(".photoswipe").each(function(){
  411.                     $(this).find('a').lightbox();
  412.                 });
  413.             }
  414.            
  415.         }
  416.        
  417.         /** carousel **/
  418.         setupCarousel(options.minItem, 2, false);          
  419.        
  420.         /** comment **/
  421.         $(".replycomment").click(function(){
  422.             var i = $(this).parents(".coment-box").parent();
  423.             var f = $("#respond");
  424.             var x = $("<div id='comment-box-reply'></div>");
  425.             var t = $("<div id='temp-comment-holder' style='display:none;'></div>");
  426.             var p = $("#comment_parent");          
  427.             var c = "data-comment-id";
  428.            
  429.             $(".closecommentform").hide();
  430.             $(".replycomment").show();
  431.             $("#comment-box-reply").remove();
  432.            
  433.             if(!$("#temp-comment-holder").length) {
  434.                 t.insertBefore(f);
  435.             }
  436.  
  437.            
  438.             x.insertAfter($(i).find('.coment-box-inner')).append(f);
  439.             p.val($(this).attr(c));
  440.            
  441.             $(this).hide();
  442.            
  443.             $(i).find(".closecommentform").show().click(function(){
  444.                 f.insertAfter($("#temp-comment-holder"));
  445.                 $("#temp-comment-holder").remove();
  446.                 $("#comment-box-reply").remove();
  447.                 $(this).hide();
  448.                 $(i).find('.replycomment').show();
  449.                 $("#comment_parent").val(0);
  450.             });        
  451.         });
  452.        
  453.     };
  454. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement