Advertisement
jegtheme

jeglio.full.js

Jul 21st, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($) {
  2.     $.Isotope.prototype._getCenteredMasonryColumns = function() {
  3.         this.width = this.element.width();
  4.        
  5.         var parentWidth = this.element.parent().width();
  6.        
  7.                       // i.e. options.masonry && options.masonry.columnWidth
  8.         var colW = this.options.masonry && this.options.masonry.columnWidth ||
  9.                       // or use the size of the first item
  10.                       this.$filteredAtoms.outerWidth(true) ||
  11.                       // if there's no items, use size of container
  12.                       parentWidth;
  13.        
  14.         var cols = Math.floor( parentWidth / colW );
  15.         cols = Math.max( cols, 1 );
  16.    
  17.         // i.e. this.masonry.cols = ....
  18.         this.masonry.cols = cols;
  19.         // i.e. this.masonry.columnWidth = ...
  20.         this.masonry.columnWidth = colW;
  21.     };
  22.      
  23.     $.Isotope.prototype._masonryReset = function() {
  24.         // layout-specific props
  25.         this.masonry = {};
  26.         // FIXME shouldn't have to call this again
  27.         this._getCenteredMasonryColumns();
  28.         var i = this.masonry.cols;
  29.         this.masonry.colYs = [];
  30.         while (i--) {
  31.             this.masonry.colYs.push( 0 );
  32.         }
  33.     };
  34.    
  35.     $.Isotope.prototype._masonryResizeChanged = function() {
  36.         var prevColCount = this.masonry.cols;
  37.         // get updated colCount
  38.         this._getCenteredMasonryColumns();
  39.         return ( this.masonry.cols !== prevColCount );
  40.     };
  41.      
  42.     $.Isotope.prototype._masonryGetContainerSize = function() {
  43.         var unusedCols = 0,
  44.             i = this.masonry.cols;
  45.         // count unused columns
  46.         while ( --i ) {
  47.             if ( this.masonry.colYs[i] !== 0 ) {
  48.                 break;
  49.             }
  50.             unusedCols++;
  51.         }
  52.        
  53.         return {
  54.             height : Math.max.apply( Math, this.masonry.colYs ),
  55.               // fit container to columns that have been used;
  56.             width : ((this.masonry.cols - unusedCols) * this.masonry.columnWidth) + 5
  57.         };
  58.     };
  59. });
  60. /** jeglio v1 **/
  61.  
  62. (function($) {
  63.     $.fn.jeglio = function( options )
  64.     {
  65.         // item mode : 0 = normal, 1 = masonry
  66.         var settings = {
  67.             expand_script       : 1, // 0 = fotorama, 1 = flexslider
  68.             itemWidth           : 180,
  69.             itemHeight          : 210,
  70.             itemMode            : 0,
  71.             itemHeightWide      : 550,
  72.             galleryDim          : 3,
  73.             descDim             : 1,
  74.             theatherMode        : false,
  75.             scrolltop           : 50,
  76.             flexDelay           : 7000,
  77.             zoomDelay           : 7000,
  78.             direction_nav       : 0,
  79.             control_nav         : 1,
  80.             portfolio_caption   : 0,
  81.             themes_schema       : "light",
  82.             loadAnimation       : 'sequpfade'  // normal | fade | seqfade | upfade | sequpfade | randomfade | randomupfade
  83.         };
  84.  
  85.         if (options) {
  86.             var options = $.extend(settings, options); 
  87.         } else {
  88.             var options = $.extend(settings);                  
  89.         }
  90.        
  91.         var $container              = $(this);
  92.         var lastclicked             = undefined;
  93.         var layoutmode              = undefined;
  94.         var itemWidth               = undefined;
  95.         var itemHeight              = undefined;
  96.         var itemGalleryWidth        = undefined;
  97.         var itemDescriptionWidth    = undefined;   
  98.         var touch                   = false;
  99.         var photoswipe              = undefined;
  100.         var iw                      = undefined;
  101.         var ih                      = undefined;
  102.         var doctitle                = document.title;
  103.         var iphonewidth             = 150;
  104.         var firstloaded             = true;
  105.         var itemTopPos              = undefined;
  106.         var itemLeftPos             = undefined;
  107.  
  108.         if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
  109.             touch = true;
  110.         }
  111.        
  112.         var galleryDim      = parseInt(options.galleryDim);
  113.         var descDim         = parseInt(options.descDim);
  114.         var lockClick       = false;
  115.        
  116.         var hovered = function(e)
  117.         {
  118.             var $this = $(e.currentTarget);
  119.             var th = $this.height();
  120.            
  121.             /** show type of item **/
  122.             var i = $this.find('i');           
  123.             $(i.get(0)).addClass('display-inline-table');
  124.            
  125.             $this.find('.shadow').stop().animate({
  126.                 height : th
  127.             }, 'fast');
  128.            
  129.             var descholder = $this.find('.desc-holder');
  130.             var dh = ( th - descholder.height() )  / 2;
  131.             $this.find('.desc-holder').stop().animate({
  132.                 bottom : dh
  133.             }, 'fast', function(){ 
  134.                 if(touch) {
  135.                     link = $($this.find('a').get(0)).attr('href');
  136.                     window.location = link;
  137.                 }
  138.             });
  139.         };
  140.        
  141.         var unhovered = function(e)
  142.         {
  143.             var $this = $(e.currentTarget);
  144.             var th = $this.height();
  145.            
  146.             // show type of item
  147.             var i = $this.find('i');           
  148.             $(i.get(0)).removeClass('display-inline-table');
  149.            
  150.             $this.find('.shadow').stop().animate({
  151.                 height : 0
  152.             }, 'fast');
  153.             $this.find('.desc-holder').stop().animate({
  154.                 bottom : 0
  155.             }, 'fast');
  156.         };
  157.        
  158.         var type_video = function(ele)
  159.         {
  160.             var w = $(ele.itemGallery).css('width');
  161.             var h = $(ele.itemGallery).css('height');
  162.            
  163.             $('video', ele.itemGallery).attr('width', w).attr('height', h);
  164.             $('img', ele.itemGallery).css('width', w).css('height', h);
  165.             $('video', ele.itemGallery).mediaelementplayer({});
  166.         };
  167.        
  168.         /** vimeo & youtube **/
  169.         var youtube_parser = function (url)
  170.         {
  171.             var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  172.             var match = url.match(regExp);
  173.            
  174.             if ( match && match[7].length == 11 ) {
  175.                 return match[7];
  176.             } else {
  177.                 alert("Url Incorrect");
  178.             }
  179.         };
  180.        
  181.         var vimeo_parser = function (url)
  182.         {
  183.             var regExp = /http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/;
  184.             var match = url.match(regExp);
  185.  
  186.             if (match){
  187.                 return match[2];
  188.             }else{
  189.                 alert("not a vimeo url");
  190.             }
  191.         };
  192.        
  193.         var type_video_youtube = function(ele)
  194.         {
  195.             var w = $(ele.itemGallery).css('width');
  196.             var h = $(ele.itemGallery).css('height');
  197.            
  198.             var youtube_id = youtube_parser($('.video-youtube-container', ele.itemGallery).attr('src'));
  199.             var iframe = '<iframe width="' + w + '" height="' + h + '" src="http://www.youtube.com/embed/' + youtube_id +  '?showinfo=0&theme=light&autohide=1&rel=0&wmode=opaque" frameborder="0" allowfullscreen></iframe>';
  200.             $('.video-youtube-container', ele.itemGallery).append(iframe);
  201.         };
  202.        
  203.         var type_video_vimeo = function(ele)
  204.         {
  205.             var w = $(ele.itemGallery).css('width');
  206.             var h = $(ele.itemGallery).css('height');
  207.            
  208.             var vimeo_id = vimeo_parser($('.video-vimeo-container', ele.itemGallery).attr('src'));
  209.             var iframe = '<iframe src="http://player.vimeo.com/video/' + vimeo_id + '?title=0&byline=0&portrait=0" webkitallowfullscreen mozallowfullscreen allowfullscreen  width="' + w + '" height="' + h + '" frameborder="0"></iframe>';
  210.             $('.video-vimeo-container', ele.itemGallery).append(iframe);
  211.         };
  212.        
  213.  
  214.         var type_audio = function(ele)
  215.         {
  216.             var w = $(ele.itemGallery).css('width');
  217.             var h = 30;
  218.             $('audio', ele.itemGallery).attr('width', w).attr('height', h);
  219.             $('audio', ele.itemGallery).mediaelementplayer({
  220.                 pluginPath: template_css + "mediaelement/"
  221.             });
  222.         }; 
  223.        
  224.         var type_gallery = function(ele)
  225.         {
  226.             var loadotherimage = function(sel) {
  227.                 var datasrc = $('img',sel).attr('data-src');
  228.                 if(datasrc != undefined) {                         
  229.                     var img = new Image();
  230.                     $(img).css("opacity" , 0);
  231.                     $('a', sel).html('').append(img);
  232.                     $(img).load(function(){
  233.                         $('img', sel).stop().animate({"opacity" : 1}, "fast");
  234.                     }).attr('src', datasrc);
  235.                 }
  236.             };
  237.            
  238.             var loadnextprev = function(slider) {                  
  239.                 // load next slide
  240.                 var next = $('.flex-active-slide', slider).next();
  241.                 loadotherimage(next);
  242.                
  243.                 // load prev slide
  244.                 var prev = $('.flex-active-slide', slider).prev();
  245.                 loadotherimage(prev);
  246.             };
  247.            
  248.             var lazyloadflex = function(slider) {                  
  249.                 var datasrc = $('.flex-active-slide img', slider).attr('data-src');
  250.                 if(datasrc != undefined){
  251.                     var img = new Image();
  252.                     $(img).css("opacity" , 0);
  253.                     $('.flex-active-slide a', slider).html('').append(img);
  254.                    
  255.                     $(img).load(function(){
  256.                         $('.flex-active-slide img', slider).stop().animate({"opacity" : 1}, "fast");
  257.                         loadnextprev(slider);
  258.                     }).attr('src', datasrc);
  259.                 } else {
  260.                     if($('.flex-active-slide img', slider).css('opacity') == 0) {
  261.                         $('.flex-active-slide img', slider).animate({"opacity" : 1}, "fast");
  262.                     }
  263.                     loadnextprev(slider);
  264.                 }
  265.             };
  266.            
  267.             var showdescription = function(slider) {
  268.                 if(options.portfolio_caption == 1) {
  269.                     var slidertitle = $('.flex-active-slide a', slider).data("title");
  270.                     $(".item-description-wrapper").html(slidertitle);
  271.  
  272.  
  273.                     if(slider.count === undefined) {
  274.                         console.log('hitting here...');
  275.                         slidertitle = $(".item-gallery-image", slider).data("title");
  276.                         $(".item-description-wrapper").html(slidertitle);
  277.                     }
  278.                 }
  279.             };
  280.  
  281.             if(options.expand_script ===  1) {
  282.                 type_image(ele);
  283.                 $(ele.itemGallery).flexslider({
  284.                     animation: "slide",
  285.                     slideDirection: "horizontal",
  286.                     slideshow: true,
  287.                     animationDuration: 300,
  288.                     slideshowSpeed: options.flexDelay,
  289.                     directionNav: options.direction_nav,
  290.                     controlNav: options.control_nav,
  291.                     keyboardNav: true,
  292.                     mousewheel: false,
  293.                     prevText: "Previous",
  294.                     nextText: "Next",
  295.                     pausePlay: false,
  296.                     pauseText: 'Pause',
  297.                     playText: 'Play',
  298.                     randomize: false,
  299.                     slideToStart: 0,
  300.                     animationLoop: true,
  301.                     pauseOnAction: true,
  302.                     pauseOnHover: false,
  303.                     controlsContainer: "",
  304.                     manualControls: "",
  305.                     start: function(slider) {
  306.                         lazyloadflex(slider);
  307.                         showdescription(slider);
  308.                     },
  309.                     end: function(slider){},
  310.                     before: function(slider){},
  311.                     after: function(slider){
  312.                         lazyloadflex(slider);
  313.                         showdescription(slider);
  314.                     }
  315.                 });
  316.             } else {
  317.                 var fitmode = ( options.fullimage === 0 ) ? "cover" : "contain" ;
  318.                 $(ele.itemGallery).fotorama({
  319.                     allowfullscreen: true,
  320.                     arrows: 'true',
  321.                     width: $(ele.itemGallery).width(),
  322.                     height : $(ele.itemGallery).height(),
  323.                     maxwidth: $(ele.itemGallery).width(),
  324.                     maxheight : $(ele.itemGallery).height(),
  325.                     nav: 'dots',
  326.                     fit : fitmode
  327.                 });
  328.             }
  329.         }; 
  330.        
  331.         var type_image = function(ele)
  332.         {
  333.             if(!touch) {
  334.                 $(ele.itemGallery).find('.item-gallery-image').jtooltip({});
  335.             }
  336.            
  337.             /** photo swipe **/
  338.             (function(PhotoSwipe){
  339.                 photoswipe = $(ele.itemGallery).find('.item-gallery-image').photoSwipe({
  340.                     backButtonHideEnabled           : false,
  341.                     captionAndToolbarAutoHideDelay  : 0,
  342.                     slideshowDelay                  : options.zoomDelay,
  343.                     slideSpeed                      : 500,
  344.                     imageScaleMethod                : 'fitNoUpscale',
  345.                     allowUserZoom                   : false,
  346.                     getImageSource                  : function(obj){ return $(obj).attr('data'); },
  347.                     getImageCaption                 : function(obj){ return $(obj).attr('data-title'); }
  348.                 });
  349.                 photoswipe.addEventHandler(PhotoSwipe.EventTypes.onHide, function(e){
  350.                     $container.isotope("reLayout");
  351.                 });
  352.             }(window.Code.PhotoSwipe));
  353.            
  354.             $('.item-gallery-image').click(function(){                     
  355.                 return false;
  356.             });
  357.         };
  358.        
  359.         var bindlovethis = function (i) {
  360.             $(".love-this", i).each(function(){
  361.                 $(this).click(function(){
  362.                     if(!$(this).hasClass("voted")) {                                   
  363.                         var $this = $(this);
  364.                         $this.addClass("locked");
  365.                         var lovecounter = $this.find('.love-counter');
  366.                         $(lovecounter).text('Loading ...').addClass('italic');
  367.  
  368.                         $.ajax({
  369.                             url: admin_url,
  370.                             type : "post",
  371.                             dataType : "json",
  372.                             data : {
  373.                                 postid      : $(this).attr('data-id'),
  374.                                 action      : 'vote_post'
  375.                             },
  376.                             success: function(data) {
  377.                                 $(lovecounter).text(data.msg);
  378.                                
  379.                                 setTimeout(function(){
  380.                                     if(data.id == 3) {
  381.                                         $this.attr('data-counter', data.total);
  382.                                         $(lovecounter).removeClass('italic');
  383.                                         $this.addClass('voted');
  384.                                     }
  385.  
  386.                                     $this.removeClass("locked");
  387.                                     $(lovecounter).text($this.attr('data-counter')).removeClass('italic');                                 
  388.                                 }, 1500);
  389.                             }
  390.                         });
  391.                     } else {
  392.                         var votedtext = $(this).attr('data-voted');
  393.                     }
  394.                 }).hover(function(){                               
  395.                         if($(this).hasClass("voted")) {
  396.                             var votedtext = $(this).attr('data-voted');
  397.                             var lovecounter = $(this).find('.love-counter');                       
  398.                             lovecounter.text(votedtext);
  399.                         } else {
  400.                             if(!$(this).hasClass("locked")) {                                      
  401.                                 var votedtext = $(this).attr('data-vote');
  402.                                 var lovecounter = $(this).find('.love-counter');                       
  403.                                 lovecounter.text(votedtext);
  404.                             }
  405.                         }
  406.                     }, function(){
  407.                         if(!$(this).hasClass("locked")) {
  408.                             var countertext = $(this).attr('data-counter');
  409.                             var lovecounter = $(this).find('.love-counter');                       
  410.                             lovecounter.text(countertext); 
  411.                         }
  412.                 });
  413.             });
  414.         };
  415.        
  416.         var show_next_prev_popup = function (i) {          
  417.             $(i).find('.item-prev, .item-next').tipTip({maxWidth: "auto", edgeOffset: 10, defaultPosition: "top", delay : 100});           
  418.         };
  419.        
  420.         var theatherClose = function(i, id, changeLocation)
  421.         {
  422.             closePrev(changeLocation);
  423.            
  424.             if(lastclicked) {
  425.                 $(lastclicked.i).find('.love-this').replaceWith(function(){
  426.                     return $('<div>').append($(i).find('.love-this').clone()).html();
  427.                 });
  428.                 bindlovethis(lastclicked.i);
  429.             }
  430.            
  431.             // stop music & video
  432.             $('video, audio', id).each(function() {
  433.                 $(this)[0].pause();
  434.             });
  435.            
  436.             $(i).fadeOut("fast", function(){
  437.                 $(id).remove();
  438.                 $("html").css("overflow-y", "auto");
  439.                 $container.css({'max-height' : '100%'});
  440.             });        
  441.         };
  442.        
  443.         // $this => clicked item
  444.         var contentTheater = function($this, title, type, love, voted){
  445.             var i               = $("#item-theater-overlay");
  446.             var itd             = $("#item-theater-detail", i);
  447.             var id              = $(".item-detail", i);
  448.             var ele             = itemDetailElement(id);
  449.             var openprev        = false;                   
  450.             var flagTheater     = 0;
  451.            
  452.             /** close previous opened section **/
  453.             if(lastclicked != undefined) {
  454.                 closePrev(false);
  455.             }          
  456.            
  457.             $("html, body").animate({
  458.                 scrollTop: 0
  459.             }, function(){
  460.                 setTimeout(function(){
  461.                     if(!flagTheater) {
  462.                         showTheater();
  463.                         flagTheater++;
  464.                     }
  465.                 }, 500);
  466.             });  
  467.            
  468.             var showTheater = function() {
  469.                 // hack for ipad
  470.                 if(touch) {
  471.                     var wh = $(window).height();
  472.                     var ofh = $container.offset();
  473.                     var mbtm = parseInt($container.css('margin-bottom'), 10);
  474.                     ch = wh - ofh.top - mbtm;
  475.                     $container.css({'max-height' : ch});
  476.                 } else {
  477.                     $("html").css("overflow-y", "hidden");
  478.                 }
  479.                
  480.                 /*** show item detail & set opacity ***/
  481.                 $(id).show().css({"opacity" : 1});
  482.                 $(itd).css({"display" : "block"});
  483.                 $(i).fadeIn("fast", function(){
  484.                    
  485.                     $(itd).css({
  486.                         'width'         : itemWidth,
  487.                         'height'        : itemHeight,
  488.                         'top'           : itemTopPos,
  489.                         'left'          : itemLeftPos,
  490.                         'position'      : 'absolute'
  491.                     });
  492.                    
  493.                     /** title **/
  494.                     document.title = title.unescapeHtml() + " - "  + doctitle.unescapeHtml();
  495.                    
  496.                     $(ele.itemGallery).css('width', itemGalleryWidth).css('height', itemHeight);
  497.                     $(ele.itemDescription).css('width', itemDescriptionWidth);
  498.                    
  499.                     // set next & prev
  500.                     var nextprev = get_next_prev($this);
  501.                     $(i).find('.item-prev').parent().attr('href' , nextprev.prev);
  502.                     $(i).find('.item-next').parent().attr('href' , nextprev.next);                 
  503.                    
  504.                     // love counter
  505.                     $(i).find('.love-this').replaceWith(function(){                    
  506.                         return $('<div>').append($this.find('.love-this').clone()).html();
  507.                     });
  508.                    
  509.                     bindlovethis(i);
  510.                    
  511.                     // bug waktu back button
  512.                     var dww = itemDescriptionWidth - parseInt(ele.descWrapper.css('margin-left'), 10) - parseInt(ele.descWrapper.css('margin-right'), 10);                 
  513.                                    
  514.                     $(ele.descWrapper).css({
  515.                         height          : (itemHeight - 50),
  516.                         width           : dww
  517.                     }).jScrollPane();
  518.                    
  519.                     switch(type) {
  520.                         case "gallery" :
  521.                             type_gallery(ele);
  522.                             break;
  523.                         case "image" :
  524.                             type_image(ele);
  525.                             break;
  526.                         case "video" :
  527.                             type_video(ele);
  528.                             break;
  529.                         case "youtube" :
  530.                             type_video_youtube(ele);
  531.                             break;
  532.                         case "vimeo" :
  533.                             type_video_vimeo(ele);
  534.                             break; 
  535.                         case "audio" :
  536.                             type_audio(ele);
  537.                             break;
  538.                         default :
  539.                             break;
  540.                     };
  541.                    
  542.                     // release lock
  543.                     lockClick = false;
  544.                    
  545.                     // save last click element
  546.                     lastclicked = {
  547.                         i : $this,
  548.                         t : type
  549.                     };
  550.                    
  551.                     setTimeout(function()
  552.                     {
  553.                         var hash = location.hash.replace("#/", "");
  554.                         var hashres = hash.split(':');
  555.                         var openlarge = hashres[1];                
  556.                        
  557.                         if(openlarge != undefined) {
  558.                             (function(PhotoSwipe){
  559.                                 $(PhotoSwipe.instances[0].originalImages[openlarge]).trigger('click');
  560.                             }(window.Code.PhotoSwipe));
  561.                         }
  562.                     }, 500);
  563.                    
  564.                     /** close when background clicked **/
  565.                     $(i).click(function(ev){
  566.                         if (ev.target == this){
  567.                             theatherClose(i, id, true);                    
  568.                         }                  
  569.                     });
  570.                    
  571.                     /** bind close me button **/
  572.                     $(".closeme", itd).show().bind("click", function(){
  573.                         theatherClose(i, id, true);
  574.                     });
  575.                 });
  576.             };
  577.                                
  578.         };
  579.        
  580.         var get_next_prev = function($this)
  581.         {
  582.             /** bind prev & next **/
  583.             var prevlink = undefined;
  584.             var nextlink = undefined;
  585.            
  586.             /** find prev link end **/
  587.             var eleprev = $this;
  588.             while(eleprev = $(eleprev).prev()){
  589.                 if(!eleprev.hasClass('isotope-hidden')) {
  590.                     break;
  591.                 }
  592.             }
  593.            
  594.             var elenext = $this;
  595.             while(elenext = $(elenext).next()){
  596.                 if(!elenext.hasClass('isotope-hidden')) {
  597.                     break;
  598.                 }
  599.             }
  600.            
  601.             prevlink = $($(eleprev).find('a').get(0)).attr('href');
  602.             nextlink = $($(elenext).find('a').get(0)).attr('href');
  603.        
  604.             if(prevlink === undefined) {
  605.                 eleprev = $('.item:last-child', $container);
  606.                 while(eleprev){    
  607.                     if(!eleprev.hasClass('isotope-hidden')) {
  608.                         break;
  609.                     }
  610.                     eleprev = $(eleprev).prev();
  611.                 }
  612.                 prevlink = $($(eleprev).find('a').get(0)).attr('href');
  613.             }
  614.            
  615.             if(nextlink === undefined) {
  616.                 elenext = $('.item:first-child', $container);
  617.                 while(elenext){
  618.                     if(!elenext.hasClass('isotope-hidden')) {
  619.                         break;
  620.                     }
  621.                     elenext = $(elenext).next();
  622.                 }
  623.                 nextlink = $($(elenext).find('a').get(0)).attr('href');
  624.             }
  625.            
  626.             $this.find('.item-prev').parent().attr('href' , prevlink);
  627.             $this.find('.item-next').parent().attr('href' , nextlink);
  628.            
  629.             show_next_prev_popup($this);
  630.            
  631.             return {
  632.                 next : nextlink,
  633.                 prev : prevlink
  634.             };
  635.             /** find prev link end **/
  636.         };
  637.        
  638.         // this clicked item
  639.         var contentLoaded = function($this, firstLoaded, title, type)
  640.         {
  641.             var ele             = itemDetailElement($this);    
  642.                        
  643.             /** close previous opened section **/      
  644.             if(lastclicked != undefined) {
  645.                 closePrev(false);
  646.             }
  647.            
  648.             $this.animate({
  649.                 width: itemWidth,
  650.                 height: itemHeight
  651.             }, 400, function () {
  652.                 /** hide item wrapper **/
  653.                 $(ele.itemWrapper).hide();
  654.                
  655.                 /** bind close me button **/
  656.                 $(ele.closeme).show().bind("click", function(){
  657.                     closePrev(true);
  658.                 });
  659.                
  660.                 /** add class unfolded **/
  661.                 $this.addClass("unfolded");            
  662.                
  663.                 /** find prev link start **/
  664.                 var nextprev = get_next_prev($this);
  665.                 $this.find('.item-prev').parent().attr('href' , nextprev.prev);
  666.                 $this.find('.item-next').parent().attr('href' , nextprev.next);
  667.                 /** find prev link end **/
  668.                
  669.                 var builditemdetail = function () {
  670.  
  671.                     /** item gallery & description width & height **/
  672.                     $(ele.itemGallery).css('width', itemGalleryWidth).css('height', itemHeight);
  673.                     $(ele.itemDescription).css('width', itemDescriptionWidth);
  674.  
  675.                     /** show item detail **/
  676.                     $(ele.itemDetail).show().animate({opacity : '1' });
  677.                                    
  678.                     if(firstLoaded)
  679.                     {
  680.                         /** set title & type **/
  681.                         $this.attr('data-title' , title);
  682.                         $this.attr('data-type'  , type);       
  683.                        
  684.                         /** assign scroll pane **/
  685.                         var width = ele.descWrapper.css('width');
  686.                        
  687.                         // bug waktu back button
  688.                         var dww = itemDescriptionWidth - parseInt(ele.descWrapper.css('margin-left'), 10) - parseInt(ele.descWrapper.css('margin-right'), 10); 
  689.                        
  690.                         $(ele.descWrapper).css({
  691.                             height  : (itemHeight - 50),
  692.                             width   : dww
  693.                         }).jScrollPane();
  694.                        
  695.                         switch(type) {
  696.                             case "gallery" :
  697.                                 setTimeout(function(){
  698.                                     type_gallery(ele);
  699.                                 }, 1000);
  700.                                 break;
  701.                             case "image" :
  702.                                 type_image(ele);
  703.                                 break;
  704.                             case "video" :
  705.                                 type_video(ele);
  706.                                 break;
  707.                             case "youtube" :
  708.                                 type_video_youtube(ele);
  709.                                 break;
  710.                             case "vimeo" :
  711.                                 type_video_vimeo(ele);
  712.                                 break; 
  713.                             case "audio" :
  714.                                 type_audio(ele);
  715.                                 break;
  716.                             default :
  717.                                 break;
  718.                         }
  719.                     }
  720.                    
  721.                     /** title **/
  722.                     document.title = title.unescapeHtml() + " - " + doctitle.unescapeHtml() ;
  723.                    
  724.                     // relase lock
  725.                     lockClick = false;
  726.                    
  727.                     /** animate item to scroll **/
  728.                     setTimeout(function(){
  729.                         $("html, body").animate({
  730.                             scrollTop: $this.offset().top - options.scrolltop
  731.                         }, 500, function(){
  732.                             // cache last clicked object
  733.                             lastclicked = {
  734.                                 i : $this,
  735.                                 t : type
  736.                             };
  737.                            
  738.                             setTimeout(function()
  739.                             {
  740.                                 var hash = location.hash.replace("#/", "");
  741.                                 var hashres = hash.split(':');
  742.                                 var openlarge = hashres[1];                
  743.                                
  744.                                 if(openlarge != undefined) {
  745.                                     (function(PhotoSwipe){
  746.                                         $(PhotoSwipe.instances[0].originalImages[openlarge]).trigger('click');
  747.                                     }(window.Code.PhotoSwipe));
  748.                                 }
  749.                             }, 500);
  750.                            
  751.                         });                    
  752.                     }, 500);
  753.                 };
  754.                
  755.                 /** relayout isotope **/
  756.                 $container.isotope("reLayout", function (e) {
  757.                     builditemdetail();
  758.                 });
  759.             });
  760.         };
  761.            
  762.         var itemDetailElement = function($this)
  763.         {
  764.             return {
  765.                 me                  : $this,
  766.                 shadow              : $this.find('.shadow'),
  767.                 itemWrapper         : $this.find('.item-wrapper'),
  768.                 closeme             : $this.find('.closeme'),
  769.                 itemDetail          : $this.find('.item-detail'),
  770.                 itemGallery         : $this.find('.item-gallery'),
  771.                 itemDescription     : $this.find('.item-description'),
  772.                 descWrapper         : $this.find('.item-desc-wrapper')
  773.             };
  774.         }; 
  775.    
  776.         var closePrev = function (changeLocation)
  777.         {
  778.             /* revert title */
  779.             document.title = doctitle.unescapeHtml();
  780.  
  781.             if(lastclicked === undefined) {
  782.                 return false;
  783.             }
  784.            
  785.             var i = lastclicked.i;
  786.            
  787.             $(i).find('.item-detail').animate({                 // hide item detail
  788.                 opacity     : 0
  789.             }, 100).hide();
  790.                        
  791.             var wh = {
  792.                 width : $(i).attr('data-width') ,
  793.                 height : $(i).attr('data-height')
  794.             };
  795.            
  796.             $(i).animate(wh, 'fast', function(){
  797.                 $(i).find('.closeme').hide();                       // hide close me button            
  798.                 $(i).find('.item-wrapper').show('fast');            // show item wrapper (summary)
  799.                 $(i).removeClass('unfolded');                       // remove class unfolded
  800.                 $(i).find('.item-detail').remove();                 // destroy item detail, we really need this to simplify code & prevent lag when many item loaded
  801.                
  802.                 // normalize item
  803.                 $(i).find('.desc-holder').css({'bottom' : 0}).find('i').removeClass('display-inline-table');               
  804.                 $(i).find('.shadow').removeClass("shadowload").height('0');     // remove white shadow on item
  805.                
  806.                 lastclicked = undefined;
  807.                 $container.isotope("reLayout");
  808.             });
  809.            
  810.             if(changeLocation) {
  811.                 window.location = "#/";
  812.             }
  813.         }; 
  814.        
  815.         var show_loader = function($this)
  816.         {
  817.             // @todo : show small-loader
  818.             var loader          = $this.find('.small-loader');
  819.             var loaderWidth     = $(loader).width();
  820.             var loaderHeight    = $(loader).height();
  821.             var thisWidth       = $this.width();
  822.             var thisHeight      = $this.height();
  823.             var postX           = ( thisWidth / 2 ) - (loaderWidth / 2);
  824.             var postY           = ( thisHeight / 2 ) - (loaderHeight / 2);     
  825.            
  826.             $this.find('.small-loader').show().css('margin-left', postX).css('margin-top', postY);
  827.         };
  828.        
  829.         var hide_loader = function($this)
  830.         {
  831.             $this.find('.small-loader').hide();
  832.         };
  833.        
  834.         var clicked = function($this)
  835.         {
  836.             if(lockClick) {
  837.                 return ;
  838.             }
  839.             else {
  840.                 lockClick           = true; // lock click      
  841.                
  842.                 /** show shadow load **/
  843.                 $this.find('.shadow').addClass('shadowload');
  844.                
  845.                 /** save current width & height **/
  846.                 $this.attr('data-width', $this.width());
  847.                 $this.attr('data-height', $this.height());
  848.                
  849.                 /** if item not exist yet, then we should call ajax and append content **/
  850.                 if($this.find('.item-detail').length <= 0) {
  851.                    
  852.                     /** show loader **/
  853.                     show_loader($this);
  854.                    
  855.                     var ajaxdata = {
  856.                         id      : $this.attr('data-id'),
  857.                         width   : itemGalleryWidth,
  858.                         height  : Math.floor(itemHeight),
  859.                         theater : options.theatherMode,
  860.                         action  : 'get_portfolio_item'
  861.                     };
  862.                    
  863.                     if(options.theatherMode) {
  864.                         if(lastclicked != undefined) {
  865.                             var i               = $("#item-theater-overlay");
  866.                             var id              = $(".item-detail", i);
  867.                             theatherClose(i, id, false);
  868.                         }
  869.                     }
  870.                    
  871.                     var showPasswordForm = function (status) {
  872.                         if(!$(".portopwd").length) {
  873.                             // create password form
  874.                             var pwdtxt = '<div class="portopwd">' +
  875.                                         '<div class="portopwd-wrapper">' +
  876.                                             '<h2>' + options.lang.portfoliotitle +  ' </h2> ' +
  877.                                             '<div>' +
  878.                                                 '<input type="password" class="pwdtxt" placeholder="' + options.lang.passwordplaceholder +  '"/>' +
  879.                                                 '<button href="#" class="btn btn-inverse pwdbtn">' + options.lang.submit + '</button>' +
  880.                                             '</div>' +
  881.                                             '<div class="pwderr"></div>' +
  882.                                             '<div alt="Close" class="pwdcls" style="display: block;">' +
  883.                                                 '<div class="icon-remove icon-white"></div>' +
  884.                                             '</div>' +
  885.                                         '</div>' +
  886.                                       '</div>';
  887.                             $('body').append(pwdtxt);
  888.                         }
  889.                        
  890.                         $(".pwdcls").click(function(){
  891.                             $this.find('.small-loader').hide();                        
  892.                             $(".portopwd").remove();
  893.                             window.location = "#/";                        
  894.                             lockClick           = false;
  895.                             $this.find('.shadow').removeClass("shadowload");
  896.                         });
  897.                        
  898.                         var submitpwdform = function () {
  899.                             ajaxdata.password = $(".pwdtxt").val();
  900.                             $(".portopwd").remove();
  901.                             loadData();
  902.                         };
  903.                        
  904.                         $(".pwdtxt").keypress(function(e){
  905.                             if(e.which == 13){
  906.                                 submitpwdform();
  907.                             }
  908.                         });
  909.                        
  910.                         $(".pwdbtn").click(function(){
  911.                             submitpwdform();
  912.                         });
  913.                     };
  914.                    
  915.                     var attach_social = function ()
  916.                     {                      
  917.                         var shareurl = $($this.get(0)).attr('data-src');
  918.                         var imageurl;
  919.                        
  920.                         if(options.theatherMode) {                         
  921.                             imageurl = $("#item-theater-overlay").find('.item-detail').attr('data-cover');
  922.                         } else {                           
  923.                             imageurl = $this.find('.item-detail').attr('data-cover');
  924.                         }                                                          
  925.                        
  926.                         /** facebook like **/
  927.                         var fbl = $(document.createElement("fb:like"))
  928.                             .attr("href", shareurl)
  929.                             .attr("send", "false")
  930.                             .attr("layout", "button_count")
  931.                             .attr("show_faces", "false");
  932.                        
  933.                         var fbl = $("<div class='fblio'></div>").append(fbl);                      
  934.                         $(".wrapper-social .facebook-sharer").empty().append(fbl);
  935.                         FB.XFBML.parse($(".fblio", $this).get(0));
  936.                        
  937.                        
  938.                         /** twitter sharer **/
  939.                         var twt = $(document.createElement("a"))
  940.                                 .attr("class", "twitter-share-button")
  941.                                 .attr("href", "http://twitter.com/share")
  942.                                 .attr("data-url", document.URL)
  943.                                 .html("Tweet");
  944.                        
  945.                         var twt = $("<div class='twtlio'></div>").append(twt);
  946.                         $(".wrapper-social .twitter-sharer").append(twt);
  947.                         twttr.widgets.load();
  948.                        
  949.                        
  950.                         /** pinterest button **/
  951.                         var pinurl = "http://pinterest.com/pin/create/button/?url="
  952.                             + encodeURIComponent(shareurl) + "&media=" + encodeURIComponent(imageurl);
  953.                        
  954.                         var pinvar = $(document.createElement("a"))
  955.                                 .attr("href", pinurl)
  956.                                 .attr("class", "pin-it-button")
  957.                                 .attr("count-layout", "horizontal")
  958.                                 .html('<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />');
  959.                        
  960.                         $(".wrapper-social .pinterest-sharer")
  961.                             .append(pinvar)
  962.                             .append('<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>');                      
  963.                        
  964.                        
  965.                         /** google plus share **/
  966.                         var gplusvar = $('<g:plusone size="medium" annotation="bubble" href="'
  967.                                 + encodeURIComponent(shareurl) + '"></g:plusone>');
  968.                         $(".wrapper-social .google-sharer").append(gplusvar);
  969.                         gapi.plusone.go("google-sharer");
  970.                        
  971.                     };
  972.                    
  973.                     var showData = function (data) {
  974.                         $this.find('.small-loader').hide();
  975.                        
  976.                         // mute player when selected content is music / video
  977.                         if(data.type == "video" || data.type == "youtube" ||
  978.                            data.type == "vimeo" || data.type == "audio") {
  979.                             muteplayer();
  980.                         } else {
  981.                             unmuteplayer();
  982.                         }
  983.                        
  984.                         if(options.theatherMode) {
  985.                             $("#item-theater-detail").append(data.content);
  986.                             contentTheater($this, data.title, data.type, data.love, data.voted);
  987.                         } else {
  988.                             $this.append(data.content);
  989.                             contentLoaded($this, true, data.title, data.type);
  990.                         }
  991.                        
  992.                         /** now we attach social like **/
  993.                         attach_social();
  994.                        
  995.                         /** hide loader **/
  996.                         hide_loader($this);
  997.                     };
  998.                    
  999.                     var loadData = function() {
  1000.                         $.ajax({
  1001.                             url: admin_url,
  1002.                             type : "post",
  1003.                             dataType : "json",
  1004.                             data : ajaxdata,
  1005.                             success: function(data) {
  1006.                                 if(data.status == 1) {
  1007.                                     // data loaded successfully
  1008.                                     showData(data);                                
  1009.                                 } else  if (data.status == 2) {
  1010.                                     // need password
  1011.                                     showPasswordForm(0);
  1012.                                 } else if (data.status == 3) {
  1013.                                     // invalid password
  1014.                                     showPasswordForm(1);
  1015.                                 } else if (data.status == 4) {                                 
  1016.                                     // wrong post format
  1017.                                 }
  1018.                                
  1019.                             }
  1020.                         });
  1021.                     };
  1022.                                        
  1023.                     /** load data from admin **/
  1024.                     loadData();
  1025.                    
  1026.                 } else {
  1027.                     // untuk sementara waktu ga bakal pernah dipake
  1028.                     // contentLoaded($this, false, $this.attr('data-title'), $this.attr('data-type'));
  1029.                 }
  1030.             }
  1031.         }; 
  1032.        
  1033.         /** use css instead js positioning **/         
  1034.         var rearrange_filter = function() {};      
  1035.         var rearange_media_query    = function () {};
  1036.        
  1037.         var loadmorefunction = function(loadhash, showloadingbutton)
  1038.         {
  1039.             var loading     = $(".load-more-button").attr('data-loading');
  1040.             var loadmore    = $(".load-more-button").attr('data-more');
  1041.             var category    = $(".load-more-button").attr('data-category');
  1042.             filterunlocked = false;
  1043.            
  1044.             if(loadhash == false) {
  1045.                 window.location = "#/";
  1046.             }
  1047.            
  1048.             if(showloadingbutton) {
  1049.                 $(".load-more-button").text(loading).addClass('load-active').fadeIn();
  1050.             } else {
  1051.                 $(".load-more-button").fadeOut();
  1052.             }
  1053.            
  1054.             var ajaxdata = {
  1055.                 id      : options.postid,
  1056.                 page    : $(".load-more-button").attr('data-page'),
  1057.                 cat     : category,
  1058.                 action  : 'portfolio_load_more'
  1059.             };
  1060.            
  1061.             $.ajax({
  1062.                 url: admin_url,
  1063.                 type : "post",
  1064.                 dataType : "json",
  1065.                 data : ajaxdata,
  1066.                 success: function(data) {
  1067.                     var $newEls = $(data.html);
  1068.                    
  1069.                     // override visiable style nya disini
  1070.                    
  1071.                     /*
  1072.                     $container.isotope({
  1073.                         visibleStyle  : { opacity : 0 }
  1074.                     });
  1075.                     */
  1076.                    
  1077.                     $container.append( $newEls );
  1078.                    
  1079.                     $container.imagesLoaded(function(){
  1080.                         $('.lio-loader').fadeOut('fast');
  1081.                        
  1082.                         $container.isotope( 'appended', $newEls, function(){
  1083.                             animload("seqfade");
  1084.                         });
  1085.                        
  1086.                         if(data.totalpage >= data.pagenext) {
  1087.                             var morepage = ( data.totalpage - data.pagenext ) + 1;  
  1088.                             $(".load-more-button").text( morepage +  loadmore).removeClass('load-active').attr('data-page', data.pagenext).fadeIn();
  1089.                         } else {                           
  1090.                             $(".load-more-button").fadeOut("slow");
  1091.                         }
  1092.                        
  1093.                         if(loadhash == true && data.totalpage >= ( data.pagenext - 1 )) {
  1094.                             // on last page we need to check if item is exist
  1095.                             if(data.totalpage  < data.pagenext ) {
  1096.                                 var hash = location.hash.replace("#/", "");
  1097.                                 var element = findElement(hash);                               
  1098.                                
  1099.                                 if(element != undefined) {
  1100.                                     winhash();
  1101.                                 }
  1102.                             } else {
  1103.                                 winhash("loadmorefunction");
  1104.                             }
  1105.                         }
  1106.                         filterunlocked = true;
  1107.                     }, function(){});
  1108.                 }
  1109.             });
  1110.         };
  1111.        
  1112.         $container.imagesLoaded( function($images, $proper, $broken)
  1113.         {
  1114.             doctitle = document.title;
  1115.  
  1116.             // close loader & show filter
  1117.             $('.lio-loader').fadeOut('fast');          
  1118.            
  1119.             // build isotope
  1120.             $container.isotope({
  1121.                 animationEngine: "jquery",
  1122.                 itemSelector: ".item",
  1123.                 masonry: {
  1124.                     columnWidth: 1
  1125.                 }
  1126.             });
  1127.            
  1128.             bindlovethis($container);
  1129.            
  1130.             /** run window resize when image loaded to prevent bug **/
  1131.             jWindowResize(false);
  1132.            
  1133.             /** then show image **/
  1134.             animload(options.loadAnimation);
  1135.                        
  1136.             setTimeout(function(){
  1137.                 $(window).hashchange();
  1138.             }, 500);       
  1139.         });
  1140.        
  1141.         var executeFirstTimer = 0;
  1142.        
  1143.         // normal | fade | seqfade | upfade | sequpfade | randomfade | randomupfade
  1144.         var animload = function(animation){
  1145.            
  1146.             var exebinwait  = 200;
  1147.             var loadfilter  = 200;
  1148.            
  1149.             // perlu begini nih biar ga keluar bug di firefox
  1150.             $container.find('.item.notloaded').each(function(){
  1151.                 $(this).css({"opacity" : 0});
  1152.             });
  1153.            
  1154.             if(animation            == "normal") {
  1155.                 $container.find('.item.notloaded').each(function(){
  1156.                     $(this).css({"opacity": 1}).removeClass('notloaded');
  1157.                 });
  1158.             } else if(animation     == "fade"){            
  1159.                
  1160.                 $container.find('.item.notloaded').each(function(){
  1161.                     $(this).stop().animate({
  1162.                         "opacity" : 1
  1163.                     }, "fast").removeClass('notloaded');
  1164.                 });
  1165.                
  1166.                 loadfilter = "slow";
  1167.                
  1168.             } else if(animation     == "seqfade"){
  1169.                
  1170.                 $container.find('.item.notloaded').each(function(i){                   
  1171.                     var element = $(this);
  1172.                     setTimeout(function() {
  1173.                         $(element).show().stop().animate({
  1174.                             "opacity" : 1
  1175.                         }, "fast").removeClass('notloaded');                           
  1176.                     }, 100 + i * 100);
  1177.                 });
  1178.                
  1179.                 loadfilter = 1000;
  1180.                 exebinwait = 400 + $container.find('.item').length * 100;
  1181.                
  1182.             } else if(animation     == "upfade"){
  1183.                
  1184.                 // setup item
  1185.                 setuptop();
  1186.                
  1187.                 $container.find('.item.notloaded').each(function(i){
  1188.                     var element = $(this);                 
  1189.                     $(element).stop().animate({
  1190.                         top         : parseInt($(element).css('top'),10)- ( $(element).height() / 2),
  1191.                         opacity     : 1
  1192.                     }, 1000).removeClass('notloaded');
  1193.                 });
  1194.                
  1195.                 loadfilter = 2000;
  1196.                 exebinwait = 1200;
  1197.                
  1198.             } else if(animation     == "sequpfade"){
  1199.                
  1200.                 // setup item
  1201.                 setuptop();
  1202.                
  1203.                 $container.find('.item.notloaded').each(function(i){
  1204.                     var element = $(this);                 
  1205.                     setTimeout(function() {
  1206.                         $(element).stop().animate({
  1207.                             top         : parseInt($(element).css('top'),10)- ( $(element).height() / 2),
  1208.                             opacity     : 1
  1209.                         }, 300).removeClass("notloaded");
  1210.                     }, 100 + i * 100);
  1211.                 });
  1212.                
  1213.                 loadfilter = 2000;
  1214.                 exebinwait = 400 + $container.find('.item').length * 100;
  1215.                
  1216.             } else if(animation     == "randomfade"){
  1217.                
  1218.                 var shufflearray = shuffleitem();
  1219.                
  1220.                 for(var i = 0; i < shufflearray.length ; i++){                 
  1221.                     setTimeout(function() {
  1222.                         var element = shufflearray.pop();                      
  1223.                         $(element).stop().animate({
  1224.                             "opacity" : 1
  1225.                         }, 200).removeClass('notloaded');  
  1226.                     }, 75 + i * 75);
  1227.                 }
  1228.                
  1229.                 loadfilter = 2000;
  1230.                 exebinwait = 100 + $container.find('.item').length * 100;              
  1231.                
  1232.             } else if(animation     == "randomupfade"){
  1233.                
  1234.                 var shufflearray = shuffleitem();
  1235.                 setuptop();
  1236.                
  1237.                 for(var i = 0; i < shufflearray.length ; i++){
  1238.                     setTimeout(function() {
  1239.                         var element = shufflearray.pop();
  1240.                         $(element).stop().animate({
  1241.                             top         : parseInt($(element).css('top'),10)- ( $(element).height() / 2),
  1242.                             opacity     : 1
  1243.                         }, 300).removeClass('notloaded');
  1244.                     }, 75 + i * 75);
  1245.                 }
  1246.                
  1247.                 loadfilter = 2000;
  1248.                 exebinwait = 100 + $container.find('.item').length * 100;
  1249.                
  1250.             }
  1251.            
  1252.             // load filter & load more button
  1253.             if(executeFirstTimer == 0) {
  1254.                 $('#liofilter').fadeIn(loadfilter);
  1255.                
  1256.                 if(!$('.load-more-button').hasClass("nofirstload")) {
  1257.                     $('.load-more-button').fadeIn(loadfilter);
  1258.                 }
  1259.                
  1260.                 // than execute bin hash
  1261.                 setTimeout(function(){
  1262.                     executeBindHash();
  1263.                 }, exebinwait);
  1264.                
  1265.                 executeFirstTimer ++;
  1266.             }
  1267.            
  1268.             setTimeout(function(){
  1269.                 $container.isotope("reLayout");
  1270.             }, ( exebinwait + 1000 ));
  1271.            
  1272.             $container.find('.item').each(function(){
  1273.                 $(this).hover(hovered,unhovered);
  1274.             });
  1275.         };
  1276.                
  1277.         var executeBindHash = function(){
  1278.             // execute bind hash cuman sampe 1x doang ya
  1279.             setTimeout(function(){
  1280.                 bindhashchange();
  1281.                 winhash("executeBindHash");
  1282.             }, 300);
  1283.         };
  1284.  
  1285.         var setuptop = function () {
  1286.             // setup item
  1287.             $container.find('.item.notloaded').each(function(i){
  1288.                 var $item   = $(this),
  1289.                 t       = parseInt($item.css('top'),10) + ( $item.height() / 2);
  1290.                 $item.css({
  1291.                     top : t + 'px',
  1292.                     opacity : 0
  1293.                 });
  1294.             });
  1295.         };
  1296.        
  1297.         var shuffleitem = function() {
  1298.             var shufflearray = new Array();
  1299.             $container.find('.item.notloaded').each(function(i){ shufflearray[i] = $(this); });
  1300.             shufflearray.sort(function(){return Math.round(Math.random());});
  1301.             return shufflearray;
  1302.         };
  1303.        
  1304.         var calc_theather = function (){
  1305.             var ww = $(window).width() - 50;
  1306.             var wh = $(window).height() - $("header").height() - $("footer").height() - 50;        
  1307.            
  1308.             var theatherdim = {};
  1309.            
  1310.             if($(window).width() > $(window).height()) {
  1311.                 var ratio = 11 / 5;
  1312.             } else {
  1313.                 var ratio = 6/5;
  1314.             }
  1315.                        
  1316.             if( ( ww / ratio ) < wh ) {
  1317.                 // use ww as base
  1318.                 theatherdim.w = ww;
  1319.                 theatherdim.h = ww / ratio;
  1320.             } else {
  1321.                 // use wh as base
  1322.                 theatherdim.h = wh;
  1323.                 theatherdim.w = wh * ratio;            
  1324.             }
  1325.            
  1326.             theatherdim.topPos      = ( $(window).height() - $("header").height() - $("footer").height() - theatherdim.h ) / 2 + $("header").height();
  1327.             theatherdim.leftPos     = ( $(window).width() - theatherdim.w ) / 2;
  1328.            
  1329.             theatherdim.descriptionWidth = theatherdim.w * 0.2;
  1330.             theatherdim.descriptionWidth = ( theatherdim.descriptionWidth < 200 ) ? 200 : theatherdim.descriptionWidth;
  1331.             theatherdim.galleryWidth     = theatherdim.w - theatherdim.descriptionWidth;
  1332.            
  1333.             if(options.descDim == 0) {
  1334.                 theatherdim.galleryWidth = theatherdim.w;
  1335.                 theatherdim.descriptionWidth = 0;
  1336.             }
  1337.            
  1338.             return theatherdim;
  1339.         };
  1340.        
  1341.  
  1342.         // detect only window width change
  1343.         var winwidth = $(window).width(), winheight = $(window).height();
  1344.         $(window).resize(function() {
  1345.             if(this.resizeTo) clearTimeout(this.resizeTo);
  1346.             this.resizeTo = setTimeout(function() {
  1347.                 if(winwidth != $(window).width()) {
  1348.                     winwidth = $(window).width();
  1349.                     // $(this).trigger("windowWidthResize");
  1350.                 }
  1351.                
  1352.                 if(winheight != $(window).height()) {
  1353.                     $(this).trigger("windowHeightResize");
  1354.                 }
  1355.             }, 250);
  1356.         });
  1357.        
  1358.        
  1359.         var windowWidthChange = function ()
  1360.         {
  1361.             if(options.theatherMode) {
  1362.                
  1363.                 if(lastclicked != undefined) {
  1364.                     var cachelastClick = lastclicked;
  1365.                    
  1366.                     var i               = $("#item-theater-overlay");
  1367.                     var id              = $(".item-detail", i);
  1368.                     theatherClose(i, id, true);
  1369.                    
  1370.                     // than reopen last clicked item
  1371.                     //console.log(cachelastClick);
  1372.                     // clicked(cachelastClick.i);
  1373.                 }
  1374.             }
  1375.         };
  1376.        
  1377.         var windowHeightChange = function ()
  1378.         {
  1379.            
  1380.         };
  1381.        
  1382.         /** then when image resize, we do this! **/
  1383.         var jWindowResize = function(relayout)
  1384.         {          
  1385.             var windowWidth     = $(window).width();
  1386.            
  1387.             var item            = $container.find('.item').get(0);             
  1388.             var imb             = parseInt($(item).css('margin-bottom'), 10);
  1389.             var iml             = parseInt($(item).css('margin-left'), 10);
  1390.            
  1391.             iw                  = options.itemWidth;                       
  1392.            
  1393.             if(options.theatherMode) {
  1394.                 var theaterdim = calc_theather();              
  1395.                                
  1396.                 itemWidth       = theaterdim.w;
  1397.                 itemHeight      = theaterdim.h;
  1398.                            
  1399.                 itemDescriptionWidth    = theaterdim.descriptionWidth;
  1400.                 itemGalleryWidth        = theaterdim.galleryWidth;
  1401.                
  1402.                 itemTopPos              = theaterdim.topPos;
  1403.                 itemLeftPos             = theaterdim.leftPos;
  1404.             } else {
  1405.                
  1406.                 if(options.themes_schema == "light") {
  1407.                     itemGalleryWidth        = ( iw * galleryDim ) + iml * (galleryDim - 1);
  1408.                     itemDescriptionWidth    = ( iw * descDim ) + ( iml * descDim );                
  1409.                 } else {
  1410.                     itemGalleryWidth        = ( iw * galleryDim ) + iml * (galleryDim - 1) + ( 6 * galleryDim ) - 3;
  1411.                     itemDescriptionWidth    = ( iw * descDim ) + ( iml * descDim ) + ( 6 * descDim ) - 3;
  1412.                 }
  1413.                
  1414.                 for(var i = (galleryDim + descDim); i > 1  ; i--) {
  1415.                     if(options.themes_schema == "light") {
  1416.                         var tempWidth   = ( iw * i ) + ( iml * i ) - iml;
  1417.                     } else {
  1418.                         var tempWidth   = ( iw * i ) + ( iml * i ) - iml + (6 * (i - 1 )) ;
  1419.                     }
  1420.                     if(tempWidth + 10 <= windowWidth){
  1421.                         itemWidth           = tempWidth;
  1422.                         itemHeight          = options.itemHeightWide ;
  1423.                         break;
  1424.                     }
  1425.                 }
  1426.             }          
  1427.            
  1428.             if(relayout) {
  1429.                 // console.log("Execute window resize with relayout");
  1430.                 $container.isotope("reLayout");
  1431.             } else {
  1432.                 // console.log("Execute window resize without relayout");
  1433.             }                  
  1434.         };
  1435.        
  1436.         var closeAllMode = function () {
  1437.             if(options.theatherMode) {
  1438.                 var i               = $("#item-theater-overlay");
  1439.                 var id              = $(".item-detail", i);
  1440.                 theatherClose(i, id, false);
  1441.             } else {
  1442.                 closePrev();
  1443.             }
  1444.         };
  1445.        
  1446.         var findElement = function(hash)
  1447.         {
  1448.             for(var i = 0; i < $('.item').length ; i++) {
  1449.                 var item = $('.item').get(i);
  1450.                 if(hash == $(item).attr('data-url')) {
  1451.                     return $(item);
  1452.                 }
  1453.             }      
  1454.         };
  1455.        
  1456.         var hidePhotoswipe = function()
  1457.         {
  1458.             if(window.Code.PhotoSwipe.activeInstances[0] == undefined) {
  1459.                 // console.log("photoswipe is undefined");
  1460.             } else {
  1461.                 window.Code.PhotoSwipe.activeInstances[0].instance.hide(0);        
  1462.             }
  1463.         };
  1464.        
  1465.         var winhash = function(echome){
  1466.             var hash = location.hash.replace("#/", "");
  1467.             var hashres = hash.split(':');
  1468.             hash = hashres[0];
  1469.            
  1470.             if(hash === "" || hash == "#") {
  1471.                 closeAllMode();
  1472.                 unmuteplayer();
  1473.             } else {
  1474.                 var element = findElement(hash);
  1475.                
  1476.                 if(element == undefined && options.use_pagging == 1) {                 
  1477.                     setTimeout(function(){                     
  1478.                         loadmorefunctionhub(true, true);
  1479.                     }, 500);
  1480.                 } else {
  1481.                     if(scw(mediaquerywidth)) {
  1482.                         if(element) {
  1483.                             setTimeout(function(){
  1484.                                 if(!options.theatherMode) {
  1485.                                     setTimeout(function(){
  1486.                                         $("html, body").animate({
  1487.                                             scrollTop: $(element).offset().top - options.scrolltop
  1488.                                         });
  1489.                                     }, 500);
  1490.                                 }
  1491.                                 clicked(element);                              
  1492.                             }, 200);
  1493.                         }
  1494.                     } else {
  1495.                         // buka page baru
  1496.                         var url = element.attr('data-src');
  1497.                         tourl(url, true);
  1498.                     }
  1499.                     hidePhotoswipe();
  1500.                 }
  1501.             }
  1502.         };
  1503.        
  1504.         var filterunlocked = true;
  1505.        
  1506.         /** filter **/
  1507.         $("#liofilter .apply-filter").click(function(){
  1508.             if(filterunlocked) {
  1509.                 $("#liofilter .apply-filter").removeClass("filter-select");
  1510.                 var selector = $(this).attr("data-filter");        
  1511.                 $(this).addClass("filter-select");
  1512.                
  1513.                 if(options.use_pagging == 0) {
  1514.                     closePrev(true);           
  1515.                     $container.isotope({filter : selector});
  1516.                 } else {
  1517.                     var category = $(this).attr('data-filter').replace(".", "").replace("*", "");
  1518.                     $(".load-more-button").attr('data-category', category ).attr('data-page',1);
  1519.                     var $el = $("#jeglio > .item").get().reverse();
  1520.                    
  1521.                     $($el).animate({
  1522.                         opacity     : 0
  1523.                     }, 200, function(){
  1524.                         $container.isotope( 'remove', $(this));
  1525.                         $(this).remove();
  1526.                     });
  1527.                     $('.lio-loader').fadeIn('fast');
  1528.                     loadmorefunctionhub(false, false);
  1529.                 }
  1530.             }
  1531.             return false;
  1532.         });
  1533.        
  1534.         /** show loader **/
  1535.         $('.lio-loader').fadeIn('fast');
  1536.        
  1537.         /** bind hash change & resize **/
  1538.         var bindhashchange = function() {
  1539.             $(window).bind('hashchange', function(){ winhash("bindhashchange"); });
  1540.         };
  1541.        
  1542.         $(window).bind('resize', function(){
  1543.             if(!firstloaded) {
  1544.                 jWindowResize(true);
  1545.             } else {
  1546.                 jWindowResize(false);
  1547.             }
  1548.             firstloaded = false;
  1549.         });
  1550.        
  1551.         $(window).bind('windowWidthResize', function(){ windowWidthChange(); });
  1552.         $(window).bind('windowHeightResize', function(){ windowHeightChange(); });
  1553.        
  1554.         var loadmorefunctionhub = function (loadhash, showloadingbutton) {
  1555.             if(filterunlocked) {
  1556.                 loadmorefunction(loadhash, showloadingbutton);
  1557.             }
  1558.         };     
  1559.        
  1560.         $(".load-more-button").click(function(){
  1561.             loadmorefunctionhub(false, true);
  1562.         });
  1563.  
  1564.         /** unbind window resize sama hashchange saat #main ke destroy **/
  1565.         $(window).bind("jmainremove", function(){          
  1566.             $(window).unbind('hashchange');
  1567.             $(window).unbind('resize');
  1568.             $("html").css("overflow-y", "auto");
  1569.             delete $.fn.jeglio;
  1570.         });
  1571.     };
  1572. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement