jegtheme

jeggal.js

Sep 11th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * jeggal.full.js
  3.  */
  4.  
  5. jQuery(document).ready(function($) {
  6.     $.Isotope.prototype._getCenteredMasonryColumns = function() {
  7.         this.width = this.element.width();
  8.        
  9.         var parentWidth = this.element.parent().width();
  10.        
  11.                       // i.e. options.masonry && options.masonry.columnWidth
  12.         var colW = this.options.masonry && this.options.masonry.columnWidth ||
  13.                       // or use the size of the first item
  14.                       this.$filteredAtoms.outerWidth(true) ||
  15.                       // if there's no items, use size of container
  16.                       parentWidth;
  17.        
  18.         var cols = Math.floor( parentWidth / colW );
  19.         cols = Math.max( cols, 1 );
  20.    
  21.         // i.e. this.masonry.cols = ....
  22.         this.masonry.cols = cols;
  23.         // i.e. this.masonry.columnWidth = ...
  24.         this.masonry.columnWidth = colW;
  25.     };
  26.      
  27.     $.Isotope.prototype._masonryReset = function() {
  28.         // layout-specific props
  29.         this.masonry = {};
  30.         // FIXME shouldn't have to call this again
  31.         this._getCenteredMasonryColumns();
  32.         var i = this.masonry.cols;
  33.         this.masonry.colYs = [];
  34.         while (i--) {
  35.             this.masonry.colYs.push( 0 );
  36.         }
  37.     };
  38.    
  39.     $.Isotope.prototype._masonryResizeChanged = function() {
  40.         var prevColCount = this.masonry.cols;
  41.         // get updated colCount
  42.         this._getCenteredMasonryColumns();
  43.         return ( this.masonry.cols !== prevColCount );
  44.     };
  45.      
  46.     $.Isotope.prototype._masonryGetContainerSize = function() {
  47.         var unusedCols = 0,
  48.             i = this.masonry.cols;
  49.         // count unused columns
  50.         while ( --i ) {
  51.             if ( this.masonry.colYs[i] !== 0 ) {
  52.                 break;
  53.             }
  54.             unusedCols++;
  55.         }
  56.        
  57.         return {
  58.             height : Math.max.apply( Math, this.masonry.colYs ),
  59.               // fit container to columns that have been used;
  60.             width : ((this.masonry.cols - unusedCols) * this.masonry.columnWidth) + 5
  61.         };
  62.     };
  63. });
  64.  
  65. /** jeggal v1 **/
  66.  
  67. (function($) {
  68.     $.fn.jeggal = function( options )
  69.     {
  70.         var settings = {
  71.             zoomDelay           : 7000,
  72.             use_pagging         : 0,
  73.             pagging_count       : 10,
  74.             loading_text        : "Loading . . . ",
  75.             loadAnimation       : 'sequpfade'  // normal | fade | seqfade | upfade | sequpfade | randomfade | randomupfade
  76.         };
  77.        
  78.         if (options) {
  79.             var options = $.extend(settings, options); 
  80.         } else {
  81.             var options = $.extend(settings);                  
  82.         }
  83.        
  84.         var $container              = $(this);     
  85.        
  86.         var contentloaded = function (loadAnimation)
  87.         {
  88.             $container.imagesLoaded( function($images, $proper, $broken)
  89.             {
  90.                 // close loader & show filter
  91.                 $('.lio-loader').fadeOut('fast');          
  92.                
  93.                 // build isotope
  94.                 $container.isotope({
  95.                     animationEngine: "jquery",
  96.                     itemSelector: ".imggal.animated",
  97.                     masonry: {
  98.                         columnWidth: 1
  99.                     }
  100.                 });
  101.                
  102.                 animload(loadAnimation);
  103.                
  104.                 (function(PhotoSwipe){
  105.                     photoswipe = $container.find('.imggal').photoSwipe({
  106.                         backButtonHideEnabled           : false,
  107.                         captionAndToolbarAutoHideDelay  : 0,
  108.                         slideshowDelay                  : options.zoomDelay,
  109.                         slideSpeed                      : 500,
  110.                         imageScaleMethod                : 'fitNoUpscale',
  111.                         allowUserZoom                   : false,
  112.                         getImageSource                  : function(obj){ return $(obj).attr('data-img'); },
  113.                         getImageCaption                 : function(obj){ return $(obj).attr('data-title'); }
  114.                     });
  115.                     photoswipe.addEventHandler(PhotoSwipe.EventTypes.onHide, function(e){
  116.                         $container.isotope("reLayout");
  117.                     });
  118.                 }(window.Code.PhotoSwipe));
  119.                
  120.             });            
  121.         };
  122.        
  123.         var setuptop = function () {
  124.             // setup item
  125.             $container.find('.imggal.animated').each(function(i){
  126.                 var $item   = $(this),
  127.                 t       = parseInt($item.css('top'),10) + ( $item.height() / 2);
  128.                 $item.css({ top : t + 'px', opacity : 0});
  129.             });
  130.         };
  131.        
  132.         var shuffleitem = function() {
  133.             var shufflearray = new Array();
  134.             $container.find('.imggal.animated').each(function(i){ shufflearray[i] = $(this); });
  135.             shufflearray.sort(function(){return Math.round(Math.random());});
  136.             return shufflearray;
  137.         };
  138.        
  139.         // normal | fade | seqfade | upfade | sequpfade | randomfade | randomupfade
  140.         var animload = function(animation){                
  141.             if(animation            == "normal") {
  142.                 $container.find('.imggal.animated').each(function(){
  143.                     $(this).css({"opacity": 1}).removeClass('animated');
  144.                 });
  145.             } else if(animation     == "fade"){
  146.                 $container.find('.imggal.animated').each(function(){
  147.                     $(this).stop().animate({
  148.                         "opacity" : 1
  149.                     }, "fast").removeClass('animated');
  150.                 });
  151.             } else if(animation     == "seqfade"){
  152.                 $container.find('.imggal.animated').each(function(i){
  153.                     var element = $(this);
  154.                     setTimeout(function() {
  155.                         $(element).show().stop().animate({
  156.                             "opacity" : 1
  157.                         }, "fast").removeClass('animated');                        
  158.                     }, 100 + i * 100);
  159.                 });
  160.             } else if(animation     == "upfade"){
  161.                 // setup item
  162.                 setuptop();
  163.                
  164.                 $container.find('.imggal.animated').each(function(i){
  165.                     var element = $(this);                 
  166.                     $(element).stop().animate({
  167.                         top         : parseInt($(element).css('top'),10)- ( $(element).height() / 2),
  168.                         opacity     : 1
  169.                     }, 1000).removeClass('animated');
  170.                 });            
  171.             } else if(animation     == "sequpfade"){
  172.                 // setup item
  173.                 setuptop();
  174.                
  175.                 $container.find('.imggal.animated').each(function(i){
  176.                     var element = $(this);                 
  177.                     setTimeout(function() {
  178.                         $(element).stop().animate({
  179.                             top         : parseInt($(element).css('top'),10)- ( $(element).height() / 2),
  180.                             opacity     : 1
  181.                         }, 300).removeClass("animated");
  182.                     }, 100 + i * 100);
  183.                 });
  184.                
  185.             } else if(animation     == "randomfade"){
  186.                 var shufflearray = shuffleitem();
  187.                
  188.                 for(var i = 0; i < shufflearray.length ; i++){                 
  189.                     setTimeout(function() {
  190.                         var element = shufflearray.pop();                      
  191.                         $(element).stop().animate({
  192.                             "opacity" : 1
  193.                         }, 200).removeClass('animated');   
  194.                     }, 75 + i * 75);
  195.                 }
  196.             }else if(animation      == "randomupfade"){    
  197.                 var shufflearray = shuffleitem();
  198.                 setuptop();
  199.                
  200.                 for(var i = 0; i < shufflearray.length ; i++){         
  201.                     setTimeout(function() {
  202.                         var element = shufflearray.pop();
  203.                         $(element).stop().animate({
  204.                             top         : parseInt($(element).css('top'),10)- ( $(element).height() / 2),
  205.                             opacity     : 1
  206.                         }, 300).removeClass('animated');
  207.                     }, 75 + i * 75);
  208.                 }              
  209.             }
  210.         };
  211.        
  212.        
  213.         var request_data = {
  214.             id          : options.postid,
  215.             action      : 'get_gallery'
  216.         };
  217.        
  218.         var showPasswordForm = function (status) {
  219.             if(!$(".portopwd").length) {
  220.                 // create password form
  221.                 var pwdtxt = '<div class="portopwd">' +
  222.                             '<div class="portopwd-wrapper">' +
  223.                                 '<h2>' + options.lang.portfoliotitle +  ' </h2> ' +
  224.                                 '<div>' +
  225.                                     '<input type="password" class="pwdtxt" placeholder="' + options.lang.passwordplaceholder +  '"/>' +
  226.                                     '<button href="#" class="btn btn-inverse pwdbtn">' + options.lang.submit + '</button>' +
  227.                                 '</div>' +
  228.                                 '<div class="pwderr"></div>' +
  229.                                 '<div alt="Close" class="pwdcls" style="display: block;">' +
  230.                                     '<div class="icon-remove icon-white"></div>' +
  231.                                 '</div>' +
  232.                             '</div>' +
  233.                           '</div>';
  234.                 $('body').append(pwdtxt);
  235.             }
  236.            
  237.             $(".pwdcls").click(function(){                         
  238.                 $(".portopwd").remove();
  239.             });
  240.            
  241.             var submitpwdform = function () {
  242.                 request_data.password = $(".pwdtxt").val();
  243.                 $(".portopwd").remove();
  244.                 loadData();
  245.             };
  246.            
  247.             $(".pwdtxt").keypress(function(e){
  248.                 if(e.which == 13){
  249.                     submitpwdform();
  250.                 }
  251.             });
  252.            
  253.             $(".pwdbtn").click(function(){
  254.                 submitpwdform();
  255.             });
  256.         };
  257.        
  258.         var partialpage = 1;
  259.         var firstrun = 0;
  260.        
  261.         var partial_content_animation = function () {
  262.            
  263.             if(firstrun == 0) {
  264.                 firstrun++;
  265.                
  266.                 $(".mpnotif").html(options.loading_text);
  267.                 $(".mpnotif").fadeIn();
  268.                
  269.                 // close loader & show filter
  270.                 $('.lio-loader').fadeOut('fast');          
  271.                
  272.                 // build isotope
  273.                 $container.isotope({
  274.                     animationEngine: "jquery",
  275.                     itemSelector: ".imggal.animated",
  276.                     masonry: {
  277.                         columnWidth: 1
  278.                     }
  279.                 });
  280.                
  281.                 animload(options.loadAnimation);
  282.                
  283.                 (function(PhotoSwipe){
  284.                     photoswipe = $container.find('.imggal').photoSwipe({
  285.                         backButtonHideEnabled           : false,
  286.                         captionAndToolbarAutoHideDelay  : 0,
  287.                         slideshowDelay                  : options.zoomDelay,
  288.                         slideSpeed                      : 500,
  289.                         imageScaleMethod                : 'fitNoUpscale',
  290.                         allowUserZoom                   : false,
  291.                         getImageSource                  : function(obj){ return $(obj).attr('data-img'); },
  292.                         getImageCaption                 : function(obj){ return $(obj).attr('data-title'); }
  293.                     });
  294.                     photoswipe.addEventHandler(PhotoSwipe.EventTypes.onHide, function(e){
  295.                         setTimeout(function(){
  296.                             $container.isotope("reLayout");
  297.                         }, 1000);
  298.                     });
  299.                 }(window.Code.PhotoSwipe));
  300.                
  301.             } else {
  302.                 $container.isotope( 'appended', $container.find('.imggal.animated'), function(){
  303.                     animload('seqfade');
  304.                 });
  305.             }
  306.         };
  307.        
  308.         var partial_load = function (){
  309.             var notloaded = $container.find('.imggal.notloaded');          
  310.            
  311.             if(notloaded.length > 0) {
  312.                 var elearray = new Array();
  313.                 for($i = 0; $i < options.pagging_count; $i++) {
  314.                     elearray[$i] = notloaded[$i];
  315.                 }
  316.                 load_image(elearray);                              
  317.             } else {
  318.                 $(".mpnotif").fadeOut();
  319.                 setTimeout(function(){
  320.                     $container.isotope( 'reLayout' );
  321.                 }, 2000);
  322.                
  323.             }
  324.         };
  325.        
  326.         var load_image = function(elearray){
  327.             // cache element
  328.             var element = elearray[0];
  329.            
  330.             if(element) {
  331.                 // remove array from first element
  332.                 elearray.shift();
  333.                
  334.                 // proceed with loading iamge
  335.                 var imgsrc = $(element).find("img").attr("data-src");
  336.                
  337.                 var img = new Image();
  338.                 $(img).load(function(){
  339.                     $(element)
  340.                         .removeClass("notloaded")
  341.                         .addClass("animated")
  342.                         .find("figure")
  343.                         .html("")
  344.                         .append(img);
  345.                     load_image(elearray);
  346.                 }).attr('src', imgsrc);
  347.             } else {
  348.                 setTimeout(function(){                 
  349.                     partial_content_animation();
  350.                     setTimeout(function(){
  351.                         partial_load();
  352.                     },1000);
  353.                 }, 1000);
  354.             }
  355.         };
  356.        
  357.         var loadData = function () {           
  358.             $.ajax({
  359.                 url: admin_url,
  360.                 type : "post",
  361.                 dataType : "json",
  362.                 data : request_data,
  363.                 success: function(data) {
  364.                     if(data.status == 1) {
  365.                         $container.html(data.content);
  366.                         if(options.use_pagging == 0) {
  367.                             contentloaded(options.loadAnimation);
  368.                         } else {
  369.                             partial_load();
  370.                         }
  371.                     }  else  if (data.status == 2) {
  372.                         // need password
  373.                         showPasswordForm(0);
  374.                     } else if (data.status == 3) {
  375.                         // invalid password
  376.                         showPasswordForm(1);
  377.                     } else if (data.status == 4) {                                 
  378.                         // wrong post format
  379.                     }
  380.                 }
  381.             });
  382.         };
  383.        
  384.         /** request ajax dulu nih **/
  385.         loadData();
  386.     };
  387. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment