Advertisement
jegtheme

jeglio.js

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