Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                <html>
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/isotope/1.5.25/jquery.isotope.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/json2/0.1/json2.min.js"></script>
    <script type="text/javascript" src="https://raw.github.com/misteroneill/resize-stop/master/jquery.resizeStop.js"></script>
  </head>
  <body>
    <div id="photos_section_container"></div>
    <div class="loader"></div>
  </body>
</html>

              
            
!

CSS

              
                /* ----- Isotope CSS - START ----- */
	.isotope-item {
		margin-bottom: 10px;
	}

	/**** Isotope Filtering ****/

	.isotope-item {
	  z-index: 2;
	}

	.isotope-hidden.isotope-item {
	  pointer-events: none;
	  z-index: 1;
	}

	/**** Isotope CSS3 transitions ****/

	.isotope,
	.isotope .isotope-item {
	  -webkit-transition-duration: 0.8s;
		 -moz-transition-duration: 0.8s;
		  -ms-transition-duration: 0.8s;
		   -o-transition-duration: 0.8s;
			  transition-duration: 0.8s;
	}

	.isotope {
	  -webkit-transition-property: height, width;
		 -moz-transition-property: height, width;
		  -ms-transition-property: height, width;
		   -o-transition-property: height, width;
			  transition-property: height, width;
	}

	.isotope .isotope-item {
	  -webkit-transition-property: -webkit-transform, opacity;
		 -moz-transition-property:    -moz-transform, opacity;
		  -ms-transition-property:     -ms-transform, opacity;
		   -o-transition-property:      -o-transform, opacity;
			  transition-property:         transform, opacity;
	}

	/**** disabling Isotope CSS3 transitions ****/

	.isotope.no-transition,
	.isotope.no-transition .isotope-item,
	.isotope .isotope-item.no-transition {
	  -webkit-transition-duration: 0s;
		 -moz-transition-duration: 0s;
		  -ms-transition-duration: 0s;
		   -o-transition-duration: 0s;
			  transition-duration: 0s;
	}
/* ----- Isotope CSS - END ----- */

/* ----- Photos style - START ----- */
#photos_section_container{
	display: block;
	height: auto;
	margin: 0;
	padding: 0;
	font-size: 0;
}
	.photos_section_wrap{		
		display: inline-block;
		vertical-align: top;
		
		width: auto; /* Determined in JS */
		height: auto;
		
		-webkit-border-radius: 7px;
		-moz-border-radius: 7px;
		border-radius: 7px;
		
		overflow: hidden;
	}
	.photos_section_wrap .photos_section_img{
		width: 100%;
		height: auto;
	}
/* ----- Photos style - END ----- */ 

.loader{
	display: block;
	height: 70px;
	
	background-image: url('http://www.upload.ee/image/3935265/ajax-loader.gif');
	background-repeat: no-repeat;
	background-position: 50% 50%;
}
              
            
!

JS

              
                // modified Isotope methods for gutters in masonry
$.Isotope.prototype._getMasonryGutterColumns = function() {
	var gutter = this.options.masonry && this.options.masonry.gutterWidth || 0;
		containerWidth = this.element.width();

	this.masonry.columnWidth = this.options.masonry && this.options.masonry.columnWidth ||
		// or use the size of the first item
		this.$filteredAtoms.outerWidth(true) ||
		// if there's no items, use size of container
		containerWidth;

	this.masonry.columnWidth += gutter;

	this.masonry.cols = Math.floor( ( containerWidth + gutter ) / this.masonry.columnWidth );
	this.masonry.cols = Math.max( this.masonry.cols, 1 );
};

$.Isotope.prototype._masonryReset = function() {
	// layout-specific props
	this.masonry = {};
	// FIXME shouldn't have to call this again
	this._getMasonryGutterColumns();
	var i = this.masonry.cols;
	this.masonry.colYs = [];
	while (i--) {
		this.masonry.colYs.push( 0 );
	}
};

