jegtheme

Fix for load more bug

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