Advertisement
jegtheme

jeglio.full.js

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