$.Isotope.prototype._masonryResizeChanged = function() {
	var prevSegments = this.masonry.cols;
	// update cols/rows
	this._getMasonryGutterColumns();
	// return if updated cols/rows is not equal to previous
	return ( this.masonry.cols !== prevSegments );
};






	
	var $container = $('#photos_section_container');
	var $item = $('.photos_section_wrap');
	var category = 'newimages';
	var columnWidthVar = null; 
	var item_margin = 10;
	var newElems = null;
	var ajaxready = true;
	var test1 = null;
	var test2 = null;

	function hideLoader(callback){
		
		$(".loader").delay(100).slideUp("slow", function(){
			callback(); // Callback Function
		});
		
	}

	function showLoader(callback){
		
		$(".loader").slideDown("slow", function(){
			callback(); // Callback Function
		});
		
	}

	function downloadImages(callback){ 

		current_images = [];				
		$.each( $item, function( key, value ) {
			current_images.push( $(this).attr("data-img-id") );
		}).promise().done(function(){ 
		
			$.ajax({
				type: 'POST',
				url: 'http://www.seksime.ee/script/my_plugins/gallery/get_photos.php', 
				/*contentType: 'application/json; charset=utf-8',*/ 
				data: { json: JSON.stringify(current_images), category: JSON.stringify(category) },
				dataType: 'json', 
				cache: false,
				success: AjaxSucceeded,  
				error: AjaxFailed
			});

			function AjaxSucceeded(result) {
				 
				// Set GLOBAL variable
				newElems = result;
				ajaxready = true;
				
				callback(); // Callback Function

			} //function AjaxSucceeded
			
			function AjaxFailed(result) {
			
				hideLoader(function(){
					alert("Failed to download more images!");
					ajaxready = true;
				});
				
				// Set GLOBAL variable
				newElems = null;
				
				callback(); // Callback Function
					
			} //function AjaxFailed
		
		});

	}

	function callResizeCalc(callback){

		var container_width = parseInt($('#photos_section_container').width());
		var items_in_row = 0;
		
		/* Mobile view */
		if(container_width >= 1 && container_width <= 550){
			items_in_row = 2;
		}
		/* Tablet view 1 */
		if(container_width >= 551 && container_width <= 956){
			items_in_row = 3;
		}
		/* Tablet view 2 */
		if(container_width >= 956 && container_width <= 1350){
			items_in_row = 6;
		}
		/* Widescreen view */
		if(container_width > 1350){
			items_in_row = 8;
		}
		
		if(items_in_row > 1){
			var item_margin_space = (items_in_row - 1) * item_margin;
		} else {
			var item_margin_space = 0;
			item_margin = 0;
		}
		
		// Set GLOBAL variables
		columnWidthVar = ( container_width - item_margin_space ) / items_in_row;
		
		callback();

	}

	function resizePhotosLayout(){
    
    alert('called resizePhotosLayout');
			
		$('.photos_section_wrap').css({'width' : columnWidthVar + 'px'});

		$('#photos_section_container').isotope({
			masonry : {
				columnWidth: columnWidthVar,
				gutterWidth: item_margin 
			}
		});
		
		$('#photos_section_container').isotope('reLayout');
		
	} // resizePhotosLayout()

	function isotopeAppend(){ 
	
		if ( $('#photos_section_container').find(".photos_section_wrap").length > 0 ) {
			// Container is not empty
			
			downloadImages(function(){
				
				var elements = $(newElems).css({ opacity: 1, 'width' : columnWidthVar + 'px' });
				$('#photos_section_container').append( elements );
				
				$('#photos_section_container').imagesLoaded(function(){
					
					$('#photos_section_container').isotope( 'appended', elements, function(){
						
						hideLoader(function(){
							elements.animate({ opacity: 1 }); 
						});
						
					});			
				
				});				

			}); // downloadImages()
			
		} else {
			// Container is empty
			
			// Calculate column sizes
			callResizeCalc(function(){
				
				// Download first images to container
				downloadImages(function(){
					
					var elements = $(newElems).css({ opacity: 0, 'width' : columnWidthVar + 'px' });
					$('#photos_section_container').append( elements );

					$('#photos_section_container').imagesLoaded(function(){

						// Initialize ISOTOPE
						$('#photos_section_container').isotope({
							itemSelector : '.photos_section_wrap',
							layoutMode : 'masonry',
							masonry : {
								columnWidth: columnWidthVar,
								gutterWidth: item_margin
							}
						});
						
						hideLoader(function(){
							elements.animate({ opacity: 1 }); 
						});
						
					});

				}); // downloadImages()
			
			}); // callResizeCalc()
			
		}
				
	} // isotopeAppend()

	$(document).ready(function(){
		
		isotopeAppend();
		
	});
	
	$('#photos_section_container').on('resizestop', function (e) { 				
		callResizeCalc(function(){
			resizePhotosLayout();
		});
	});

	$(window).scroll(function(e) {
		
		// Fix multiple ajax calls being fired
		if (ajaxready === false) return;

		var nearToBottom = 50;

		if ( $(window).scrollTop() + $(window).height() > $(document).height() - nearToBottom ) { 
			ajaxready = false;
			showLoader(function(){
				isotopeAppend();
			});
		}

	});
	

              
            
!
999px
We would have called your functions earlier, but we were in a bind.

Console